1 $:.unshift File.join(File.dirname(__FILE__), "..")
5 require 'shogi_server/board'
6 require 'shogi_server/piece'
8 class TestUsi < Test::Unit::TestCase
10 @usi = ShogiServer::Usi.new
14 hirate_sfen = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL";
15 board = ShogiServer::Board.new
16 assert_equal @usi.parseBoard(hirate_sfen, board), 0
18 hirate = ShogiServer::Board.new
22 assert_equal hirate.to_s, board.to_s
26 board = ShogiServer::Board.new
28 hirate_sfen = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b -";
29 hirate_sfen_escaped = "lnsgkgsnl_1r5b1_ppppppppp_9_9_9_PPPPPPPPP_1B5R1_LNSGKGSNL.b.-";
30 assert_equal hirate_sfen, @usi.board2usi(board, board.teban)
31 assert_equal hirate_sfen_escaped, ShogiServer::Usi.escape(@usi.board2usi(board, board.teban))
34 def test_board_with_hands1
35 b = ShogiServer::Board.new
38 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
39 P2 * -HI * * * * * -KA *
40 P3-FU-FU-FU-FU-FU-FU-FU-FU *
44 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
45 P8 * +KA * * * * * +HI *
46 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
49 assert_equal "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b P", @usi.board2usi(b, b.teban)
52 def test_board_with_hands2
53 b = ShogiServer::Board.new
56 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
57 P2 * -HI * * * * * -KA *
58 P3-FU-FU-FU-FU-FU-FU-FU-FU *
62 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
63 P8 * +KA * * * * * +HI *
64 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
67 assert_equal "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b p", @usi.board2usi(b, b.teban)
70 def test_board_with_hands3
71 b = ShogiServer::Board.new
74 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
75 P2 * -HI * * * * * -KA *
76 P3-FU-FU-FU-FU-FU-FU-FU * *
80 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
81 P8 * +KA * * * * * +HI *
82 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
85 assert_equal "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b 2p", @usi.board2usi(b, b.teban)