OSDN Git Service

* [shogi-server]
[shogi-server/shogi-server.git] / shogi_server / pairing.rb
index bb840fe..7d70cbb 100644 (file)
@@ -1,7 +1,7 @@
 ## $Id$
 
 ## Copyright (C) 2004 NABEYA Kenichi (aka nanami@2ch)
-## Copyright (C) 2007-2008 Daigo Moriwaki (daigo at debian dot org)
+## Copyright (C) 2007-2012 Daigo Moriwaki (daigo at debian dot org)
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -60,8 +60,16 @@ module ShogiServer
                 StartGameWithoutHumans.new]
       end
 
-      def match(players)
-        logics = default_factory
+      def floodgate_zyunisen
+        return [LogPlayers.new,
+                ExcludeUnratedPlayers.new,
+                ExcludeSacrificeGps500.new,
+                MakeEven.new,
+                LeastDiff.new,
+                StartGameWithoutHumans.new]
+      end
+
+      def match(players, logics)
         logics.inject(players) do |result, item|
           item.match(result)
           result
@@ -298,7 +306,7 @@ module ShogiServer
     def match(players)
       super
       return if less_than_one?(players)
-      one = players.choice
+      one = players.sample
       log_message("Floodgate: Deleted %s at random" % [one.name])
       players.delete(one)
       log_players(players)
@@ -388,17 +396,6 @@ module ShogiServer
       players.shuffle
     end
 
-    def average_rate(players)
-      n=0
-      sum=0
-      players.find_all{|p| p.rate}.each do |p|
-        n += 1
-        sum += p.rate
-      end
-
-      return n > 0 ? sum/n : 2150 # interger
-    end
-
     # Returns a player's rate value.
     # 1. If it has a valid rate, return the rate.
     # 2. If it has no valid rate, return average of the following values:
@@ -504,10 +501,23 @@ module ShogiServer
           min_score = s
         end
       end
-      log_message("Floodgate: the least score %d (%d per player)" % [min_score, min_score/players.size])
+      log_message("Floodgate: the least score %d (%d per player) [%s]" % [min_score, min_score/players.size, scores.join(" ")])
 
-      players = matches[min_index]
+      players.replace(matches[min_index])
     end
   end
 
+  # This pairing method excludes unrated players
+  #
+  class ExcludeUnratedPlayers < Pairing
+
+    def match(players)
+      super
+
+      log_message("Floodgate: Deleting unrated players...")
+      players.delete_if{|a| a.rate == 0}
+      log_players(players)
+    end
+  end # class ExcludeUnratedPlayers
+
 end # ShogiServer