OSDN Git Service

Removed the deprecated method.
[shogi-server/shogi-server.git] / test / TC_board.rb
1 $:.unshift File.join(File.dirname(__FILE__), "..")
2
3 require 'test/unit'
4 require 'shogi_server'
5 require 'shogi_server/board'
6 require 'shogi_server/piece'
7
8 class Test_kachi < Test::Unit::TestCase
9   def test_kachi_good
10     b = ShogiServer::Board.new
11     b.set_from_str(<<EOM)
12 P1+HI+HI+KA+KA+OU *  *  *  * 
13 P2+FU+FU+FU+FU+FU+FU *  *  * 
14 P+00FU00FU
15 EOM
16     assert_equal(true, b.good_kachi?(true))
17
18     b = ShogiServer::Board.new
19     b.set_from_str(<<EOM)
20 P8-HI-HI-KA-KA-OU *  *  *  * 
21 P9-FU-FU-FU-FU-FU-FU *  *  * 
22 P-00FU
23 EOM
24     assert_equal(true, b.good_kachi?(false))
25   end
26
27   def test_kachi_good
28     b = ShogiServer::Board.new
29     b.set_from_str(<<EOM)
30 P1+HI+HI+KA+KA+OU *  *  *  * 
31 P2+FU+FU+FU+FU+FU+FU *  *  * 
32 P+00FU00FU
33 EOM
34     assert_equal(true, b.good_kachi?(true))
35
36     b = ShogiServer::Board.new
37     b.set_from_str(<<EOM)
38 P8-HI-HI-KA-KA-OU *  *  *  * 
39 P9-FU-FU-FU-FU-FU-FU *  *  * 
40 P-00FU
41 EOM
42     assert_equal(true, b.good_kachi?(false))
43   end
44
45   def test_kachi_bad
46     b = ShogiServer::Board.new
47     b.set_from_str(<<EOM)
48 P1+HI+HI+KA+KA+OU *  *  *  * 
49 P2+FU+FU+FU+FU+FU+FU *  *  * 
50 P+00FU
51 EOM
52     assert_equal(false, b.good_kachi?(true)) # point is not enough
53
54     b = ShogiServer::Board.new
55     b.set_from_str(<<EOM)
56 P8-HI-HI-KA-KA-OU *  *  *  * 
57 P9-FU-FU-FU-FU-FU-FU *  *  * 
58 EOM
59     assert_equal(false, b.good_kachi?(false)) # point is not enough
60
61     b = ShogiServer::Board.new
62     b.set_from_str(<<EOM)
63 P1+HI+HI+KA+KA+OU *  *  *  * 
64 P2+FU+FU+FU+FU+FU *  *  *  *
65 P+00FU00FU00FU
66 EOM
67     assert_equal(false, b.good_kachi?(true)) # number on board is not enough
68
69     b = ShogiServer::Board.new
70     b.set_from_str(<<EOM)
71 P8-HI-HI-KA-KA-OU *  *  *  * 
72 P9-FU-FU-FU-FU-FU *  *  *  * 
73 P-00FU00FU
74 EOM
75     assert_equal(false, b.good_kachi?(false)) # number on board is not enough
76
77     b = ShogiServer::Board.new
78     b.set_from_str(<<EOM)
79 P1+HI+HI+KA+KA+OU *  *  * -HI
80 P2+FU+FU+FU+FU+FU+FU *  *  * 
81 P+00FU00FU
82 EOM
83     assert_equal(false, b.good_kachi?(true)) # checkmate
84
85     b = ShogiServer::Board.new
86     b.set_from_str(<<EOM)
87 P8-HI-HI-KA-KA-OU *  *  * +HI
88 P9-FU-FU-FU-FU-FU-FU *  *  * 
89 P-00FU
90 EOM
91     assert_equal(false, b.good_kachi?(false)) # checkmate
92
93     b = ShogiServer::Board.new
94     b.set_from_str(<<EOM)
95 P1+TO+TO * +TO+TO+OU * +TO * 
96 P2 *  *  *  *  *  *  *  * +KI
97 P3 *  *  * +TO+NG+TO+TO+TO+NY
98 P4 *  *  *  *  *  *  *  *  * 
99 P5 *  *  *  *  *  *  *  * +UM
100 P6 *  *  * -KI-NG-RY *  *  * 
101 P7-TO * -TO-NG * -TO-TO-TO * 
102 P8-RY *  * -NK-TO-OU-TO-TO * 
103 P9 * -TO *  *  *  *  *  *  * 
104 P+00KI00KI00KE
105 P-00KA00GI00KE00KE00KY00KY00KY
106 -
107 EOM
108     assert_equal(true, b.good_kachi?(false))
109   end
110 end
111
112 class Test_gps < Test::Unit::TestCase
113   def test_gote_promote
114     b = ShogiServer::Board.new
115     b.set_from_str(<<EOM)
116 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
117 P2 * -HI *  *  *  *  *  *  * 
118 P3-FU * -FU-FU-FU-FU-KA-FU-FU
119 P4 *  *  *  *  *  *  *  *  * 
120 P5 * -FU+FU *  *  *  *  *  * 
121 P6 *  *  *  *  *  *  *  *  * 
122 P7+FU+FU+KE+FU+FU+FU+FU+FU+FU
123 P8 *  *  *  *  *  *  * +HI * 
124 P9+KY * +GI+KI+OU+KI+GI+KE+KY
125 P+00FU
126 P-00KA
127 EOM
128     assert_equal(:normal, b.handle_one_move("-3377UM"))
129   end
130
131   def test_capture_promoted_and_put
132     b = ShogiServer::Board.new
133     b.set_from_str(<<EOM)
134 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
135 P2 * -HI *  *  *  *  * -KA * 
136 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
137 P4 *  *  *  *  *  *  *  *  * 
138 P5 *  *  *  *  *  *  *  *  * 
139 P6 *  *  *  *  *  *  *  *  * 
140 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
141 P8 * +KA *  *  *  *  * +HI * 
142 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
143 EOM
144
145     assert_equal(:normal, b.handle_one_move("+7776FU"))
146     assert_equal(:normal, b.handle_one_move("-3334FU"))
147     assert_equal(:normal, b.handle_one_move("+2726FU"))
148     assert_equal(:normal, b.handle_one_move("-4344FU"))
149     assert_equal(:normal, b.handle_one_move("+3948GI"))
150     assert_equal(:normal, b.handle_one_move("-8242HI"))
151     assert_equal(:normal, b.handle_one_move("+5756FU"))
152     assert_equal(:normal, b.handle_one_move("-3132GI"))
153     assert_equal(:normal, b.handle_one_move("+5968OU"))
154     assert_equal(:normal, b.handle_one_move("-5162OU"))
155     assert_equal(:normal, b.handle_one_move("+6878OU"))
156     assert_equal(:normal, b.handle_one_move("-6272OU"))
157     assert_equal(:normal, b.handle_one_move("+4958KI"))
158     assert_equal(:normal, b.handle_one_move("-7282OU"))
159     assert_equal(:normal, b.handle_one_move("+9796FU"))
160     assert_equal(:normal, b.handle_one_move("-9394FU"))
161     assert_equal(:normal, b.handle_one_move("+2625FU"))
162     assert_equal(:normal, b.handle_one_move("-2233KA"))
163     assert_equal(:normal, b.handle_one_move("+3736FU"))
164     assert_equal(:normal, b.handle_one_move("-7172GI"))
165     assert_equal(:normal, b.handle_one_move("+7968GI"))
166     assert_equal(:normal, b.handle_one_move("-4152KI"))
167     assert_equal(:normal, b.handle_one_move("+6857GI"))
168     assert_equal(:normal, b.handle_one_move("-3243GI"))
169     assert_equal(:normal, b.handle_one_move("+6968KI"))
170     assert_equal(:normal, b.handle_one_move("-5354FU"))
171     assert_equal(:normal, b.handle_one_move("+1716FU"))
172     assert_equal(:normal, b.handle_one_move("-1314FU"))
173     assert_equal(:normal, b.handle_one_move("+4746FU"))
174     assert_equal(:normal, b.handle_one_move("-6364FU"))
175     assert_equal(:normal, b.handle_one_move("+4645FU"))
176     assert_equal(:normal, b.handle_one_move("-5263KI"))
177     assert_equal(:normal, b.handle_one_move("+2937KE"))
178     assert_equal(:normal, b.handle_one_move("-7374FU"))
179     assert_equal(:normal, b.handle_one_move("+2524FU"))
180     assert_equal(:normal, b.handle_one_move("-2324FU"))
181     assert_equal(:normal, b.handle_one_move("+4544FU"))
182     assert_equal(:normal, b.handle_one_move("-4344GI"))
183     assert_equal(:normal, b.handle_one_move("+0045FU"))
184     assert_equal(:normal, b.handle_one_move("-4445GI"))
185     assert_equal(:normal, b.handle_one_move("+8833UM"))
186     assert_equal(:normal, b.handle_one_move("-2133KE"))
187     assert_equal(:normal, b.handle_one_move("+0088KA"))
188     assert_equal(:normal, b.handle_one_move("-5455FU"))
189     assert_equal(:normal, b.handle_one_move("+8855KA"))
190     assert_equal(:normal, b.handle_one_move("-4243HI"))
191     assert_equal(:normal, b.handle_one_move("+2824HI"))
192     assert_equal(:normal, b.handle_one_move("-4554GI"))
193     assert_equal(:normal, b.handle_one_move("+0044FU"))
194     assert_equal(:normal, b.handle_one_move("-4353HI"))
195     assert_equal(:normal, b.handle_one_move("+2422RY"))
196     assert_equal(:normal, b.handle_one_move("-5455GI"))
197     assert_equal(:normal, b.handle_one_move("+5655FU"))
198     assert_equal(:normal, b.handle_one_move("-0056FU"))
199     assert_equal(:normal, b.handle_one_move("+5756GI"))
200     assert_equal(:normal, b.handle_one_move("-0057FU"))
201     assert_equal(:normal, b.handle_one_move("+4857GI"))
202     assert_equal(:normal, b.handle_one_move("-9495FU"))
203     assert_equal(:normal, b.handle_one_move("+9695FU"))
204     assert_equal(:normal, b.handle_one_move("-0096FU"))
205     assert_equal(:normal, b.handle_one_move("+9996KY"))
206     assert_equal(:normal, b.handle_one_move("-0085KA"))
207   end
208 end
209
210
211 class Test_promote < Test::Unit::TestCase
212   def test_fu
213     b = ShogiServer::Board.new
214     b.set_from_str(<<EOM)
215 P1-OU * +OU *
216 P2 *  *  *  *
217 P3+FU *  * +HI
218 P4 * +FU *  *
219 P5 *  * +FU *
220 EOM
221     assert_equal(:normal, b.handle_one_move("+9392TO"))
222     assert_equal(:normal, b.handle_one_move("+8483TO"))
223     assert_equal(:illegal, b.handle_one_move("+7574TO"))
224     assert_equal(:normal, b.handle_one_move("+6364RY"))
225   end
226 end
227
228 class Test_move < Test::Unit::TestCase
229   def test_fu
230     b = ShogiServer::Board.new
231     b.set_from_str(<<EOM)
232 P1-OU * +OU
233 P2 * +FU *
234 EOM
235     assert_equal(:illegal, b.handle_one_move("+8281FU"))
236   end
237   def test_hi
238     b = ShogiServer::Board.new
239     b.set_from_str(<<EOM)
240 P1-OU * +OU
241 P2 * +HI *
242 EOM
243     assert_equal(:normal, b.handle_one_move("+8212HI"))
244     assert_equal(:illegal, b.handle_one_move("+1223HI"))
245   end
246   def test_ry
247     b = ShogiServer::Board.new
248     b.set_from_str(<<EOM)
249 P1-OU * +OU
250 P2 * +RY *
251 EOM
252     assert_equal(:normal, b.handle_one_move("+8212RY"))
253     assert_equal(:normal, b.handle_one_move("+1223RY"))
254   end
255 end
256
257 class Test_put < Test::Unit::TestCase
258   def test_fu
259     b = ShogiServer::Board.new
260     b.set_from_str(<<EOM)
261 P1-OU * +OU
262 P+00FU00FU
263 EOM
264     assert_equal(:illegal, b.handle_one_move("+0011FU"))
265     assert_equal(:normal, b.handle_one_move("+0022FU"))
266   end
267   def test_ky
268      b = ShogiServer::Board.new
269      b.set_from_str(<<EOM)
270 P1-OU * +OU
271 P+00KY00KY
272 EOM
273     assert_equal(:illegal, b.handle_one_move("+0011KY"))
274     assert_equal(:normal, b.handle_one_move("+0022KY"))
275   end
276
277   def test_ke
278     b = ShogiServer::Board.new
279     b.set_from_str(<<EOM)
280 P1-OU * +OU
281 P+00KE00KE00KE
282 EOM
283     assert_equal(:illegal, b.handle_one_move("+0011KE"))
284     assert_equal(:illegal, b.handle_one_move("+0022KE"))
285     assert_equal(:normal, b.handle_one_move("+0033KE"))
286   end
287 end
288
289
290 class Test_2fu < Test::Unit::TestCase
291   def test_2fu
292     b = ShogiServer::Board.new
293     b.set_from_str(<<EOM)
294 P1-OU * +OU
295 P+00FU00FU
296 EOM
297     assert_equal(:normal, b.handle_one_move("+0022FU"))
298     assert_equal(:illegal, b.handle_one_move("+0023FU"))
299
300     b = ShogiServer::Board.new
301     b.set_from_str(<<EOM)
302 P1-OU * +OU
303 P+00FU00FU
304 EOM
305     assert_equal(:normal, b.handle_one_move("+0022FU"))
306     assert_equal(:normal, b.handle_one_move("+0032FU"))
307   end
308 end
309
310 class Test_sennichite < Test::Unit::TestCase
311   def test_oute_sennichite0
312     b = ShogiServer::Board.new
313     b.set_from_str(<<EOM)
314 P1-OU *  * +OU
315 P2 *  * +HI *
316 EOM
317 ##    b.history[b.to_s] = 1
318     assert_equal(:normal, b.handle_one_move("+7271HI")) #1
319     assert_equal(:normal, b.handle_one_move("-9192OU"))
320     assert_equal(:normal, b.handle_one_move("+7172HI"))
321     assert_equal(:normal, b.handle_one_move("-9291OU"))
322
323     assert_equal(:normal, b.handle_one_move("+7271HI")) # 2
324     assert_equal(:normal, b.handle_one_move("-9192OU"))
325     assert_equal(:normal, b.handle_one_move("+7172HI"))
326     assert_equal(:normal, b.handle_one_move("-9291OU"))
327
328     assert_equal(:normal, b.handle_one_move("+7271HI")) # 3
329     assert_equal(:normal, b.handle_one_move("-9192OU"))
330     assert_equal(:normal, b.handle_one_move("+7172HI"))
331     assert_equal(:normal, b.handle_one_move("-9291OU"))
332
333     assert_equal(:oute_sennichite_sente_lose, b.handle_one_move("+7271HI")) # 4
334   end
335
336   def test_oute_sennichite1 #330
337     b = ShogiServer::Board.new
338     b.set_from_str(<<EOM)
339 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
340 P2 * -HI *  *  *  *  * -KA * 
341 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
342 P4 *  *  *  *  *  *  *  *  * 
343 P5 *  *  *  *  *  *  *  *  * 
344 P6 *  *  *  *  *  *  *  *  * 
345 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
346 P8 * +KA *  *  *  *  * +HI * 
347 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
348 EOM
349 b.history[b.to_s] = 1
350
351     assert_equal(:normal, b.handle_one_move("+2726FU"))
352     assert_equal(:normal, b.handle_one_move("-8384FU"))
353     assert_equal(:normal, b.handle_one_move("+2625FU"))
354     assert_equal(:normal, b.handle_one_move("-8485FU"))
355     assert_equal(:normal, b.handle_one_move("+6978KI"))
356     assert_equal(:normal, b.handle_one_move("-4132KI"))
357     assert_equal(:normal, b.handle_one_move("+2524FU"))
358     assert_equal(:normal, b.handle_one_move("-2324FU"))
359     assert_equal(:normal, b.handle_one_move("+2824HI"))
360     assert_equal(:normal, b.handle_one_move("-0023FU"))
361     assert_equal(:normal, b.handle_one_move("+2484HI"))
362     assert_equal(:normal, b.handle_one_move("-8284HI"))
363     assert_equal(:normal, b.handle_one_move("+4938KI"))
364     assert_equal(:normal, b.handle_one_move("-9394FU"))
365     assert_equal(:normal, b.handle_one_move("+5969OU"))
366     assert_equal(:normal, b.handle_one_move("-0049HI"))
367
368     assert_equal(:normal, b.handle_one_move("+6968OU"))
369     assert_equal(:normal, b.handle_one_move("-4948RY"))
370     assert_equal(:normal, b.handle_one_move("+6869OU"))
371     assert_equal(:normal, b.handle_one_move("-4849RY"))
372
373     assert_equal(:normal, b.handle_one_move("+6968OU"))
374     assert_equal(:normal, b.handle_one_move("-4948RY"))
375     assert_equal(:normal, b.handle_one_move("+6869OU"))
376     assert_equal(:normal, b.handle_one_move("-4849RY"))
377
378     assert_equal(:normal, b.handle_one_move("+6968OU"))
379     assert_equal(:normal, b.handle_one_move("-4948RY"))
380     assert_equal(:normal, b.handle_one_move("+6869OU"))
381     assert_equal(:normal, b.handle_one_move("-4849RY"))
382
383     assert_equal(:normal, b.handle_one_move("+6968OU")) # added
384     assert_equal(:oute_sennichite_gote_lose, b.handle_one_move("-4948RY"))
385   end
386
387   def test_not_oute_sennichite
388     b = ShogiServer::Board.new
389     b.set_from_str(<<EOM)
390 P1-OU *  * +OU
391 P2 *  * +HI *
392 EOM
393 ##    b.history[b.to_s] = 1
394     assert_equal(:normal, b.handle_one_move("+7271HI")) #1
395     assert_equal(:normal, b.handle_one_move("-9192OU"))
396     assert_equal(:normal, b.handle_one_move("+7172HI"))
397     assert_equal(:normal, b.handle_one_move("-9291OU"))
398
399     assert_equal(:normal, b.handle_one_move("+7271HI")) # 2
400     assert_equal(:normal, b.handle_one_move("-9192OU"))
401     assert_equal(:normal, b.handle_one_move("+7174HI")) # stop oute here
402     assert_equal(:normal, b.handle_one_move("-9291OU"))
403
404     assert_equal(:normal, b.handle_one_move("+7471HI")) # 3
405     assert_equal(:normal, b.handle_one_move("-9192OU"))
406     assert_equal(:normal, b.handle_one_move("+7172HI"))
407     assert_equal(:normal, b.handle_one_move("-9291OU"))
408
409     assert_equal(:sennichite, b.handle_one_move("+7271HI")) # 4
410   end
411
412   def test_sennichite0
413     b = ShogiServer::Board.new
414     b.set_from_str(<<EOM)
415 P1-OU * +OU
416 EOM
417     b.history[b.to_s] = 1
418     assert_equal(:normal, b.handle_one_move("+7172OU"))
419     assert_equal(:normal, b.handle_one_move("-9192OU"))
420     assert_equal(:normal, b.handle_one_move("+7271OU"))
421     assert_equal(:normal, b.handle_one_move("-9291OU")) # 2
422
423     assert_equal(:normal, b.handle_one_move("+7172OU"))
424     assert_equal(:normal, b.handle_one_move("-9192OU"))
425     assert_equal(:normal, b.handle_one_move("+7271OU"))
426     assert_equal(:normal, b.handle_one_move("-9291OU")) # 3
427
428     assert_equal(:normal, b.handle_one_move("+7172OU"))
429     assert_equal(:normal, b.handle_one_move("-9192OU"))
430     assert_equal(:normal, b.handle_one_move("+7271OU"))
431     assert_equal(:sennichite, b.handle_one_move("-9291OU")) # 4
432   end
433
434   def test_sennichite1          # 329
435     b = ShogiServer::Board.new
436     b.set_from_str(<<EOM)
437 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
438 P2 * -HI *  *  *  *  * -KA * 
439 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
440 P4 *  *  *  *  *  *  *  *  * 
441 P5 *  *  *  *  *  *  *  *  * 
442 P6 *  *  *  *  *  *  *  *  * 
443 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
444 P8 * +KA *  *  *  *  * +HI * 
445 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
446 EOM
447     b.history[b.to_s] = 1
448
449     assert_equal(:normal, b.handle_one_move("+2858HI"))
450     assert_equal(:normal, b.handle_one_move("-8252HI"))
451     assert_equal(:normal, b.handle_one_move("+5828HI"))
452     assert_equal(:normal, b.handle_one_move("-5282HI"))
453     assert_equal(:normal, b.handle_one_move("+2858HI"))
454     assert_equal(:normal, b.handle_one_move("-8252HI"))
455     assert_equal(:normal, b.handle_one_move("+5828HI"))
456     assert_equal(:normal, b.handle_one_move("-5282HI"))
457     assert_equal(:normal, b.handle_one_move("+2858HI"))
458     assert_equal(:normal, b.handle_one_move("-8252HI"))
459     assert_equal(:normal, b.handle_one_move("+5828HI"))
460     assert_equal(:sennichite, b.handle_one_move("-5282HI"))
461   end
462 end
463
464 class Test_checkmate < Test::Unit::TestCase
465   def test_ki
466     b = ShogiServer::Board.new
467     b.set_from_str(<<EOM)
468 P1-OU * +OU
469 P2 * +KI
470 EOM
471     assert_equal(true, b.checkmated?(false)) # gote is loosing
472     assert_equal(false, b.checkmated?(true))
473   end
474
475   def test_hi
476     b = ShogiServer::Board.new
477     b.set_from_str(<<EOM)
478 P1-OU * +HI+OU
479 EOM
480     assert_equal(true, b.checkmated?(false)) # gote is loosing
481     assert_equal(false, b.checkmated?(true))
482
483     b = ShogiServer::Board.new
484     b.set_from_str(<<EOM)
485 P1-OU * 
486 P2 * +HI+OU
487 EOM
488     assert_equal(false, b.checkmated?(false)) # hisha can't capture
489     assert_equal(false, b.checkmated?(true))
490
491     b = ShogiServer::Board.new
492     b.set_from_str(<<EOM)
493 P1-OU * 
494 P2 * +RY+OU
495 EOM
496     assert_equal(true, b.checkmated?(false)) # ryu can capture
497     assert_equal(false, b.checkmated?(true))
498   end
499
500   def test_KE
501     b = ShogiServer::Board.new
502     b.set_from_str(<<EOM)
503 P1-OU * +OU
504 P2 *  *  *
505 P3 * +KE *
506 EOM
507     assert_equal(true, b.checkmated?(false))
508     assert_equal(false, b.checkmated?(true))
509   end
510 end
511
512 class Test_uchifuzume < Test::Unit::TestCase
513   def test_uchifuzume1          # 331
514     b = ShogiServer::Board.new
515     b.set_from_str(<<EOM)
516 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
517 P2 * -HI *  *  *  *  * -KA * 
518 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
519 P4 *  *  *  *  *  *  *  *  * 
520 P5 *  *  *  *  *  *  *  *  * 
521 P6 *  *  *  *  *  *  *  *  * 
522 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
523 P8 * +KA *  *  *  *  * +HI * 
524 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
525 EOM
526
527     assert_equal(:normal, b.handle_one_move("+2726FU"))
528     assert_equal(:normal, b.handle_one_move("-8384FU"))
529     assert_equal(:normal, b.handle_one_move("+2625FU"))
530     assert_equal(:normal, b.handle_one_move("-8485FU"))
531     assert_equal(:normal, b.handle_one_move("+2524FU"))
532     assert_equal(:normal, b.handle_one_move("-2324FU"))
533     assert_equal(:normal, b.handle_one_move("+2824HI"))
534     assert_equal(:normal, b.handle_one_move("-8586FU"))
535     assert_equal(:normal, b.handle_one_move("+8786FU"))
536     assert_equal(:normal, b.handle_one_move("-0087FU"))
537     assert_equal(:normal, b.handle_one_move("+0023FU"))
538     assert_equal(:normal, b.handle_one_move("-8788TO"))
539     assert_equal(:normal, b.handle_one_move("+2322TO"))
540     assert_equal(:normal, b.handle_one_move("-8879TO"))
541     assert_equal(:normal, b.handle_one_move("+2231TO"))
542     assert_equal(:normal, b.handle_one_move("-7969TO"))
543     assert_equal(:normal, b.handle_one_move("+5969OU"))
544     assert_equal(:normal, b.handle_one_move("-8286HI"))
545     assert_equal(:normal, b.handle_one_move("+3141TO"))
546     assert_equal(:normal, b.handle_one_move("-5141OU"))
547     assert_equal(:normal, b.handle_one_move("+2484HI"))
548     assert_equal(:normal, b.handle_one_move("-8684HI"))
549     assert_equal(:normal, b.handle_one_move("+6978OU"))
550     assert_equal(:normal, b.handle_one_move("-8424HI"))
551     assert_equal(:normal, b.handle_one_move("+7776FU"))
552     assert_equal(:normal, b.handle_one_move("-7374FU"))
553     assert_equal(:normal, b.handle_one_move("+7675FU"))
554     assert_equal(:normal, b.handle_one_move("-7475FU"))
555     assert_equal(:normal, b.handle_one_move("+0079KI"))
556     assert_equal(:normal, b.handle_one_move("-7576FU"))
557     assert_equal(:normal, b.handle_one_move("+7888OU"))
558     assert_equal(:normal, b.handle_one_move("-7677TO"))
559     assert_equal(:normal, b.handle_one_move("+8877OU"))
560     assert_equal(:normal, b.handle_one_move("-2474HI"))
561     assert_equal(:normal, b.handle_one_move("+7788OU"))
562     assert_equal(:normal, b.handle_one_move("-0086KI"))
563     assert_equal(:normal, b.handle_one_move("+9998KY"))
564     assert_equal(:normal, b.handle_one_move("-7424HI"))
565     assert_equal(:normal, b.handle_one_move("+0099GI"))
566     assert_equal(:normal, b.handle_one_move("-0028HI"))
567     assert_equal(:normal, b.handle_one_move("+0078FU"))
568     assert_equal(:uchifuzume, b.handle_one_move("-0087FU"))
569   end
570
571   def test_uchifuzume2
572     # http://wdoor.c.u-tokyo.ac.jp/shogi/tools/view/index.cgi?go_last=on&csa=http%3A%2F%2Fwdoor.c.u-tokyo.ac.jp%2Fshogi%2Flogs%2FLATEST%2Fwdoor%2Bfloodgate-900-0%2Busapyon-on-note%2BKShogi900%2B20080217020012.csa
573     b = ShogiServer::Board.new
574     b.set_from_str(<<EOM)
575 P1-KY-KE * -KI * -OU * -KE-KY
576 P2 *  * +TO *  *  *  *  *  *
577 P3 *  *  *  * -KI-KI * -FU *
578 P4 *  * -FU * -FU-FU-FU *  *
579 P5 * -RY+GI+OU *  *  * +FU+FU
580 P6-FU * +FU+KI+GI+FU+FU * +KY
581 P7 *  *  * -RY *  *  *  *  *
582 P8 *  *  *  *  *  *  *  *  *
583 P9+KY+KE *  *  *  *  *  *  *
584 P+00FU00FU00FU00FU00FU00GI00GI00KA00KE
585 P-00FU00KA
586 -
587 EOM
588     assert_equal(:uchifuzume, b.handle_one_move("-0064FU"))
589   end
590
591   def test_uchifuzume3
592     # http://wdoor.c.u-tokyo.ac.jp/shogi/tools/view/index.cgi?go_last=on&csa=http%3A%2F%2Fwdoor.c.u-tokyo.ac.jp%2Fshogi%2Flogs%2FLATEST%2Fwdoor%2Bfloodgate-900-0%2Busapyon-on-note%2Bgps_normal%2B20080215133008.csa
593     b = ShogiServer::Board.new
594     b.set_from_str(<<EOM)
595 P1 * -GI * -KI-OU * -GI * -KY
596 P2 *  *  *  * -FU *  *  *  *
597 P3+OU * -FU-FU * -FU-KI-FU *
598 P4+KI+KE-RY * -GI *  *  * -FU
599 P5 *  *  *  *  *  *  *  *  *
600 P6+FU *  *  * +KY *  *  * +FU
601 P7 * +FU *  * +FU *  *  *  *
602 P8 * +GI *  *  *  *  *  *  *
603 P9+KY+KE *  *  *  *  *  * -UM
604 P+00KA00KI00KE00KY00FU00FU00FU
605 P-00HI00KE00FU00FU00FU00FU00FU
606 -
607 EOM
608     assert_equal(:normal, b.handle_one_move("-0092FU"))
609   end
610
611   def test_ou
612     b = ShogiServer::Board.new
613     b.set_from_str(<<EOM)
614 P1-OU * +OU
615 P2+FU *  *
616 P3 * +HI *
617 EOM
618     assert_equal(false, b.uchifuzume?(true))
619
620     b = ShogiServer::Board.new
621     b.set_from_str(<<EOM)
622 P1-OU * +OU
623 P2+FU *  *
624 P3 * +RY *
625 EOM
626     assert_equal(true, b.uchifuzume?(true))
627
628     b = ShogiServer::Board.new
629     b.set_from_str(<<EOM)
630 P2-OU * +OU
631 P3+FU *  *
632 P4 * +RY *
633 EOM
634     assert_equal(false, b.uchifuzume?(true)) # ou can move backward
635
636     b = ShogiServer::Board.new
637     b.set_from_str(<<EOM)
638 P2-OU * +OU
639 P3+FU * +KA
640 P4 * +RY *
641 EOM
642     assert_equal(true, b.uchifuzume?(true)) # ou can move backward and kaku can capture it
643  end                   
644
645
646   def test_friend
647     b = ShogiServer::Board.new
648     b.set_from_str(<<EOM)
649 P1-OU * +OU
650 P2+FU * -HI
651 P3 * +RY *
652 EOM
653     assert_equal(false, b.uchifuzume?(true))
654
655     b = ShogiServer::Board.new
656     b.set_from_str(<<EOM)
657 P1-OU * +OU
658 P2+FU * +FU-HI
659 P3 * +RY *
660 EOM
661     assert_equal(true, b.uchifuzume?(true)) # hisha blocked by fu
662
663     b = ShogiServer::Board.new
664     b.set_from_str(<<EOM)
665 P1-OU * +OU
666 P2+FU *  *
667 P3-GI+RY *
668 EOM
669     assert_equal(true, b.uchifuzume?(true))
670
671     b = ShogiServer::Board.new
672     b.set_from_str(<<EOM)
673 P1-OU * +OU
674 P2+FU *  *
675 P3-KI+RY *
676 EOM
677     assert_equal(false, b.uchifuzume?(true))
678
679     b = ShogiServer::Board.new
680     b.set_from_str(<<EOM)
681 P1-OU * +OU
682 P2+FU *  *
683 P3-NG+RY *
684 EOM
685     assert_equal(false, b.uchifuzume?(true))
686  end
687 end
688
689 class TestBoardForBuoy < Test::Unit::TestCase
690   def setup
691     @board = ShogiServer::Board.new
692   end
693
694   def test_set_from_moves_empty
695     moves = []
696     rt = @board.set_from_moves moves
697     assert_equal(:normal, rt)
698   end
699
700   def test_set_from_moves
701     moves = ["+7776FU", "-3334FU"]
702     assert_nothing_raised do
703       @board.set_from_moves moves
704     end
705
706     correct = ShogiServer::Board.new
707     correct.set_from_str <<EOF
708 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
709 P2 * -HI *  *  *  *  * -KA * 
710 P3-FU-FU-FU-FU-FU-FU * -FU-FU
711 P4 *  *  *  *  *  * -FU *  * 
712 P5 *  *  *  *  *  *  *  *  * 
713 P6 *  * +FU *  *  *  *  *  * 
714 P7+FU+FU * +FU+FU+FU+FU+FU+FU
715 P8 * +KA *  *  *  *  * +HI * 
716 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
717 +
718 EOF
719     assert_equal(correct.to_s, @board.to_s)
720   end
721
722   def test_set_from_moves_error1
723     moves = ["+7776FU", "-3435FU"]
724     assert_raise ArgumentError do
725       @board.set_from_moves moves
726     end
727   end
728
729   def test_set_from_moves_error2
730     moves = ["+7776FU", "+8786FU"]
731     assert_raise ArgumentError do
732       @board.set_from_moves moves
733     end
734   end
735 end # TestBoardForBuoy
736
737 class TestSplitMoves < Test::Unit::TestCase
738   def test_split_moves1
739     rs = ShogiServer::Board::split_moves "+7776FU"
740     assert_equal ["+7776FU"], rs
741   end
742
743   def test_split_moves2
744     rs = ShogiServer::Board::split_moves "+7776FU-3334FU"
745     assert_equal ["+7776FU", "-3334FU"], rs
746   end
747
748   def test_split_moves3
749     assert_nothing_raised do
750       ShogiServer::Board::split_moves ""
751     end
752   end
753
754   def test_split_moves_error1
755     assert_raise ShogiServer::WrongMoves do
756       ShogiServer::Board::split_moves "dummy"
757     end
758   end
759 end