OSDN Git Service

Merge branch '201410-maxmoves'
authorDaigo Moriwaki <daigo@debian.org>
Sat, 17 Jan 2015 01:47:58 +0000 (10:47 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sat, 17 Jan 2015 01:47:58 +0000 (10:47 +0900)
Conflicts:
changelog
shogi_server.rb

15 files changed:
changelog
csa-file-filter
mk_game_results
mk_html
mk_rate
shogi-server
shogi-server-profile
shogi_server/game.rb
shogi_server/league/floodgate.rb
shogi_server/login.rb
shogi_server/usi.rb
test/TC_floodgate.rb
test/TC_usi.rb
utils/statistics.rb
webserver

index b244078..bdd04c4 100644 (file)
--- a/changelog
+++ b/changelog
@@ -4,6 +4,59 @@
          - shogi_server.rb: Follow an API change in a upstream class:
            LogDevice.previous_period_end
 
+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-12-23  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - Addressed Ruby incompatibility on ShogiServer::Usi::alphabetToDan.
+           It (and usiToCsa.rb) did not work with Ruby 1.9.3. This issue
+           has now been fixed.
+           Thanks to Hiraoka-san for debugging.
+
+2014-11-30  Daigo Moriwaki <daigo at debian dot org>
+
+       * [mk_html]
+         - Corrected a url.
+
+2014-11-24  Daigo Moriwaki <daigo at debian dot org>
+
+       * Ruby 2.0:
+         - Ruby 2.0.0 or later is recommended to use with shogi-server
+           since Ruby 1.8 reached its End-of-Life on the end of July, 2014.
+       * [shogi-server]
+         - Addressed a warning of duplicated range in a regular expression.
+
+2014-10-13  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - A player, attempting to login with the current live player
+           stalling for more than a day, can forcibly override the current
+           player.
+         - Kifu record files now includes rating scores of players at the
+           time when games start.  Previously, for rating games, a record
+           file includes player IDs of both players with a line starting with
+           "'rating".  Now it also shows rating scores for players who have
+           valid scores.  The formats for black and white players are as
+           follows:
+             'black_rate:<player_id>:<score>
+             'white_rate:<player_id>:<score>
+           A sample output:
+             'rating:Test_sente+275876e34cf609db118f3d84b799a790:Test_gote+275876e34cf609db118f3d84b799a790
+             'black_rate:Test_sente+275876e34cf609db118f3d84b799a790:2763.0
+             'white_rate:Test_gote+275876e34cf609db118f3d84b799a790:2345.0
+
 2014-10-12  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi_server]
            than n plies. Otherwise (or if n is zero), abnormal games are
            counted out of rating games.
 
+2014-01-07  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - Released: Revision "20140107"
+
 2013-12-29  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
index 79d3a49..a9a3f8f 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/ruby1.9.1
+#!/usr/bin/ruby
 # $Id$
 #
 # Author:: Daigo Moriwaki
@@ -50,9 +50,9 @@
 # 
 # Sample Command lines that isntall prerequires will work on Debian.
 # 
-# * Ruby 1.9.3 or 1.8.7 including RDoc
+# * Ruby 2.0.0 or later including RDoc
 # 
-#   $ sudo aptitude install ruby ruby1.9.1
+#   $ sudo aptitude install ruby ruby
 # 
 # == Example
 #
index 0da4ace..0260f88 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/ruby1.9.1
+#!/usr/bin/ruby
 # $Id$
 #
 # Author:: Daigo Moriwaki
@@ -35,9 +35,9 @@
 #
 # Sample Command lines that isntall prerequires will work on Debian.
 #
-# * Ruby 1.9.3 or 1.8.7
+# * Ruby 2.0.0 or later
 #
-#   $ sudo aptitude install ruby1.9.1
+#   $ sudo aptitude install ruby
 #
 # == Run
 #
diff --git a/mk_html b/mk_html
index e472670..6cd7217 100755 (executable)
--- a/mk_html
+++ b/mk_html
@@ -1,4 +1,4 @@
-#!/usr/bin/ruby1.9.1
+#!/usr/bin/ruby
 # $Id$
 #
 # Author:: Daigo Moriwaki
@@ -41,9 +41,9 @@
 #
 # == Prerequire
 #
-# * Ruby 1.9.3 or 1.8.7
+# * Ruby 2.0.0 or later
 #
-#   $ sudo aptitude install ruby ruby1.9.1
+#   $ sudo aptitude install ruby ruby
 #
 # == Example
 #
@@ -172,7 +172,7 @@ def main
   %>
   <tr class="<%=player_decoration%>">
     <td class="name">
-        <a id="popup<%=popup_id+=1%>" href="http://wdoor.c.u-tokyo.ac.jp/shogi/tools/view/show-player.cgi?event=LATEST&amp;filter=floodgate&amp;show_self_play=1&amp;user=<%=u key%>"><%= h yaml[key]['name'] %></a>
+        <a id="popup<%=popup_id+=1%>" href="http://wdoor.c.u-tokyo.ac.jp/shogi/view/show-player.cgi?event=LATEST&amp;filter=floodgate&amp;show_self_play=1&amp;user=<%=u key%>"><%= h yaml[key]['name'] %></a>
         <script type="text/javascript">
           var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
             context:"popup<%=popup_id%>",
