@loss = 0
@last_game_win = false
@sente = nil
+ @game_name = ""
end
# Idetifier of the player in the rating system
# true for Sente; false for Gote
attr_accessor :sente
+ # game name
+ attr_accessor :game_name
+
+ def is_human?
+ return [%r!_human$!, %r!_human@!].any? do |re|
+ re.match(@name)
+ end
+ end
+
+ def is_computer?
+ return !is_human?
+ end
+
def modified_at
@modified_at || Time.now
end
@protocol = nil # CSA or x1
@eol = eol || "\m" # favorite eol code
@game = nil
- @game_name = ""
@mytime = 0 # set in start method also
@socket_buffer = []
@main_thread = Thread::current
end
attr_accessor :socket, :status
- attr_accessor :protocol, :eol, :game, :mytime, :game_name
+ attr_accessor :protocol, :eol, :game, :mytime
attr_accessor :main_thread
attr_reader :socket_buffer
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
$mutex.unlock
end
end # enf of while
+ log_warning("%s's socket was suddenly closed" % [@name])
end # def run
end # class