ogs_katacheck 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1aab2ad84305b247e1322ca044945c54f70b791018335241fad5dd84dd366334
4
+ data.tar.gz: d27f633ba9711c8919dbd31a3804894223d8abe580fe038b4fada757f0c74690
5
+ SHA512:
6
+ metadata.gz: 319fb6ca517da68aa5b239df2d2549104f2e3908fdcc2c3e022d635806db2f1b0db7967494b623f43f8b25d86803718bcee0df27a1bf9996dd5889875963472f
7
+ data.tar.gz: af2912f11d6146ded07656e729540a565ad06313131b3442aa67a553cb968139447d2d56e1ac621270655c58f421ed17c0bb66682b88be3574cddb46d19feb3d
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,4 @@
1
+ # Change Log
2
+
3
+ ### 0.1.0
4
+ - Added ability to check games against OGS full reviews.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ogs_katacheck.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem 'faraday'
8
+ # gem 'pry'
@@ -0,0 +1,37 @@
1
+ # OGS KataCheck
2
+
3
+ This CLI gem is intended to aid OGS team members in the investigation of suspected AI cheaters.
4
+
5
+ It pulls game information from the OGS API and checks the user submitted moves against full reviews run on the game.
6
+
7
+ ## Installation
8
+
9
+ You will need to have Ruby installed on your machine to run this CLI. If you are using a Mac, this is already done for you. If on a Windows machine you can install it by following [these instructions](https://stackify.com/install-ruby-on-windows-everything-you-need-to-get-going/).
10
+
11
+ To install this Gem, open a terminal and run:
12
+
13
+ $ gem install ogs_katacheck
14
+
15
+ ## Usage
16
+
17
+ After installing OGS KataCheck, you can run it by opening a terminal and typing:
18
+
19
+ $ ogs-katacheck
20
+
21
+ You will be asked to enter a game ID. This can be simply copied and pasted from OGS.
22
+
23
+ You will then be presented with a list of available OGS AI reviews. **Only full reviews** are useable with this tool. If you do not see a full review in the list, open the game in OGS and run a full review. Once the server has completed the review, re-run the tool.
24
+
25
+ The tool will output the number of user submitted moves that match the top 4 moves suggested by the AI in the review. Obviously, `tier 1` and `tier 2` moves are most important to look at, but the overall percentages can also be helpful.
26
+
27
+ ***Note:** A high percentage match in a game does not necessarily mean the user is cheating, but high percentage matches across many games will certainly warrant further investigation.*
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rubymineshaft/ogs_katacheck.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ogs_katacheck"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/ogs_katacheck'
4
+
5
+ OGSKataCheck::CLI.new.call
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require 'pry'
2
+ require 'faraday'
3
+ require 'json'
4
+ require_relative "./ogs_katacheck/version"
5
+ require_relative "./ogs_katacheck/cli"
6
+ require_relative "./ogs_katacheck/review"
7
+ require_relative "./ogs_katacheck/full_review"
@@ -0,0 +1,58 @@
1
+ class OGSKataCheck::CLI
2
+
3
+ def call
4
+ puts "Enter the Game ID you'd like to check for AI use:"
5
+
6
+ game_id = gets.strip
7
+ get_reviews(game_id)
8
+ show_review_menu(game_id)
9
+ check_id = gets.strip.to_i
10
+ check(check_id)
11
+ puts ""
12
+ puts "Check another game? (Y/N)"
13
+ input = gets.strip.downcase
14
+ if input == "y"
15
+ Review.destroy_all
16
+ FullReview.destroy_all
17
+ call
18
+ else
19
+ show_farewell
20
+ end
21
+ end
22
+
23
+ def get_reviews(game_id)
24
+ response = Faraday.get "https://online-go.com/api/v1/games/#{game_id}/ai_reviews"
25
+ data = JSON.parse(response.body)
26
+ data.each_with_index do |review, index|
27
+ Review.new(review, number: index + 1)
28
+ end
29
+
30
+ end
31
+
32
+ def show_review_menu(game_id)
33
+ puts ""
34
+ puts ""
35
+ puts "Game ID: #{game_id}"
36
+ puts ""
37
+ puts "The following reviews are available:"
38
+
39
+ Review.all.each do |review|
40
+ puts "#{review.number}. #{review.id} - #{review.engine} - #{review.type} - #{review.date}"
41
+ end
42
+
43
+ puts ""
44
+ puts "Enter the number of a review to check:"
45
+
46
+ end
47
+
48
+ def check(check_id)
49
+ puts "Processing. Please wait..."
50
+ review = Review.find_by_number(check_id)
51
+ review.check
52
+ end
53
+
54
+ def show_farewell
55
+ puts "Goodbye!"
56
+ end
57
+
58
+ end
@@ -0,0 +1,70 @@
1
+ class FullReview
2
+ attr_accessor :win_rates, :scores, :id, :type, :game_id, :engine, :engine_version, :network, :network_size, :date, :strength, :win_rate, :moves,
3
+ :total_moves, :black_tier_1, :black_tier_2, :black_tier_3, :black_tier_4, :white_tier_1, :white_tier_2, :white_tier_3, :white_tier_4, :black_total, :white_total
4
+
5
+ @@all = []
6
+
7
+ def initialize(attributes)
8
+ attributes.each {|key, value| self.send(("#{key}="), value)}
9
+ @black_tier_1 = [0, 0]
10
+ @black_tier_2 = [0, 0]
11
+ @black_tier_3 = [0, 0]
12
+ @black_tier_4 = [0, 0]
13
+ @black_total = [0, 0]
14
+ @white_total = [0, 0]
15
+ @white_tier_1 = [0, 0]
16
+ @white_tier_2 = [0, 0]
17
+ @white_tier_3 = [0, 0]
18
+ @white_tier_4 = [0, 0]
19
+
20
+ @@all << self
21
+ end
22
+
23
+ def self.all
24
+ @@all
25
+ end
26
+
27
+ def self.destroy_all
28
+ self.all.clear
29
+ end
30
+
31
+ def calculate_percentages
32
+ @black_tier_1[1] = @black_tier_1[0].to_f / @total_moves / 2 * 100
33
+ @black_tier_2[1] = @black_tier_2[0].to_f / @total_moves / 2 * 100
34
+ @black_tier_3[1] = @black_tier_3[0].to_f / @total_moves / 2 * 100
35
+ @black_tier_4[1] = @black_tier_4[0].to_f / @total_moves / 2 * 100
36
+ @white_tier_1[1] = @white_tier_1[0].to_f / @total_moves / 2 * 100
37
+ @white_tier_2[1] = @white_tier_2[0].to_f / @total_moves / 2 * 100
38
+ @white_tier_3[1] = @white_tier_3[0].to_f / @total_moves / 2 * 100
39
+ @white_tier_4[1] = @white_tier_4[0].to_f / @total_moves / 2 * 100
40
+
41
+ @black_total[0] = @black_tier_1[0] + @black_tier_2[0] + @black_tier_3[0] + @black_tier_4[0]
42
+ @white_total[0] = @white_tier_1[0] + @white_tier_2[0] + @white_tier_3[0] + @white_tier_4[0]
43
+
44
+ @white_total[1] = @white_tier_1[1] + @white_tier_2[1] + @white_tier_3[1] + @white_tier_4[1]
45
+ @black_total[1] = @black_tier_1[1] + @black_tier_2[1] + @black_tier_3[1] + @black_tier_4[1]
46
+ end
47
+
48
+
49
+ def process
50
+ @total_moves = @moves.count;
51
+
52
+ @moves.each do |move|
53
+ current_move = move[1]["move_number"]
54
+ previous_move = @moves[(current_move.to_i - 1).to_s]
55
+ move_made = move[1]["move"]
56
+ if current_move.to_i >= 2
57
+ if previous_move["branches"][0]["moves"][0] == move_made
58
+ current_move % 2 == 0 ? @white_tier_1[0] += 1 : @black_tier_1[0] += 1
59
+ elsif previous_move["branches"].count >= 2 && previous_move["branches"][1]["moves"][0] == move_made
60
+ current_move % 2 == 0 ? @white_tier_2[0] += 1 : @black_tier_2[0] += 1
61
+ elsif previous_move["branches"].count >= 3 && previous_move["branches"][2]["moves"][0] == move_made
62
+ current_move % 2 == 0 ? @white_tier_3[0] += 1 : @black_tier_3[0] += 1
63
+ elsif previous_move["branches"].count >= 4 && previous_move["branches"][3]["moves"][0] == move_made
64
+ current_move % 2 == 0 ? @white_tier_4[0] += 1 : @black_tier_4[0] += 1
65
+ end
66
+ end
67
+ end
68
+ calculate_percentages
69
+ end
70
+ end
@@ -0,0 +1,49 @@
1
+ class Review
2
+ attr_accessor :full_review, :number, :id, :type, :game_id, :engine, :engine_version, :network, :network_size, :date, :strength, :win_rate, :moves
3
+ @@all = []
4
+
5
+ def initialize(attributes, number:)
6
+ attributes.each {|key, value| self.send(("#{key}="), value)}
7
+ @number = number
8
+ @@all << self
9
+ end
10
+
11
+ def self.all
12
+ @@all
13
+ end
14
+
15
+ def self.destroy_all
16
+ self.all.clear
17
+ end
18
+
19
+ def self.find_by_number(number)
20
+ @@all.find{|review| review.number == number}
21
+ end
22
+
23
+ def check
24
+
25
+ puts "Checking player submitted moves against #{@engine} #{@type} review ##{@id}..."
26
+ review = load_review
27
+ review.process
28
+ puts ""
29
+ puts "-----------------------------------------------------"
30
+ puts "Black Tier 1 Moves: #{review.black_tier_1[0]} --- #{review.black_tier_1[1].round(2)}%"
31
+ puts "Black Tier 2 Moves: #{review.black_tier_2[0]} --- #{review.black_tier_2[1].round(2)}%"
32
+ puts "Black Tier 3 Moves: #{review.black_tier_3[0]} --- #{review.black_tier_3[1].round(2)}%"
33
+ puts "Black Tier 4 Moves: #{review.black_tier_4[0]} --- #{review.black_tier_4[1].round(2)}%"
34
+ puts "-----------------------------------------------------"
35
+ puts "White Tier 1 Moves: #{review.white_tier_1[0]} --- #{review.white_tier_1[1].round(2)}%"
36
+ puts "White Tier 2 Moves: #{review.white_tier_2[0]} --- #{review.white_tier_2[1].round(2)}%"
37
+ puts "White Tier 3 Moves: #{review.white_tier_3[0]} --- #{review.white_tier_3[1].round(2)}%"
38
+ puts "White Tier 4 Moves: #{review.white_tier_4[0]} --- #{review.white_tier_4[1].round(2)}%"
39
+ puts "-----------------------------------------------------"
40
+ puts "Black Total Top Moves: #{review.black_total[0]} --- #{review.black_total[1].round(2)}%"
41
+ puts "White Total Top Moves: #{review.white_total[0]} --- #{review.white_total[1].round(2)}%"
42
+ puts "-----------------------------------------------------"
43
+
44
+ end
45
+
46
+ def load_review
47
+ FullReview.new(JSON.parse(Faraday.get("https://online-go.com/termination-api/game/#{@game_id}/ai_review/#{@id}").body))
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module OGSKataCheck
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/ogs_katacheck/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "ogs_katacheck"
5
+ spec.version = OGSKataCheck::VERSION
6
+ spec.authors = ["RubyMineshaft"]
7
+ spec.email = ["rubymineshaft@online-go.com"]
8
+
9
+ spec.summary = %q{CLI that checks user submitted moves against AI game reviews.}
10
+ spec.description = %q{This CLI gem is written for OGS team members in order to aid in investigating suspicions of botting.}
11
+ spec.homepage = "https://github.com/RubyMineshaft/ogs_katacheck"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "https://github.com/RubyMineshaft/ogs_katacheck/blob/main/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ogs_katacheck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - RubyMineshaft
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This CLI gem is written for OGS team members in order to aid in investigating
14
+ suspicions of botting.
15
+ email:
16
+ - rubymineshaft@online-go.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/ogs-katacheck
28
+ - bin/setup
29
+ - lib/ogs_katacheck.rb
30
+ - lib/ogs_katacheck/cli.rb
31
+ - lib/ogs_katacheck/full_review.rb
32
+ - lib/ogs_katacheck/review.rb
33
+ - lib/ogs_katacheck/version.rb
34
+ - ogs_katacheck.gemspec
35
+ homepage: https://github.com/RubyMineshaft/ogs_katacheck
36
+ licenses: []
37
+ metadata:
38
+ homepage_uri: https://github.com/RubyMineshaft/ogs_katacheck
39
+ source_code_uri: https://github.com/RubyMineshaft/ogs_katacheck
40
+ changelog_uri: https://github.com/RubyMineshaft/ogs_katacheck/blob/main/CHANGELOG.md
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.3.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.7.10
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: CLI that checks user submitted moves against AI game reviews.
61
+ test_files: []