OSDN Git Service

* [shogi-server] Ignore the last move of two sequential ones
authordaigo <beatles@users.sourceforge.jp>
Sun, 7 Mar 2010 12:56:01 +0000 (21:56 +0900)
committerDaigo Moriwaki <daigo at debian dot org>
Sun, 7 Mar 2010 14:13:12 +0000 (23:13 +0900)
- If two sequential moves from a player are identical, the last
  one will be ignored and a game is in play. This situation might
  happen with human players, especially on slow network,
  impatiently sending a move twice.

changelog
shogi_server/command.rb
test/TC_functional.rb
test/TC_jishogi_kachi.rb
test/TC_oute_sennichite.rb
test/TC_uchifuzume.rb
test/baseclient.rb
test/mock_game.rb

index 76b79b9..6129633 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,11 @@
+2010-03-07  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - If two sequential moves from a player are identical, the last
+           one will be ignored and a game is in play. This situation might
+           happen with human players, especially on slow network,
+           impatiently sending a move twice. 
+
 2010-02-27  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
index ee81965..403d5b9 100644 (file)
@@ -139,6 +139,11 @@ module ShogiServer
       if (@player.status == "game")
         array_str = @str.split(",")
         move = array_str.shift
+        if @player.game.last_move &&
+           @player.game.last_move.split(",").first == move
+          log_warning("Received two sequencial identical moves [#{move}] from #{@player.name}. The last one was ignored.")
+          return :continue
+        end
         additional = array_str.shift
         comment = nil
         if /^'(.*)/ =~ additional
index 27e9171..5de7dd2 100644 (file)
@@ -296,3 +296,17 @@ class TestFunctionalChatCommand < BaseClient
     assert("", str)
   end
 end
+
+class TestTwoSameMoves < CSABaseClient
+  def test_two_same_moves
+    result, result2 = handshake do
+      cmd  "+7776FU"
+      cmd2 "-3334FU"
+      cmd2 "-3334FU"
+      cmd  "+2726FU"
+      sleep 1
+    end
+    assert(/#ILLEGAL_MOVE/ !~ result)
+    assert(/#ILLEGAL_MOVE/ !~ result2)
+  end
+end
index 33e8602..38f9b49 100644 (file)
@@ -7,8 +7,10 @@ class JishogiTest < ReadFileClient
     handshake(csa)
     cmd2 "%KACHI"
     sleep 1
-    result1 = read_nonblock(@socket1)
-    result2 = read_nonblock(@socket2)
+    result1 = cmd ""
+    result2 = cmd2 ""
+    result1 += read_nonblock(@socket1)
+    result2 += read_nonblock(@socket2)
     logout12
     assert_match(/#JISHOGI.#LOSE/m, result1)
     assert_match(/#JISHOGI.#WIN/m, result2)
index 2938047..fda83b4 100644 (file)
@@ -7,8 +7,10 @@ class OuteSennichiteTest < ReadFileClient
     handshake(csa)
     #cmd2 "%KACHI"
     sleep 1
-    result1 = read_nonblock(@socket1)
-    result2 = read_nonblock(@socket2)
+    result1 = cmd ""
+    result2 = cmd2 ""
+    result1 += read_nonblock(@socket1)
+    result2 += read_nonblock(@socket2)
     logout12
     assert_match(/#OUTE_SENNICHITE.#LOSE/m, result1)
     assert_match(/#OUTE_SENNICHITE.#WIN/m, result2)
@@ -19,8 +21,10 @@ class OuteSennichiteTest < ReadFileClient
     handshake(csa)
     #cmd2 "%KACHI"
     sleep 1
-    result1 = read_nonblock(@socket1)
-    result2 = read_nonblock(@socket2)
+    result1 = cmd ""
+    result2 = cmd2 ""
+    result1 += read_nonblock(@socket1)
+    result2 += read_nonblock(@socket2)
     logout12
     assert_match(/#OUTE_SENNICHITE.#WIN/m, result1)
     assert_match(/#OUTE_SENNICHITE.#LOSE/m, result2)
@@ -31,8 +35,10 @@ class OuteSennichiteTest < ReadFileClient
     handshake(csa)
     #cmd2 "%KACHI"
     sleep 1
-    result1 = read_nonblock(@socket1)
-    result2 = read_nonblock(@socket2)
+    result1 = cmd ""
+    result2 = cmd2 ""
+    result1 += read_nonblock(@socket1)
+    result2 += read_nonblock(@socket2)
     logout12
     assert_match(/#OUTE_SENNICHITE.#LOSE/m, result1)
     assert_match(/#OUTE_SENNICHITE.#WIN/m, result2)
index 97b86b3..1798a0e 100644 (file)
@@ -8,6 +8,8 @@ class UchifuzumeTest < ReadFileClient
     result2 = cmd2 "-0064FU"
     result1 = cmd  "%TORYO"
     sleep 1
+    result1 = cmd ""
+    result2 = cmd2 ""
     result1 += read_nonblock(@socket1)
     result2 += read_nonblock(@socket2)
     logout12
@@ -21,8 +23,10 @@ class UchifuzumeTest < ReadFileClient
     cmd2 "-0092FU"
     cmd  "%TORYO"
     sleep 1
-    result1 = read_nonblock(@socket1)
-    result2 = read_nonblock(@socket2)
+    result1 = cmd ""
+    result2 = cmd2 ""
+    result1 += read_nonblock(@socket1)
+    result2 += read_nonblock(@socket2)
     logout12
     assert_match(/#LOSE/m, result1)
     assert_match(/#WIN/m, result2)
index eea2969..d8d487b 100644 (file)
@@ -7,7 +7,9 @@ class BaseClient < Test::Unit::TestCase
     port = 4000
     params = {"Host" => "localhost", "Port" => port, "Prompt" => //}
     @socket1 = TCPSocket.open("localhost", port)
+    @socket1.sync = true
     @socket2 = TCPSocket.open("localhost", port)
+    @socket2.sync = true
   end
 
   def teardown
@@ -111,8 +113,10 @@ class ReadFileClient < BaseClient
     while line = csa_io.gets do
       case line
       when /^\+\d{4}\w{2}/
+        cmd ""
         cmd $&
       when /^\-\d{4}\w{2}/
+        cmd2 ""
         cmd2 $&
       end
     end
index a30b326..943434c 100644 (file)
@@ -7,6 +7,7 @@ class MockGame
   attr_accessor :started
   attr_accessor :game_id
   attr_accessor :game_name
+  attr_accessor :last_move
 
   def initialize
     @finish_flag     = false