shogi-server source
Revisión | 32adcedbca9b794239ae0d2c63fb248dc8102372 (tree) |
---|---|
Tiempo | 2013-12-26 23:52:35 |
Autor | Daigo Moriwaki <daigo@debi...> |
Commiter | Daigo Moriwaki |
[shogi-server] - Previously, parameters in Floodgate time configuration file were not applied to actual instances. This issue has been fixed.
@@ -1,3 +1,9 @@ | ||
1 | +2013-12-26 Daigo Moriwaki <daigo at debian dot org> | |
2 | + | |
3 | + * [shogi-server] | |
4 | + - Previously, parameters in Floodgate time configuration file were | |
5 | + not applied to actual instances. This issue has been fixed. | |
6 | + | |
1 | 7 | 2013-12-21 Daigo Moriwaki <daigo at debian dot org> |
2 | 8 | |
3 | 9 | * [shogi-server] |
@@ -27,16 +27,17 @@ class League | ||
27 | 27 | # |
28 | 28 | attr_reader :next_time |
29 | 29 | attr_reader :league, :game_name |
30 | - attr_reader :pairing_factory | |
30 | + attr_reader :pairing_factory, :sacrifice | |
31 | 31 | attr_reader :options |
32 | 32 | |
33 | 33 | def initialize(league, hash={}) |
34 | 34 | @league = league |
35 | - @next_time = hash[:next_time] || nil | |
36 | - @game_name = hash[:game_name] || "floodgate-900-0" | |
37 | - @pairing_factory = "default_factory" # will be updated by NextTimeGenerator | |
38 | - # Options will be updated by NextTimeGenerator | |
39 | - @options = {:sacrifice => "gps500+e293220e3f8a3e59f79f6b0efffaa931"} | |
35 | + @next_time = hash[:next_time] || nil | |
36 | + @game_name = hash[:game_name] || "floodgate-900-0" | |
37 | + @pairing_factory = hash[:pairing_factory] || "default_factory" # will be updated by NextTimeGenerator | |
38 | + @sacrifice = hash[:sacrifice] || "gps500+e293220e3f8a3e59f79f6b0efffaa931" | |
39 | + # @options is passed to a pairing factory | |
40 | + @options = {:sacrifice => @sacrifice} | |
40 | 41 | charge if @next_time.nil? |
41 | 42 | end |
42 | 43 |
@@ -68,15 +68,16 @@ module ShogiServer | ||
68 | 68 | floodgate.match_game |
69 | 69 | end |
70 | 70 | |
71 | - # Regenerate floodgate instances from next_array for the next matches. | |
72 | - # @param next_array array of [game_name, next_time] | |
71 | + # Regenerate floodgate instances from next_instances for the next matches. | |
72 | + # @param next_instances array of [game_name, next_time] | |
73 | 73 | # |
74 | - def regenerate_leagues(next_array) | |
75 | - leagues = next_array.collect do |game_name, next_time| | |
76 | - log_message("Regenerating a floodgate league...: %s %s" % [game_name, next_time]) | |
74 | + def regenerate_leagues(next_instances) | |
75 | + leagues = next_instances.collect do |prev| | |
76 | + log_message("Regenerating a floodgate league...: %s %s %s" % | |
77 | + [prev.game_name, prev.next_time, prev.sacrifice]) | |
77 | 78 | floodgate = ShogiServer::League::Floodgate.new($league, |
78 | - {:game_name => game_name, | |
79 | - :next_time => next_time}) | |
79 | + {:game_name => prev.game_name, :next_time => prev.next_time, | |
80 | + :pairing_factory => prev.pairing_factory, :sacrifice => prev.sacrifice}) | |
80 | 81 | end |
81 | 82 | floodgate_reload_log(leagues) |
82 | 83 | return leagues |
@@ -98,20 +99,18 @@ module ShogiServer | ||
98 | 99 | floodgate = next_league(leagues) |
99 | 100 | next if wait_next_floodgate(floodgate) |
100 | 101 | |
101 | - next_array = leagues.collect do |floodgate| | |
102 | - if (floodgate.next_time - Time.now) > 0 | |
103 | - [floodgate.game_name, floodgate.next_time] | |
104 | - else | |
102 | + next_instances = leagues.collect do |floodgate| | |
103 | + unless (floodgate.next_time - Time.now) > 0 | |
105 | 104 | start_games(floodgate) |
106 | 105 | floodgate.charge # updates next_time |
107 | - [floodgate.game_name, floodgate.next_time] | |
108 | 106 | end |
107 | + floodgate | |
109 | 108 | end |
110 | 109 | |
111 | 110 | reload_shogi_server |
112 | 111 | |
113 | 112 | # Regenerate floodgate instances after ShogiServer.realod |
114 | - leagues = regenerate_leagues(next_array) | |
113 | + leagues = regenerate_leagues(next_instances) | |
115 | 114 | rescue Exception => ex |
116 | 115 | # ignore errors |
117 | 116 | log_error("[in Floodgate's thread] #{ex} #{ex.backtrace}") |
@@ -65,7 +65,13 @@ class TestSetupFloodgate < Test::Unit::TestCase | ||
65 | 65 | def test_regenerate_leagues |
66 | 66 | game_names = %w(floodgate-900-0 floodgate-3600-0) |
67 | 67 | now = Time.now |
68 | - next_array = [["floodgate-900-0", now+100], ["floodgate-3600-0", now+200]] | |
68 | + next_array = [] | |
69 | + next_array << ShogiServer::League::Floodgate.new($league, | |
70 | + {:game_name => "floodgate-900-0", | |
71 | + :next_time => (now+100)}) | |
72 | + next_array << ShogiServer::League::Floodgate.new($league, | |
73 | + {:game_name => "floodgate-3600-0", | |
74 | + :next_time => (now+200)}) | |
69 | 75 | objs = @sf.regenerate_leagues(next_array) |
70 | 76 | assert_equal 2, objs.size |
71 | 77 | assert_instance_of ShogiServer::League::Floodgate, objs[0] |