ruby-go 0.0.2 → 0.1.0
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 +12 -4
- data/lib/stone.rb +4 -3
- data/test/go_test.rb +1 -27
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e3d4d105a75e4217d5c4c626899d08084d7bb2a
|
4
|
+
data.tar.gz: 1b78f5368e9e2bd0f5a0c3c68b3d50007ccf4bd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f46345e4c5a8fa9007b8997aaea6a6eaa47ab64668d176b2d6596f23c44c8a26cdbe33393795424efea50ea5a670eaf56b5434839720207c8b956d89491ef04d
|
7
|
+
data.tar.gz: 2a6498dbc6ae5bb58daac3db170e96d3c67afe314d66c614f9c065211130607a203dd1e6ba05ce4ca46403949781d2ee66da1e61113792a920bbf013973e435a
|
data/lib/game.rb
CHANGED
@@ -14,7 +14,7 @@ class Game
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_sgf
|
17
|
-
sgf = "(;GM[1]FF[4]CA[UTF-8]AP[jphager2]SZ[
|
17
|
+
sgf = "(;GM[1]FF[4]CA[UTF-8]AP[jphager2]SZ[#{board.size}]PW[White]PB[Black]"
|
18
18
|
|
19
19
|
@moves.each do |move|
|
20
20
|
sgf << move[:stone].to_sgf
|
@@ -39,8 +39,12 @@ class Game
|
|
39
39
|
play(WhiteStone.new(x,y))
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
43
|
-
|
42
|
+
def black_pass
|
43
|
+
pass(:black)
|
44
|
+
end
|
45
|
+
|
46
|
+
def white_pass
|
47
|
+
pass(:white)
|
44
48
|
end
|
45
49
|
|
46
50
|
def undo
|
@@ -62,6 +66,10 @@ class Game
|
|
62
66
|
end
|
63
67
|
|
64
68
|
private
|
69
|
+
def pass(color)
|
70
|
+
@moves << {stone: NullStone.new(color), captures: [], pass: true}
|
71
|
+
end
|
72
|
+
|
65
73
|
def play(stone)
|
66
74
|
@board.place(stone)
|
67
75
|
@moves << {stone: stone, captures: [], pass: false}
|
@@ -75,7 +83,7 @@ class Game
|
|
75
83
|
captures = @moves[-2][:captures]
|
76
84
|
stone = @moves.last[:stone]
|
77
85
|
|
78
|
-
if captures
|
86
|
+
if captures.include?(stone)
|
79
87
|
undo
|
80
88
|
raise IllegalMove,
|
81
89
|
"You cannot capture the ko, play a ko threat first"
|
data/lib/stone.rb
CHANGED
@@ -88,14 +88,15 @@ class WhiteStone < Stone
|
|
88
88
|
end
|
89
89
|
|
90
90
|
class NullStone < Stone
|
91
|
-
def initialize(
|
91
|
+
def initialize(color = :empty)
|
92
92
|
@x, @y = nil, nil
|
93
|
+
@color = color
|
93
94
|
end
|
94
95
|
|
95
96
|
def remove_from_board(board)
|
96
97
|
end
|
97
98
|
|
98
|
-
def
|
99
|
-
""
|
99
|
+
def to_sgf
|
100
|
+
";#{color.to_s[0].upcase}[]"
|
100
101
|
end
|
101
102
|
end
|
data/test/go_test.rb
CHANGED
@@ -130,32 +130,6 @@ class GoTest < Minitest::Test
|
|
130
130
|
game.white(4,3)
|
131
131
|
end
|
132
132
|
end
|
133
|
+
end
|
133
134
|
|
134
|
-
def big_capture_area_game
|
135
|
-
game = Game.new
|
136
|
-
game.black(0,0)
|
137
|
-
game.white(1,1)
|
138
|
-
game.black(0,1)
|
139
|
-
game.white(0,2)
|
140
|
-
game.black(1,0)
|
141
|
-
game.white(2,0)
|
142
|
-
game
|
143
|
-
end
|
144
135
|
|
145
|
-
def test_can_play_in_previous_capture_area_that_is_not_a_ko
|
146
|
-
game = big_capture_area_game
|
147
|
-
assert_equal Liberty.new(0,0), game.board.at(0,0)
|
148
|
-
game.black(0,0)
|
149
|
-
assert_equal BlackStone.new(0,0), game.board.at(0,0)
|
150
|
-
|
151
|
-
game = big_capture_area_game
|
152
|
-
assert_equal Liberty.new(0,1), game.board.at(0,1)
|
153
|
-
game.black(0,1)
|
154
|
-
assert_equal BlackStone.new(0,1), game.board.at(0,1)
|
155
|
-
|
156
|
-
game = big_capture_area_game
|
157
|
-
assert_equal Liberty.new(1,0), game.board.at(1,0)
|
158
|
-
game.black(1,0)
|
159
|
-
assert_equal BlackStone.new(1,0), game.board.at(1,0)
|
160
|
-
end
|
161
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-go
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jphager2
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: SgfParser
|