OSDN Git Service

Debugging Floodgate
authorbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Sun, 5 Oct 2008 15:05:13 +0000 (15:05 +0000)
committerbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Sun, 5 Oct 2008 15:05:13 +0000 (15:05 +0000)
shogi_server/league/floodgate.rb
shogi_server/pairing.rb
test/TC_floodgate.rb

index 3e0433e..d7df4e6 100644 (file)
@@ -41,8 +41,6 @@ class League
         Floodgate.game_name?(pl.game_name) &&
         pl.sente == nil
       end
-      #log_warning("DEBUG: %s" % [File.join(File.dirname(__FILE__), "pairing.rb")])
-      #load File.join(File.dirname(__FILE__), "pairing.rb")
       Pairing.default_pairing.match(players)
     end
   end # class Floodgate
index 8f292a9..01f4fe0 100644 (file)
@@ -38,7 +38,7 @@ module ShogiServer
       def random_pairing
         return [ExcludeSacrificeGps500.new,
                 MakeEven.new,
-                RandomPairing.new,
+                Randomize.new,
                 StartGame.new]
       end
 
@@ -61,10 +61,10 @@ module ShogiServer
 
     def less_than_one?(players)
       if players.size < 1
-        log_warning("Floodgate: At least one player is required")
+        log_warning("Floodgate: There should be at least one player.")
         return true
       else
-        return true
+        return false
       end
     end
 
@@ -76,7 +76,11 @@ module ShogiServer
           one.name
         end
       end
-      log_message("Floodgate: [Players] %s" % [str_array.join(", ")])
+      if str_array.empty?
+        log_message("Floodgate: [Players] None is here.")
+      else
+        log_message("Floodgate: [Players] %s." % [str_array.join(", ")])
+      end
     end
   end # Pairing
 
@@ -84,11 +88,12 @@ module ShogiServer
     def match(players)
       super
       if players.size < 2
-        log_warning("There should be more than one player: %d" % [players.size])
+        log_warning("Floodgate: There should be more than one player: %d" % [players.size])
         return
       end
       if players.size.odd?
-        log_warning("There are odd players: %d" % [players.size])
+        log_warning("Floodgate: There are odd players: %d. %s will not be matched." % 
+                    [players.size, players.last.name])
       end
 
       log_players(players)
@@ -220,7 +225,7 @@ module ShogiServer
   class MakeEven < Pairing
     def match(players)
       super
-      return if players.even?
+      return if players.size.even?
       log_message("Floodgate: there are odd players: %d. Deleting one..." % 
                   [players.size])
       DeletePlayerAtRandom.new.match(players)
index 7b0bc0d..94b7a60 100644 (file)
@@ -168,6 +168,40 @@ class TestDeleteMostPlayingPlayer < Test::Unit::TestCase
   end
 end
 
+class TestMakeEven < Test::Unit::TestCase  
+  def setup
+    srand(10)
+    @pairing= ShogiServer::MakeEven.new
+    @a = ShogiServer::BasicPlayer.new
+    @a.name = "a"
+    @a.win  = 1
+    @a.loss = 2
+    @a.rate = 0
+    @b = ShogiServer::BasicPlayer.new
+    @b.name = "b"
+    @b.win  = 10
+    @b.loss = 20
+    @b.rate = 1500
+    @c = ShogiServer::BasicPlayer.new
+    @c.name = "c"
+    @c.win  = 100
+    @c.loss = 200
+    @c.rate = 1000
+  end
+
+ def test_match_even
+    players = [@a, @b]
+    @pairing.match(players)
+    assert_equal([@a,@b], players)
+ end
+
+ def test_match_odd
+    players = [@a, @b, @c]
+    @pairing.match(players)
+    assert_equal([@a, @b], players)
+  end
+end
+
 class TestLeastRatePlayer < Test::Unit::TestCase  
   def setup
     @pairing= ShogiServer::DeleteLeastRatePlayer.new