• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

shogi-server source


Commit MetaInfo

Revisãod7dc48d302a0b0ffaeba2f7a05099912e148a1c6 (tree)
Hora2013-12-29 16:33:19
AutorDaigo Moriwaki <daigo@debi...>
CommiterDaigo Moriwaki

Mensagem de Log

Merge branch '201312-fix-sacrifice'

Mudança Sumário

Diff

--- a/changelog
+++ b/changelog
@@ -1,3 +1,9 @@
1+2013-12-29 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+
17 2013-12-21 Daigo Moriwaki <daigo at debian dot org>
28
39 * [shogi-server]
--- a/shogi_server/league/floodgate.rb
+++ b/shogi_server/league/floodgate.rb
@@ -27,16 +27,17 @@ class League
2727 #
2828 attr_reader :next_time
2929 attr_reader :league, :game_name
30- attr_reader :pairing_factory
3130 attr_reader :options
3231
3332 def initialize(league, hash={})
3433 @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"}
34+ @next_time = hash[:next_time] || nil
35+ @game_name = hash[:game_name] || "floodgate-900-0"
36+ # Options will be updated by NextTimeGenerator and then passed to a
37+ # pairing factory.
38+ @options = {}
39+ @options[:pairing_factory] = hash[:pairing_factory] || "default_factory"
40+ @options[:sacrifice] = hash[:sacrifice] || "gps500+e293220e3f8a3e59f79f6b0efffaa931"
4041 charge if @next_time.nil?
4142 end
4243
@@ -44,25 +45,33 @@ class League
4445 return Regexp.new(@game_name).match(str) ? true : false
4546 end
4647
48+ def pairing_factory
49+ return @options[:pairing_factory]
50+ end
51+
52+ def sacrifice
53+ return @options[:sacrifice]
54+ end
55+
4756 def charge
4857 ntg = NextTimeGenerator.factory(@game_name)
49- @pairing_factory = ntg.pairing_factory
50- @options[:sacrifice] = ntg.sacrifice
5158 if ntg
5259 @next_time = ntg.call(Time.now)
60+ @options[:pairing_factory] = ntg.pairing_factory
61+ @options[:sacrifice] = ntg.sacrifice
5362 else
5463 @next_time = nil
5564 end
5665 end
5766
5867 def match_game
59- log_message("Starting Floodgate games...: %s, %s" % [@game_name, @pairing_factory])
68+ log_message("Starting Floodgate games...: %s, %s" % [@game_name, @options])
6069 players = @league.find_all_players do |pl|
6170 pl.status == "game_waiting" &&
6271 game_name?(pl.game_name) &&
6372 pl.sente == nil
6473 end
65- logics = Pairing.send(@pairing_factory, @options)
74+ logics = Pairing.send(@options[:pairing_factory], @options)
6675 Pairing.match(players, logics)
6776 end
6877
@@ -150,9 +159,9 @@ class League
150159 @lines.each do |line|
151160 case line
152161 when %r!^\s*set\s+pairing_factory\s+(\w+)!
153- @pairing_factory = $1
162+ @pairing_factory = $1.chomp
154163 when %r!^\s*set\s+sacrifice\s+(.*)!
155- @sacrifice = $1
164+ @sacrifice = $1.chomp
156165 when %r!^\s*(\w+)\s+(\d{1,2}):(\d{1,2})!
157166 dow, hour, minute = $1, $2.to_i, $3.to_i
158167 dow_index = ::ShogiServer::parse_dow(dow)
--- a/shogi_server/league/floodgate_thread.rb
+++ b/shogi_server/league/floodgate_thread.rb
@@ -68,15 +68,16 @@ module ShogiServer
6868 floodgate.match_game
6969 end
7070
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]
7373 #
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 %s" %
77+ [prev.game_name, prev.next_time, prev.pairing_factory, prev.sacrifice])
7778 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})
8081 end
8182 floodgate_reload_log(leagues)
8283 return leagues
@@ -98,20 +99,18 @@ module ShogiServer
9899 floodgate = next_league(leagues)
99100 next if wait_next_floodgate(floodgate)
100101
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
105104 start_games(floodgate)
106105 floodgate.charge # updates next_time
107- [floodgate.game_name, floodgate.next_time]
108106 end
107+ floodgate
109108 end
110109
111110 reload_shogi_server
112111
113112 # Regenerate floodgate instances after ShogiServer.realod
114- leagues = regenerate_leagues(next_array)
113+ leagues = regenerate_leagues(next_instances)
115114 rescue Exception => ex
116115 # ignore errors
117116 log_error("[in Floodgate's thread] #{ex} #{ex.backtrace}")
--- a/test/TC_floodgate_thread.rb
+++ b/test/TC_floodgate_thread.rb
@@ -65,7 +65,13 @@ class TestSetupFloodgate < Test::Unit::TestCase
6565 def test_regenerate_leagues
6666 game_names = %w(floodgate-900-0 floodgate-3600-0)
6767 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)})
6975 objs = @sf.regenerate_leagues(next_array)
7076 assert_equal 2, objs.size
7177 assert_instance_of ShogiServer::League::Floodgate, objs[0]
--- a/test/TC_fork.rb
+++ b/test/TC_fork.rb
@@ -1,3 +1,4 @@
1+$:.unshift File.dirname(__FILE__)
12 $:.unshift File.join(File.dirname(__FILE__), "..")
23 $topdir = File.expand_path File.dirname(__FILE__)
34 require "baseclient"