diff --git a/mk_rate b/mk_rate
index 6090225..f2c24c6 100755 (executable)
--- a/mk_rate
+++ b/mk_rate
@@ -1,4 +1,4 @@
-#!/usr/bin/ruby1.9.1
+#!/usr/bin/ruby
 # $Id$
 #
 # Author:: Daigo Moriwaki
@@ -76,9 +76,9 @@
 #
 # Sample Command lines that install prerequires will work on Debian.
 #
-# * Ruby 1.9.3 or 1.8.7 (including Rubygems)
+# * Ruby 2.0.0 or later (including Rubygems)
 #
-#   $ sudo aptitude install ruby1.9.1
+#   $ sudo aptitude install ruby
 #
 # * Ruby bindings for the GNU Scientific Library (GSL[http://rb-gsl.rubyforge.org/])
 #
@@ -86,7 +86,7 @@
 #
 # * RGL: {Ruby Graph Library}[http://rubyforge.org/projects/rgl/]
 #
-#   $ sudo gem1.9.1 install rgl
+#   $ sudo gem install rgl
 #
 # == Examples
 #
index 111cc8b..8073889 100755 (executable)
@@ -40,6 +40,8 @@ require 'tempfile'
 # MAIN
 #
 
+ONE_DAY = 3600 * 24   # in seconds
+
 ShogiServer.reload
 
 # Return
@@ -348,9 +350,14 @@ def login_loop(client)
         player = ShogiServer::Player::new(str, client, eol)
         login  = ShogiServer::Login::factory(str, player)
         if (current_player = $league.find(player.name))
+          # Even if a player is in the 'game' state, when the status of the
+          # player has not been updated for more than a day, it is very
+          # likely that the player is stalling. In such a case, a new player
+          # can override the current player.
           if (current_player.password == player.password &&
-              current_player.status != "game")
-            log_message(sprintf("user %s login forcely", player.name))
+              (current_player.status != "game" ||
+               Time.now - current_player.modifiled_at > ONE_DAY))
+            log_message("user %s login forcely (previously modified at %s)" % [player.name, player.modified_at])
             current_player.kill
           else
             login.incorrect_duplicated_player(str)
index 6f024c9..01f6fc7 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/ruby1.9.1
+#! /usr/bin/ruby
 # $Id$
 #
 # Author:: Daigo Moriwaki
@@ -38,7 +38,7 @@
 #
 # * {ruby-prof}[http://rubyforge.org/projects/ruby-prof/]
 #
-#   $ sudo gem1.9.1 install ruby-prof
+#   $ sudo gem install ruby-prof
 #
 # == Run
 #
index f610a95..a43b752 100644 (file)
@@ -337,6 +337,12 @@ class Game
       black_name = @sente.rated? ? @sente.player_id : @sente.name
       white_name = @gote.rated?  ? @gote.player_id  : @gote.name
       @fh.puts("'rating:%s:%s" % [black_name, white_name])
+      if @sente.rated? && @sente.rate != 0
+        @fh.puts("'black_rate:%s:%s" % [@sente.player_id, @sente.rate])
+      end
+      if @gote.rated? && @gote.rate != 0
+        @fh.puts("'white_rate:%s:%s" % [@gote.player_id, @gote.rate])
+      end
     end
     unless @board.initial_moves.empty?
       @fh.puts "'buoy game starting with %d moves" % [@board.initial_moves.size]
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 5af4398..79e770e 100644 (file)
@@ -79,7 +79,7 @@ class Login
   end
 
   def Login.good_identifier?(str)
-    if str =~ /\A[\w\d_@\-\.]{1,#{Max_Identifier_Length}}\z/
+    if str =~ /\A[\w@\-\.]{1,#{Max_Identifier_Length}}\z/
       return true
     else
       return false
index 39ca24e..788bd4f 100644 (file)
@@ -28,7 +28,10 @@ module ShogiServer # for a namespace
       # i -> 9
       def alphabetToDan(s)
         if RUBY_VERSION >= "1.9.1"
-          return s.bytes[0]-96
+          # String.bytes is incompatible:
+          #  - Ruby 1.9.3 String.bytes returns Enumerator
+          #  - Ruby 2.1.0 String.bytes returns [Integer]
+          return s.each_byte.next-96
         else
           return s[0]-96
         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
index 8dbe045..a102f92 100644 (file)
@@ -102,4 +102,10 @@ EOB
 
     assert_equal(usi_moves, cu.usi_moves)
   end
+
+  def test_alphabetToDan
+    assert_equal(1, ShogiServer::Usi::alphabetToDan("axxx"))
+    assert_equal(2, ShogiServer::Usi::alphabetToDan("bxxx"))
+    assert_equal(9, ShogiServer::Usi::alphabetToDan("ixxx"))
+  end
 end
index 568758f..b931317 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/ruby1.9.1
+#!/usr/bin/ruby
 # This program shows statistics of CSA kifu files like following: 
 #   - Monthly #games and #players
 #   - Game results
index 1c5acbd..a993dd9 100755 (executable)
--- a/webserver
+++ b/webserver
@@ -1,4 +1,4 @@
-#!/usr/bin/ruby1.9.1
+#!/usr/bin/ruby
 
 ## Copyright (C) 2007-2012 Daigo Moriwaki <daigo at debian dot org>
 ##