OSDN Git Service

* [shogi-server]
authorbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Sun, 1 Feb 2009 05:44:10 +0000 (05:44 +0000)
committerbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Sun, 1 Feb 2009 05:44:10 +0000 (05:44 +0000)
  - The shogi-server records csa files of games in an illegal
    format. This issue has been fixed. (Closes: #14635)
  - A ##[MONITOR] command for showing a game result such as %TORYO
    was not correct. This issue has been fixed.

changelog
shogi_server/game.rb
test/TC_functional.rb

index e599f59..89dcc32 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,6 +1,14 @@
+2009-02-01 Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - The shogi-server records csa files of games in an illegal
+           format. This issue has been fixed. (Closes: #14635)
+         - A ##[MONITOR] command for showing a game result such as %TORYO
+           was not correct. This issue has been fixed.  
+
 2009-01-13 Daigo Moriwaki <daigo at debian dot org>
 
-       * [shogi_server]
+       * [shogi-server]
          - It failed to proccess a game result, OuteKaihiMoreWin where a
            checked king does not escape. This issue has been fixed.
 
index fadb5e6..365b608 100644 (file)
@@ -28,7 +28,7 @@ module ShogiServer # for a namespace
 class MonitorObserver
   def update(game_result)
     game_result.game.each_monitor do |monitor|
-      monitor.write_safe("##[MONITOR][%s] %s\n" % [game_result.game.game_id, game_result.type])
+      monitor.write_safe("##[MONITOR][%s] %s\n" % [game_result.game.game_id, game_result.result_type])
     end
   end
 end
@@ -46,7 +46,7 @@ class GameResult
   attr_reader :black
   # White plyer object
   attr_reader :white
-  # Command to send monitors such as '%%TORYO' etc...
+  # Command to send monitors such as '%TORYO' etc...
   attr_reader :result_type
 
   def initialize(game, p1, p2)
@@ -92,7 +92,7 @@ class GameResult
   end
 
   def log_board
-    log(@game.board.to_s.gsub(/^/, "\'"))
+    log(@game.board.to_s.gsub(/^/, "\'").chomp)
   end
 
 end
@@ -118,9 +118,9 @@ class GameResultWin < GameResult
       black_result = "lose"
       white_result = "win"
     end
-    log("'summary:%s:%s %s:%s %s\n" % [type, 
-                                       @black.name, black_result,
-                                       @white.name, white_result])
+    log("'summary:%s:%s %s:%s %s" % [type, 
+                                     @black.name, black_result,
+                                     @white.name, white_result])
 
   end
 end
@@ -129,9 +129,9 @@ class GameResultAbnormalWin < GameResultWin
   def process
     @winner.write_safe("%TORYO\n#RESIGN\n#WIN\n")
     @loser.write_safe( "%TORYO\n#RESIGN\n#LOSE\n")
-    log("%%TORYO\n")
+    log("%TORYO")
     log_summary("abnormal")
-    @result_type = "%%TORYO"
+    @result_type = "%TORYO"
     notify
   end
 end
@@ -151,9 +151,9 @@ class GameResultKachiWin < GameResultWin
   def process
     @winner.write_safe("%KACHI\n#JISHOGI\n#WIN\n")
     @loser.write_safe( "%KACHI\n#JISHOGI\n#LOSE\n")
-    log("%%KACHI\n")
+    log("%KACHI")
     log_summary("kachi")
-    @result_type = "%%KACHI"
+    @result_type = "%KACHI"
     notify
   end
 end
@@ -163,9 +163,9 @@ class GameResultIllegalKachiWin < GameResultWin
   def process
     @winner.write_safe("%KACHI\n#ILLEGAL_MOVE\n#WIN\n")
     @loser.write_safe( "%KACHI\n#ILLEGAL_MOVE\n#LOSE\n")
-    log("%%KACHI\n")
+    log("%KACHI")
     log_summary("illegal kachi")
-    @result_type = "%%KACHI"
+    @result_type = "%KACHI"
     notify
   end
 end
@@ -213,9 +213,9 @@ class GameResultToryoWin < GameResultWin
   def process
     @winner.write_safe("%TORYO\n#RESIGN\n#WIN\n")
     @loser.write_safe( "%TORYO\n#RESIGN\n#LOSE\n")
-    log("%%TORYO\n")
+    log("%TORYO")
     log_summary("toryo")
-    @result_type = "%%TORYO"
+    @result_type = "%TORYO"
     notify
   end
 end
@@ -239,7 +239,7 @@ class GameResultDraw < GameResult
   
   def log_summary(type)
     log_board
-    log("'summary:%s:%s draw:%s draw\n" % [type, @black.name, @white.name])
+    log("'summary:%s:%s draw:%s draw" % [type, @black.name, @white.name])
   end
 end
 
index da98435..c29c160 100644 (file)
@@ -5,10 +5,10 @@ class TestClientAtmark < BaseClient
   # login with trip
   def login
     cmd "LOGIN testsente@p1 dummy x1"
-    cmd "%%GAME testcase-1500-0 +"
+    cmd "%%GAME testClientAtmark-1500-0 +"
     
     cmd2 "LOGIN testgote@p2 dummy2 x1"
-    cmd2 "%%CHALLENGE testcase-1500-0 -"
+    cmd2 "%%CHALLENGE testClientAtmark-1500-0 -"
   end
 
   def test_toryo
@@ -17,6 +17,53 @@ class TestClientAtmark < BaseClient
     end
     assert(/#LOSE/ =~ result)
     assert(/#WIN/  =~ result2)
+
+    now = Time.now
+    year  = now.strftime("%Y")
+    month = now.strftime("%m")
+    day   = now.strftime("%d")
+    path = File.join( File.dirname(__FILE__), "..", year, month, day, "*testClientAtmark-1500-0*")
+    log_files = Dir.glob(path)
+    assert(!log_files.empty?) 
+    log_content = File.open(log_files.sort.last).read
+
+    # "$EVENT", "$START_TIME" and "'$END_TIME" are removed since they vary dinamically.
+    should_be = <<-EOF
+V2
+N+testsente@p1
+N-testgote@p2
+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+P2 * -HI *  *  *  *  * -KA * 
+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
+P4 *  *  *  *  *  *  *  *  * 
+P5 *  *  *  *  *  *  *  *  * 
+P6 *  *  *  *  *  *  *  *  * 
+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
+P8 * +KA *  *  *  *  * +HI * 
+P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
++
+'rating:testsente@p1+275876e34cf609db118f3d84b799a790:testgote@p2+c0c40e7a94eea7e2c238b75273087710
++2726FU
+T1
+-3334FU
+T1
+%TORYO
+'P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+'P2 * -HI *  *  *  *  * -KA * 
+'P3-FU-FU-FU-FU-FU-FU * -FU-FU
+'P4 *  *  *  *  *  * -FU *  * 
+'P5 *  *  *  *  *  *  *  *  * 
+'P6 *  *  *  *  *  *  * +FU * 
+'P7+FU+FU+FU+FU+FU+FU+FU * +FU
+'P8 * +KA *  *  *  *  * +HI * 
+'P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
+'+
+'summary:toryo:testsente@p1 lose:testgote@p2 win
+EOF
+
+    log_content.gsub!(/^\$.*?\n/m, "")
+    log_content.gsub!(/^'\$.*?\n/m, "")
+    assert_equal(should_be, log_content)
   end
 end