chess 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36668063cb71d331dbb172611791d43e0b5d465c0cd9e87baf80bc35cf11e551
4
- data.tar.gz: 516ebc6fb472885ec871c6fbd955f489a6afec26c52250a9612210e61f6ce883
3
+ metadata.gz: d5ebf213b0cfe5414754b1e1de84f9b27a958980c9da5e52b09301419a0f51a3
4
+ data.tar.gz: b8d71f48aac60f4183d19c8d7407ee2c5d90ad591f734aeac8a49ce351989fa2
5
5
  SHA512:
6
- metadata.gz: d3e811ed0ac4ad177ef1991cd38bbabf84b2139a8d12ea18b0f251621ed744cc54afe9252b489874a6f121551899a5382cffff67158281ca6ce64b5fe0ce2b61
7
- data.tar.gz: cad20b859cc7c41b4dfba6b92e0de8bc14317b86f0e4ffeb9f656819a2f507160534eeca6c0944a251964bf2d8ec20fc199548c50d293cf4f7a1c6b64797ae3c
6
+ metadata.gz: eca934b958eaae5a65d1b3cef8890a3093e27fa521ab73d9f0f70c11b18f7b1015fb3a0db9fbc528c5f2bcc101c4fb94db4a0b194020694972fd180e58581ad5
7
+ data.tar.gz: d5aeec92185bbc74206839fea269ddb088ed24c8dcad1c0e1dee9f294ef6299bdc355333f9415b47616abd5e87518b7969b314b56fb93d53667e652148c998a6
@@ -18,7 +18,7 @@ jobs:
18
18
  runs-on: ubuntu-latest
19
19
  strategy:
20
20
  matrix:
21
- ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
21
+ ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3']
22
22
 
23
23
  steps:
24
24
  - uses: actions/checkout@v2
@@ -35,7 +35,7 @@ jobs:
35
35
  - name: Run tests
36
36
  run: bundle exec rake test
37
37
  env:
38
- CODECOV: true
38
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
39
39
  # - name: Upload coverage report to Codecov
40
40
  # uses: codecov/codecov-action@v1
41
41
  # with:
@@ -45,7 +45,7 @@ jobs:
45
45
  runs-on: ubuntu-latest
46
46
  strategy:
47
47
  matrix:
48
- ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
48
+ ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3']
49
49
 
50
50
  steps:
51
51
  - uses: actions/checkout@v2
data/Gemfile CHANGED
@@ -2,3 +2,15 @@ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in chess.gemspec
4
4
  gemspec
5
+
6
+ gem 'bundler'
7
+ gem 'codecov'
8
+ gem 'debug'
9
+ gem 'minitest'
10
+ gem 'rake'
11
+ gem 'rubocop'
12
+ gem 'rubocop-minitest'
13
+ gem 'rubocop-performance'
14
+ gem 'rubocop-rake'
15
+ gem 'simplecov'
16
+ gem 'yard', '>= 0.9.20'
data/Gemfile.lock CHANGED
@@ -1,55 +1,73 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chess (0.3.4)
4
+ chess (0.3.5)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
- byebug (11.1.3)
11
10
  codecov (0.6.0)
12
11
  simplecov (>= 0.15, < 0.22)
13
- docile (1.4.0)
14
- json (2.6.2)
15
- minitest (5.16.2)
16
- parallel (1.22.1)
17
- parser (3.1.2.0)
12
+ debug (1.9.2)
13
+ irb (~> 1.10)
14
+ reline (>= 0.3.8)
15
+ docile (1.4.1)
16
+ io-console (0.7.2)
17
+ irb (1.14.0)
18
+ rdoc (>= 4.0.0)
19
+ reline (>= 0.4.2)
20
+ json (2.7.2)
21
+ language_server-protocol (3.17.0.3)
22
+ minitest (5.25.1)
23
+ parallel (1.26.3)
24
+ parser (3.3.4.2)
18
25
  ast (~> 2.4.1)
26
+ racc
27
+ psych (5.1.2)
28
+ stringio
29
+ racc (1.8.1)
19
30
  rainbow (3.1.1)
