+2013-03-31 Daigo Moriwaki <daigo at debian dot org>
+
+ * [shogi-server]
+ - %%FORK command: %%FORK <source_game> [<new_buoy_game>] [<nth-move>]
+ The new_buoy_game parameter is now optional. If it is not
+ supplied, Shogi-server generates a new buoy game name from
+ source_game.
+
2013-02-23 Daigo Moriwaki <daigo at debian dot org>
* [shogi-server]
nth_move = $3.to_i
end
cmd = ForkCommand.new(str, player, source_game, new_buoy_game, nth_move)
+ when /^%%FORK\s+(\S+)$/
+ source_game = $1
+ new_buoy_game = nil
+ nth_move = nil
+ cmd = ForkCommand.new(str, player, source_game, new_buoy_game, nth_move)
when /^\s*$/
cmd = SpaceCommand.new(str, player)
when /^%%%[^%]/
@new_buoy_game = new_buoy_game
@nth_move = nth_move # may be nil
end
+ attr_reader :new_buoy_game
+
+ def decide_new_buoy_game_name
+ name = nil
+ total_time = nil
+ byo_time = nil
+
+ if @source_game.split("+").size >= 2 &&
+ /^([^-]+)-(\d+)-(\d+)/ =~ @source_game.split("+")[1]
+ name = $1
+ total_time = $2
+ byo_time = $3
+ end
+ if name == nil || total_time == nil || byo_time == nil
+ @player.write_safe(sprintf("##[ERROR] wrong source game name to make a new buoy game name: %s\n", @source_game))
+ log_error "Received a wrong source game name to make a new buoy game name: %s from %s." % [@source_game, @player.name]
+ return :continue
+ end
+ @new_buoy_game = "buoy_%s_%d-%s-%s" % [name, @nth_move, total_time, byo_time]
+ @player.write_safe(sprintf("##[FORK]: new buoy game name: %s\n", @new_buoy_game))
+ @player.write_safe("##[FORK] +OK\n")
+ end
def call
game = $league.games[@source_game]
moves[0...@nth_move].each do |m|
new_moves_str << m.join(",")
end
+
+ unless @new_buoy_game
+ decide_new_buoy_game_name
+ end
+
buoy_cmd = SetBuoyCommand.new(@str, @player, @new_buoy_game, new_moves_str, 1)
return buoy_cmd.call
end
assert_instance_of(ShogiServer::ForkCommand, cmd)
end
+ def test_fork_command2
+ cmd = ShogiServer::Command.factory("%%FORK server-denou-14400-60+p1+p2+20130223185013", @p)
+ assert_instance_of(ShogiServer::ForkCommand, cmd)
+ end
+
def test_void_command
cmd = ShogiServer::Command.factory("%%%HOGE", @p)
assert_instance_of(ShogiServer::VoidCommand, cmd)
#
#
+class TestForkCommand < Test::Unit::TestCase
+ def setup
+ @player = MockPlayer.new
+ end
+
+ def test_new_buoy_game_name
+ src = "%%FORK server+denou-14400-60+p1+p2+20130223185013"
+ c = ShogiServer::ForkCommand.new src, @player, "server+denou-14400-60+p1+p2+20130223185013", nil, 13
+ c.decide_new_buoy_game_name
+ assert_equal "buoy_denou_13-14400-60", c.new_buoy_game
+ end
+end
+
+#
+#
class TestGetBuoyCountCommand < BaseTestBuoyCommand
def test_call
buoy_game = ShogiServer::BuoyGame.new("buoy_testdeletebuoy-1500-0", "+7776FU", @p.name, 1)
@player.out.join)
end
end
-
@admin.logout
end
+
+ def test_fork2
+ buoy = ShogiServer::Buoy.new
+
+ @admin = SocketPlayer.new "dummy", "admin", "*"
+ @admin.connect
+ @admin.reader
+ @admin.login
+
+ result, result2 = handshake do
+ source_game = parse_game_name(@admin)
+ @admin.puts "%%FORK #{source_game}" # nil for new_buoy_game name
+ sleep 1
+ assert /##\[FORK\]: new buoy game name: buoy_TestFork_1-1500-0/ =~ @admin.message
+ end
+
+ assert buoy.is_new_game?("buoy_TestFork_1-1500-0")
+ @p1 = SocketPlayer.new "buoy_TestFork_1", "p1", true
+ @p2 = SocketPlayer.new "buoy_TestFork_1", "p2", false
+ @p1.connect
+ @p2.connect
+ @p1.reader
+ @p2.reader
+ @p1.login
+ @p2.login
+ sleep 1
+ @p1.game
+ @p2.game
+ sleep 1
+ @p1.agree
+ @p2.agree
+ sleep 1
+ assert /^Total_Time:1500/ =~ @p1.message
+ assert /^Total_Time:1500/ =~ @p2.message
+ @p2.move("-3334FU")
+ sleep 1
+ @p1.toryo
+ sleep 1
+ @p2.logout
+ @p1.logout
+
+ @admin.logout
+ end
end