OSDN Git Service

Merge remote-tracking branch 'origin/wdoor-stable' into wdoor-stable
authorDaigo Moriwaki <daigo@debian.org>
Sat, 27 Dec 2014 14:32:58 +0000 (23:32 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sat, 27 Dec 2014 14:32:58 +0000 (23:32 +0900)
Conflicts:
changelog

changelog
shogi_server/league/floodgate.rb
test/TC_floodgate.rb

index 1b7f8c3..40e2302 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,16 @@
+2014-12-27  Daigo Moriwaki <daigo at debian dot org>
+
+       * [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-30  Daigo Moriwaki <daigo at debian dot org>
 
        * [mk_html]
index 24ff68f..ff2d98e 100644 (file)
@@ -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
     
     #
index 56e242e..c169b26 100644 (file)
@@ -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