OSDN Git Service

The 'test' directory has been moved under 'shogi-server'
[shogi-server/shogi-server.git] / pairing.rb
index 4cca5ab..6a922d8 100644 (file)
@@ -4,8 +4,8 @@ module ShogiServer
 
     class << self
       def default_pairing
-        return SwissPairing.new
-        #return ExcludeSacrifice.new(SwissPairing.new)
+        #return SwissPairing.new
+        return ExcludeSacrifice.new(SwissPairing.new)
         #return RandomPairing.new
         #return ExcludeSacrifice.new(RandomPairing.new)
       end
@@ -27,6 +27,10 @@ module ShogiServer
       Game.new(p1.game_name, p1, p2)
     end
 
+    def include_newbie?(players)
+      return players.find{|a| a.rate == 0} == nil ? false : true
+    end
+
     def delete_player_at_random(players)
       return players.delete_at(rand(players.size))
     end
@@ -37,6 +41,7 @@ module ShogiServer
     end
     
     def delete_most_playing_player(players)
+      # TODO ??? undefined method `<=>' for nil:NilClass
       max_player = players.max {|a,b| a.win + a.loss <=> b.win + b.loss}
       return players.delete(max_player)
     end
@@ -74,7 +79,7 @@ module ShogiServer
       return if players.size < 2
 
       if players.size % 2 == 1
-        delete_most_playing_player(players)
+        delete_player_at_random(players)
       end
       pairing_and_start_game(players)
     end
@@ -89,7 +94,11 @@ module ShogiServer
       remains     = players - win_players
       if win_players.size >= 2
         if win_players.size % 2 == 1
-          remains << delete_least_rate_player(win_players)
+#          if include_newbie?(win_players)
+            remains << delete_player_at_random(win_players)
+#          else
+#            remains << delete_least_rate_player(win_players)
+#          end
         end         
         pairing_and_start_game(win_players)
       else
@@ -97,7 +106,8 @@ module ShogiServer
       end
       return if remains.size < 2
       if remains.size % 2 == 1
-        delete_most_playing_player(remains)
+        delete_player_at_random(remains)
+        # delete_most_playing_player(remains)
       end
       pairing_and_start_game(remains)
     end
@@ -114,9 +124,9 @@ module ShogiServer
     def match(players)
       if @sacrifice && 
          players.size % 2 == 1 && 
-         players.find{|a| a.id == @sacrifice}
+         players.find{|a| a.player_id == @sacrifice}
         log_message("Floodgate: first, exclude %s" % [@sacrifice])
-        players.delete_if{|a| a.id == @sacrifice}
+        players.delete_if{|a| a.player_id == @sacrifice}
       end
       @pairing.match(players)
     end