20
- rake (13.0.6)
21
- regexp_parser (2.5.0)
22
- rexml (3.2.5)
23
- rubocop (1.31.2)
31
+ rake (13.2.1)
32
+ rdoc (6.7.0)
33
+ psych (>= 4.0.0)
34
+ regexp_parser (2.9.2)
35
+ reline (0.5.9)
36
+ io-console (~> 0.5)
37
+ rexml (3.3.6)
38
+ strscan
39
+ rubocop (1.65.1)
24
40
  json (~> 2.3)
41
+ language_server-protocol (>= 3.17.0)
25
42
  parallel (~> 1.10)
26
- parser (>= 3.1.0.0)
43
+ parser (>= 3.3.0.2)
27
44
  rainbow (>= 2.2.2, < 4.0)
28
- regexp_parser (>= 1.8, < 3.0)
45
+ regexp_parser (>= 2.4, < 3.0)
29
46
  rexml (>= 3.2.5, < 4.0)
30
- rubocop-ast (>= 1.18.0, < 2.0)
47
+ rubocop-ast (>= 1.31.1, < 2.0)
31
48
  ruby-progressbar (~> 1.7)
32
- unicode-display_width (>= 1.4.0, < 3.0)
33
- rubocop-ast (1.19.1)
34
- parser (>= 3.1.1.0)
35
- rubocop-minitest (0.20.1)
36
- rubocop (>= 0.90, < 2.0)
37
- rubocop-performance (1.14.2)
38
- rubocop (>= 1.7.0, < 2.0)
39
- rubocop-ast (>= 0.4.0)
49
+ unicode-display_width (>= 2.4.0, < 3.0)
50
+ rubocop-ast (1.32.1)
51
+ parser (>= 3.3.1.0)
52
+ rubocop-minitest (0.35.1)
53
+ rubocop (>= 1.61, < 2.0)
54
+ rubocop-ast (>= 1.31.1, < 2.0)
55
+ rubocop-performance (1.21.1)
56
+ rubocop (>= 1.48.1, < 2.0)
57
+ rubocop-ast (>= 1.31.1, < 2.0)
40
58
  rubocop-rake (0.6.0)
41
59
  rubocop (~> 1.0)
42
- ruby-progressbar (1.11.0)
60
+ ruby-progressbar (1.13.0)
43
61
  simplecov (0.21.2)
44
62
  docile (~> 1.1)
45
63
  simplecov-html (~> 0.11)
46
64
  simplecov_json_formatter (~> 0.1)
47
65
  simplecov-html (0.12.3)
48
66
  simplecov_json_formatter (0.1.4)
49
- unicode-display_width (2.2.0)
50
- webrick (1.7.0)
51
- yard (0.9.28)
52
- webrick (~> 1.7.0)
67
+ stringio (3.1.1)
68
+ strscan (3.1.0)
69
+ unicode-display_width (2.5.0)
70
+ yard (0.9.36)
53
71
 
54
72
  PLATFORMS
55
73
  ruby
@@ -57,17 +75,17 @@ PLATFORMS
57
75
  x86_64-darwin-19
58
76
 
59
77
  DEPENDENCIES
60
- bundler (~> 2)
61
- byebug (~> 11)
78
+ bundler
62
79
  chess!
63
- codecov (~> 0)
64
- minitest (~> 5)
65
- rake (~> 13)
66
- rubocop (~> 1)
67
- rubocop-minitest (~> 0)
68
- rubocop-performance (~> 1)
69
- rubocop-rake (~> 0)
70
- simplecov (~> 0)
80
+ codecov
81
+ debug
82
+ minitest
83
+ rake
84
+ rubocop
85
+ rubocop-minitest
86
+ rubocop-performance
87
+ rubocop-rake
88
+ simplecov
71
89
  yard (>= 0.9.20)
72
90
 
73
91
  BUNDLED WITH
data/chess.gemspec CHANGED
@@ -18,15 +18,4 @@ Gem::Specification.new do |s|
18
18
  s.metadata['rubygems_mfa_required'] = 'true'
19
19
 
20
20
  s.required_ruby_version = '>= 2.5'
