ruby-chess 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/game.rb +2 -2
- data/test/game_test.rb +0 -6
- data/test/undo_test.rb +40 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1b894b21c69fe96008a3f0aa9d278b088922def
|
4
|
+
data.tar.gz: 83a5adfcd584129560509a38d4f77b330415a47b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83ab88ae8b33c15e38c7f5cef45bee2f16fc906b324a6eb2b7d6e5f5134be7e17b02d3a560325387cc4ad7d64ab78815c3c938efd74a3d27e3d7bf3ee41cecff
|
7
|
+
data.tar.gz: 280b21f9bb99c26c06c2906a80a18e7dc47615da1005f79d7d251302682b8157d6ba6cf07d09b903093b36126d370bbf3f2e2e0d325b5ba118e9ca75500b7063
|
data/lib/game.rb
CHANGED
@@ -23,8 +23,8 @@ class Game
|
|
23
23
|
|
24
24
|
def undo
|
25
25
|
move = @moves.pop
|
26
|
-
piece = at(*move[:piece][:
|
27
|
-
new_piece = piece.class.new(*move[:piece][:
|
26
|
+
piece = at(*move[:piece][:point_b])
|
27
|
+
new_piece = piece.class.new(*move[:piece][:point_a])
|
28
28
|
capture = move[:capture]
|
29
29
|
|
30
30
|
@board.remove(piece)
|
data/test/game_test.rb
CHANGED
@@ -31,12 +31,6 @@ class GameTest < Minitest::Test
|
|
31
31
|
assert_kind_of BlackPawn, this_game.at(6,5)
|
32
32
|
end
|
33
33
|
|
34
|
-
def test_game_can_undo_moves
|
35
|
-
game = white_in_check
|
36
|
-
2.times {game.undo}
|
37
|
-
assert_kind_of EmptySpace, game.at(1,3)
|
38
|
-
end
|
39
|
-
|
40
34
|
def test_cannot_play_while_in_check
|
41
35
|
game = white_in_check
|
42
36
|
assert_raises(Game::IllegalMove) do
|
data/test/undo_test.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative '../lib/chess'
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
class UndoTest < Minitest::Test
|
6
|
+
|
7
|
+
def white_in_check
|
8
|
+
game = Game.new
|
9
|
+
game.play([4,1],[4,3])
|
10
|
+
game.play([3,6],[3,5])
|
11
|
+
game.play([6,1],[6,3])
|
12
|
+
game.play([2,7],[6,3])
|
13
|
+
game
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_game_can_undo_moves
|
17
|
+
game = white_in_check
|
18
|
+
2.times {game.undo}
|
19
|
+
assert_kind_of EmptySpace, game.at(6,3)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_undo_adds_removed_pieces
|
23
|
+
game = Game.new
|
24
|
+
game.play([4,1],[4,3])
|
25
|
+
game.play([3,6],[3,4])
|
26
|
+
game.play([4,3],[3,4])
|
27
|
+
game.undo
|
28
|
+
assert_kind_of BlackPawn, game.at(3,4)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_undo_reverses_the_last_move
|
32
|
+
game = Game.new
|
33
|
+
game.play([4,1],[4,3])
|
34
|
+
game.play([3,6],[3,4])
|
35
|
+
game.play([4,3],[3,4])
|
36
|
+
game.undo
|
37
|
+
assert_kind_of WhitePawn, game.at(4,3)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-chess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jphager2
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- test/pawn_test.rb
|
42
42
|
- test/queen_test.rb
|
43
43
|
- test/rook_test.rb
|
44
|
+
- test/undo_test.rb
|
44
45
|
homepage: https://github.com/jphager2/chess
|
45
46
|
licenses:
|
46
47
|
- MIT
|