OSDN Git Service

players.yaml is now read only. The server no longer writes last_game_win data to...
[shogi-server/shogi-server.git] / shogi_server / pairing.rb
index 8f292a9..992dbcb 100644 (file)
@@ -29,16 +29,18 @@ module ShogiServer
       end
 
       def sort_by_rate_with_randomness
-        return [ExcludeSacrificeGps500.new,
+        return [LogPlayers.new,
+                ExcludeSacrificeGps500.new,
                 MakeEven.new,
                 SortByRateWithRandomness.new(1200, 2400),
                 StartGame.new]
       end
 
       def random_pairing
-        return [ExcludeSacrificeGps500.new,
+        return [LogPlayers.new,
+                ExcludeSacrificeGps500.new,
                 MakeEven.new,
-                RandomPairing.new,
+                Randomize.new,
                 StartGame.new]
       end
 
@@ -46,6 +48,7 @@ module ShogiServer
         logics = default_factory
         logics.inject(players) do |result, item|
           item.match(result)
+          result
         end
       end
     end # class << self
@@ -61,10 +64,10 @@ module ShogiServer
 
     def less_than_one?(players)
       if players.size < 1
-        log_warning("Floodgate: At least one player is required")
+        log_warning("Floodgate: There should be at least one player.")
         return true
       else
-        return true
+        return false
       end
     end
 
@@ -76,19 +79,31 @@ module ShogiServer
           one.name
         end
       end
-      log_message("Floodgate: [Players] %s" % [str_array.join(", ")])
+      if str_array.empty?
+        log_message("Floodgate: [Players] None is here.")
+      else
+        log_message("Floodgate: [Players] %s." % [str_array.join(", ")])
+      end
     end
   end # Pairing
 
+
+  class LogPlayers < Pairing
+    def match(players)
+      log_players(players)
+    end
+  end
+
   class StartGame < Pairing
     def match(players)
       super
       if players.size < 2
-        log_warning("There should be more than one player: %d" % [players.size])
+        log_warning("Floodgate: There should be more than one player: %d" % [players.size])
         return
       end
       if players.size.odd?
-        log_warning("There are odd players: %d" % [players.size])
+        log_warning("Floodgate: There are odd players: %d. %s will not be matched." % 
+                    [players.size, players.last.name])
       end
 
       log_players(players)
@@ -99,7 +114,7 @@ module ShogiServer
       end
     end
 
-    def start_game
+    def start_game(p1, p2)
       log_message("Floodgate: BLACK %s; WHITE %s" % [p1.name, p2.name])
       p1.sente = true
       p2.sente = false
@@ -220,7 +235,7 @@ module ShogiServer
   class MakeEven < Pairing
     def match(players)
       super
-      return if players.even?
+      return if players.size.even?
       log_message("Floodgate: there are odd players: %d. Deleting one..." % 
                   [players.size])
       DeletePlayerAtRandom.new.match(players)