OSDN Git Service

- shogi_server/pairing.rb:
authorDaigo Moriwaki <beatles@users.sourceforge.jp>
Fri, 28 Dec 2012 06:23:45 +0000 (15:23 +0900)
committerDaigo Moriwaki <beatles@users.sourceforge.jp>
Fri, 28 Dec 2012 06:27:00 +0000 (15:27 +0900)
  + There was a bug in the logic avoiding human-human match.
    This issue has been fixed.
  + Improved the logic avoiding human-human match. Human-human
    matches will less likely happen.

changelog
shogi_server/pairing.rb
test/TC_pairing.rb

index 10bf44c..a919b75 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,12 @@
+2012-12-28  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - shogi_server/pairing.rb:
+           + There was a bug in the logic avoiding human-human match.
+             This issue has been fixed.
+           + Improved the logic avoiding human-human match. Human-human
+             matches will less likely happen.
+
 2010-10-06  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
index c4819c7..64b4b46 100644 (file)
@@ -163,7 +163,7 @@ module ShogiServer
         for i in 0..(humans.size-2)  # -2
           next if humans[i].odd?
           if humans[i]+1 == humans[i+1]
-            pairing_possible = i
+            pairing_possible = humans[i]
             break
           end
         end
@@ -173,7 +173,7 @@ module ShogiServer
         end
 
         current_index = pairing_possible
-        j = (current_index == 0 ? current_index : current_index-1)
+        j = [0, current_index - 2].max
         while j < players.size
           break if players[j].is_computer?
           j += 1
index 30e9546..0902443 100644 (file)
@@ -144,6 +144,26 @@ class TestStartGameWithoutHumans < Test::Unit::TestCase
     @d.win  = 1000
     @d.loss = 2000
     @d.rate = 2000
+    @e = ShogiServer::BasicPlayer.new
+    @e.name = "e"
+    @e.win  = 3000
+    @e.loss = 3000
+    @e.rate = 3000
+    @f = ShogiServer::BasicPlayer.new
+    @f.name = "f"
+    @f.win  = 4000
+    @f.loss = 4000
+    @f.rate = 4000
+    @g = ShogiServer::BasicPlayer.new
+    @g.name = "g"
+    @g.win  = 5000
+    @g.loss = 5000
+    @g.rate = 5000
+    @h = ShogiServer::BasicPlayer.new
+    @h.name = "h"
+    @h.win  = 6000
+    @h.loss = 6000
+    @h.rate = 6000
   end
 
   def test_match_one_player
@@ -276,8 +296,8 @@ class TestStartGameWithoutHumans < Test::Unit::TestCase
     players = [@a,@b,@c,@d]
     @pairing.match(players)
     assert_equal(2, $paired.size)
-    assert(same_pair?([@a,@b], $paired[0]))
-    assert(same_pair?([@c,@d], $paired[1]))
+    assert(same_pair?([@a,@c], $paired[0]))
+    assert(same_pair?([@b,@d], $paired[1]))
   end
 
   def test_match_four_players_abcd_human
@@ -291,6 +311,20 @@ class TestStartGameWithoutHumans < Test::Unit::TestCase
     assert(same_pair?([@a,@b], $paired[0]))
     assert(same_pair?([@c,@d], $paired[1]))
   end
+
+  def test_match_eight_players_efgh_human
+    @e.name += "_human"
+    @f.name += "_human"
+    @g.name += "_human"
+    @h.name += "_human"
+    players = [@a,@b,@c,@d,@e,@f,@g,@h]
+    @pairing.match(players)
+    assert_equal(4, $paired.size)
+    assert(same_pair?([@e,@c], $paired[0]))
+    assert(same_pair?([@d,@g], $paired[1]))
+    assert(same_pair?([@a,@f], $paired[2]))
+    assert(same_pair?([@b,@h], $paired[3]))
+  end
 end