* To_Move of a proposed game lines was incorrect.
module ShogiServer # for a namespace
+class WrongMoves < ArgumentError; end
+
class Board
+
+ # Split a moves line into an array of a move string.
+ # If it fails to parse the moves, it raises WrongMoves.
+ # @param moves a moves line. Ex. "+776FU-3334Fu"
+ # @return an array of a move string. Ex. ["+7776FU", "-3334FU"]
+ #
+ def Board.split_moves(moves)
+ ret = []
+
+ rs = moves.gsub %r{[\+\-]\d{4}\w{2}} do |s|
+ ret << s
+ ""
+ end
+ raise WrongMoves, rs unless rs.empty?
+
+ return ret
+ end
def initialize(move_count=0)
@sente_hands = Array::new
if buoy_game.instance_of? NilBuoyGame
# error. never reach
end
+
+ moves_array = Board::split_moves(buoy_game.moves)
board = Board.new
begin
- board.set_from_moves(buoy_game.moves)
+ board.set_from_moves(moves_array)
rescue => err
# it will never happen since moves have already been checked
log_error "Failed to set up a buoy game: #{moves}"
#
#
class SetBuoyCommand < Command
- class WrongMoves < ArgumentError; end
def initialize(str, player, game_name, moves, count)
super(str, player)
end
# check moves
- moves_array = split_moves @moves
-
+ moves_array = Board::split_moves(@moves)
board = Board.new
begin
board.set_from_moves(moves_array)
log_error "Received wrong moves: %s from %s. [%s]" % [@moves, @player.name, e.message]
return :continue
end
-
- private
-
- # Split a moves line into an array of a move string.
- # If it fails to parse the moves, it raises WrongMoves.
- # @param moves a moves line. Ex. "+776FU-3334Fu"
- # @return an array of a move string. Ex. ["+7776FU", "-3334FU"]
- #
- def split_moves(moves)
- ret = []
-
- rs = moves.gsub %r{[\+\-]\d{4}\w{2}} do |s|
- ret << s
- ""
- end
- raise WrongMoves, rs unless rs.empty?
-
- return ret
- end
end
#
Name-:#{@gote.name}
Your_Turn:#{sg_flag}
Rematch_On_Draw:NO
-To_Move:+
+To_Move:#{@board.teban ? "+" : "-"}
BEGIN Time
Time_Unit:1sec
Total_Time:#{@total_time}
end
end # TestBoardForBuoy
+class TestSplitMoves < Test::Unit::TestCase
+ def test_split_moves1
+ rs = ShogiServer::Board::split_moves "+7776FU"
+ assert_equal ["+7776FU"], rs
+ end
+
+ def test_split_moves2
+ rs = ShogiServer::Board::split_moves "+7776FU-3334FU"
+ assert_equal ["+7776FU", "-3334FU"], rs
+ end
+
+ def test_split_moves3
+ assert_nothing_raised do
+ ShogiServer::Board::split_moves ""
+ end
+ end
+
+ def test_split_moves_error1
+ assert_raise ShogiServer::WrongMoves do
+ ShogiServer::Board::split_moves "dummy"
+ end
+ end
+end
@p.name = "set_buoy_player"
end
- def test_split_moves1
- cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_hoge-1500-0", "+7776FU", 1
- rs = cmd.__send__ :split_moves, "+7776FU"
- assert_equal ["+7776FU"], rs
- end
-
- def test_split_moves2
- cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_hoge-1500-0", "+7776FU", 1
- rs = cmd.__send__ :split_moves, "+7776FU-3334FU"
- assert_equal ["+7776FU", "-3334FU"], rs
- end
-
- def test_split_moves3
- cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_hoge-1500-0", "+7776FU", 1
- assert_nothing_raised do
- cmd.__send__ :split_moves, ""
- end
- end
-
- def test_split_moves_error1
- cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_hoge-1500-0", "+7776FU", 1
- assert_raise ShogiServer::SetBuoyCommand::WrongMoves do
- cmd.__send__ :split_moves, "dummy"
- end
- end
-
def test_call_2
assert @buoy.is_new_game?("buoy_hoge-1500-0")
cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_hoge-1500-0", "+7776FU", 2