X-Git-Url: http://git.sourceforge.jp/view?p=shogi-server%2Fshogi-server.git;a=blobdiff_plain;f=shogi_server%2Fgame.rb;h=9bcecfb011bbd66222668d01e89de54afb96834b;hp=50bdbaaa8c52125069ea4aab1f1adb50b1a34c2b;hb=ce94a8dae6ddceb9b3af0b43d56da3d11062335e;hpb=3ffaeead65a729c5d6203eaf2a56050c3269402b diff --git a/shogi_server/game.rb b/shogi_server/game.rb index 50bdbaa..9bcecfb 100644 --- a/shogi_server/game.rb +++ b/shogi_server/game.rb @@ -63,16 +63,42 @@ class Game end end + TimeControlParams = Struct.new(:total_time, :byoyomi, :fischer, :stop_watch, :error) + + # Parse time related parts of a game name. + # + # Return an array of a total allotted time, byoyomi seconds and fischer + # seconds; if it fails to parse, return nil. + def Game.parse_time(game_name) + ret = TimeControlParams.new(0, 0, 0, false, false) + + if (game_name =~ /-(\d+)-(\d+F?)$/) + ret[:total_time] = $1.to_i + tmp = $2 + if tmp =~ /^0\d/ + ret[:stop_watch] = true + end + if tmp[-1] == "F" + ret[:fischer] = tmp.chop.to_i + else + ret[:byoyomi] = tmp.to_i + end + return ret + end + + ret[:error] = true + return ret + end + def initialize(game_name, player0, player1, board) @monitors = Array::new # array of MonitorHandler* @game_name = game_name - if (@game_name =~ /-(\d+)-(\d+)$/) - @total_time = $1.to_i - @byoyomi = $2.to_i - - @time_clock = TimeClock::factory(Least_Time_Per_Move, @game_name) - end + time_map = Game.parse_time @game_name + @total_time = time_map[:total_time] + @byoyomi = time_map[:byoyomi] + @fischer = time_map[:fischer] + @time_clock = TimeClock::factory(board.least_time_per_move, @game_name) if (player0.sente) @sente, @gote = player0, player1 @@ -131,7 +157,7 @@ class Game propose end - attr_accessor :game_name, :total_time, :byoyomi, :sente, :gote, :game_id, :board, :current_player, :next_player, :fh, :monitors, :time_clock + attr_accessor :game_name, :total_time, :byoyomi, :fischer, :sente, :gote, :game_id, :board, :current_player, :next_player, :fh, :monitors, :time_clock attr_accessor :last_move, :current_turn attr_reader :result, :prepared_time @@ -292,6 +318,8 @@ class Game elsif (move_status == :oute_kaihimore) # the current player losed @result = GameResultOuteKaihiMoreWin.new(self, @next_player, @current_player) + elsif (move_status == :max_moves) + @result = GameResultMaxMovesDraw.new(self, @current_player, @next_player) else finish_flag = false end @@ -323,6 +351,11 @@ class Game @fh.puts("V2") @fh.puts("N+#{@sente.name}") @fh.puts("N-#{@gote.name}") + @fh.puts("'Max_Moves:#{@board.max_moves}") + @fh.puts("'Least_Time_Per_Move:#{@board.least_time_per_move}") + if @fischer > 0 + @fh.puts("'Increment:#{@fischer}") + end @fh.puts("$EVENT:#{@game_id}") @sente.write_safe(propose_message("+")) @@ -360,7 +393,7 @@ class Game def show() str0 = <