+2010-02-27 Daigo Moriwaki <daigo at debian dot org>
+
+ * [shogi-server]
+ - The server now provides more accurate time control. Previouslly,
+ a player's thinking time included a time waiting to get the giant
+ lock. This may have caused games to time up, especially, during
+ byo-yomi etc.
+
2010-01-22 Daigo Moriwaki <daigo at debian dot org>
* [shogi-server]
class Command
# Factory method
#
- def Command.factory(str, player)
+ def Command.factory(str, player, time=Time.now)
cmd = nil
case str
when ""
cmd = ErrorCommand.new(str, player)
end
+ cmd.time = time
return cmd
end
def initialize(str, player)
@str = str
@player = player
+ @time = Time.now # this should be replaced later with a real time
end
+ attr_accessor :time
end
# Application-level protocol for Keep-Alive.
if /^'(.*)/ =~ additional
comment = array_str.unshift("'*#{$1.toeuc}")
end
- s = @player.game.handle_one_move(move, @player)
+ s = @player.game.handle_one_move(move, @player, @time)
@player.game.log_game(Kconv.toeuc(comment.first)) if (comment && comment.first && !s)
return :return if (s && @player.protocol == LoginCSA::PROTOCOL)
end
def in_game_status
rc = :continue
- s = @player.game.handle_one_move(@str, @player)
+ s = @player.game.handle_one_move(@str, @player, @time)
rc = :return if (s && @player.protocol == LoginCSA::PROTOCOL)
return rc
end
# class Game
- def handle_one_move(str, player)
+ def handle_one_move(str, player, end_time)
unless turn?(player)
return false if str == :timeout
end
finish_flag = true
- @end_time = Time::new
+ @end_time = end_time
t = [(@end_time - @start_time).floor, Least_Time_Per_Move].max
move_status = nil
def run(csa_1st_str=nil)
while ( csa_1st_str ||
str = gets_safe(@socket, (@socket_buffer.empty? ? Default_Timeout : 1)) )
+ time = Time.now
log(:info, :in, str) if str && str.instance_of?(String)
$mutex.lock
begin
end
str.chomp! if (str.class == String) # may be strip! ?
- cmd = ShogiServer::Command.factory(str, self)
+ delay = Time.now - time
+ if delay > 5
+ log_warning("Detected a long delay: %.2f sec" % [delay])
+ end
+ cmd = ShogiServer::Command.factory(str, self, time)
case cmd.call
when :return
return
@monitoroff_called = false
end
- def handle_one_move(move, player)
+ def handle_one_move(move, player, time)
return @finish_flag
end