chessmate 0.7.0 → 0.7.1
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/lib/chessmate.rb +13 -13
- data/spec/chessmate_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3eb25de34a44fabc8d5c94cff25979b5664c075c5cc897eb151c4513a749789
|
4
|
+
data.tar.gz: 1ee304bf8f9ca8adb1cfceb143b44abeb6af447539ac1854622237d7b81e2791
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e53760a34c345c7297cd59dbe6f77d06c3ac08f9507d7bdcf06528327199ccbbe808ea65f5103a688268b0b849039a31148ccd1c17b36ad091811d9be3bb89c
|
7
|
+
data.tar.gz: 80089bb5808ab2fcb7f4a2dd8c65ef9500d5dc31759cfbd655c6552179e665698e8910867f2d24c94f4e7deac11f990c7714a34602f9ecfa9f04e7a14521fd8b
|
data/lib/chessmate.rb
CHANGED
@@ -27,14 +27,14 @@ class ChessMate
|
|
27
27
|
@en_passant = en_passant || DeepDup.deep_dup(DEFAULT[:en_passant])
|
28
28
|
@castling = castling || DeepDup.deep_dup(DEFAULT[:castling])
|
29
29
|
@in_check = in_check || DeepDup.deep_dup(DEFAULT[:in_check])
|
30
|
-
|
30
|
+
|
31
31
|
@allow_out_of_turn = if allow_out_of_turn.nil?
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
ENV['TEST'] == 'true' || false
|
33
|
+
elsif [true, false].include?(allow_out_of_turn)
|
34
|
+
allow_out_of_turn
|
35
|
+
else
|
36
|
+
false
|
37
|
+
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def update(orig, dest = nil)
|
@@ -127,9 +127,9 @@ class ChessMate
|
|
127
127
|
|
128
128
|
piece = @board[orig_y][orig_x]
|
129
129
|
piece_type = piece[1]
|
130
|
-
allowed_turn = piece[0] ==
|
130
|
+
allowed_turn = piece[0] == 'W' ? :odd? : :even?
|
131
131
|
|
132
|
-
return false unless @allow_out_of_turn || @turn.send(allowed_turn)
|
132
|
+
return false unless @allow_out_of_turn || @turn.send(allowed_turn) || test
|
133
133
|
|
134
134
|
board = test_board.nil? ? @board : test_board
|
135
135
|
valid_move = case piece_type
|
@@ -148,10 +148,10 @@ class ChessMate
|
|
148
148
|
else
|
149
149
|
false
|
150
150
|
end
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
151
|
+
unless test
|
152
|
+
in_check_after_move = in_check_after_move?(orig_pos, dest_pos)
|
153
|
+
update(orig_pos, dest_pos) if valid_move && !test && !in_check_after_move
|
154
|
+
end
|
155
155
|
|
156
156
|
valid_move && !in_check_after_move
|
157
157
|
end
|
data/spec/chessmate_spec.rb
CHANGED
@@ -217,8 +217,8 @@ describe ChessMate do
|
|
217
217
|
chess = ChessMate.new(allow_out_of_turn: false)
|
218
218
|
expect(chess.move('a7', 'a6')).to eql(false)
|
219
219
|
expect(chess.board).to eql(DEFAULT[:board])
|
220
|
-
expect(chess.move('a2','a3')).to eql(true)
|
221
|
-
expect(chess.move('a3','a4')).to eql(false)
|
220
|
+
expect(chess.move('a2', 'a3')).to eql(true)
|
221
|
+
expect(chess.move('a3', 'a4')).to eql(false)
|
222
222
|
end
|
223
223
|
|
224
224
|
it 'option to allow players to move out of turn' do
|