ruby-go 0.0.2 → 0.1.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/game.rb +12 -4
  3. data/lib/stone.rb +4 -3
  4. data/test/go_test.rb +1 -27
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f24b07ee968e8a121f825d7c64e615649b8379e
4
- data.tar.gz: 647b951b33b4394a657ddb1a749b8677ad6497c7
3
+ metadata.gz: 0e3d4d105a75e4217d5c4c626899d08084d7bb2a
4
+ data.tar.gz: 1b78f5368e9e2bd0f5a0c3c68b3d50007ccf4bd5
5
5
  SHA512:
6
- metadata.gz: 365788568b669d24207f3e52c604cf218f5c4e6228ec1316b5847a8e9ceadfd25f2f03807cfba0fc5793c79e88fbceffc3559b471e69c9762c43a7382ca401bb
7
- data.tar.gz: b0c4e34d1cf9482e68322dcc3e9f6bc7b47ae1a6952baa4c7ac47b047599082ccddd05e677f3ec4fd62aa12bf76a4f52e21a8dbbd3b390fd59f80fecc475bf43
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[19]PW[White]PB[Black]"
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 pass
43
- @moves << {stone: NullStone.new(), captures: [], pass: true}
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 == [stone]
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(*args)
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 to_sfg
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.2
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: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: SgfParser