OSDN Git Service

Merge remote-tracking branch 'origin/master' into wdoor-stable
[shogi-server/shogi-server.git] / test / TC_game.rb
index a2b8366..08ffcf2 100644 (file)
@@ -5,6 +5,9 @@ require 'shogi_server/board'
 require 'shogi_server/game'
 require 'shogi_server/player'
 
+$options = {}
+$options["least-time-per-move"] = 1
+
 def log_message(str)
   $stderr.puts str
 end
@@ -52,7 +55,7 @@ BEGIN Time
 Time_Unit:1sec
 Total_Time:1500
 Byoyomi:0
-Least_Time_Per_Move:1
+Least_Time_Per_Move:#{$options["least-time-per-move"]}
 END Time
 BEGIN Position
 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
@@ -86,7 +89,7 @@ BEGIN Time
 Time_Unit:1sec
 Total_Time:1500
 Byoyomi:0
-Least_Time_Per_Move:1
+Least_Time_Per_Move:#{$options["least-time-per-move"]}
 END Time
 BEGIN Position
 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
@@ -154,7 +157,7 @@ BEGIN Time
 Time_Unit:1sec
 Total_Time:1500
 Byoyomi:0
-Least_Time_Per_Move:1
+Least_Time_Per_Move:#{$options["least-time-per-move"]}
 END Time
 BEGIN Position
 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
@@ -189,7 +192,7 @@ BEGIN Time
 Time_Unit:1sec
 Total_Time:1500
 Byoyomi:0
-Least_Time_Per_Move:1
+Least_Time_Per_Move:#{$options["least-time-per-move"]}
 END Time
 BEGIN Position
 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
@@ -261,7 +264,7 @@ BEGIN Time
 Time_Unit:1sec
 Total_Time:1500
 Byoyomi:0
-Least_Time_Per_Move:1
+Least_Time_Per_Move:#{$options["least-time-per-move"]}
 END Time
 BEGIN Position
 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
@@ -297,7 +300,7 @@ BEGIN Time
 Time_Unit:1sec
 Total_Time:1500
 Byoyomi:0
-Least_Time_Per_Move:1
+Least_Time_Per_Move:#{$options["least-time-per-move"]}
 END Time
 BEGIN Position
 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
@@ -368,5 +371,41 @@ EOF
     game.monitoroff(handler2)
     assert_equal(0, game.monitors.size)
   end
+
+  def test_decide_turns
+    p1 = MockPlayer.new
+    p1.name = "p1"
+    p2 = MockPlayer.new
+    p2.name = "p2"
+
+    p1.sente=nil; p2.sente=false
+    ShogiServer::Game::decide_turns(p1, "+", p2)
+    assert_equal true, p1.sente
+
+    p1.sente=nil; p2.sente=nil
+    ShogiServer::Game::decide_turns(p1, "+", p2)
+    assert_equal true, p1.sente
+
+    p1.sente=nil; p2.sente=true
+    ShogiServer::Game::decide_turns(p1, "-", p2)
+    assert_equal false, p1.sente
+
+    p1.sente=nil; p2.sente=nil
+    ShogiServer::Game::decide_turns(p1, "-", p2)
+    assert_equal false, p1.sente
+
+    p1.sente=nil; p2.sente=false
+    ShogiServer::Game::decide_turns(p1, "*", p2)
+    assert_equal true, p1.sente
+
+    p1.sente=nil; p2.sente=true
+    ShogiServer::Game::decide_turns(p1, "*", p2)
+    assert_equal false, p1.sente
+
+    p1.sente=nil; p2.sente=nil
+    ShogiServer::Game::decide_turns(p1, "*", p2)
+    assert (p1.sente == true  && p2.sente == false) ||
+           (p1.sente == false && p2.sente == true)
+  end
 end