OSDN Git Service

* Debugged History.
[shogi-server/shogi-server.git] / shogi_server / league / floodgate.rb
index 1d7d9e1..f0c18e4 100644 (file)
@@ -7,8 +7,10 @@ module ShogiServer
 class League
   class Floodgate
     class << self
+      # "floodgate-900-0"
+      #
       def game_name?(str)
-        return /^floodgate-\d+-\d+$/.match(str) ? true : false
+        return /^floodgate\-\d+\-\d$/.match(str) ? true : false
       end
     end
 
@@ -57,10 +59,14 @@ class League
       class << self
         def factory
           file = Pathname.new $options["floodgate-history"]
-          return History.new file
+          history = History.new file
+          history.load
+          return history
         end
       end
 
+      attr_reader :records
+
       # file_path_name is a Pathname object for this storage
       #
       def initialize(file_path_name)
@@ -122,26 +128,26 @@ class League
       end
       
       def last_win?(player_id)
-        rc = last_valid_record(player_id)
+        rc = last_valid_game(player_id)
         return false unless rc
         return rc[:winner] == player_id
       end
       
       def last_lose?(player_id)
-        rc = last_valid_record(player_id)
+        rc = last_valid_game(player_id)
         return false unless rc
         return rc[:loser] == player_id
       end
 
-      def last_valid_record(player_id)
+      def last_valid_game(player_id)
         records = nil
-        @mutex.synchronize do
+        @@mutex.synchronize do
           records = @records.reverse
         end
         rc = records.find do |rc|
           rc[:winner] && 
           rc[:loser]  && 
-          (rc[:black] == player_id || rc[:while] == player_id)
+          (rc[:black] == player_id || rc[:white] == player_id)
         end
         return rc
       end