OSDN Git Service

[shogi-server] - shogi_server/pairing.rb: Impose penalty on matches between likely...
authorDaigo Moriwaki <daigo@debian.org>
Sat, 21 Dec 2013 08:47:13 +0000 (17:47 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sat, 21 Dec 2013 08:47:13 +0000 (17:47 +0900)
changelog
shogi_server/pairing.rb
test/TC_pairing.rb

index 37d6d10..3d114b7 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,9 @@
+2013-12-21  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - shogi_server/pairing.rb: Impose penalty on matches between
+           likely kin players.
+
 2013-12-15  Daigo Moriwaki <daigo at debian dot org>
 
        * [webserver]
index 946af2f..fec47af 100644 (file)
@@ -494,6 +494,13 @@ module ShogiServer
         if p1.is_human? && p2.is_human?
           ret += 800
         end
+
+        # 2.3 a match with likely kin players
+        if (p1.player_id[0..6] == p2.player_id[0..6])
+          ret += 800
+        elsif (p1.player_id[0..3] == p2.player_id[0..3])
+          ret += 400
+        end
       end
 
       ret
index 30f353e..94274fa 100644 (file)
@@ -411,6 +411,19 @@ class TestLeastDiff < Test::Unit::TestCase
     @x.player_id = "x"
     @x.name = "x"
 
+    @abcdefg1 = ShogiServer::BasicPlayer.new
+    @abcdefg1.player_id = "abcdefg1"
+    @abcdefg1.name = "abcdefg1"
+    @abcdefg1.rate = 2100
+    @abcdefg2 = ShogiServer::BasicPlayer.new
+    @abcdefg2.player_id = "abcdefg2"
+    @abcdefg2.name = "abcdefg2"
+    @abcdefg2.rate = 2200
+    @abcdxyz = ShogiServer::BasicPlayer.new
+    @abcdxyz.player_id = "abcdxyz"
+    @abcdxyz.name = "abcdxyz"
+    @abcdxyz.rate = 2300
+
     $league.add(@a)
     $league.add(@b)
     $league.add(@c)
@@ -420,6 +433,9 @@ class TestLeastDiff < Test::Unit::TestCase
     $league.add(@g)
     $league.add(@h)
     $league.add(@x)
+    $league.add(@abcdefg1)
+    $league.add(@abcdefg2)
+    $league.add(@abcdxyz)
   end
 
   def teardown
@@ -548,6 +564,16 @@ class TestLeastDiff < Test::Unit::TestCase
     assert_equal(@b.rate-@a.rate+400+@h.rate-@g.rate+400, @pairing.calculate_diff_with_penalty(players, @history))
   end
 
+  def test_calculate_diff_with_kin_4_players
+    players = [@abcdefg1, @abcdxyz]
+    assert_equal(@abcdxyz.rate - @abcdefg1.rate + 400, @pairing.calculate_diff_with_penalty(players,nil))
+  end
+
+  def test_calculate_diff_with_kin_7_players
+    players = [@abcdefg1, @abcdefg2]
+    assert_equal(@abcdefg2.rate - @abcdefg1.rate + 800, @pairing.calculate_diff_with_penalty(players,nil))
+  end
+
   def test_get_player_rate_0
     assert_equal(2150, @pairing.get_player_rate(@x, @history))