chess 0.3.2 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +3 -3
- data/.gitignore +5 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +35 -31
- data/README.md +1 -1
- data/Rakefile +3 -3
- data/chess.gemspec +9 -9
- data/ext/chess/chess.bundle +0 -0
- data/ext/{chess.c → chess/chess.c} +1 -0
- data/lib/chess/game.rb +18 -4
- data/lib/chess/pgn.rb +3 -3
- data/lib/chess/utf8_notation.rb +0 -3
- data/lib/chess/version.rb +1 -1
- data/lib/chess.rb +13 -5
- data/test/test_game.rb +2 -2
- data/test/test_uci_castling.rb +34 -0
- metadata +35 -1254
- /data/ext/{MakefileC → chess/MakefileC} +0 -0
- /data/ext/{bitboard.c → chess/bitboard.c} +0 -0
- /data/ext/{bitboard.h → chess/bitboard.h} +0 -0
- /data/ext/{board.c → chess/board.c} +0 -0
- /data/ext/{board.h → chess/board.h} +0 -0
- /data/ext/{chess.h → chess/chess.h} +0 -0
- /data/ext/{common.c → chess/common.c} +0 -0
- /data/ext/{common.h → chess/common.h} +0 -0
- /data/ext/{extconf.rb → chess/extconf.rb} +0 -0
- /data/ext/{game.c → chess/game.c} +0 -0
- /data/ext/{game.h → chess/game.h} +0 -0
- /data/ext/{special.c → chess/special.c} +0 -0
- /data/ext/{special.h → chess/special.h} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36668063cb71d331dbb172611791d43e0b5d465c0cd9e87baf80bc35cf11e551
|
4
|
+
data.tar.gz: 516ebc6fb472885ec871c6fbd955f489a6afec26c52250a9612210e61f6ce883
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3e811ed0ac4ad177ef1991cd38bbabf84b2139a8d12ea18b0f251621ed744cc54afe9252b489874a6f121551899a5382cffff67158281ca6ce64b5fe0ce2b61
|
7
|
+
data.tar.gz: cad20b859cc7c41b4dfba6b92e0de8bc14317b86f0e4ffeb9f656819a2f507160534eeca6c0944a251964bf2d8ec20fc199548c50d293cf4f7a1c6b64797ae3c
|
data/.github/workflows/ruby.yml
CHANGED
@@ -18,7 +18,7 @@ jobs:
|
|
18
18
|
runs-on: ubuntu-latest
|
19
19
|
strategy:
|
20
20
|
matrix:
|
21
|
-
ruby-version: ['2.
|
21
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
|
22
22
|
|
23
23
|
steps:
|
24
24
|
- uses: actions/checkout@v2
|
@@ -28,7 +28,7 @@ jobs:
|
|
28
28
|
ruby-version: ${{ matrix.ruby-version }}
|
29
29
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
30
30
|
- name: Compile extension
|
31
|
-
working-directory: ./ext
|
31
|
+
working-directory: ./ext/chess
|
32
32
|
run: |
|
33
33
|
ruby extconf.rb
|
34
34
|
make
|
@@ -45,7 +45,7 @@ jobs:
|
|
45
45
|
runs-on: ubuntu-latest
|
46
46
|
strategy:
|
47
47
|
matrix:
|
48
|
-
ruby-version: ['2.
|
48
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
|
49
49
|
|
50
50
|
steps:
|
51
51
|
- uses: actions/checkout@v2
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,51 +1,55 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
chess (0.3.
|
4
|
+
chess (0.3.4)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
10
|
byebug (11.1.3)
|
11
|
-
codecov (0.
|
11
|
+
codecov (0.6.0)
|
12
12
|
simplecov (>= 0.15, < 0.22)
|
13
|
-
docile (1.
|
14
|
-
|
15
|
-
|
16
|
-
|
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)
|
17
18
|
ast (~> 2.4.1)
|
18
|
-
rainbow (3.
|
19
|
-
rake (13.0.
|
20
|
-
regexp_parser (2.0
|
21
|
-
rexml (3.2.
|
22
|
-
rubocop (1.
|
19
|
+
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)
|
24
|
+
json (~> 2.3)
|
23
25
|
parallel (~> 1.10)
|
24
|
-
parser (>= 3.
|
26
|
+
parser (>= 3.1.0.0)
|
25
27
|
rainbow (>= 2.2.2, < 4.0)
|
26
28
|
regexp_parser (>= 1.8, < 3.0)
|
27
|
-
rexml
|
28
|
-
rubocop-ast (>= 1.
|
29
|
+
rexml (>= 3.2.5, < 4.0)
|
30
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
29
31
|
ruby-progressbar (~> 1.7)
|
30
32
|
unicode-display_width (>= 1.4.0, < 3.0)
|
31
|
-
rubocop-ast (1.
|
32
|
-
parser (>=
|
33
|
-
rubocop-minitest (0.
|
34
|
-
rubocop (>= 0.
|
35
|
-
rubocop-performance (1.
|
36
|
-
rubocop (>=
|
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)
|
37
39
|
rubocop-ast (>= 0.4.0)
|
38
|
-
rubocop-rake (0.
|
39
|
-
rubocop
|
40
|
+
rubocop-rake (0.6.0)
|
41
|
+
rubocop (~> 1.0)
|
40
42
|
ruby-progressbar (1.11.0)
|
41
43
|
simplecov (0.21.2)
|
42
44
|
docile (~> 1.1)
|
43
45
|
simplecov-html (~> 0.11)
|
44
46
|
simplecov_json_formatter (~> 0.1)
|
45
47
|
simplecov-html (0.12.3)
|
46
|
-
simplecov_json_formatter (0.1.
|
47
|
-
unicode-display_width (2.
|
48
|
-
|
48
|
+
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)
|
49
53
|
|
50
54
|
PLATFORMS
|
51
55
|
ruby
|
@@ -56,15 +60,15 @@ DEPENDENCIES
|
|
56
60
|
bundler (~> 2)
|
57
61
|
byebug (~> 11)
|
58
62
|
chess!
|
59
|
-
codecov (~> 0
|
63
|
+
codecov (~> 0)
|
60
64
|
minitest (~> 5)
|
61
65
|
rake (~> 13)
|
62
66
|
rubocop (~> 1)
|
63
|
-
rubocop-minitest (~> 0
|
67
|
+
rubocop-minitest (~> 0)
|
64
68
|
rubocop-performance (~> 1)
|
65
|
-
rubocop-rake (~> 0
|
66
|
-
simplecov (~> 0
|
67
|
-
yard (
|
69
|
+
rubocop-rake (~> 0)
|
70
|
+
simplecov (~> 0)
|
71
|
+
yard (>= 0.9.20)
|
68
72
|
|
69
73
|
BUNDLED WITH
|
70
|
-
2.
|
74
|
+
2.3.8
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'bundler/gem_tasks'
|
|
2
2
|
|
3
3
|
require 'yard'
|
4
4
|
YARD::Rake::YardocTask.new do |t|
|
5
|
-
t.files = ['lib/**/*.rb', 'ext
|
5
|
+
t.files = ['lib/**/*.rb', 'ext/**/*.c']
|
6
6
|
t.options << '-rREADME.md'
|
7
7
|
t.options << '--title=Chess'
|
8
8
|
t.options << '-mmarkdown'
|
@@ -12,7 +12,7 @@ end
|
|
12
12
|
require 'rake/testtask'
|
13
13
|
task default: :test
|
14
14
|
Rake::TestTask.new do |test|
|
15
|
-
test.libs
|
15
|
+
test.libs += %w[ext lib test]
|
16
16
|
test.warning = true
|
17
|
-
test.test_files = FileList["test/test_#{ENV
|
17
|
+
test.test_files = FileList["test/test_#{ENV.fetch('T', '*')}.rb"]
|
18
18
|
end
|
data/chess.gemspec
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'chess/version'
|
1
|
+
require_relative 'lib/chess/version'
|
3
2
|
|
4
3
|
Gem::Specification.new do |s|
|
5
4
|
s.name = 'chess'
|
@@ -12,21 +11,22 @@ Gem::Specification.new do |s|
|
|
12
11
|
s.license = 'LGPLv3'
|
13
12
|
|
14
13
|
s.files = `git ls-files`.split("\n")
|
15
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
14
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
17
|
-
s.extensions = ['ext/extconf.rb']
|
15
|
+
s.extensions = ['ext/chess/extconf.rb']
|
18
16
|
s.require_paths = ['lib']
|
19
17
|
|
18
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
19
|
+
|
20
20
|
s.required_ruby_version = '>= 2.5'
|
21
21
|
s.add_development_dependency 'bundler', '~> 2'
|
22
22
|
s.add_development_dependency 'byebug', '~> 11'
|
23
|
-
s.add_development_dependency 'codecov', '~> 0
|
23
|
+
s.add_development_dependency 'codecov', '~> 0'
|
24
24
|
s.add_development_dependency 'minitest', '~> 5'
|
25
25
|
s.add_development_dependency 'rake', '~> 13'
|
26
26
|
s.add_development_dependency 'rubocop', '~> 1'
|
27
|
-
s.add_development_dependency 'rubocop-minitest', '~> 0
|
27
|
+
s.add_development_dependency 'rubocop-minitest', '~> 0'
|
28
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', '
|
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
32
|
end
|
Binary file
|
@@ -716,6 +716,7 @@ Init_chess ()
|
|
716
716
|
* This ensures a fast library.
|
717
717
|
*/
|
718
718
|
board_klass = rb_define_class_under (chess, "Board", rb_cObject);
|
719
|
+
rb_undef_alloc_func (board_klass);
|
719
720
|
rb_define_method (board_klass, "placement", board_placement, 0);
|
720
721
|
rb_define_method (board_klass, "[]", board_get_piece, 1);
|
721
722
|
rb_define_method (board_klass, "check?", board_king_in_check, 0);
|
data/lib/chess/game.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../../ext/chess')
|
2
|
-
|
3
1
|
module Chess
|
4
2
|
# This class rappresents a chess game.
|
5
3
|
class Game < CGame
|
@@ -155,16 +153,32 @@ module Chess
|
|
155
153
|
promotion: match[4] # Promote with
|
156
154
|
}
|
157
155
|
expand[:from] = match[2] if match[2] && match[2].size == 2
|
156
|
+
|
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
|
166
|
+
|
158
167
|
return expand
|
159
|
-
|
168
|
+
end
|
169
|
+
|
170
|
+
# Castling notation
|
171
|
+
if SHORT_CASTLING_REGEXP.match?(notation)
|
160
172
|
return { name: 'K', dis: nil, from: 'e8', to: 'g8', promotion: nil } if self.board.active_color # black king short castling
|
161
173
|
|
162
174
|
return { name: 'K', dis: nil, from: 'e1', to: 'g1', promotion: nil } # white king short castling
|
163
|
-
|
175
|
+
end
|
176
|
+
if LONG_CASTLING_REGEXP.match?(notation)
|
164
177
|
return { name: 'K', dis: nil, from: 'e8', to: 'c8', promotion: nil } if self.board.active_color # black king long castling
|
165
178
|
|
166
179
|
return { name: 'K', dis: nil, from: 'e1', to: 'c1', promotion: nil } # white king long castling
|
167
180
|
end
|
181
|
+
|
168
182
|
raise BadNotationError.new(notation)
|
169
183
|
end
|
170
184
|
end
|
data/lib/chess/pgn.rb
CHANGED
@@ -49,7 +49,7 @@ module Chess
|
|
49
49
|
# @raise [InvalidPgnFormatError]
|
50
50
|
# @raise [IllegalMoveError]
|
51
51
|
def load(filename, check_moves: false)
|
52
|
-
str = File.
|
52
|
+
str = File.read(filename)
|
53
53
|
load_from_string(str, check_moves: check_moves)
|
54
54
|
end
|
55
55
|
|
@@ -88,7 +88,7 @@ module Chess
|
|
88
88
|
s << "\n"
|
89
89
|
m = ''
|
90
90
|
@moves.each_with_index do |move, i|
|
91
|
-
m << "#{i / 2 + 1}. " if i.even?
|
91
|
+
m << "#{(i / 2) + 1}. " if i.even?
|
92
92
|
m << "#{move} "
|
93
93
|
end
|
94
94
|
m << @result unless @result.nil?
|
@@ -98,7 +98,7 @@ module Chess
|
|
98
98
|
# Write PGN to file.
|
99
99
|
# @param [String] filename The path of the PGN file.
|
100
100
|
def write(filename)
|
101
|
-
File.
|
101
|
+
File.write(filename, self.to_s)
|
102
102
|
end
|
103
103
|
|
104
104
|
# # @!visibility private
|
data/lib/chess/utf8_notation.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
module Chess
|
2
|
-
# rubocop:disable Style/AsciiComments
|
3
|
-
|
4
2
|
# With this module is possible call the method {#to_utf8} on a string. This
|
5
3
|
# method convert the chess piece identifier character into UTF8 chess
|
6
4
|
# character.
|
@@ -36,7 +34,6 @@ module Chess
|
|
36
34
|
self.gsub(/[PRNBQKprnbqk]/, UTF8_MAP)
|
37
35
|
end
|
38
36
|
end
|
39
|
-
# rubocop:enable Style/AsciiComments
|
40
37
|
end
|
41
38
|
|
42
39
|
String.prepend(Chess::UTF8Notation)
|
data/lib/chess/version.rb
CHANGED
data/lib/chess.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
|
-
require 'chess/
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require 'chess/chess' # this is the compiled ruby extension (chess.so or chess.bundle)
|
2
|
+
require_relative 'chess/exceptions'
|
3
|
+
require_relative 'chess/game'
|
4
|
+
require_relative 'chess/gnuchess'
|
5
|
+
require_relative 'chess/pgn'
|
6
|
+
require_relative 'chess/version'
|
7
|
+
|
8
|
+
# While development to require 'chess' from irb run with `irb -I lib:ext`
|
9
|
+
# $ irb -I lib:ext
|
10
|
+
# irb(main):001:0> require 'chess'
|
11
|
+
# => true
|
12
|
+
# irb(main):002:0> Chess::Game.new
|
13
|
+
# => #<Chess::Game:0x0000000000000001>
|
data/test/test_game.rb
CHANGED
@@ -24,7 +24,7 @@ class ChessTest < Minitest::Test
|
|
24
24
|
game.resign(:black)
|
25
25
|
assert_equal :white_won_resign, game.status
|
26
26
|
assert game.over?
|
27
|
-
|
27
|
+
assert_equal '1-0', game.result
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_status_black_won_resign
|
@@ -33,7 +33,7 @@ class ChessTest < Minitest::Test
|
|
33
33
|
game.resign(:white)
|
34
34
|
assert_equal :black_won_resign, game.status
|
35
35
|
assert game.over?
|
36
|
-
|
36
|
+
assert_equal '0-1', game.result
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_status_insufficient_material
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UCICastrlingTest < Minitest::Test
|
4
|
+
def test_uci_white_short_castling
|
5
|
+
game = Chess::Game.new
|
6
|
+
game.moves = %w[e4 c5 c3 d5 exd5 Qxd5 d4 Nf6 Nf3 e6 Be2 Be7 e1h1 Nc6]
|
7
|
+
assert_equal '*', game.result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_uci_white_long_castling
|
11
|
+
game = Chess::Game.new
|
12
|
+
game.moves = %w[e4 c5 Nf3 Nc6 d4 cxd4 Nxd4 Nf6 Nc3 d6 Bg5 Qb6 Nb3 e6 Qd2 Be7 e1a1]
|
13
|
+
assert_equal '*', game.result
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_uci_black_short_castling
|
17
|
+
game = Chess::Game.new
|
18
|
+
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]
|
19
|
+
assert_equal '*', game.result
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_uci_black_long_castling
|
23
|
+
game = Chess::Game.new
|
24
|
+
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]
|
25
|
+
assert_equal '*', game.result
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_uci_invalid_white_long_castling
|
29
|
+
game = Chess::Game.new
|
30
|
+
assert_raises(Chess::IllegalMoveError) do
|
31
|
+
game.moves = %w[e4 c5 Nf3 Nc6 d4 cxd4 Nxd4 Nf6 Nc3 d6 Bg5 Qb6 Nb3 e6 Qd2 Be7 e8a8]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|