OSDN Git Service

[shogi-server] [mk_game_results] Change schema to add number of moves
authorDaigo Moriwaki <daigo@debian.org>
Sat, 2 Sep 2017 11:22:27 +0000 (20:22 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sat, 2 Sep 2017 11:22:27 +0000 (20:22 +0900)
The format of an internal game result summary file, '00LIST',
has been changed to add number of moves of a game, which would be of
help for a script calculating rating scores.
(Closes #37491)

changelog
mk_game_results
shogi_server/game_result.rb

index b33c74a..1dac463 100644 (file)
--- a/changelog
+++ b/changelog
@@ -5,6 +5,11 @@
          "%SENNICHITE" are now recorded in CSA files when a game ends for
          timed up or sennichite respectively.
          (Closes #37490)
+       * [shogi-server] [mk_game_results] Change schema to add number of
+         moves The format of an internal game result summary file, '00LIST',
+         has been changed to add number of moves of a game, which would be of
+         help for a script calculating rating scores.
+         (Closes #37491)
 
 2017-02-26 Daigo Moriwaki <daigo at debian dot org>
 
index 0260f88..f08ca98 100755 (executable)
 require 'getoptlong'
 
 # Parse a CSA file. A tab-delimited line format is
-#   time  state  black_mark  black_id  white_id  white_mark  filepath 
+#   time  state  black_mark  black_id  white_id  white_mark  filepath  moves
 # time:: YYYY/MM/DD hh:mm:ss
 # black_mark:: win lose draw
 # black_id::   black player's id
 # white_mark:: win lose draw
 # white_id::   white player's id
 # filepath::   absolute file path
+# moves:: number of moves
 #
 # @parameter file an absolute path of a csa file
 #
@@ -64,36 +65,49 @@ def grep(file)
     str = File.open(file, "r").read
   end
 
-  if /^N\+(.*)$/ =~ str then black_name = $1.strip end
-  if /^N\-(.*)$/ =~ str then white_name = $1.strip end
+    black_name = ""
+    black_mark = ""
+    black_id = ""
+    white_name = ""
+    white_mark = ""
+    white_id = ""
+    state = ""
+    time = ""
+    moves = 0
+    str.each_line do |line|
+        line.strip!
+        case line
+            when /^[\+\-]\d{4}\w{2}.*$/
+                moves += 1
+      when /^N\+(.*)$/
+                black_name = $1.strip
+      when /^N\-(.*)$/
+                white_name = $1.strip
+      when /^'summary:(.*)$/
+        state, p1, p2 = $1.split(":").map {|a| a.strip}
+        p1_name, p1_mark = p1.split(" ")
+        p2_name, p2_mark = p2.split(" ")
+        if p1_name == black_name
+          black_name, black_mark = p1_name, p1_mark
+          white_name, white_mark = p2_name, p2_mark
+        elsif p2_name == black_name
+          black_name, black_mark = p2_name, p2_mark
+          white_name, white_mark = p1_name, p1_mark
+        else
+          raise "Never reach!: #{black_name}, #{p1}, #{p2} in #{file}"
+        end
+      when /^'\$END_TIME:(.*)$/
+        time = $1.strip
+      when /^'rating:(.*)$/
+        black_id, white_id = $1.split(":").map {|a| a.strip}
+    end # case
+    end # do line
 
-  if /^'summary:(.*)$/ =~ str
-    state, p1, p2 = $1.split(":").map {|a| a.strip}    
-    p1_name, p1_mark = p1.split(" ")
-    p2_name, p2_mark = p2.split(" ")
-    if p1_name == black_name
-      black_name, black_mark = p1_name, p1_mark
-      white_name, white_mark = p2_name, p2_mark
-    elsif p2_name == black_name
-      black_name, black_mark = p2_name, p2_mark
-      white_name, white_mark = p1_name, p1_mark
-    else
-      raise "Never reach!: #{black} #{white} #{p3} #{p2}"
-    end
-  end
-
-  if /^'\$END_TIME:(.*)$/ =~ str
-    time = $1.strip
-  end
-
-  if /^'rating:(.*)$/ =~ str
-    black_id, white_id = $1.split(":").map {|a| a.strip}
-    if black_id && white_id && (black_id != white_id) &&
-       black_mark && white_mark && state && time
-      puts [time, state, black_mark, black_id, white_id, white_mark, file].join("\t")
-    end
+  if black_id && white_id && (black_id != white_id) &&
+     black_mark && white_mark && state && time
+    puts [time, state, black_mark, black_id, white_id, white_mark, file, moves].join("\t")
+    $stdout.flush
   end
-  $stdout.flush
 end
 
 # Show Usage
@@ -144,4 +158,4 @@ if __FILE__ == $0
   main
 end
 
-# vim: ts=2 sw=2 sts=0
+# vim: tabstop=4 shiftwidth=4 expandtab
index 27902b9..15542de 100644 (file)
@@ -52,7 +52,8 @@ class LoggingObserver
            black_name,
            white_name,
            game_result.white_result,
-           game_result.game.logfile]
+           game_result.game.logfile,
+          game_result.game.board.move_count]
     begin
       # Note that this is proccessed in the gian lock.
       File.open(@logfile, "a") do |f|