21
- s.add_development_dependency 'bundler', '~> 2'
22
- s.add_development_dependency 'byebug', '~> 11'
23
- s.add_development_dependency 'codecov', '~> 0'
24
- s.add_development_dependency 'minitest', '~> 5'
25
- s.add_development_dependency 'rake', '~> 13'
26
- s.add_development_dependency 'rubocop', '~> 1'
27
- s.add_development_dependency 'rubocop-minitest', '~> 0'
28
- s.add_development_dependency 'rubocop-performance', '~> 1'
29
- s.add_development_dependency 'rubocop-rake', '~> 0'
30
- s.add_development_dependency 'simplecov', '~> 0'
31
- s.add_development_dependency 'yard', '>= 0.9.20'
32
21
  end
data/ext/chess/extconf.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # Creating a gem that includes an extension that is built at install time
2
+ # https://guides.rubygems.org/gems-with-extensions/
3
+
1
4
  ENV['RC_ARCHS'] = '' if RUBY_PLATFORM.include?('darwin')
2
5
 
3
6
  require 'mkmf'
data/lib/chess/game.rb CHANGED
@@ -155,14 +155,8 @@ module Chess
155
155
  expand[:from] = match[2] if match[2] && match[2].size == 2
156
156
 
157
157
  # Support UCI protocol (Lichess)
158
- case expand[:from]
159
- when 'e1'
160
- expand[:to] = 'g1' if expand[:to] == 'h1' # UCI protocol (Lichess) white king short castling
161
- expand[:to] = 'c1' if expand[:to] == 'a1' # UCI protocol (Lichess) white king long castling
162
- when 'e8'
163
- expand[:to] = 'g8' if expand[:to] == 'h8' # UCI protocol (Lichess) black king short castling
164
- expand[:to] = 'c8' if expand[:to] == 'a8' # UCI protocol (Lichess) black king long castling
165
- end
158
+ uci_to_coord = uci_castling_to_coord(expand[:from], expand[:to])
159
+ expand[:to] = uci_to_coord if uci_to_coord
166
160
 
167
161
  return expand
168
162
  end
@@ -181,6 +175,19 @@ module Chess
181
175
 
182
176
  raise BadNotationError.new(notation)
183
177
  end
178
+
179
+ # Support Castling notation valid in UCI (Universal Chess Interface)
180
+ # protocol (Lichess)
181
+ def uci_castling_to_coord(from, to)
182
+ if from == 'e1' && self.board['e1'] == 'K'
183
+ return 'g1' if to == 'h1' # UCI protocol (Lichess) white king short castling
184
+ return 'c1' if to == 'a1' # UCI protocol (Lichess) white king long castling
185
+ elsif from == 'e8' && self.board['e8'] == 'k'
186
+ return 'g8' if to == 'h8' # UCI protocol (Lichess) black king short castling
187
+ return 'c8' if to == 'a8' # UCI protocol (Lichess) black king long castling
188
+ end
189
+ return nil
190
+ end
184
191
  end
185
192
 
