chess 0.3.2 → 0.3.3
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 +2 -2
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +35 -31
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/chess.gemspec +7 -6
- data/lib/chess/game.rb +18 -2
- data/lib/chess/pgn.rb +3 -3
- data/lib/chess/utf8_notation.rb +0 -3
- data/lib/chess/version.rb +1 -1
- data/test/test_game.rb +2 -2
- data/test/test_uci_castling.rb +34 -0
- metadata +19 -1239
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00f424b92a6c4551574198f0f90be9b15a868ff51793e78c2d203b757ad7c735
|
4
|
+
data.tar.gz: 2fe26a9a27b7a2ab68745ed8469dd3a0fe4a0222a33662e0f1a669b7ecd8c9db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f595f0999604ca4599c178276e54dbd0394f3c637116958c89887b452ece5d8b43fa9e3930a08577d922b35edcbbf95a86a0314dc8a5ee5aee22e522a5e2069
|
7
|
+
data.tar.gz: 151b85e0ea1605ede20d1d8615903b6ccc2a51586ab5ab309405d70c4d3af1d9b64f3745859b0df5740101168f511288c64f1eed5b41ea131e1014409671523e
|
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']
|
22
22
|
|
23
23
|
steps:
|
24
24
|
- uses: actions/checkout@v2
|
@@ -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']
|
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.3)
|
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
data/chess.gemspec
CHANGED
@@ -12,21 +12,22 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.license = 'LGPLv3'
|
13
13
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
17
16
|
s.extensions = ['ext/extconf.rb']
|
18
17
|
s.require_paths = ['lib']
|
19
18
|
|
19
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
20
|
+
|
20
21
|
s.required_ruby_version = '>= 2.5'
|
21
22
|
s.add_development_dependency 'bundler', '~> 2'
|
22
23
|
s.add_development_dependency 'byebug', '~> 11'
|
23
|
-
s.add_development_dependency 'codecov', '~> 0
|
24
|
+
s.add_development_dependency 'codecov', '~> 0'
|
24
25
|
s.add_development_dependency 'minitest', '~> 5'
|
25
26
|
s.add_development_dependency 'rake', '~> 13'
|
26
27
|
s.add_development_dependency 'rubocop', '~> 1'
|
27
|
-
s.add_development_dependency 'rubocop-minitest', '~> 0
|
28
|
+
s.add_development_dependency 'rubocop-minitest', '~> 0'
|
28
29
|
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', '
|
30
|
+
s.add_development_dependency 'rubocop-rake', '~> 0'
|
31
|
+
s.add_development_dependency 'simplecov', '~> 0'
|
32
|
+
s.add_development_dependency 'yard', '>= 0.9.20'
|
32
33
|
end
|
data/lib/chess/game.rb
CHANGED
@@ -155,16 +155,32 @@ module Chess
|
|
155
155
|
promotion: match[4] # Promote with
|
156
156
|
}
|
157
157
|
expand[:from] = match[2] if match[2] && match[2].size == 2
|
158
|
+
|
159
|
+
# Support UCI protocol (Lichess)
|
160
|
+
case expand[:from]
|
161
|
+
when 'e1'
|
162
|
+
expand[:to] = 'g1' if expand[:to] == 'h1' # UCI protocol (Lichess) white king short castling
|
163
|
+
expand[:to] = 'c1' if expand[:to] == 'a1' # UCI protocol (Lichess) white king long castling
|
164
|
+
when 'e8'
|
165
|
+
expand[:to] = 'g8' if expand[:to] == 'h8' # UCI protocol (Lichess) black king short castling
|
166
|
+
expand[:to] = 'c8' if expand[:to] == 'a8' # UCI protocol (Lichess) black king long castling
|
167
|
+
end
|
168
|
+
|
158
169
|
return expand
|
159
|
-
|
170
|
+
end
|
171
|
+
|
172
|
+
# Castling notation
|
173
|
+
if SHORT_CASTLING_REGEXP.match?(notation)
|
160
174
|
return { name: 'K', dis: nil, from: 'e8', to: 'g8', promotion: nil } if self.board.active_color # black king short castling
|
161
175
|
|
162
176
|
return { name: 'K', dis: nil, from: 'e1', to: 'g1', promotion: nil } # white king short castling
|
163
|
-
|
177
|
+
end
|
178
|
+
if LONG_CASTLING_REGEXP.match?(notation)
|
164
179
|
return { name: 'K', dis: nil, from: 'e8', to: 'c8', promotion: nil } if self.board.active_color # black king long castling
|
165
180
|
|
166
181
|
return { name: 'K', dis: nil, from: 'e1', to: 'c1', promotion: nil } # white king long castling
|
167
182
|
end
|
183
|
+
|
168
184
|
raise BadNotationError.new(notation)
|
169
185
|
end
|
170
186
|
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/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
|