ruby-go 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/game.rb +4 -12
  3. data/lib/stone.rb +3 -4
  4. data/test/go_test.rb +27 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e3d4d105a75e4217d5c4c626899d08084d7bb2a
4
- data.tar.gz: 1b78f5368e9e2bd0f5a0c3c68b3d50007ccf4bd5
3
+ metadata.gz: 74efecc082ec565b2ffa7c416f8a28497706c895
4
+ data.tar.gz: 5f702299cf817f5fc56d70910b225ecc92879fd8
5
5
  SHA512:
6
- metadata.gz: f46345e4c5a8fa9007b8997aaea6a6eaa47ab64668d176b2d6596f23c44c8a26cdbe33393795424efea50ea5a670eaf56b5434839720207c8b956d89491ef04d
7
- data.tar.gz: 2a6498dbc6ae5bb58daac3db170e96d3c67afe314d66c614f9c065211130607a203dd1e6ba05ce4ca46403949781d2ee66da1e61113792a920bbf013973e435a
6
+ metadata.gz: 1531c446d300958152b41c69c0b05a8f503f90f0bdc35cd041e52f15db2370000971f1b3f2a83acc5a3097a789a4a324a2a3a344979ef1e9a9a0785db7e2a779
7
+ data.tar.gz: 50b2b336a5f64132537ad193a0efe1c1a17867757539a730272fbbe6b4231f87f2eab036fb38ac67531bfcbf20289c8acee094458e84a43c0e5599878b9548eb
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[#{board.size}]PW[White]PB[Black]"
17
+ sgf = "(;GM[1]FF[4]CA[UTF-8]AP[jphager2]SZ[19]PW[White]PB[Black]"
18
18
 
19
19
  @moves.each do |move|
20
20
  sgf << move[:stone].to_sgf
@@ -39,12 +39,8 @@ class Game
39
39
  play(WhiteStone.new(x,y))
40
40
  end
41
41
 
42
- def black_pass
43
- pass(:black)
44
- end
45
-
46
- def white_pass
47
- pass(:white)
42
+ def pass
43
+ @moves << {stone: NullStone.new(), captures: [], pass: true}
48
44
  end
49
45
 
50
46
  def undo
@@ -66,10 +62,6 @@ class Game
66
62
  end
67
63
 
68
64
  private
69
- def pass(color)
70
- @moves << {stone: NullStone.new(color), captures: [], pass: true}
71
- end
72
-
73
65
  def play(stone)
74
66
  @board.place(stone)
75
67
  @moves << {stone: stone, captures: [], pass: false}
@@ -83,7 +75,7 @@ class Game
83
75
  captures = @moves[-2][:captures]
84
76
  stone = @moves.last[:stone]
85
77
 
86
- if captures.include?(stone)
78
+ if captures == [stone]
87
79
  undo
88
80
  raise IllegalMove,
89
81
  "You cannot capture the ko, play a ko threat first"
data/lib/stone.rb CHANGED
@@ -88,15 +88,14 @@ class WhiteStone < Stone
88
88
  end
89
89
 
90
90
  class NullStone < Stone
91
- def initialize(color = :empty)
91
+ def initialize(*args)
92
92
  @x, @y = nil, nil
93
- @color = color
94
93
  end
95
94
 
96
95
  def remove_from_board(board)
97
96
  end
98
97
 
99
- def to_sgf
100
- ";#{color.to_s[0].upcase}[]"
98
+ def to_sfg
99
+ ""
101
100
  end
102
101
  end
data/test/go_test.rb CHANGED
@@ -130,6 +130,32 @@ class GoTest < Minitest::Test
130
130
  game.white(4,3)
131
131
  end
132
132
  end
133
- end
134
133
 
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
135
144
 
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - jphager2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-30 00:00:00.000000000 Z
11
+ date: 2016-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: SgfParser