186
193
  MOVE_REGEXP = /^([RNBQK])?([a-h]|[1-8]|[a-h][1-8])?(?:x)?([a-h][1-8])(?:=?([RrNnBbQq]))?(?:ep)?(?:\+|\#)?$/.freeze
@@ -75,7 +75,8 @@ module Chess
75
75
  until done
76
76
  pipe.write("go\n")
77
77
  while (line = pipe.gets)
78
- break if /My move is : /.match?(line) || / : resign/.match?(line)
78
+ break if line.include?('My move is : ')
79
+ break if line.include?(' : resign')
79
80
 
80
81
  if / : 1-0 {White mates}/.match?(line)
81
82
  done = :white_won
data/lib/chess/pgn.rb CHANGED
@@ -62,7 +62,7 @@ module Chess
62
62
  def load_from_string(str, check_moves: false)
63
63
  str.gsub!(/\{.*?\}/, '') # remove comments
64
64
  TAGS.each do |t|
65
- instance_variable_set("@#{t}", str.match(/^\[#{t.capitalize} ".*"\]\s?$/).to_s.strip[t.size + 3..-3])
65
+ instance_variable_set(:"@#{t}", str.match(/^\[#{t.capitalize} ".*"\]\s?$/).to_s.strip[t.size + 3..-3])
66
66
  end
67
67
  @result = '1/2-1/2' if @result == '1/2'
68
68
  game_index = str.index(/^1\./)
@@ -82,7 +82,7 @@ module Chess
82
82
  def to_s
83
83
  s = ''
84
84
  TAGS.each do |t|
85
- tag = instance_variable_defined?("@#{t}") ? instance_variable_get("@#{t}") : ''
85
+ tag = instance_variable_defined?(:"@#{t}") ? instance_variable_get(:"@#{t}") : ''
86
86
  s << "[#{t.capitalize} \"#{tag}\"]\n"
87
87
  end
88
88
  s << "\n"
data/lib/chess/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # The Chess library module.
2
2
  module Chess
3
3
  # The library version.
4
- VERSION = '0.3.4'.freeze
4
+ VERSION = '0.3.5'.freeze
5
5
  end
@@ -8,7 +8,7 @@ class ChessTest < Minitest::Test
8
8
  path = File.join(TestHelper::BIG_PGN_COLLECTION, filename)
9
9
  break unless File.exist?(path)
10
10
 
11
- define_method "test_big_pgn_#{filename}" do
11
+ define_method :"test_big_pgn_#{filename}" do
12
12
  pgn = Chess::Pgn.new(path)
13
13
  game = Chess::Game.new(pgn.moves)
14
14
  assert(game.checkmate?) if pgn.moves.last.match?(/\#$/)
@@ -4,9 +4,11 @@ class ChessTest < Minitest::Test
4
4
  TestHelper.pgns('checkmate').each do |file|
5
5
  name = File.basename(file, '.pgn')
6
6
  win = file.include?('white') ? 'white' : 'black'
7
- define_method "test_#{win}_checkmate_#{name}" do
7
+
8
+ define_method :"test_#{win}_checkmate_#{name}" do
8
9
  pgn = Chess::Pgn.new(file)
9
10
  game = Chess::Game.new(pgn.moves)
11
+
10
12
  assert(game.board.checkmate?)
11
13
  if file.include?('white_won')
12
14
  assert_equal('1-0', game.result)
@@ -3,9 +3,11 @@ require 'test_helper'
3
3
  class ChessTest < Minitest::Test
4
4
  TestHelper.pgns('fifty_move_rule').each do |file|
5
5
  name = File.basename(file, '.pgn')
6
- define_method "test_fifty_move_rule_#{name}" do
6
+
7
+ define_method :"test_fifty_move_rule_#{name}" do
7
8
  pgn = Chess::Pgn.new(file)
8
9
  game = Chess::Game.new(pgn.moves)
10
+
9
11
  assert game.board.fifty_move_rule?
10
12
  end
11
13
  end
data/test/test_game.rb CHANGED
@@ -4,24 +4,28 @@ class ChessTest < Minitest::Test
4
4
  def test_moves
5
5
  game = Chess::Game.new
6
6
  game.moves = %w[e4 e5]
7
+
7
8
  assert_equal %w[e4 e5], game.moves
8
9
  end
9
10
 
10
11
  def test_active_player
11
12
  game = Chess::Game.new
12
13
  game << 'a3'
14
+
13
15
  assert_equal :black, game.active_player
14
16
  end
15
17
 
16
18
  def test_inactive_player
17
19
  game = Chess::Game.new
18
20
  game.moves = %w[a3 f5]
21
+
19
22
  assert_equal :black, game.inactive_player
20
23
  end
21
24
 
22
25
  def test_status_white_won_resign
23
26
  game = Chess::Game.new
24
27
  game.resign(:black)
28
+
25
29
  assert_equal :white_won_resign, game.status
26
30
  assert game.over?
27
31
  assert_equal '1-0', game.result
@@ -31,6 +35,7 @@ class ChessTest < Minitest::Test
31
35
  game = Chess::Game.new
32
36
  game << 'e4'
33
37
  game.resign(:white)
38
+
34
39
  assert_equal :black_won_resign, game.status
35
40
  assert game.over?
36
41
  assert_equal '0-1', game.result
@@ -39,6 +44,7 @@ class ChessTest < Minitest::Test
39
44
  def test_status_insufficient_material
40
45
  pgn = TestHelper.pick_pgn('insufficient_material/0001.pgn')
41
46
  game = Chess::Game.new(pgn.moves)
47
+
42
48
  assert_equal :insufficient_material, game.status
43
49
  end
44
50
 
@@ -46,6 +52,7 @@ class ChessTest < Minitest::Test
46
52
  pgn = TestHelper.pick_pgn('fifty_move_rule/0001.pgn')
47
53
  game = Chess::Game.new(pgn.moves)
48
54
  game.draw
55
+
49
56
  assert_equal :fifty_move_rule, game.status
50
57
  end
51
58
 
@@ -53,12 +60,14 @@ class ChessTest < Minitest::Test
53
60
  pgn = TestHelper.pick_pgn('threefold_repetition/0001.pgn')
54
61
  game = Chess::Game.new(pgn.moves)
55
62
  game.draw
63
+
56
64
  assert_equal :threefold_repetition, game.status
57
65
  end
58
66
 
59
67
  def test_pgn
60
68
  pgn = TestHelper.pick_pgn('valid/0001.pgn')
61
69
  game = Chess::Game.new(pgn.moves)
70
+
62
71
  expected_pgn = <<~PGN
63
72
  [Event ""]
64
73
  [Site ""]
data/test/test_helper.rb CHANGED
@@ -2,14 +2,14 @@ require 'simplecov'
2
2
  SimpleCov.start do
3
3
  add_filter 'lib/chess/gnuchess.rb'
4
4
  end
5
- if ENV['CODECOV'] == 'true'
5
+ if ENV['CODECOV_TOKEN']
6
6
  require 'codecov'
7
7
  SimpleCov.formatter = SimpleCov::Formatter::Codecov
8
8
  end
9
9
 
10
10
  require 'chess'
11
+ require 'debug'
11
12
  require 'minitest/autorun'
12
- require 'byebug'
13
13
 
14
14
  module TestHelper
15
15
  PGN_COLLECTION = 'test/pgn_collection'.freeze
@@ -3,6 +3,7 @@ require 'test_helper'
3
3
  class ChessTest < Minitest::Test
4
4
  def test_illegal_moves
5
5
  game = Chess::Game.new
6
+
6
7
  %w[Qf6 Rd4 Nc3=Q].each do |move|
7
8
  assert_raises(Chess::IllegalMoveError) do
8
9
  game << move
@@ -15,15 +15,17 @@ class ChessTest < Minitest::Test
15
15
  ].freeze
16
16
 
17
17
  FENS.each_with_index do |fen, i|
18
- define_method("test_insufficient_material_by_fen_#{i}") do
18
+ define_method :"test_insufficient_material_by_fen_#{i}" do
19
19
  game = Chess::Game.load_fen(fen)
20
+
20
21
  assert game.board.insufficient_material?
21
22
  end
22
23
  end
23
24
 
24
25
  ONLY_KINGS_FENS.each_with_index do |fen, i|
25
- define_method("test_only_kings_by_fen_#{i}") do
26
+ define_method :"test_only_kings_by_fen_#{i}" do
26
27
  game = Chess::Game.load_fen(fen)
28
+
27
29
  assert game.board.insufficient_material?
28
30
  assert game.board.only_kings?
29
31
  end
@@ -31,9 +33,11 @@ class ChessTest < Minitest::Test
31
33
 
32
34
  TestHelper.pgns('insufficient_material').each do |file|
33
35
  name = File.basename(file, '.pgn')
34
- define_method "test_insufficient_material_#{name}" do
36
+
37
+ define_method :"test_insufficient_material_#{name}" do
35
38
  pgn = Chess::Pgn.new(file)
36
39
  game = Chess::Game.new(pgn.moves)
40
+
37
41
  assert game.board.insufficient_material?
38
42
  end
39
43
  end
@@ -3,6 +3,7 @@ require 'test_helper'
3
3
  class ChessTest < Minitest::Test
4
4
  def test_fen_in_progress
5
5
  g = Chess::Game.load_fen('rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2')
6
+
6
7
  assert_equal 'P', g.board['e4']
7
8
  assert_equal 'p', g.board['c5']
8
9
  assert_equal 'K', g.board[4]
@@ -12,6 +13,7 @@ class ChessTest < Minitest::Test
12
13
 
13
14
  def test_fen_white_won
14
15
  g = Chess::Game.load_fen('rnbqkbnr/1ppp1Qpp/8/p3p3/2B1P3/8/PPPP1PPP/RNB1K1NR b KQkq - 1 3')
16
+
15
17
  assert_equal 'Q', g.board['f7']
16
18
  assert_equal 'p', g.board['e5']
17
19
  assert_equal 'P', g.board[28]
@@ -21,6 +23,7 @@ class ChessTest < Minitest::Test
21
23
 
22
24
  def test_fen_black_won
23
25
  g = Chess::Game.load_fen('rnb1kbnr/pppp1ppp/4p3/8/5PPq/8/PPPPP2P/RNBQKBNR w KQkq - 1 3')
26
+
24
27
  assert_equal 'q', g.board['h4']
25
28
  assert_equal 'P', g.board['f4']
26
29
  assert_equal 'p', g.board[44]
@@ -30,6 +33,7 @@ class ChessTest < Minitest::Test
30
33
 
31
34
  def test_fen_stalemate
32
35
  g = Chess::Game.load_fen('8/6b1/8/8/8/n7/PP6/K7 w KQkq - 1 3')
36
+
33
37
  assert_equal 'b', g.board['g7']
34
38
  assert_equal 'n', g.board['a3']
35
39
  assert_equal 'K', g.board[0]
@@ -40,12 +44,14 @@ class ChessTest < Minitest::Test
40
44
  def test_fen_castling_from
41
45
  g = Chess::Game.load_fen('2b1kbnr/rpq1pp1p/2n3p1/8/3Q4/2P5/PP3PPP/RN2KBNR w KQk - 0 9')
42
46
  g.move('Kd1')
47
+
43
48
  assert_equal '2b1kbnr/rpq1pp1p/2n3p1/8/3Q4/2P5/PP3PPP/RN1K1BNR b k - 1 9', g.board.to_fen
44
49
  end
45
50
 
46
51
  def test_fen_castling_to
47
52
  g = Chess::Game.load_fen('2b1kbnr/rpq1pp1p/2n3p1/8/3Q4/2P5/PP3PPP/RN2KBNR w KQk - 0 9')
48
53
  g.move('Qh8')
54
+
49
55
  assert_equal '2b1kbnQ/rpq1pp1p/2n3p1/8/8/2P5/PP3PPP/RN2KBNR b KQ - 0 9', g.board.to_fen
50
56
  end
51
57
  end
@@ -17,10 +17,11 @@ class ChessTest < Minitest::Test
17
17
  }.freeze
18
18
 
19
19
  GENS.each do |fen, generators|
20
- define_method("test_move_generator_#{fen}") do
20
+ define_method :"test_move_generator_#{fen}" do
21
21
  game = Chess::Game.load_fen(fen)
22
22
  generators.each do |from, moves|
23
23
  result = game.board.generate_moves(from)
24
+
24
25
  assert_equal moves.sort, result.sort
25
26
  end
26
27
  end
data/test/test_pgn.rb CHANGED
@@ -3,7 +3,8 @@ require 'test_helper'
3
3
  class ChessTest < Minitest::Test
4
4
  TestHelper.pgns('invalid').each do |file|
5
5
  name = File.basename(file, '.pgn')
6
- define_method "test_invalid_pgn_#{name}" do
6
+
7
+ define_method :"test_invalid_pgn_#{name}" do
7
8
  assert_raises(Chess::InvalidPgnFormatError) do
8
9
  Chess::Pgn.new(file)
9
10
  end
@@ -12,7 +13,8 @@ class ChessTest < Minitest::Test
12
13
 
13
14
  TestHelper.pgns('illegal').each do |file|
14
15
  name = File.basename(file, '.pgn')
15
- define_method "test_illegal_pgn_#{name}" do
16
+
17
+ define_method :"test_illegal_pgn_#{name}" do
16
18
  assert_raises(Chess::IllegalMoveError) do
17
19
  Chess::Pgn.new(file, check_moves: true)
18
20
  end
@@ -33,6 +35,7 @@ class ChessTest < Minitest::Test
33
35
  PGN
34
36
  pgn = Chess::Pgn.new
35
37
  pgn.load_from_string(pgn_string, check_moves: true)
38
+
36
39
  assert_equal '70th ch-ITA', pgn.event
37
40
  assert_equal 'Siena ITA', pgn.site
38
41
  assert_equal '10', pgn.round
@@ -57,6 +60,7 @@ class ChessTest < Minitest::Test
57
60
  PGN
58
61
  pgn = Chess::Pgn.new
59
62
  pgn.load_from_string(pgn_string, check_moves: true)
63
+
60
64
  assert_nil pgn.event
61
65
  assert_nil pgn.site
62
66
  assert_nil pgn.round
@@ -80,10 +84,10 @@ class ChessTest < Minitest::Test
80
84
  pgn.white = 'Pioz'
81
85
  pgn.black = 'Elizabeth Harmon'
82
86
  pgn.write(tempfile.path)
83
-
84
87
  loaded_pgn = Chess::Pgn.new
85
88
  loaded_pgn.load(tempfile.path)
86
89
  tempfile.delete
90
+
87
91
  assert_equal 'Ruby Chess Tournament', loaded_pgn.event
88
92
  assert_equal 'Ruby Chess test suite', loaded_pgn.site
89
93
  assert_equal '1984.10.21', loaded_pgn.date
@@ -97,9 +101,11 @@ class ChessTest < Minitest::Test
97
101
  def test_set_date
98
102
  pgn = Chess::Pgn.new
99
103
  pgn.date = Time.parse('21-10-1984')
104
+
100
105
  assert_equal '1984.10.21', pgn.date
101
106
 
102
107
  pgn.date = '1984.10.21'
108
+
103
109
  assert_equal '1984.10.21', pgn.date
104
110
  end
105
111
  end
@@ -3,7 +3,8 @@ require 'test_helper'
3
3
  class ChessTest < Minitest::Test
4
4
  TestHelper.pgns('valid').each do |file|
5
5
  name = File.basename(file, '.pgn')
6
- define_method "test_pgn_#{name}" do
6
+
7
+ define_method :"test_pgn_#{name}" do
7
8
  pgn = Chess::Pgn.new(file)
8
9
  game = Chess::Game.new
9
10
  pgn.moves.each do |m|
@@ -12,9 +13,11 @@ class ChessTest < Minitest::Test
12
13
  assert(game.board.checkmate?) if m.match?(/\#$/)
13
14
  end
14
15
  end
15
- define_method "test_pgn_result_#{name}" do
16
+
17
+ define_method :"test_pgn_result_#{name}" do
16
18
  pgn = Chess::Pgn.new(file)
17
19
  game = Chess::Game.load_pgn(file)
20
+
18
21
  assert_equal(pgn.result, game.result)
19
22
  end
20
23
  end
@@ -3,9 +3,11 @@ require 'test_helper'
3
3
  class ChessTest < Minitest::Test
4
4
  TestHelper.pgns('stalemate').each do |file|
5
5
  name = File.basename(file, '.pgn')
6
- define_method "test_stalemate_#{name}" do
6
+
7
+ define_method :"test_stalemate_#{name}" do
7
8
  pgn = Chess::Pgn.new(file)
8
9
  game = Chess::Game.new(pgn.moves)
10
+
9
11
  assert(game.board.stalemate?)
10
12
  assert_equal('1/2-1/2', game.result)
11
13
  end
@@ -3,9 +3,11 @@ require 'test_helper'
3
3
  class ChessTest < Minitest::Test
4
4
  TestHelper.pgns('threefold_repetition').each do |file|
5
5
  name = File.basename(file, '.pgn')
6
- define_method "test_threefold_repetition_#{name}" do
6
+
7
+ define_method :"test_threefold_repetition_#{name}" do
7
8
  pgn = Chess::Pgn.new(file)
8
9
  game = Chess::Game.new(pgn.moves)
10
+
9
11
  assert game.threefold_repetition?
10
12
  end
11
13
  end
@@ -4,24 +4,28 @@ class UCICastrlingTest < Minitest::Test
4
4
  def test_uci_white_short_castling
5
5
  game = Chess::Game.new
6
6
  game.moves = %w[e4 c5 c3 d5 exd5 Qxd5 d4 Nf6 Nf3 e6 Be2 Be7 e1h1 Nc6]
7
+
7
8
  assert_equal '*', game.result
8
9
  end
9
10
 
10
11
  def test_uci_white_long_castling
11
12
  game = Chess::Game.new
12
13
  game.moves = %w[e4 c5 Nf3 Nc6 d4 cxd4 Nxd4 Nf6 Nc3 d6 Bg5 Qb6 Nb3 e6 Qd2 Be7 e1a1]
14
+
13
15
  assert_equal '*', game.result
14
16
  end
15
17
 
16
18
  def test_uci_black_short_castling
17
19
  game = Chess::Game.new
18
20
  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]
21
+
19
22
  assert_equal '*', game.result
20
23
  end
21
24
 
22
25
  def test_uci_black_long_castling
23
26
  game = Chess::Game.new
24
27
  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]
28
+
25
29
  assert_equal '*', game.result
26
30
  end
27
31
 
@@ -31,4 +35,18 @@ class UCICastrlingTest < Minitest::Test
31
35
  game.moves = %w[e4 c5 Nf3 Nc6 d4 cxd4 Nxd4 Nf6 Nc3 d6 Bg5 Qb6 Nb3 e6 Qd2 Be7 e8a8]
32
36
  end
33
37
  end
38
+
39
+ def test_github_issue31
40
+ g = Chess::Game.load_fen('4Q3/8/8/8/8/8/4K3/7k w - - 0 1')
41
+
42
+ assert_equal 'Q', g.board['e8']
43
+ assert_equal 'K', g.board['e2']
44
+ assert_equal 'k', g.board['h1']
45
+ assert_equal '*', g.result
46
+ assert_equal :in_progress, g.status
47
+
48
+ g << 'e8a8' # It should not be considered as a UCI casting
49
+
50
+ assert_equal 'Q', g.board['a8']
51
+ end
34
52
  end
metadata CHANGED
@@ -1,169 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chess
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrico Pilotto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-26 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '2'
27
- - !ruby/object:Gem::Dependency
28
- name: byebug
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '11'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '11'
41
- - !ruby/object:Gem::Dependency
42
- name: codecov
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '5'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '5'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '13'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '13'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop-minitest
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rubocop-performance
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '1'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '1'
125
- - !ruby/object:Gem::Dependency
126
- name: rubocop-rake
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: simplecov
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: yard
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: 0.9.20
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: 0.9.20
11
+ date: 2024-08-28 00:00:00.000000000 Z
12
+ dependencies: []
167
13
  description: A fast chess library that use bitboards to play chess with Ruby.
168
14
  email:
169
15
  - epilotto@gmx.com
@@ -212,7 +58,6 @@ files:
212
58
  - ext/chess/bitboard.h
213
59
  - ext/chess/board.c
214
60
  - ext/chess/board.h
215
- - ext/chess/chess.bundle
216
61
  - ext/chess/chess.c
217
62
  - ext/chess/chess.h
218
63
  - ext/chess/common.c
@@ -1472,7 +1317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1472
1317
  - !ruby/object:Gem::Version
1473
1318
  version: '0'
1474
1319
  requirements: []
1475
- rubygems_version: 3.4.7
1320
+ rubygems_version: 3.5.11
1476
1321
  signing_key:
1477
1322
  specification_version: 4
1478
1323
  summary: A fast chess library to play chess with Ruby.
Binary file