13 return /^floodgate\-\d+\-\d+$/.match(str) ? true : false
17 attr_reader :next_time, :league
19 def initialize(league, hash={})
21 @next_time = hash[:next_time] || nil
22 @game_name = hash[:game_name] || "floodgate-900-0"
27 return Regexp.new(@game_name).match(str) ? true : false
35 @next_time = Time.mktime(now.year, now.month, now.day, now.hour, 30)
37 @next_time = Time.mktime(now.year, now.month, now.day, now.hour) + 3600
40 # for test, each 30 seconds
42 @next_time = Time.mktime(now.year, now.month, now.day, now.hour, now.min, 30)
44 @next_time = Time.mktime(now.year, now.month, now.day, now.hour, now.min) + 60
50 players = @league.find_all_players do |pl|
51 pl.status == "game_waiting" &&
52 game_name?(pl.game_name) &&
55 Pairing.match(players)
66 file = Pathname.new $options["floodgate-history"]
67 history = History.new file
75 # Initialize this instance.
76 # @param file_path_name a Pathname object for this storage
78 def initialize(file_path_name)
81 @file = file_path_name
84 # Return a hash describing the game_result
86 # :black: Black's player id
87 # :white: White's player id
88 # :winner: Winner's player id or nil for the game without a winner
89 # :loser: Loser's player id or nil for the game without a loser
91 def make_record(game_result)
93 hash[:game_id] = game_result.game.game_id
94 hash[:black] = game_result.black.player_id
95 hash[:white] = game_result.white.player_id
98 hash[:winner] = game_result.winner.player_id
99 hash[:loser] = game_result.loser.player_id
108 return unless @file.exist?
110 @records = YAML.load_file(@file)
111 unless @records && @records.instance_of?(Array)
112 $logger.error "%s is not a valid yaml file. Instead, an empty array will be used and updated." % [@file]
119 @file.open("w") do |f|
120 f << YAML.dump(@records)
127 def update(game_result)
128 record = make_record(game_result)
129 @@mutex.synchronize do
132 while @records.size > @max_records
139 def last_win?(player_id)
140 rc = last_valid_game(player_id)
141 return false unless rc
142 return rc[:winner] == player_id
145 def last_lose?(player_id)
146 rc = last_valid_game(player_id)
147 return false unless rc
148 return rc[:loser] == player_id
151 def last_valid_game(player_id)
153 @@mutex.synchronize do
154 records = @records.reverse
156 rc = records.find do |rc|
159 (rc[:black] == player_id || rc[:white] == player_id)
166 end # class Floodgate
170 end # module ShogiServer