OSDN Git Service

command.rb: More elaborate error messages for the %%GAME command.
[shogi-server/shogi-server.git] / shogi_server / game.rb
index ee90d52..afb5d08 100644 (file)
@@ -87,7 +87,16 @@ class Game
     @sente.game = self
     @gote.game  = self
 
-    @last_move = @board.initial_moves.empty? ? "" : "%s,T1" % [@board.initial_moves.last]
+    @last_move = ""
+    unless @board.initial_moves.empty?
+      last_move = @board.initial_moves.last
+      case last_move
+      when Array
+        @last_move = last_move.join(",")
+      when String
+        @last_move = "%s,T1" % [last_move]
+      end
+    end
     @current_turn = @board.initial_moves.size
 
     @sente.status = "agree_waiting"
@@ -332,8 +341,14 @@ class Game
     unless @board.initial_moves.empty?
       @fh.puts "'buoy game starting with %d moves" % [@board.initial_moves.size]
       @board.initial_moves.each do |move|
-        @fh.puts move
-        @fh.puts "T1"
+        case move
+        when Array
+          @fh.puts move[0]
+          @fh.puts move[1]
+        when String
+          @fh.puts move
+          @fh.puts "T1"
+        end
       end
     end
   end
@@ -392,7 +407,14 @@ Least_Time_Per_Move:#{Least_Time_Per_Move}
 END Time
 BEGIN Position
 #{@board.initial_string.chomp}
-#{@board.initial_moves.collect {|m| m + ",T1"}.join("\n")}
+#{@board.initial_moves.collect do |m|
+  case m
+  when Array
+    m.join(",")
+  when String
+    m + ",T1"
+  end
+end.join("\n")}
 END Position
 END Game_Summary
 EOM
@@ -408,6 +430,21 @@ EOM
 
     return false
   end
+
+  # Read the .csa file and returns an array of moves and times.
+  # ex. [["+7776FU","T2"], ["-3334FU","T5"]]
+  #
+  def read_moves
+    ret = []
+    IO.foreach(@logfile) do |line|
+      if /^[\+\-]\d{4}[A-Z]{2}/ =~ line
+        ret << [line.chomp]
+      elsif /^T\d*/ =~ line
+        ret[-1] << line.chomp
+      end
+    end
+    return ret
+  end
   
   private