+# LoggingObserver appends a result of each game to a log file, which will
+# be used to calculate rating scores of players.
+#
+class LoggingObserver
+ def initialize
+ @logfile = File.join($league.dir, "00LIST")
+ end
+
+ def update(game_result)
+ end_time_str = game_result.end_time.strftime("%Y/%m/%d %H:%M:%S")
+ black = game_result.black
+ white = game_result.white
+ black_name = black.rated? ? black.player_id : black.name
+ white_name = white.rated? ? white.player_id : white.name
+ msg = [end_time_str,
+ game_result.log_summary_type,
+ game_result.black_result,
+ black_name,
+ white_name,
+ game_result.white_result,
+ game_result.game.logfile]
+ begin
+ # Note that this is proccessed in the gian lock.
+ File.open(@logfile, "a") do |f|
+ f << msg.join("\t") << "\n"
+ end
+ rescue => e
+ # ignore
+ $stderr.puts "Failed to write to the game result file: #{@logfile}" if $DEBUG
+ end
+ end
+end
+
+# Base abstract class for a game result.
+# Imediate subclasses are GameResultWin and GameResultDraw.