X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=shogi_server%2Fgame.rb;h=6225c79f022c7fefa79faf5b8a800727f64acc20;hb=9f5313a36a411c5aa04dc8d7e4103740136dddef;hp=0134ddd36a29e01d4763e93928327e3182d91e63;hpb=b378ba13c26b11254d3cef81d6d6a26cb824e43c;p=shogi-server%2Fshogi-server.git diff --git a/shogi_server/game.rb b/shogi_server/game.rb index 0134ddd..6225c79 100644 --- a/shogi_server/game.rb +++ b/shogi_server/game.rb @@ -76,6 +76,7 @@ class GameResult $options["floodgate-history"] add_observer League::Floodgate::History.factory end + end def process @@ -262,7 +263,7 @@ class Game @@mutex = Mutex.new @@time = 0 - def initialize(game_name, player0, player1) + def initialize(game_name, player0, player1, board) @monitors = Array::new @game_name = game_name if (@game_name =~ /-(\d+)-(\d+)$/) @@ -277,12 +278,17 @@ class Game end @sente.socket_buffer.clear @gote.socket_buffer.clear - @current_player, @next_player = @sente, @gote + @board = board + if @board.teban + @current_player, @next_player = @sente, @gote + else + @current_player, @next_player = @gote, @sente + end @sente.game = self @gote.game = self - @last_move = "" - @current_turn = 0 + @last_move = @board.initial_moves.empty? ? "" : "%s,T1" % [@board.initial_moves.last] + @current_turn = @board.initial_moves.size @sente.status = "agree_waiting" @gote.status = "agree_waiting" @@ -305,8 +311,6 @@ class Game log_message(sprintf("game created %s", @game_id)) - @board = Board::new - @board.initial @start_time = nil @fh = open(@logfile, "w") @fh.sync = true @@ -318,6 +322,9 @@ class Game attr_accessor :last_move, :current_turn attr_reader :result, :prepared_time + # Path of a log file for this game. + attr_reader :logfile + def rated? @sente.rated? && @gote.rated? end @@ -483,8 +490,16 @@ class Game return finish_flag end + def is_startable_status? + return (@sente && @gote && + (@sente.status == "start_waiting") && + (@gote.status == "start_waiting")) + end + def start log_message(sprintf("game started %s", @game_id)) + @sente.status = "game" + @gote.status = "game" @sente.write_safe(sprintf("START:%s\n", @game_id)) @gote.write_safe(sprintf("START:%s\n", @game_id)) @sente.mytime = @total_time @@ -520,6 +535,13 @@ EOM white_name = @gote.rated? ? @gote.player_id : @gote.name @fh.puts("'rating:%s:%s" % [black_name, white_name]) end + unless @board.initial_moves.empty? + @fh.puts "'buoy game starting with %d moves" % [@board.initial_moves.size] + @board.initial_moves.each do |move| + @fh.puts move + @fh.puts "T1" + end + end end def show() @@ -567,7 +589,7 @@ Name+:#{@sente.name} 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} @@ -575,18 +597,7 @@ Byoyomi:#{@byoyomi} Least_Time_Per_Move:#{Least_Time_Per_Move} END Time BEGIN Position -P1-KY-KE-GI-KI-OU-KI-GI-KE-KY -P2 * -HI * * * * * -KA * -P3-FU-FU-FU-FU-FU-FU-FU-FU-FU -P4 * * * * * * * * * -P5 * * * * * * * * * -P6 * * * * * * * * * -P7+FU+FU+FU+FU+FU+FU+FU+FU+FU -P8 * +KA * * * * * +HI * -P9+KY+KE+GI+KI+OU+KI+GI+KE+KY -P+ -P- -+ +#{@board.to_s.chomp} END Position END Game_Summary EOM