11 return /^floodgate-\d+-\d+$/.match(str) ? true : false
15 attr_reader :next_time, :league
17 def initialize(league, next_time=nil)
19 @next_time = next_time
28 @next_time = Time.mktime(now.year, now.month, now.day, now.hour, 30)
30 @next_time = Time.mktime(now.year, now.month, now.day, now.hour) + 3600
33 # for test, each 30 seconds
35 @next_time = Time.mktime(now.year, now.month, now.day, now.hour, now.min, 30)
37 @next_time = Time.mktime(now.year, now.month, now.day, now.hour, now.min) + 60
43 players = @league.find_all_players do |pl|
44 pl.status == "game_waiting" &&
45 Floodgate.game_name?(pl.game_name) &&
48 Pairing.match(players)
59 file = Pathname.new $options["floodgate-history"]
60 return History.new file
66 # file_path_name is a Pathname object for this storage
68 def initialize(file_path_name)
71 @file = file_path_name
74 # Return a hash describing the game_result
76 # :black: Black's player id
77 # :white: White's player id
78 # :winner: Winner's player id or nil for the game without a winner
79 # :loser: Loser's player id or nil for the game without a loser
81 def make_record(game_result)
83 hash[:game_id] = game_result.game.game_id
84 hash[:black] = game_result.black.player_id
85 hash[:white] = game_result.white.player_id
88 hash[:winner] = game_result.winner.player_id
89 hash[:loser] = game_result.loser.player_id
98 return unless @file.exist?
100 yaml = @file.open("r") {|f| f.read}
101 @records = YAML.load(yaml)
106 @file.open("w+") do |f|
107 f << YAML.dump(@records)
114 def update(game_result)
115 record = make_record(game_result)
116 @@mutex.synchronize do
119 while @records.size > @max_records
126 def last_win?(player_id)
127 rc = last_valid_game(player_id)
128 return false unless rc
129 return rc[:winner] == player_id
132 def last_lose?(player_id)
133 rc = last_valid_game(player_id)
134 return false unless rc
135 return rc[:loser] == player_id
138 def last_valid_game(player_id)
140 @@mutex.synchronize do
141 records = @records.reverse
143 rc = records.find do |rc|
146 (rc[:black] == player_id || rc[:white] == player_id)
153 end # class Floodgate
157 end # module ShogiServer