chessmate 0.8.2 → 0.8.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 +4 -4
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/Gemfile.lock +2 -2
- data/LICENSE +0 -0
- data/README.md +8 -10
- data/lib/chessmate.rb +0 -0
- data/lib/helpers/chess_logger.rb +1 -1
- data/lib/helpers/default.rb +0 -0
- data/lib/helpers/notation_parser.rb +0 -0
- data/lib/pieces/bishop.rb +0 -0
- data/lib/pieces/king.rb +0 -0
- data/lib/pieces/knight.rb +0 -0
- data/lib/pieces/pawn.rb +0 -0
- data/lib/pieces/piece.rb +0 -0
- data/lib/pieces/queen.rb +0 -0
- data/lib/pieces/rook.rb +0 -0
- data/pre-commit.sh +0 -0
- data/spec/chessmate_spec.rb +34 -0
- data/spec/logger_spec.rb +32 -7
- data/spec/notation_parser_spec.rb +0 -0
- data/spec/piece_spec.rb +0 -0
- data/spec/spec_helper.rb +0 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eaacf6aa4d8e0dd9a6b40f01fb136c1fbe50c201fff256d062965dd0e37cea10
|
4
|
+
data.tar.gz: fd4f655e91cbc7fa4c47df3b986ce5e77eb918de29e8bbe9f7c59f093b28d5a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb07a9daa65eeafd1158aebcdcd457700d157cd226b5382c8f9a8a794e6397dced03c4223bbaa6bb42b27a1762f078efec21b640ad09c5eb51b07c2f08006bba
|
7
|
+
data.tar.gz: 3d1e5177494c9a450ffdc87731551f010035aa24a1f1cec37091345ac9ceddbc13bab8cb1ce4561a94ae1a7dd8e2e4d25e86f2131c4a87fe73a4bc8b527e1981
|
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/Gemfile.lock
CHANGED
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -31,13 +31,13 @@ Click [here](http://chessmate-demo.herokuapp.com/) to play with a Rails app runn
|
|
31
31
|
## Usage
|
32
32
|
Simply add ChessMate to your Gemfile:
|
33
33
|
|
34
|
-
```
|
34
|
+
```ruby
|
35
35
|
gem 'chessmate'
|
36
36
|
```
|
37
37
|
|
38
38
|
and then you can require it in a model, controller, etc.
|
39
39
|
|
40
|
-
```
|
40
|
+
```ruby
|
41
41
|
require 'chessmate'
|
42
42
|
```
|
43
43
|
|
@@ -45,13 +45,13 @@ From there, you are free to utilize all the functions and features of ChessMate!
|
|
45
45
|
|
46
46
|
## Building a new game and playing
|
47
47
|
|
48
|
-
```
|
48
|
+
```ruby
|
49
49
|
game = ChessMate.new
|
50
50
|
```
|
51
51
|
|
52
52
|
Moving pieces works based on chess notation: for example, a common first move is `e2` to `e4`. ChessMate accepts these squares as arguments to the `move` method, so you don't need to specify a piece type like in normal chess notation. To make this move in ChessMate:
|
53
53
|
|
54
|
-
```
|
54
|
+
```ruby
|
55
55
|
game.move('e2', 'e4')
|
56
56
|
```
|
57
57
|
|
@@ -59,9 +59,9 @@ If a move is invalid, `ChessMate.move` will return `false`, and the board and ga
|
|
59
59
|
|
60
60
|
Other functions you might call:
|
61
61
|
|
62
|
-
```
|
62
|
+
```ruby
|
63
63
|
game.promote?(square) # Check if a square is capable of pawn promotion
|
64
|
-
game.promote!(square, piece)
|
64
|
+
game.promote!(square, piece) # Promote a promotable pawn, accepts 'rook'/'knight'/'bishop'/'queen'
|
65
65
|
game.in_check? # Determine if either color is currently in check
|
66
66
|
game.checkmate?(color) # Determine if the game is over, accepts 'W'/'B'
|
67
67
|
game.draw?(color) # Same as checkmate, for draw
|
@@ -74,7 +74,7 @@ With ChessMate, it's very easy to build your own custom games. Below is a list o
|
|
74
74
|
|
75
75
|
For instance, for a custom board, on turn 10, with the white king in check:
|
76
76
|
|
77
|
-
```
|
77
|
+
```ruby
|
78
78
|
custom_board = [
|
79
79
|
[nil, nil, nil, nil, 'BK', nil, nil, nil],
|
80
80
|
[nil, nil, nil, nil, 'BQ', nil, nil, nil],
|
@@ -94,7 +94,7 @@ game = ChessMate.new(board: custom_board, turn: turn, in_check: in_check)
|
|
94
94
|
ChessMate can build a game with those parameters!
|
95
95
|
|
96
96
|
Here is a list of all the defaults:
|
97
|
-
```
|
97
|
+
```ruby
|
98
98
|
board: [
|
99
99
|
%w[BR BN BB BQ BK BB BN BR],
|
100
100
|
%w[BP BP BP BP BP BP BP BP],
|
@@ -128,5 +128,3 @@ castling: {
|
|
128
128
|
|
129
129
|
## Contributing
|
130
130
|
ChessMate is open to contributions! If you have a feature request, a bug, or a suggestion, please open an issue! Please note that a review is required and passing TravisCI build before your PR can be merged with master.
|
131
|
-
|
132
|
-
Currently looking to expand ChessMate features by allowing chess notation logging as well as better documentation!
|
data/lib/chessmate.rb
CHANGED
File without changes
|
data/lib/helpers/chess_logger.rb
CHANGED
@@ -73,7 +73,7 @@ class ChessLogger
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def check_or_mate
|
76
|
-
game = ChessMate.new(board: @board, ignore_logging: true)
|
76
|
+
game = ChessMate.new(board: @board, ignore_logging: true, allow_out_of_turn: true)
|
77
77
|
encoded_orig = NotationParser.encode_notation(@orig)
|
78
78
|
encoded_dest = NotationParser.encode_notation(@dest)
|
79
79
|
opposite_color_letter = @piece_color == 'W' ? 'B' : 'W'
|
data/lib/helpers/default.rb
CHANGED
File without changes
|
File without changes
|
data/lib/pieces/bishop.rb
CHANGED
File without changes
|
data/lib/pieces/king.rb
CHANGED
File without changes
|
data/lib/pieces/knight.rb
CHANGED
File without changes
|
data/lib/pieces/pawn.rb
CHANGED
File without changes
|
data/lib/pieces/piece.rb
CHANGED
File without changes
|
data/lib/pieces/queen.rb
CHANGED
File without changes
|
data/lib/pieces/rook.rb
CHANGED
File without changes
|
data/pre-commit.sh
CHANGED
File without changes
|
data/spec/chessmate_spec.rb
CHANGED
@@ -1457,6 +1457,40 @@ describe ChessMate do
|
|
1457
1457
|
chess.promote!([0, 0], 'queen')
|
1458
1458
|
expect(chess.move_history[-1]).to eql('a8=(Q)')
|
1459
1459
|
end
|
1460
|
+
|
1461
|
+
context 'check moves' do
|
1462
|
+
it 'logs checks against black' do
|
1463
|
+
board = [
|
1464
|
+
[nil, nil, nil, 'WQ', nil, nil, nil, nil],
|
1465
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
1466
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
1467
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
1468
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
1469
|
+
['WN', nil, nil, nil, nil, nil, nil, nil],
|
1470
|
+
[nil, nil, nil, 'BP', nil, 'BP', nil, nil],
|
1471
|
+
[nil, nil, nil, 'BR', 'BK', 'BR', nil, nil]
|
1472
|
+
]
|
1473
|
+
chess = ChessMate.new(board: board)
|
1474
|
+
chess.move('a3', 'c2')
|
1475
|
+
expect(chess.move_history.last).to eql('Nc2+')
|
1476
|
+
end
|
1477
|
+
|
1478
|
+
it 'logs checks against white' do
|
1479
|
+
board = [
|
1480
|
+
[nil, nil, nil, 'BQ', nil, nil, nil, nil],
|
1481
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
1482
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
1483
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
1484
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
1485
|
+
['BN', nil, nil, nil, nil, nil, nil, nil],
|
1486
|
+
[nil, nil, nil, 'WP', nil, 'WP', nil, nil],
|
1487
|
+
[nil, nil, nil, 'WR', 'WK', 'WR', nil, nil]
|
1488
|
+
]
|
1489
|
+
chess = ChessMate.new(board: board)
|
1490
|
+
chess.move('a3', 'c2')
|
1491
|
+
expect(chess.move_history.last).to eql('Nc2+')
|
1492
|
+
end
|
1493
|
+
end
|
1460
1494
|
end
|
1461
1495
|
end
|
1462
1496
|
|
data/spec/logger_spec.rb
CHANGED
@@ -50,7 +50,7 @@ describe 'ChessLogger' do
|
|
50
50
|
['WR', nil, nil, nil, 'WK', nil, nil, 'WR']
|
51
51
|
]
|
52
52
|
|
53
|
-
@
|
53
|
+
@white_check_board = [
|
54
54
|
[nil, nil, nil, 'BQ', nil, nil, nil, nil],
|
55
55
|
[nil, nil, nil, nil, nil, nil, nil, nil],
|
56
56
|
[nil, nil, nil, nil, nil, nil, nil, nil],
|
@@ -60,6 +60,17 @@ describe 'ChessLogger' do
|
|
60
60
|
[nil, nil, nil, 'WP', nil, 'WP', nil, nil],
|
61
61
|
[nil, nil, nil, 'WR', 'WK', 'WR', nil, nil]
|
62
62
|
]
|
63
|
+
|
64
|
+
@black_check_board = [
|
65
|
+
[nil, nil, nil, 'WQ', nil, nil, nil, nil],
|
66
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
67
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
68
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
69
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
70
|
+
['WN', nil, nil, nil, nil, nil, nil, nil],
|
71
|
+
[nil, nil, nil, 'BP', nil, 'BP', nil, nil],
|
72
|
+
[nil, nil, nil, 'BR', 'BK', 'BR', nil, nil]
|
73
|
+
]
|
63
74
|
end
|
64
75
|
|
65
76
|
context 'pawn moves' do
|
@@ -169,14 +180,28 @@ describe 'ChessLogger' do
|
|
169
180
|
end
|
170
181
|
|
171
182
|
context 'game status indications' do
|
172
|
-
|
173
|
-
|
174
|
-
|
183
|
+
context 'for white' do
|
184
|
+
it 'should log check' do
|
185
|
+
logger = ChessLogger.new([5, 0], [6, 2], @white_check_board)
|
186
|
+
expect(logger.log_move).to eql('Nc2+')
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'should log checkmate' do
|
190
|
+
logger = ChessLogger.new([0, 3], [0, 4], @white_check_board)
|
191
|
+
expect(logger.log_move).to eql('Qe8#')
|
192
|
+
end
|
175
193
|
end
|
176
194
|
|
177
|
-
|
178
|
-
|
179
|
-
|
195
|
+
context 'for black' do
|
196
|
+
it 'should log check' do
|
197
|
+
logger = ChessLogger.new([5, 0], [6, 2], @black_check_board)
|
198
|
+
expect(logger.log_move).to eql('Nc2+')
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should log checkmate' do
|
202
|
+
logger = ChessLogger.new([0, 3], [0, 4], @black_check_board)
|
203
|
+
expect(logger.log_move).to eql('Qe8#')
|
204
|
+
end
|
180
205
|
end
|
181
206
|
end
|
182
207
|
end
|
File without changes
|
data/spec/piece_spec.rb
CHANGED
File without changes
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chessmate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Porter
|
@@ -121,15 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 2.5.8
|
125
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
127
|
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
|
-
|
132
|
-
rubygems_version: 2.7.6.2
|
131
|
+
rubygems_version: 3.0.3
|
133
132
|
signing_key:
|
134
133
|
specification_version: 4
|
135
134
|
summary: Chess for Rails
|