OSDN Git Service

[shogi-server] - Previously, parameters in Floodgate time configuration file were...
authorDaigo Moriwaki <daigo@debian.org>
Thu, 26 Dec 2013 14:52:35 +0000 (23:52 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Thu, 26 Dec 2013 14:52:35 +0000 (23:52 +0900)
changelog
shogi_server/league/floodgate.rb
shogi_server/league/floodgate_thread.rb
test/TC_floodgate_thread.rb

index 3d114b7..fd7fe66 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,9 @@
+2013-12-26  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - Previously, parameters in Floodgate time configuration file were
+           not applied to actual instances. This issue has been fixed.
+
 2013-12-21  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
 2013-12-21  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
index 5d6ccaa..27be353 100644 (file)
@@ -27,16 +27,17 @@ class League
     #
     attr_reader :next_time
     attr_reader :league, :game_name
     #
     attr_reader :next_time
     attr_reader :league, :game_name
-    attr_reader :pairing_factory
+    attr_reader :pairing_factory, :sacrifice
     attr_reader :options
 
     def initialize(league, hash={})
       @league = league
     attr_reader :options
 
     def initialize(league, hash={})
       @league = league
-      @next_time = hash[:next_time] || nil
-      @game_name = hash[:game_name] || "floodgate-900-0"
-      @pairing_factory = "default_factory" # will be updated by NextTimeGenerator
-      # Options will be updated by NextTimeGenerator
-      @options = {:sacrifice => "gps500+e293220e3f8a3e59f79f6b0efffaa931"}
+      @next_time       = hash[:next_time] || nil
+      @game_name       = hash[:game_name] || "floodgate-900-0"
+      @pairing_factory = hash[:pairing_factory] || "default_factory" # will be updated by NextTimeGenerator
+      @sacrifice       = hash[:sacrifice] || "gps500+e293220e3f8a3e59f79f6b0efffaa931"
+      # @options is passed to a pairing factory
+      @options = {:sacrifice => @sacrifice}
       charge if @next_time.nil?
     end
 
       charge if @next_time.nil?
     end
 
index 231c8ce..a1b3d11 100644 (file)
@@ -68,15 +68,16 @@ module ShogiServer
       floodgate.match_game
     end
 
       floodgate.match_game
     end
 
-    # Regenerate floodgate instances from next_array for the next matches.
-    # @param next_array array of [game_name, next_time]
+    # Regenerate floodgate instances from next_instances for the next matches.
+    # @param next_instances array of [game_name, next_time]
     #
     #
-    def regenerate_leagues(next_array)
-      leagues = next_array.collect do |game_name, next_time|
-        log_message("Regenerating a floodgate league...: %s %s" % [game_name, next_time])
+    def regenerate_leagues(next_instances)
+      leagues = next_instances.collect do |prev|
+        log_message("Regenerating a floodgate league...: %s %s %s" %
+                    [prev.game_name, prev.next_time, prev.sacrifice])
         floodgate = ShogiServer::League::Floodgate.new($league, 
         floodgate = ShogiServer::League::Floodgate.new($league, 
-                                                       {:game_name => game_name,
-                                                        :next_time => next_time})
+                      {:game_name       => prev.game_name,       :next_time => prev.next_time,
+                       :pairing_factory => prev.pairing_factory, :sacrifice => prev.sacrifice})
       end
       floodgate_reload_log(leagues)
       return leagues
       end
       floodgate_reload_log(leagues)
       return leagues
@@ -98,20 +99,18 @@ module ShogiServer
             floodgate = next_league(leagues)
             next if wait_next_floodgate(floodgate)
 
             floodgate = next_league(leagues)
             next if wait_next_floodgate(floodgate)
 
-            next_array = leagues.collect do |floodgate|
-              if (floodgate.next_time - Time.now) > 0
-                [floodgate.game_name, floodgate.next_time]
-              else
+            next_instances = leagues.collect do |floodgate|
+              unless (floodgate.next_time - Time.now) > 0
                 start_games(floodgate)
                 floodgate.charge # updates next_time
                 start_games(floodgate)
                 floodgate.charge # updates next_time
-                [floodgate.game_name, floodgate.next_time] 
               end
               end
+              floodgate
             end
 
             reload_shogi_server
 
             # Regenerate floodgate instances after ShogiServer.realod
             end
 
             reload_shogi_server
 
             # Regenerate floodgate instances after ShogiServer.realod
-            leagues = regenerate_leagues(next_array)
+            leagues = regenerate_leagues(next_instances)
           rescue Exception => ex 
             # ignore errors
             log_error("[in Floodgate's thread] #{ex} #{ex.backtrace}")
           rescue Exception => ex 
             # ignore errors
             log_error("[in Floodgate's thread] #{ex} #{ex.backtrace}")
index 434f2b8..f1fb034 100644 (file)
@@ -65,7 +65,13 @@ class TestSetupFloodgate < Test::Unit::TestCase
   def test_regenerate_leagues
     game_names = %w(floodgate-900-0 floodgate-3600-0)
     now = Time.now
   def test_regenerate_leagues
     game_names = %w(floodgate-900-0 floodgate-3600-0)
     now = Time.now
-    next_array = [["floodgate-900-0", now+100], ["floodgate-3600-0", now+200]]
+    next_array = []
+    next_array << ShogiServer::League::Floodgate.new($league, 
+                    {:game_name => "floodgate-900-0",
+                     :next_time => (now+100)})
+    next_array << ShogiServer::League::Floodgate.new($league, 
+                    {:game_name => "floodgate-3600-0",
+                     :next_time => (now+200)})
     objs = @sf.regenerate_leagues(next_array)
     assert_equal 2, objs.size
     assert_instance_of ShogiServer::League::Floodgate, objs[0]
     objs = @sf.regenerate_leagues(next_array)
     assert_equal 2, objs.size
     assert_instance_of ShogiServer::League::Floodgate, objs[0]