-
- if (@next_player.status != "game") # rival is logout or disconnected
- abnormal_win()
- elsif (status == :timeout)
- timeout_lose()
- elsif (move_status == :illegal)
- illegal_lose()
- elsif (move_status == :kachi_win)
- kachi_win()
- elsif (move_status == :kachi_lose)
- kachi_lose()
- elsif (move_status == :toryo)
- toryo_lose()
- elsif (move_status == :outori)
- outori_win()
- elsif (move_status == :sennichite)
- sennichite_draw()
- elsif (move_status == :oute_sennichite)
- oute_sennichite_lose()
- elsif (move_status == :uchifuzume)
- uchifuzume_lose()
- elsif (move_status == :oute_kaihimore)
- oute_kaihimore_lose()
- else
- finish_flag = false
- end
- finish() if finish_flag
- (@current_player, @next_player) = [@next_player, @current_player]
- @start_time = Time::new
- return finish_flag
- end
- end
-
- def abnormal_win
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("%TORYO\n#RESIGN\n#WIN\n")
- @next_player.write_safe("%TORYO\n#RESIGN\n#LOSE\n")
- @fh.printf("%%TORYO\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:abnormal:%s win:%s lose\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] %%TORYO\n", @id))
- end
- end
-
- def abnormal_lose
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("%TORYO\n#RESIGN\n#LOSE\n")
- @next_player.write_safe("%TORYO\n#RESIGN\n#WIN\n")
- @fh.printf("%%TORYO\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:abnormal:%s lose:%s win\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] %%TORYO\n", @id))
- end
- end
-
- def sennichite_draw
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("#SENNICHITE\n#DRAW\n")
- @next_player.write_safe("#SENNICHITE\n#DRAW\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:sennichite:%s draw:%s draw\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] #SENNICHITE\n", @id))
- end
- end
-
- def oute_sennichite_lose
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("#OUTE_SENNICHITE\n#LOSE\n")
- @next_player.write_safe("#OUTE_SENNICHITE\n#WIN\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:oute_sennichite:%s lose:%s win\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] #OUTE_SENNICHITE\n", @id))
- end
- end
-
- def illegal_lose
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("#ILLEGAL_MOVE\n#LOSE\n")
- @next_player.write_safe("#ILLEGAL_MOVE\n#WIN\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:illegal move:%s lose:%s win\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] #ILLEGAL_MOVE\n", @id))
- end
- end
-
- def uchifuzume_lose
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("#ILLEGAL_MOVE\n#LOSE\n")
- @next_player.write_safe("#ILLEGAL_MOVE\n#WIN\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:uchifuzume:%s lose:%s win\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] #ILLEGAL_MOVE\n", @id))
- end
- end
-
- def oute_kaihimore_lose
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("#ILLEGAL_MOVE\n#LOSE\n")
- @next_player.write_safe("#ILLEGAL_MOVE\n#WIN\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:oute_kaihimore:%s lose:%s win\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] #ILLEGAL_MOVE\n", @id))
- end
- end
-
- def timeout_lose
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("#TIME_UP\n#LOSE\n")
- @next_player.write_safe("#TIME_UP\n#WIN\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:time up:%s lose:%s win\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] #TIME_UP\n", @id))
- end
- end
-
- def kachi_win
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("%KACHI\n#JISHOGI\n#WIN\n")
- @next_player.write_safe("%KACHI\n#JISHOGI\n#LOSE\n")
- @fh.printf("%%KACHI\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:kachi:%s win:%s lose\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] %%KACHI\n", @id))
- end
- end
-
- def kachi_lose
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("%KACHI\n#ILLEGAL_MOVE\n#LOSE\n")
- @next_player.write_safe("%KACHI\n#ILLEGAL_MOVE\n#WIN\n")
- @fh.printf("%%KACHI\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:illegal kachi:%s lose:%s win\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] %%KACHI\n", @id))
- end
- end
-
- def toryo_lose
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("%TORYO\n#RESIGN\n#LOSE\n")
- @next_player.write_safe("%TORYO\n#RESIGN\n#WIN\n")
- @fh.printf("%%TORYO\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:toryo:%s lose:%s win\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] %%TORYO\n", @id))
- end
- end
-
- def outori_win
- @current_player.status = "connected"
- @next_player.status = "connected"
- @current_player.write_safe("#ILLEGAL_MOVE\n#WIN\n")
- @next_player.write_safe("#ILLEGAL_MOVE\n#LOSE\n")
- @fh.print(@board.to_s.gsub(/^/, "\'"))
- @fh.printf("'summary:outori:%s win:%s lose\n", @current_player.name, @next_player.name)
- @monitors.each do |monitor|
- monitor.write_safe(sprintf("##[MONITOR][%s] #ILLEGAL_MOVE\n", @id))
- end
- end
-
- def start
- log_message(sprintf("game started %s", @id))
- @sente.write_safe(sprintf("START:%s\n", @id))
- @gote.write_safe(sprintf("START:%s\n", @id))
- @sente.mytime = @total_time
- @gote.mytime = @total_time
- @start_time = Time::new
- end
-
- def propose
- begin
- @fh = open(@logfile, "w")
- @fh.sync = true
-
- @fh.printf("V2\n")
- @fh.printf("N+%s\n", @sente.name)
- @fh.printf("N-%s\n", @gote.name)
- @fh.printf("$EVENT:%s\n", @id)
-
- @sente.write_safe(propose_message("+"))
- @gote.write_safe(propose_message("-"))
-
- @fh.printf("$START_TIME:%s\n", Time::new.strftime("%Y/%m/%d %H:%M:%S"))
- @fh.print <<EOM
-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
-+
-EOM
- end
- end
-
- def show()
- str0 = <<EOM
-BEGIN Game_Summary
-Protocol_Version:1.1
-Protocol_Mode:Server
-Format:Shogi 1.0
-Declaration:Jishogi 1.1
-Game_ID:#{@id}
-Name+:#{@sente.name}
-Name-:#{@gote.name}
-Rematch_On_Draw:NO
-To_Move:+
-BEGIN Time
-Time_Unit:1sec
-Total_Time:#{@total_time}
-Byoyomi:#{@byoyomi}
-Least_Time_Per_Move:#{Least_Time_Per_Move}
-Remaining_Time+:#{@sente.mytime}
-Remaining_Time-:#{@gote.mytime}
-Last_Move:#{@last_move}
-Current_Turn:#{@current_turn}
-END Time
-BEGIN Position
-EOM
-
- str1 = <<EOM
-END Position
-END Game_Summary
-EOM
-
- return str0 + @board.to_s + str1
- end
-
- def propose_message(sg_flag)
- str = <<EOM
-BEGIN Game_Summary
-Protocol_Version:1.1
-Protocol_Mode:Server
-Format:Shogi 1.0
-Declaration:Jishogi 1.1
-Game_ID:#{@id}
-Name+:#{@sente.name}
-Name-:#{@gote.name}
-Your_Turn:#{sg_flag}
-Rematch_On_Draw:NO
-To_Move:+
-BEGIN Time
-Time_Unit:1sec
-Total_Time:#{@total_time}
-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-
-+
-END Position
-END Game_Summary
-EOM
- return str
- end
-
- private
-
- def issue_current_time
- time = Time::new.strftime("%Y%m%d%H%M%S").to_i
- @@mutex.synchronize do
- while time <= @@time do
- time += 1
- end
- @@time = time