chess_validator 0.2.13 → 0.2.14
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/move_logic.rb +3 -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: ae31a40890e32644ea7bab6a82407dea4d40f155a6557777b401b260b18d41d0
|
4
|
+
data.tar.gz: ce29175b6af41591075e5158488c26bffc4cb92ee040d7389d6f751fa8117679
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc687efb628401bcf9f5f3374b877a4eca8c4d496004dafdff545e66332416565aaa17a988eaf6e83750e39357f2dea684638402f6c641427a0c4460caebefae
|
7
|
+
data.tar.gz: 3fcb3650f113f585147f3afa567134564717f4952af4794de1c0c4b4d3c6cb25ddcd2ae041fc1300c14a45cf1f58279c728578f06aa5b81d220e9774136dce7e
|
data/lib/move_logic.rb
CHANGED
@@ -130,6 +130,7 @@ module ChessValidator
|
|
130
130
|
def king_will_be_safe?(piece, board, move)
|
131
131
|
new_board = with_next_move(piece, board, move)
|
132
132
|
king, occupied_spaces = find_king_and_spaces(new_board, piece.color)
|
133
|
+
return false if king.nil?
|
133
134
|
king_is_safe?(king.color, new_board, king.position, occupied_spaces)
|
134
135
|
end
|
135
136
|
|
@@ -161,7 +162,7 @@ module ChessValidator
|
|
161
162
|
board.values.none? { |piece| [between, move].include?(piece.position) } &&
|
162
163
|
empty_b_square
|
163
164
|
else
|
164
|
-
valid_destination?(king, board, move) &&
|
165
|
+
valid_destination?(king, board, move) && king_will_be_safe?(king, board, move)
|
165
166
|
end
|
166
167
|
end
|
167
168
|
|
@@ -210,7 +211,7 @@ module ChessValidator
|
|
210
211
|
def valid_destination?(piece, board, move)
|
211
212
|
target_piece = find_piece(board, move)
|
212
213
|
if target_piece
|
213
|
-
target_piece.color != piece.color &&
|
214
|
+
target_piece.color != piece.color && target_piece.piece_type.downcase != 'k'
|
214
215
|
else
|
215
216
|
true
|
216
217
|
end
|