OSDN Git Service

[shogi-server] Give more penalty on assigning matches with same players. (Closes...
authorDaigo Moriwaki <daigo@debian.org>
Sat, 7 Apr 2018 06:07:34 +0000 (15:07 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sat, 7 Apr 2018 06:07:34 +0000 (15:07 +0900)
changelog
shogi_server/pairing.rb
test/TC_pairing.rb

index 75667d2..707b575 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,9 @@
+2018-04-07  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server] Give more penalty on assigning matches with same
+         players.
+         (Closes #38178)
+
 2017-09-03  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server] Write game results in categorical files
index cc2ea62..f2094e8 100644 (file)
@@ -496,6 +496,11 @@ module ShogiServer
             (history.last_opponent(p1.player_id) == p2.player_id ||
              history.last_opponent(p2.player_id) == p1.player_id))
           ret += 400
+         if p1.estimated_rate != 0 || p2.estimated_rate != 0
+            # unrated players should make games with various players.
+             very_large = 4000
+            ret += very_large
+         end
         end
 
         # 2.2 Human vs Human
index 86970ca..aa49ea9 100644 (file)
@@ -424,6 +424,11 @@ class TestLeastDiff < Test::Unit::TestCase
     @abcdxyz.name = "abcdxyz"
     @abcdxyz.rate = 2300
 
+    @unrated = ShogiServer::BasicPlayer.new
+    @unrated.player_id = "unrated"
+    @unrated.name = "unrated"
+    @unrated.estimated_rate = 450
+
     $league.add(@a)
     $league.add(@b)
     $league.add(@c)
@@ -580,6 +585,32 @@ class TestLeastDiff < Test::Unit::TestCase
     assert_equal(@abcdefg2.rate - @abcdefg1.rate + 800, @pairing.calculate_diff_with_penalty(players,nil))
   end
 
+  def test_calculate_diff_with_unrated_player
+    players = [@unrated, @a]
+    dummy = nil
+    def @history.make_record(game_result)
+      {:game_id => "wdoor+floodgate-900-0-a-unrated-1",
+       :black => "a",  :white => "unrated",
+       :winner => "unrated", :loser => "a"}
+    end
+    @history.update(dummy)
+    assert_equal(4000 + 400 + (@a.rate - @unrated.estimated_rate).abs,
+               @pairing.calculate_diff_with_penalty(players,@history))
+  end
+
+  def test_calculate_diff_with_unrated_player_2
+    players = [@a, @unrated]
+    dummy = nil
+    def @history.make_record(game_result)
+      {:game_id => "wdoor+floodgate-900-0-a-unrated-1",
+       :black => "a",  :white => "unrated",
+       :winner => "unrated", :loser => "a"}
+    end
+    @history.update(dummy)
+    assert_equal(4000 + 400 + (@a.rate - @unrated.estimated_rate).abs,
+               @pairing.calculate_diff_with_penalty(players,@history))
+  end
+
   def test_get_player_rate_0
     assert_equal(2150, @pairing.get_player_rate(@x, @history))