From: Daigo Moriwaki Date: Sat, 27 Dec 2014 13:10:00 +0000 (+0900) Subject: * [shogi-server] When a non-rated player participates in Floodgate, the following... X-Git-Tag: 20170902~24^2^2 X-Git-Url: http://git.sourceforge.jp/view?p=shogi-server%2Fshogi-server.git;a=commitdiff_plain;h=refs%2Ftags%2F20141227 * [shogi-server] When a non-rated player participates in Floodgate, the following exception was thrown and a Floodgate game would not start: undefined method `[]' for nil:NilClass ["/home/shogi-server/www/x/shogi_server/pairing.rb:499:in `block in calculate_diff_with_penalty'" This issue has been resolved. Only players who have player ID (i.e. those who log in with valid password) are now allowed to participate in Floodgate as the spec web page [http://shogi-server.sourceforge.jp/rating.html] describes. --- diff --git a/changelog b/changelog index 82f4473..cc38b29 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,16 @@ +2014-12-27 Daigo Moriwaki + + * [shogi-server] + - When a non-rated player participates in Floodgate, the following exception + was thrown and a Floodgate game would not start: + undefined method `[]' for nil:NilClass + ["/home/shogi-server/www/x/shogi_server/pairing.rb:499:in `block + in calculate_diff_with_penalty'" + This issue has been resolved. Only players who have player ID + (i.e. those who log in with valid password) are now allowed to + participate in Floodgate as the spec web page + [http://shogi-server.sourceforge.jp/rating.html] describes. + 2014-11-24 Daigo Moriwaki * Ruby 2.0: diff --git a/shogi_server/league/floodgate.rb b/shogi_server/league/floodgate.rb index 24ff68f..ff2d98e 100644 --- a/shogi_server/league/floodgate.rb +++ b/shogi_server/league/floodgate.rb @@ -64,15 +64,23 @@ class League end end - def match_game - log_message("Starting Floodgate games...: %s, %s" % [@game_name, @options]) + # Returns an array of players who are allowed to participate in this + # Floodgate match + # + def select_players players = @league.find_all_players do |pl| pl.status == "game_waiting" && game_name?(pl.game_name) && - pl.sente == nil + pl.sente == nil && + pl.rated? # Only players who have player ID can participate in Floodgate (rating match) end + return players + end + + def match_game + log_message("Starting Floodgate games...: %s, %s" % [@game_name, @options]) logics = Pairing.send(@options[:pairing_factory], @options) - Pairing.match(players, logics) + Pairing.match(select_players(), logics) end # diff --git a/test/TC_floodgate.rb b/test/TC_floodgate.rb index 56e242e..c169b26 100644 --- a/test/TC_floodgate.rb +++ b/test/TC_floodgate.rb @@ -8,6 +8,15 @@ require 'test/mock_log_message' $topdir = File.expand_path File.dirname(__FILE__) +class SimplePlayer < ShogiServer::BasicPlayer + attr_accessor :status + def initialize + super + @status = "game_waiting" + @game_name = "floodgate-900-0" + end +end + class TestFloodgate < Test::Unit::TestCase def setup @fg = ShogiServer::League::Floodgate.new(nil) @@ -32,6 +41,37 @@ class TestFloodgate < Test::Unit::TestCase assert(fg.game_name?("floodgate-3600-0")) end + def test_select_players + league = ShogiServer::League.new(File.dirname(__FILE__)) + league.event = "test" + league.setup_players_database + + a = SimplePlayer.new + a.win = 1 + a.loss = 2 + a.rate = 0 + a.name = "a" + a.player_id = "a+123" + b = SimplePlayer.new + b.win = 10 + b.loss = 20 + b.rate = 1500 + b.name = "b" + b.player_id = "b+456" + c = SimplePlayer.new + c.win = 100 + c.loss = 200 + c.rate = 1000 + c.name = "c" + + league.add a + league.add b + league.add c + + fg = ShogiServer::League::Floodgate.new(league, {:game_name => "floodgate-900-0"}) + + assert_equal([a,b], fg.select_players) + end end class TestDeleteMostPlayingPlayer < Test::Unit::TestCase