From 15b0f027ce898dc6f36f62673a57dd8552e571c5 Mon Sep 17 00:00:00 2001 From: pioz Date: Wed, 28 Aug 2024 11:05:54 +0200 Subject: [PATCH] Update gems, fix rubocop offenses, fix CODECOV_TOKEN --- .github/workflows/ruby.yml | 4 +- Gemfile | 12 ++++ Gemfile.lock | 90 ++++++++++++++++++------------ chess.gemspec | 11 ---- lib/chess/game.rb | 22 +++++--- lib/chess/gnuchess.rb | 3 +- lib/chess/pgn.rb | 4 +- lib/chess/version.rb | 2 +- test/test_big_pgn_collection.rb | 2 +- test/test_checkmate.rb | 4 +- test/test_fifty_rule_move.rb | 4 +- test/test_game.rb | 9 +++ test/test_helper.rb | 4 +- test/test_illegal_moves.rb | 1 + test/test_insufficient_material.rb | 10 +++- test/test_load_fen.rb | 6 ++ test/test_move_generator.rb | 3 +- test/test_pgn.rb | 12 +++- test/test_pgn_collection.rb | 7 ++- test/test_stalemate.rb | 4 +- test/test_threefold_repetition.rb | 4 +- test/test_uci_castling.rb | 9 ++- 22 files changed, 151 insertions(+), 76 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index b67699f..d6cf7a8 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -35,7 +35,7 @@ jobs: - name: Run tests run: bundle exec rake test env: - CODECOV: true + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} # - name: Upload coverage report to Codecov # uses: codecov/codecov-action@v1 # with: @@ -45,7 +45,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2'] + ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3'] steps: - uses: actions/checkout@v2 diff --git a/Gemfile b/Gemfile index 1e5fbc3..b63ce2f 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,15 @@ source 'http://rubygems.org' # Specify your gem's dependencies in chess.gemspec gemspec + +gem 'bundler' +gem 'codecov' +gem 'debug' +gem 'minitest' +gem 'rake' +gem 'rubocop' +gem 'rubocop-minitest' +gem 'rubocop-performance' +gem 'rubocop-rake' +gem 'simplecov' +gem 'yard', '>= 0.9.20' diff --git a/Gemfile.lock b/Gemfile.lock index 8edf8c9..5e33ef9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,53 +1,73 @@ PATH remote: . specs: - chess (0.3.4) + chess (0.3.5) GEM remote: http://rubygems.org/ specs: ast (2.4.2) - byebug (11.1.3) codecov (0.6.0) simplecov (>= 0.15, < 0.22) - docile (1.4.0) - json (2.6.2) - minitest (5.16.2) - parallel (1.22.1) - parser (3.1.2.0) + debug (1.9.2) + irb (~> 1.10) + reline (>= 0.3.8) + docile (1.4.1) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + json (2.7.2) + language_server-protocol (3.17.0.3) + minitest (5.25.1) + parallel (1.26.3) + parser (3.3.4.2) ast (~> 2.4.1) + racc + psych (5.1.2) + stringio + racc (1.8.1) rainbow (3.1.1) - rake (13.0.6) - regexp_parser (2.5.0) - rexml (3.2.5) - rubocop (1.31.2) + rake (13.2.1) + rdoc (6.7.0) + psych (>= 4.0.0) + regexp_parser (2.9.2) + reline (0.5.9) + io-console (~> 0.5) + rexml (3.3.6) + strscan + rubocop (1.65.1) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) + regexp_parser (>= 2.4, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.18.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.19.1) - parser (>= 3.1.1.0) - rubocop-minitest (0.20.1) - rubocop (>= 0.90, < 2.0) - rubocop-performance (1.14.2) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.32.1) + parser (>= 3.3.1.0) + rubocop-minitest (0.35.1) + rubocop (>= 1.61, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-performance (1.21.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - ruby-progressbar (1.11.0) + ruby-progressbar (1.13.0) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - unicode-display_width (2.2.0) - yard (0.9.35) + stringio (3.1.1) + strscan (3.1.0) + unicode-display_width (2.5.0) + yard (0.9.36) PLATFORMS ruby @@ -55,17 +75,17 @@ PLATFORMS x86_64-darwin-19 DEPENDENCIES - bundler (~> 2) - byebug (~> 11) + bundler chess! - codecov (~> 0) - minitest (~> 5) - rake (~> 13) - rubocop (~> 1) - rubocop-minitest (~> 0) - rubocop-performance (~> 1) - rubocop-rake (~> 0) - simplecov (~> 0) + codecov + debug + minitest + rake + rubocop + rubocop-minitest + rubocop-performance + rubocop-rake + simplecov yard (>= 0.9.20) BUNDLED WITH diff --git a/chess.gemspec b/chess.gemspec index 2f75542..d6aa4db 100644 --- a/chess.gemspec +++ b/chess.gemspec @@ -18,15 +18,4 @@ Gem::Specification.new do |s| s.metadata['rubygems_mfa_required'] = 'true' s.required_ruby_version = '>= 2.5' - s.add_development_dependency 'bundler', '~> 2' - s.add_development_dependency 'byebug', '~> 11' - s.add_development_dependency 'codecov', '~> 0' - s.add_development_dependency 'minitest', '~> 5' - s.add_development_dependency 'rake', '~> 13' - s.add_development_dependency 'rubocop', '~> 1' - s.add_development_dependency 'rubocop-minitest', '~> 0' - s.add_development_dependency 'rubocop-performance', '~> 1' - s.add_development_dependency 'rubocop-rake', '~> 0' - s.add_development_dependency 'simplecov', '~> 0' - s.add_development_dependency 'yard', '>= 0.9.20' end diff --git a/lib/chess/game.rb b/lib/chess/game.rb index f4cfd69..5b6544b 100644 --- a/lib/chess/game.rb +++ b/lib/chess/game.rb @@ -155,13 +155,8 @@ def expand_move(notation) expand[:from] = match[2] if match[2] && match[2].size == 2 # Support UCI protocol (Lichess) - if expand[:from] == 'e1' && self.board['e1'] == 'K' - expand[:to] = 'g1' if expand[:to] == 'h1' # UCI protocol (Lichess) white king short castling - expand[:to] = 'c1' if expand[:to] == 'a1' # UCI protocol (Lichess) white king long castling - elsif expand[:from] == 'e8' && self.board['e8'] == 'k' - expand[:to] = 'g8' if expand[:to] == 'h8' # UCI protocol (Lichess) black king short castling - expand[:to] = 'c8' if expand[:to] == 'a8' # UCI protocol (Lichess) black king long castling - end + uci_to_coord = uci_castling_to_coord(expand[:from], expand[:to]) + expand[:to] = uci_to_coord if uci_to_coord return expand end @@ -180,6 +175,19 @@ def expand_move(notation) raise BadNotationError.new(notation) end + + # Support Castling notation valid in UCI (Universal Chess Interface) + # protocol (Lichess) + def uci_castling_to_coord(from, to) + if from == 'e1' && self.board['e1'] == 'K' + return 'g1' if to == 'h1' # UCI protocol (Lichess) white king short castling + return 'c1' if to == 'a1' # UCI protocol (Lichess) white king long castling + elsif from == 'e8' && self.board['e8'] == 'k' + return 'g8' if to == 'h8' # UCI protocol (Lichess) black king short castling + return 'c8' if to == 'a8' # UCI protocol (Lichess) black king long castling + end + return nil + end end MOVE_REGEXP = /^([RNBQK])?([a-h]|[1-8]|[a-h][1-8])?(?:x)?([a-h][1-8])(?:=?([RrNnBbQq]))?(?:ep)?(?:\+|\#)?$/.freeze diff --git a/lib/chess/gnuchess.rb b/lib/chess/gnuchess.rb index 4aa4f25..2c8824c 100644 --- a/lib/chess/gnuchess.rb +++ b/lib/chess/gnuchess.rb @@ -75,7 +75,8 @@ def gen_pgn(file_to_save, moves = []) until done pipe.write("go\n") while (line = pipe.gets) - break if /My move is : /.match?(line) || / : resign/.match?(line) + break if line.include?('My move is : ') + break if line.include?(' : resign') if / : 1-0 {White mates}/.match?(line) done = :white_won diff --git a/lib/chess/pgn.rb b/lib/chess/pgn.rb index 3753913..5335b4b 100644 --- a/lib/chess/pgn.rb +++ b/lib/chess/pgn.rb @@ -62,7 +62,7 @@ def load(filename, check_moves: false) def load_from_string(str, check_moves: false) str.gsub!(/\{.*?\}/, '') # remove comments TAGS.each do |t| - instance_variable_set("@#{t}", str.match(/^\[#{t.capitalize} ".*"\]\s?$/).to_s.strip[t.size + 3..-3]) + instance_variable_set(:"@#{t}", str.match(/^\[#{t.capitalize} ".*"\]\s?$/).to_s.strip[t.size + 3..-3]) end @result = '1/2-1/2' if @result == '1/2' game_index = str.index(/^1\./) @@ -82,7 +82,7 @@ def load_from_string(str, check_moves: false) def to_s s = '' TAGS.each do |t| - tag = instance_variable_defined?("@#{t}") ? instance_variable_get("@#{t}") : '' + tag = instance_variable_defined?(:"@#{t}") ? instance_variable_get(:"@#{t}") : '' s << "[#{t.capitalize} \"#{tag}\"]\n" end s << "\n" diff --git a/lib/chess/version.rb b/lib/chess/version.rb index a0a30f5..6943b00 100644 --- a/lib/chess/version.rb +++ b/lib/chess/version.rb @@ -1,5 +1,5 @@ # The Chess library module. module Chess # The library version. - VERSION = '0.3.4'.freeze + VERSION = '0.3.5'.freeze end diff --git a/test/test_big_pgn_collection.rb b/test/test_big_pgn_collection.rb index 03197d2..4aab6c4 100644 --- a/test/test_big_pgn_collection.rb +++ b/test/test_big_pgn_collection.rb @@ -8,7 +8,7 @@ class ChessTest < Minitest::Test path = File.join(TestHelper::BIG_PGN_COLLECTION, filename) break unless File.exist?(path) - define_method "test_big_pgn_#{filename}" do + define_method :"test_big_pgn_#{filename}" do pgn = Chess::Pgn.new(path) game = Chess::Game.new(pgn.moves) assert(game.checkmate?) if pgn.moves.last.match?(/\#$/) diff --git a/test/test_checkmate.rb b/test/test_checkmate.rb index d85205c..b2ebe43 100644 --- a/test/test_checkmate.rb +++ b/test/test_checkmate.rb @@ -4,9 +4,11 @@ class ChessTest < Minitest::Test TestHelper.pgns('checkmate').each do |file| name = File.basename(file, '.pgn') win = file.include?('white') ? 'white' : 'black' - define_method "test_#{win}_checkmate_#{name}" do + + define_method :"test_#{win}_checkmate_#{name}" do pgn = Chess::Pgn.new(file) game = Chess::Game.new(pgn.moves) + assert(game.board.checkmate?) if file.include?('white_won') assert_equal('1-0', game.result) diff --git a/test/test_fifty_rule_move.rb b/test/test_fifty_rule_move.rb index 574b7af..55580dc 100644 --- a/test/test_fifty_rule_move.rb +++ b/test/test_fifty_rule_move.rb @@ -3,9 +3,11 @@ class ChessTest < Minitest::Test TestHelper.pgns('fifty_move_rule').each do |file| name = File.basename(file, '.pgn') - define_method "test_fifty_move_rule_#{name}" do + + define_method :"test_fifty_move_rule_#{name}" do pgn = Chess::Pgn.new(file) game = Chess::Game.new(pgn.moves) + assert game.board.fifty_move_rule? end end diff --git a/test/test_game.rb b/test/test_game.rb index 877d6db..5835499 100644 --- a/test/test_game.rb +++ b/test/test_game.rb @@ -4,24 +4,28 @@ class ChessTest < Minitest::Test def test_moves game = Chess::Game.new game.moves = %w[e4 e5] + assert_equal %w[e4 e5], game.moves end def test_active_player game = Chess::Game.new game << 'a3' + assert_equal :black, game.active_player end def test_inactive_player game = Chess::Game.new game.moves = %w[a3 f5] + assert_equal :black, game.inactive_player end def test_status_white_won_resign game = Chess::Game.new game.resign(:black) + assert_equal :white_won_resign, game.status assert game.over? assert_equal '1-0', game.result @@ -31,6 +35,7 @@ def test_status_black_won_resign game = Chess::Game.new game << 'e4' game.resign(:white) + assert_equal :black_won_resign, game.status assert game.over? assert_equal '0-1', game.result @@ -39,6 +44,7 @@ def test_status_black_won_resign def test_status_insufficient_material pgn = TestHelper.pick_pgn('insufficient_material/0001.pgn') game = Chess::Game.new(pgn.moves) + assert_equal :insufficient_material, game.status end @@ -46,6 +52,7 @@ def test_status_fifty_move_rule pgn = TestHelper.pick_pgn('fifty_move_rule/0001.pgn') game = Chess::Game.new(pgn.moves) game.draw + assert_equal :fifty_move_rule, game.status end @@ -53,12 +60,14 @@ def test_status_threefold_repetition pgn = TestHelper.pick_pgn('threefold_repetition/0001.pgn') game = Chess::Game.new(pgn.moves) game.draw + assert_equal :threefold_repetition, game.status end def test_pgn pgn = TestHelper.pick_pgn('valid/0001.pgn') game = Chess::Game.new(pgn.moves) + expected_pgn = <<~PGN [Event ""] [Site ""] diff --git a/test/test_helper.rb b/test/test_helper.rb index 9789df0..48eecc7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,14 +2,14 @@ SimpleCov.start do add_filter 'lib/chess/gnuchess.rb' end -if ENV['CODECOV'] == 'true' +if ENV['CODECOV_TOKEN'].present? require 'codecov' SimpleCov.formatter = SimpleCov::Formatter::Codecov end require 'chess' +require 'debug' require 'minitest/autorun' -require 'byebug' module TestHelper PGN_COLLECTION = 'test/pgn_collection'.freeze diff --git a/test/test_illegal_moves.rb b/test/test_illegal_moves.rb index dd7417a..a3d966b 100644 --- a/test/test_illegal_moves.rb +++ b/test/test_illegal_moves.rb @@ -3,6 +3,7 @@ class ChessTest < Minitest::Test def test_illegal_moves game = Chess::Game.new + %w[Qf6 Rd4 Nc3=Q].each do |move| assert_raises(Chess::IllegalMoveError) do game << move diff --git a/test/test_insufficient_material.rb b/test/test_insufficient_material.rb index 78c642a..92de42d 100644 --- a/test/test_insufficient_material.rb +++ b/test/test_insufficient_material.rb @@ -15,15 +15,17 @@ class ChessTest < Minitest::Test ].freeze FENS.each_with_index do |fen, i| - define_method("test_insufficient_material_by_fen_#{i}") do + define_method :"test_insufficient_material_by_fen_#{i}" do game = Chess::Game.load_fen(fen) + assert game.board.insufficient_material? end end ONLY_KINGS_FENS.each_with_index do |fen, i| - define_method("test_only_kings_by_fen_#{i}") do + define_method :"test_only_kings_by_fen_#{i}" do game = Chess::Game.load_fen(fen) + assert game.board.insufficient_material? assert game.board.only_kings? end @@ -31,9 +33,11 @@ class ChessTest < Minitest::Test TestHelper.pgns('insufficient_material').each do |file| name = File.basename(file, '.pgn') - define_method "test_insufficient_material_#{name}" do + + define_method :"test_insufficient_material_#{name}" do pgn = Chess::Pgn.new(file) game = Chess::Game.new(pgn.moves) + assert game.board.insufficient_material? end end diff --git a/test/test_load_fen.rb b/test/test_load_fen.rb index 464d481..14475bb 100644 --- a/test/test_load_fen.rb +++ b/test/test_load_fen.rb @@ -3,6 +3,7 @@ class ChessTest < Minitest::Test def test_fen_in_progress g = Chess::Game.load_fen('rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2') + assert_equal 'P', g.board['e4'] assert_equal 'p', g.board['c5'] assert_equal 'K', g.board[4] @@ -12,6 +13,7 @@ def test_fen_in_progress def test_fen_white_won g = Chess::Game.load_fen('rnbqkbnr/1ppp1Qpp/8/p3p3/2B1P3/8/PPPP1PPP/RNB1K1NR b KQkq - 1 3') + assert_equal 'Q', g.board['f7'] assert_equal 'p', g.board['e5'] assert_equal 'P', g.board[28] @@ -21,6 +23,7 @@ def test_fen_white_won def test_fen_black_won g = Chess::Game.load_fen('rnb1kbnr/pppp1ppp/4p3/8/5PPq/8/PPPPP2P/RNBQKBNR w KQkq - 1 3') + assert_equal 'q', g.board['h4'] assert_equal 'P', g.board['f4'] assert_equal 'p', g.board[44] @@ -30,6 +33,7 @@ def test_fen_black_won def test_fen_stalemate g = Chess::Game.load_fen('8/6b1/8/8/8/n7/PP6/K7 w KQkq - 1 3') + assert_equal 'b', g.board['g7'] assert_equal 'n', g.board['a3'] assert_equal 'K', g.board[0] @@ -40,12 +44,14 @@ def test_fen_stalemate def test_fen_castling_from g = Chess::Game.load_fen('2b1kbnr/rpq1pp1p/2n3p1/8/3Q4/2P5/PP3PPP/RN2KBNR w KQk - 0 9') g.move('Kd1') + assert_equal '2b1kbnr/rpq1pp1p/2n3p1/8/3Q4/2P5/PP3PPP/RN1K1BNR b k - 1 9', g.board.to_fen end def test_fen_castling_to g = Chess::Game.load_fen('2b1kbnr/rpq1pp1p/2n3p1/8/3Q4/2P5/PP3PPP/RN2KBNR w KQk - 0 9') g.move('Qh8') + assert_equal '2b1kbnQ/rpq1pp1p/2n3p1/8/8/2P5/PP3PPP/RN2KBNR b KQ - 0 9', g.board.to_fen end end diff --git a/test/test_move_generator.rb b/test/test_move_generator.rb index 8540740..7602d26 100644 --- a/test/test_move_generator.rb +++ b/test/test_move_generator.rb @@ -17,10 +17,11 @@ class ChessTest < Minitest::Test }.freeze GENS.each do |fen, generators| - define_method("test_move_generator_#{fen}") do + define_method :"test_move_generator_#{fen}" do game = Chess::Game.load_fen(fen) generators.each do |from, moves| result = game.board.generate_moves(from) + assert_equal moves.sort, result.sort end end diff --git a/test/test_pgn.rb b/test/test_pgn.rb index 271315c..045b862 100644 --- a/test/test_pgn.rb +++ b/test/test_pgn.rb @@ -3,7 +3,8 @@ class ChessTest < Minitest::Test TestHelper.pgns('invalid').each do |file| name = File.basename(file, '.pgn') - define_method "test_invalid_pgn_#{name}" do + + define_method :"test_invalid_pgn_#{name}" do assert_raises(Chess::InvalidPgnFormatError) do Chess::Pgn.new(file) end @@ -12,7 +13,8 @@ class ChessTest < Minitest::Test TestHelper.pgns('illegal').each do |file| name = File.basename(file, '.pgn') - define_method "test_illegal_pgn_#{name}" do + + define_method :"test_illegal_pgn_#{name}" do assert_raises(Chess::IllegalMoveError) do Chess::Pgn.new(file, check_moves: true) end @@ -33,6 +35,7 @@ def test_load_from_string PGN pgn = Chess::Pgn.new pgn.load_from_string(pgn_string, check_moves: true) + assert_equal '70th ch-ITA', pgn.event assert_equal 'Siena ITA', pgn.site assert_equal '10', pgn.round @@ -57,6 +60,7 @@ def test_load_from_string_without_tags PGN pgn = Chess::Pgn.new pgn.load_from_string(pgn_string, check_moves: true) + assert_nil pgn.event assert_nil pgn.site assert_nil pgn.round @@ -80,10 +84,10 @@ def test_write_pgn pgn.white = 'Pioz' pgn.black = 'Elizabeth Harmon' pgn.write(tempfile.path) - loaded_pgn = Chess::Pgn.new loaded_pgn.load(tempfile.path) tempfile.delete + assert_equal 'Ruby Chess Tournament', loaded_pgn.event assert_equal 'Ruby Chess test suite', loaded_pgn.site assert_equal '1984.10.21', loaded_pgn.date @@ -97,9 +101,11 @@ def test_write_pgn def test_set_date pgn = Chess::Pgn.new pgn.date = Time.parse('21-10-1984') + assert_equal '1984.10.21', pgn.date pgn.date = '1984.10.21' + assert_equal '1984.10.21', pgn.date end end diff --git a/test/test_pgn_collection.rb b/test/test_pgn_collection.rb index d85d307..549b636 100644 --- a/test/test_pgn_collection.rb +++ b/test/test_pgn_collection.rb @@ -3,7 +3,8 @@ class ChessTest < Minitest::Test TestHelper.pgns('valid').each do |file| name = File.basename(file, '.pgn') - define_method "test_pgn_#{name}" do + + define_method :"test_pgn_#{name}" do pgn = Chess::Pgn.new(file) game = Chess::Game.new pgn.moves.each do |m| @@ -12,9 +13,11 @@ class ChessTest < Minitest::Test assert(game.board.checkmate?) if m.match?(/\#$/) end end - define_method "test_pgn_result_#{name}" do + + define_method :"test_pgn_result_#{name}" do pgn = Chess::Pgn.new(file) game = Chess::Game.load_pgn(file) + assert_equal(pgn.result, game.result) end end diff --git a/test/test_stalemate.rb b/test/test_stalemate.rb index 9ff3ff2..5153ddc 100644 --- a/test/test_stalemate.rb +++ b/test/test_stalemate.rb @@ -3,9 +3,11 @@ class ChessTest < Minitest::Test TestHelper.pgns('stalemate').each do |file| name = File.basename(file, '.pgn') - define_method "test_stalemate_#{name}" do + + define_method :"test_stalemate_#{name}" do pgn = Chess::Pgn.new(file) game = Chess::Game.new(pgn.moves) + assert(game.board.stalemate?) assert_equal('1/2-1/2', game.result) end diff --git a/test/test_threefold_repetition.rb b/test/test_threefold_repetition.rb index 287c577..53f2ff1 100644 --- a/test/test_threefold_repetition.rb +++ b/test/test_threefold_repetition.rb @@ -3,9 +3,11 @@ class ChessTest < Minitest::Test TestHelper.pgns('threefold_repetition').each do |file| name = File.basename(file, '.pgn') - define_method "test_threefold_repetition_#{name}" do + + define_method :"test_threefold_repetition_#{name}" do pgn = Chess::Pgn.new(file) game = Chess::Game.new(pgn.moves) + assert game.threefold_repetition? end end diff --git a/test/test_uci_castling.rb b/test/test_uci_castling.rb index 81984cc..dc12a45 100644 --- a/test/test_uci_castling.rb +++ b/test/test_uci_castling.rb @@ -4,24 +4,28 @@ class UCICastrlingTest < Minitest::Test def test_uci_white_short_castling game = Chess::Game.new game.moves = %w[e4 c5 c3 d5 exd5 Qxd5 d4 Nf6 Nf3 e6 Be2 Be7 e1h1 Nc6] + assert_equal '*', game.result end def test_uci_white_long_castling game = Chess::Game.new game.moves = %w[e4 c5 Nf3 Nc6 d4 cxd4 Nxd4 Nf6 Nc3 d6 Bg5 Qb6 Nb3 e6 Qd2 Be7 e1a1] + assert_equal '*', game.result end def test_uci_black_short_castling game = Chess::Game.new game.moves = %w[d4 d5 c4 dxc4 e4 e5 Nf3 Bb4+ Nc3 exd4 Nxd4 Ne7 Bf4 Bxc3+ bxc3 Ng6 Bg3 Qe7 Bxc4 Qxe4+ Qe2 Qxe2+ Bxe2 Na6 Rb1 e8h8] + assert_equal '*', game.result end def test_uci_black_long_castling game = Chess::Game.new game.moves = %w[e4 c5 Nf3 d6 d4 cxd4 Qxd4 Nc6 Bb5 Bd7 Bxc6 Bxc6 Bg5 Nf6 Bxf6 gxf6 Nc3 e6 e1c1 Be7 Rhe1 Rg8 Qe3 Rxg2 Rg1 Rg6 Nd4 Qb6 h4 e8a8] + assert_equal '*', game.result end @@ -32,14 +36,17 @@ def test_uci_invalid_white_long_castling end end - def test_github_issue_31 + def test_github_issue31 g = Chess::Game.load_fen('4Q3/8/8/8/8/8/4K3/7k w - - 0 1') + assert_equal 'Q', g.board['e8'] assert_equal 'K', g.board['e2'] assert_equal 'k', g.board['h1'] assert_equal '*', g.result assert_equal :in_progress, g.status + g << 'e8a8' # It should not be considered as a UCI casting + assert_equal 'Q', g.board['a8'] end end