From: Daigo Moriwaki Date: Fri, 28 Dec 2012 06:23:45 +0000 (+0900) Subject: - shogi_server/pairing.rb: X-Git-Tag: 20170902~34^2~11^2 X-Git-Url: http://git.sourceforge.jp/view?p=shogi-server%2Fshogi-server.git;a=commitdiff_plain;h=81d6582813f9af7f2c23c0f056ee6960b3299e05;ds=sidebyside - 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. --- diff --git a/changelog b/changelog index 10bf44c..a919b75 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,12 @@ +2012-12-28 Daigo Moriwaki + + * [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 * [shogi-server] diff --git a/shogi_server/pairing.rb b/shogi_server/pairing.rb index c4819c7..64b4b46 100644 --- a/shogi_server/pairing.rb +++ b/shogi_server/pairing.rb @@ -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 diff --git a/test/TC_pairing.rb b/test/TC_pairing.rb index 30e9546..0902443 100644 --- a/test/TC_pairing.rb +++ b/test/TC_pairing.rb @@ -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