ruby-chess 0.0.1 → 0.0.2
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/board.rb +2 -2
- data/lib/game.rb +3 -4
- data/test/game_test.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3a4ce154416026e554379b3a5ca09ca1f7b37ac
|
4
|
+
data.tar.gz: 2f4a80afbe2e50cda73bfebbfcf301cbf183bb9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75219a358a760de19304d904ba23861a220afc57e24fb111e9fb92ef866af25ce3590d4e80af11be10f9f1cc633516cb411537c2ccdee40f2741c29a44dd2f9a
|
7
|
+
data.tar.gz: 596000ad217c193bb07402d35cefc435c0f4dbfcabaf9032048bafb1e7b88e553d1e37189eb35d147907cfc2f56721fc824817b3a2c694cd3efc6a2691525dfb
|
data/lib/board.rb
CHANGED
@@ -29,8 +29,8 @@ class Board
|
|
29
29
|
pieces << BlackBishop.new(x,7) << WhiteBishop.new(x,0)
|
30
30
|
end
|
31
31
|
|
32
|
-
pieces << BlackQueen.new(
|
33
|
-
pieces << BlackKing.new(
|
32
|
+
pieces << BlackQueen.new(3,7) << WhiteQueen.new(4,0)
|
33
|
+
pieces << BlackKing.new(4,7) << WhiteKing.new(3,0)
|
34
34
|
|
35
35
|
pieces.each {|piece| place(piece)}
|
36
36
|
end
|
data/lib/game.rb
CHANGED
@@ -3,7 +3,7 @@ class Game
|
|
3
3
|
attr_reader :turn
|
4
4
|
def initialize
|
5
5
|
@board = Board.new
|
6
|
-
@
|
6
|
+
@king_to_check = {black: @board.at(3,0), white: @board.at(4,7)}
|
7
7
|
@moves = []
|
8
8
|
@turn = :white
|
9
9
|
@over = false
|
@@ -52,13 +52,12 @@ class Game
|
|
52
52
|
},
|
53
53
|
capture: at_destination,
|
54
54
|
}
|
55
|
+
switch_turn
|
55
56
|
|
56
|
-
if @
|
57
|
+
if @king_to_check[@turn].checked?(@board)
|
57
58
|
undo
|
58
59
|
raise Game::IllegalMove, "#{@turn}'s king is in check!"
|
59
60
|
end
|
60
|
-
|
61
|
-
switch_turn
|
62
61
|
end
|
63
62
|
|
64
63
|
def resign
|
data/test/game_test.rb
CHANGED
@@ -14,10 +14,10 @@ class GameTest < Minitest::Test
|
|
14
14
|
|
15
15
|
def white_in_check
|
16
16
|
game = Game.new
|
17
|
-
game.play([
|
18
|
-
game.play([
|
19
|
-
game.play([
|
20
|
-
game.play([
|
17
|
+
game.play([4,1],[4,3])
|
18
|
+
game.play([3,6],[3,5])
|
19
|
+
game.play([6,1],[6,3])
|
20
|
+
game.play([2,7],[6,3])
|
21
21
|
game
|
22
22
|
end
|
23
23
|
|
@@ -46,10 +46,10 @@ class GameTest < Minitest::Test
|
|
46
46
|
|
47
47
|
def test_cannot_move_into_check
|
48
48
|
game = white_in_check
|
49
|
-
game.play([
|
49
|
+
game.play([5,1],[5,2])
|
50
50
|
game.play([6,6],[6,5])
|
51
51
|
assert_raises(Game::IllegalMove) do
|
52
|
-
game.play([
|
52
|
+
game.play([5,2],[5,3])
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|