-
- @sente.write(sprintf("START:%s\n", @id))
- @gote.write(sprintf("START:%s\n", @id))
- while(true)
- @currnet_player = @sente
- @next_player = @gote
- handle_one_move(@currnet_player, @next_player)
-
- @currnet_player = @gote
- @next_player = @sente
- handle_one_move(@currnet_player, @next_player)
- end
- rescue ShogiWatchdogTimeout
- sg_flag_of_timeout = $!.message
- if (sg_flag_of_timeout == "+")
- loser = @sente
- winner = @gote
- else
- loser = @sente
- winner = @gote
- end
- printf("watchdog timeout by %s\n", loser.name)
- loser.write("#TIME_UP\n#LOSE\n")
- winner.write("#TIME_UP\n#WIN\n")
- rescue TimeoutError, ShogiTimeout
- printf("%s: end timeup by %s\n", Time::new.to_s, @currnet_player.name)
- @currnet_player.write("#TIME_UP\n#LOSE\n")
- @next_player.write("#TIME_UP\n#WIN\n")
- rescue ShogiReject
- sender = $!.message
- printf("%s: reject by %s\n", Time::new.to_s, sender)
- str = sprintf("REJECT:%s by %s\n", @id, sender)
- @sente.write(str)
- @gote.write(str)
- rescue ShogiIllegalMove
- printf("%s: end illegal move by %s\n", Time::new.to_s, @currnet_player.name)
- move = $!.message
- @fh.printf("%%ERROR\n")
- @currnet_player.write(sprintf("%s\n#ILLEGAL_MOVE\n#LOSE\n", move))
- @next_player.write(sprintf("%s\n#ILLEGAL_MOVE\n#WIN\n", move))
- rescue ShogiEnd
- printf("%s: end by %s\n", Time::new.to_s, @currnet_player.name)
- move = $!.message
- case move
- when "%TORYO"
- @currnet_player.write(sprintf("%s\n#RESIGN\n#LOSE\n", move))
- @next_player.write(sprintf("%s\n#RESIGN\n#WIN\n", move))
- when "%KACHI"
- @currnet_player.write(sprintf("%s\n#JISHOGI\n#WIN\n", move))
- @next_player.write(sprintf("%s\n#JISHOGI\n#LOSE\n", move))
- end