OSDN Git Service

Applied a patch from the wdoor-stable branch: Improved the logic avoiding human-human...
authorDaigo Moriwaki <beatles@users.sourceforge.jp>
Fri, 28 Dec 2012 08:44:29 +0000 (17:44 +0900)
committerDaigo Moriwaki <beatles@users.sourceforge.jp>
Fri, 28 Dec 2012 08:44:29 +0000 (17:44 +0900)
> commit 81d6582813f9af7f2c23c0f056ee6960b3299e05
> Author: Daigo Moriwaki <beatles@users.sourceforge.jp>
> Date:   Fri Dec 28 15:23:45 2012 +0900
>
>     - 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.

changelog
shogi_server/pairing.rb
test/TC_pairing.rb

index b6b8261..949397c 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.
+
 2012-01-07  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
index 6a660ec..d49366d 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