chess 0.3.2 → 0.3.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c0769e70cd986cfb2f23d8f8eb2551cd72745e35dc5cde6832bbab0d35015d5
4
- data.tar.gz: 9dd9e4fa0b620f8905e46d33ed6969a09a896e07018d3857dec3926e6da2571b
3
+ metadata.gz: 00f424b92a6c4551574198f0f90be9b15a868ff51793e78c2d203b757ad7c735
4
+ data.tar.gz: 2fe26a9a27b7a2ab68745ed8469dd3a0fe4a0222a33662e0f1a669b7ecd8c9db
5
5
  SHA512:
6
- metadata.gz: d6bb94f4bc3a86cfb593c0e2c233bf75887c1c10be1f968d9dcc4e169e5add14dd18624c9d2932284e6f4fcacdf43fabb65457575fa29a7d308f7366d6f6d227
7
- data.tar.gz: e68c4d62784204158e9829c85265fb354357b30af59cfdc790eeea498fb93e88c136712e6b61979017488a0a14836a2a07ac7c90dc091ad2bf5dcc739c9d5845
6
+ metadata.gz: 1f595f0999604ca4599c178276e54dbd0394f3c637116958c89887b452ece5d8b43fa9e3930a08577d922b35edcbbf95a86a0314dc8a5ee5aee22e522a5e2069
7
+ data.tar.gz: 151b85e0ea1605ede20d1d8615903b6ccc2a51586ab5ab309405d70c4d3af1d9b64f3745859b0df5740101168f511288c64f1eed5b41ea131e1014409671523e
@@ -18,7 +18,7 @@ jobs:
18
18
  runs-on: ubuntu-latest
19
19
  strategy:
20
20
  matrix:
21
- ruby-version: ['2.5', '2.6', '2.7', '3.0']
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.5', '2.6', '2.7', '3.0']
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
@@ -1,6 +1,7 @@
1
1
  *.gem
2
2
  .bundle
3
3
  .byebug_history
4
+ .ruby-version
4
5
  .yardoc/
5
6
  coverage/
6
7
  ext/chess
data/.rubocop.yml CHANGED
@@ -29,6 +29,9 @@ Metrics/MethodLength:
29
29
  Metrics/PerceivedComplexity:
30
30
  Max: 20
31
31
 
32
+ Minitest/AssertPredicate:
33
+ Enabled: false
34
+
32
35
  Minitest/MultipleAssertions:
33
36
  Enabled: false
34
37
 
data/Gemfile.lock CHANGED
@@ -1,51 +1,55 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chess (0.3.2)
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.4.2)
11
+ codecov (0.6.0)
12
12
  simplecov (>= 0.15, < 0.22)
13
- docile (1.3.5)
14
- minitest (5.14.3)
15
- parallel (1.20.1)
16
- parser (3.0.0.0)
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.0.0)
19
- rake (13.0.3)
20
- regexp_parser (2.0.3)
21
- rexml (3.2.4)
22
- rubocop (1.8.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.0.0.0)
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.2.0, < 2.0)
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.4.1)
32
- parser (>= 2.7.1.5)
33
- rubocop-minitest (0.10.3)
34
- rubocop (>= 0.87, < 2.0)
35
- rubocop-performance (1.9.2)
36
- rubocop (>= 0.90.0, < 2.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)
37
39
  rubocop-ast (>= 0.4.0)
38
- rubocop-rake (0.5.1)
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.2)
47
- unicode-display_width (2.0.0)
48
- yard (0.9.26)
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.4)
63
+ codecov (~> 0)
60
64
  minitest (~> 5)
61
65
  rake (~> 13)
62
66
  rubocop (~> 1)
63
- rubocop-minitest (~> 0.10)
67
+ rubocop-minitest (~> 0)
64
68
  rubocop-performance (~> 1)
65
- rubocop-rake (~> 0.5)
66
- simplecov (~> 0.21)
67
- yard (~> 0.9)
69
+ rubocop-rake (~> 0)
70
+ simplecov (~> 0)
71
+ yard (>= 0.9.20)
68
72
 
69
73
  BUNDLED WITH
70
- 2.2.7
74
+ 2.3.8
data/README.md CHANGED
@@ -34,7 +34,7 @@ end
34
34
  puts g.status
35
35
  ```
36
36
 
37
- **Documentation** is available **[here](http://pioz.github.com/chess)**.
37
+ **Documentation** is available **[here](http://pioz.github.io/chess)**.
38
38
 
39
39
  ## Questions or problems?
40
40
 
data/Rakefile CHANGED
@@ -14,5 +14,5 @@ task default: :test
14
14
  Rake::TestTask.new do |test|
15
15
  test.libs << 'test'
16
16
  test.warning = true
17
- test.test_files = FileList["test/test_#{ENV['T'] || '*'}.rb"]
17
+ test.test_files = FileList["test/test_#{ENV.fetch('T', '*')}.rb"]
18
18
  end
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.4'
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.10'
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.5'
30
- s.add_development_dependency 'simplecov', '~> 0.21'
31
- s.add_development_dependency 'yard', '~> 0.9'
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
- elsif SHORT_CASTLING_REGEXP.match?(notation)
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
- elsif LONG_CASTLING_REGEXP.match?(notation)
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.open(filename, 'r').read
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.open(filename, 'w') { |f| f.write(self.to_s) }
101
+ File.write(filename, self.to_s)
102
102
  end
103
103
 
104
104
  # # @!visibility private
@@ -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
@@ -1,5 +1,5 @@
1
1
  # The Chess library module.
2
2
  module Chess
3
3
  # The library version.
4
- VERSION = '0.3.2'.freeze
4
+ VERSION = '0.3.3'.freeze
5
5
  end
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
- assert '1-0', game.result
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
- assert '0-1', game.result
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