OSDN Git Service

Fixed a bug #23245.
authordaigo <beatles@users.sourceforge.jp>
Sat, 18 Sep 2010 02:45:54 +0000 (11:45 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sat, 18 Sep 2010 02:45:54 +0000 (11:45 +0900)
For hadicapped games, wrong initial positions were delivered to players and
monitors. This issue has been fixed. (Closes: #23245)

changelog
shogi_server/board.rb
shogi_server/game.rb
test/TC_functional.rb
test/TC_handicapped_boards.rb

index a38bc08..36010b7 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,11 @@
+2010-09-18  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - shogi_server/board.rb, game.rb: For hadicapped games, wrong
+           initial positions were delivered to players and monitors.  This
+           issue has been fixed. (Closes: #23245) 
+           Thanks to HIDETCHI for reporting the issue.
+
 2010-09-05  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
index ca12959..d2b304b 100644 (file)
@@ -675,6 +675,8 @@ EOF
     return :normal
   end
 
+  # Return a CSA-styled string notation of the current position.
+  #
   def to_s
     a = Array::new
     y = 1
@@ -711,6 +713,14 @@ EOF
     a.push("%s\n" % [@teban ? "+" : "-"])
     return a.join
   end
+
+  # Return a CSA-styled string notation of the initial position.
+  #
+  def initial_string
+    tmp_board = self.class.new
+    tmp_board.initial
+    return tmp_board.to_s
+  end
 end
 
 end # ShogiServer
index f8c20fb..ee90d52 100644 (file)
@@ -323,18 +323,7 @@ class Game
 
     now = Time.now.strftime("%Y/%m/%d %H:%M:%S")
     @fh.puts("$START_TIME:#{now}")
-    @fh.print <<EOM
-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
-+
-EOM
+    @fh.print(@board.initial_string)
     if rated?
       black_name = @sente.rated? ? @sente.player_id : @sente.name
       white_name = @gote.rated?  ? @gote.player_id  : @gote.name
@@ -402,7 +391,7 @@ Byoyomi:#{@byoyomi}
 Least_Time_Per_Move:#{Least_Time_Per_Move}
 END Time
 BEGIN Position
-#{Board::INITIAL_HIRATE_POSITION}
+#{@board.initial_string.chomp}
 #{@board.initial_moves.collect {|m| m + ",T1"}.join("\n")}
 END Position
 END Game_Summary
index 44b5240..fdf0d0b 100644 (file)
@@ -68,6 +68,73 @@ EOF
   end
 end
 
+class TestHandicappedGame < BaseClient
+  # login with trip
+  def set_name
+    super
+    @game_name = "hc2p_hoge"
+    @p1_name = "B"
+    @p2_name = "W"
+  end
+
+  def test_toryo
+    result, result2 = handshake do
+      @p1.toryo
+      wait_finish
+    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, "*hc2p_hoge-1500-0*")
+    log_files = Dir.glob(path)
+    assert(!log_files.empty?) 
+    sleep 0.1
+    log_content = File.read(log_files.sort.last)
+
+    # "$EVENT", "$START_TIME" and "'$END_TIME" are removed since they vary dinamically.
+    should_be = <<-EOF
+V2
+N+hc2p_hoge_B
+N-hc2p_hoge_W
+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 *  *  *  *  *  *  *  *  * 
+P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
++
+'rating:hc2p_hoge_B+275876e34cf609db118f3d84b799a790:hc2p_hoge_W+275876e34cf609db118f3d84b799a790
++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 *  *  *  *  *  *  *  *  * 
+'P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
+'+
+'summary:toryo:hc2p_hoge_B lose:hc2p_hoge_W win
+EOF
+
+    log_content.gsub!(/^\$.*?\n/m, "")
+    log_content.gsub!(/^'\$.*?\n/m, "")
+    assert_equal(should_be, log_content)
+  end
+end
+
 
 class TestComment < BaseClient
   def test_toryo
index 0413ec0..ddf3e25 100644 (file)
@@ -24,6 +24,7 @@ P9 * +KE+GI+KI+OU+KI+GI+KE+KY
 +
 EOF
     assert_equal(answer, str)
+    assert_equal(answer, board.initial_string)
   end
 
   def test_hcbishop
@@ -44,6 +45,7 @@ P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
 +
 EOF
     assert_equal(answer, str)
+    assert_equal(answer, board.initial_string)
   end
 
   def test_hcrook
@@ -64,6 +66,7 @@ P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
 +
 EOF
     assert_equal(answer, str)
+    assert_equal(answer, board.initial_string)
   end
 
   def test_hcrooklance
@@ -84,6 +87,7 @@ P9 * +KE+GI+KI+OU+KI+GI+KE+KY
 +
 EOF
     assert_equal(answer, str)
+    assert_equal(answer, board.initial_string)
   end
 
   def test_hc2p
@@ -124,6 +128,7 @@ P9 * +KE+GI+KI+OU+KI+GI+KE *
 +
 EOF
     assert_equal(answer, str)
+    assert_equal(answer, board.initial_string)
   end
 
   def test_hc6p
@@ -164,6 +169,7 @@ P9 *  *  * +KI+OU+KI *  *  *
 +
 EOF
     assert_equal(answer, str)
+    assert_equal(answer, board.initial_string)
   end
 
   def test_hc10p
@@ -184,6 +190,7 @@ P9 *  *  *  * +OU *  *  *  *
 +
 EOF
     assert_equal(answer, str)
+    assert_equal(answer, board.initial_string)
   end
 
 end