1 $:.unshift File.join(File.dirname(__FILE__), "..")
3 require 'test/mock_player'
4 require 'shogi_server/board'
5 require 'shogi_server/game'
6 require 'shogi_server/player'
20 $league = ShogiServer::League.new(File.dirname(__FILE__))
21 $league.event = "test"
23 class TestGame < Test::Unit::TestCase
26 game_name = "hoge-1500-0"
27 board = ShogiServer::Board.new
36 game = ShogiServer::Game.new game_name, p1, p2, board
37 assert_equal "", game.last_move
44 Declaration:Jishogi 1.1
45 Game_ID:#{game.game_id}
58 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
59 P2 * -HI * * * * * -KA *
60 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
64 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
65 P8 * +KA * * * * * +HI *
66 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
71 assert_equal(p1_out, p1.out.first)
78 Declaration:Jishogi 1.1
79 Game_ID:#{game.game_id}
92 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
93 P2 * -HI * * * * * -KA *
94 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
98 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
99 P8 * +KA * * * * * +HI *
100 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
105 assert_equal(p2_out, p2.out.first)
107 file = Pathname.new(game.logfile)
109 assert_equal(<<EOF, log.gsub(/^\$START_TIME.*?\n/,''))
113 $EVENT:#{game.game_id}
114 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
115 P2 * -HI * * * * * -KA *
116 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
120 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
121 P8 * +KA * * * * * +HI *
122 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
127 def test_new_buoy_1_move
128 game_name = "buoyhoge-1500-0"
129 board = ShogiServer::Board.new
130 board.set_from_moves ["+7776FU"]
138 game = ShogiServer::Game.new game_name, p1, p2, board
139 assert_equal "+7776FU,T1", game.last_move
146 Declaration:Jishogi 1.1
147 Game_ID:#{game.game_id}
157 Least_Time_Per_Move:1
160 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
161 P2 * -HI * * * * * -KA *
162 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
166 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
167 P8 * +KA * * * * * +HI *
168 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
174 assert_equal(p1_out, p1.out.first)
181 Declaration:Jishogi 1.1
182 Game_ID:#{game.game_id}
192 Least_Time_Per_Move:1
195 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
196 P2 * -HI * * * * * -KA *
197 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
201 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
202 P8 * +KA * * * * * +HI *
203 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
209 assert_equal(p2_out, p2.out.first)
211 file = Pathname.new(game.logfile)
213 assert_equal(<<EOF, log.gsub(/^\$START_TIME.*?\n/,''))
217 $EVENT:#{game.game_id}
218 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
219 P2 * -HI * * * * * -KA *
220 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
224 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
225 P8 * +KA * * * * * +HI *
226 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
228 'buoy game starting with 1 moves
234 def test_new_buoy_2_moves
235 game_name = "buoyhoge-1500-0"
236 board = ShogiServer::Board.new
237 board.set_from_moves ["+7776FU", "-3334FU"]
245 game = ShogiServer::Game.new game_name, p1, p2, board
246 assert_equal "-3334FU,T1", game.last_move
253 Declaration:Jishogi 1.1
254 Game_ID:#{game.game_id}
264 Least_Time_Per_Move:1
267 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
268 P2 * -HI * * * * * -KA *
269 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
273 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
274 P8 * +KA * * * * * +HI *
275 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
282 assert_equal(p1_out, p1.out.first)
289 Declaration:Jishogi 1.1
290 Game_ID:#{game.game_id}
300 Least_Time_Per_Move:1
303 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
304 P2 * -HI * * * * * -KA *
305 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
309 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
310 P8 * +KA * * * * * +HI *
311 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
318 assert_equal(p2_out, p2.out.first)
320 file = Pathname.new(game.logfile)
322 assert_equal(<<EOF, log.gsub(/^\$START_TIME.*?\n/,''))
326 $EVENT:#{game.game_id}
327 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
328 P2 * -HI * * * * * -KA *
329 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
333 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
334 P8 * +KA * * * * * +HI *
335 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
337 'buoy game starting with 2 moves
346 game_name = "hoge-1500-0"
347 board = ShogiServer::Board.new
356 game = ShogiServer::Game.new game_name, p1, p2, board
357 handler1 = ShogiServer::MonitorHandler1.new p1
358 handler2 = ShogiServer::MonitorHandler2.new p2
360 assert_equal(0, game.monitors.size)
361 game.monitoron(handler1)
362 assert_equal(1, game.monitors.size)
363 game.monitoron(handler2)
364 assert_equal(2, game.monitors.size)
365 game.monitoroff(handler1)
366 assert_equal(1, game.monitors.size)
367 assert_equal(handler2, game.monitors.last)
368 game.monitoroff(handler2)
369 assert_equal(0, game.monitors.size)