OSDN Git Service

* [shogi-server]
authorDaigo Moriwaki <beatles@users.sourceforge.jp>
Sat, 23 Jan 2010 08:35:29 +0000 (17:35 +0900)
committerDaigo Moriwaki <beatles@users.sourceforge.jp>
Sat, 23 Jan 2010 08:35:29 +0000 (17:35 +0900)
  - Experimental feature: support handicapped games.
    Game names that have the following prefixes are recognized as
    handicapped games. Turn symbols "+" and "-" mean Uwate (expert)
    and Shitate (beginner) respectively (i.e. Uwate players first).
    "*" is not available.
    - hclance_
    - hcbishop_
    - hcrook_
    - hcrooklance_
    - hc2p_
    - hc4p_
    - hc6p_
    - hc10p_

changelog
shogi_server/command.rb
shogi_server/login.rb
test/TC_ALL.rb
test/TC_handicapped_boards.rb [new file with mode: 0644]
test/TC_login.rb

index 7a9c40c..fb8617c 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,20 @@
+2010-01-22  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - Experimental feature: support handicapped games.
+           Game names that have the following prefixes are recognized as
+           handicapped games. Turn symbols "+" and "-" mean Uwate (expert)
+           and Shitate (beginner) respectively (i.e. Uwate players first).
+           "*" is not available. 
+           - hclance_
+           - hcbishop_
+           - hcrook_
+           - hcrooklance_
+           - hc2p_
+           - hc4p_
+           - hc6p_
+           - hc10p_
+
 2010-01-16  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
index 55b56f1..a63cac2 100644 (file)
@@ -474,14 +474,13 @@ module ShogiServer
         end
         @player.sente = nil
       else
-        if (@my_sente_str == "*")
+        if (@my_sente_str == "*") && !Login.handicapped_game_name?(@game_name)
           rival = $league.get_player("game_waiting", @game_name, nil, @player) # no preference
         elsif (@my_sente_str == "+")
           rival = $league.get_player("game_waiting", @game_name, false, @player) # rival must be gote
         elsif (@my_sente_str == "-")
           rival = $league.get_player("game_waiting", @game_name, true, @player) # rival must be sente
         else
-          ## never reached
           @player.write_safe(sprintf("##[ERROR] bad game option\n"))
           return :continue
         end
@@ -536,7 +535,8 @@ module ShogiServer
             Game::new(@player.game_name, @player, rival, board)
           end
         else
-          board = Board.new
+          klass = Login.handicapped_game_name?(@game_name) || Board
+          board = klass.new
           board.initial
           Game::new(@player.game_name, @player, rival, board)
         end
index 6a08fba..086e14f 100644 (file)
@@ -17,6 +17,8 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+require 'shogi_server/handicapped_boards'
+
 module ShogiServer # for a namespace
 
 ######################################################
@@ -43,6 +45,39 @@ class Login
     end
   end
 
+  # Check if a game name str is a handicapped game.
+  # @return a subclass of Board coresponding to the handicapped game; false,
+  # otherwise.
+  #
+  def Login.handicapped_game_name?(str)
+    return false unless good_game_name?(str)
+    ret = nil
+    
+    case str
+    when %r!^hclance_!
+      ret = HCKYBoard
+    when %r!^hcbishop_!
+      ret = HCKABoard
+    when %r!^hcrook_!
+      ret = HCHIBoard
+    when %r!^hcrooklance_!
+      ret = HCHIKYBoard
+    when %r!^hc2p_!
+      ret = HC2PBoard
+    when %r!^hc4p_!
+      ret = HC4PBoard
+    when %r!^hc6p_!
+      ret = HC6PBoard
+    when %r!^hc8p_!
+      ret = HC8PBoard
+    when %r!^hc10p_!
+      ret = HC10PBoard
+    else
+      ret = false
+    end
+    return ret
+  end
+
   def Login.good_identifier?(str)
     if str =~ /\A[\w\d_@\-\.]{1,#{Max_Identifier_Length}}\z/
       return true
index a514722..c8463be 100644 (file)
@@ -11,6 +11,7 @@ require 'TC_floodgate_next_time_generator'
 require 'TC_functional'
 require 'TC_game'
 require 'TC_game_result'
+require 'TC_handicapped_boards'
 require 'TC_jishogi_kachi'
 require 'TC_league'
 require 'TC_login'
diff --git a/test/TC_handicapped_boards.rb b/test/TC_handicapped_boards.rb
new file mode 100644 (file)
index 0000000..0413ec0
--- /dev/null
@@ -0,0 +1,190 @@
+$:.unshift File.join(File.dirname(__FILE__), "..")
+
+require 'test/unit'
+require 'shogi_server'
+require 'shogi_server/handicapped_boards'
+
+class TestHandicappedGameName < Test::Unit::TestCase
+
+  def test_hclance
+    klass = ShogiServer::Login.handicapped_game_name?("hclance_hoge-900-0")
+    board = klass.new
+    board.initial
+    str = board.to_s
+    answer = <<EOF
+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+P2 * -HI *  *  *  *  * -KA * 
+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
+P4 *  *  *  *  *  *  *  *  * 
+P5 *  *  *  *  *  *  *  *  * 
+P6 *  *  *  *  *  *  *  *  * 
+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
+P8 * +KA *  *  *  *  * +HI * 
+P9 * +KE+GI+KI+OU+KI+GI+KE+KY
++
+EOF
+    assert_equal(answer, str)
+  end
+
+  def test_hcbishop
+    klass = ShogiServer::Login.handicapped_game_name?("hcbishop_hoge-900-0")
+    board = klass.new
+    board.initial
+    str = board.to_s
+    answer = <<EOF
+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+P2 * -HI *  *  *  *  * -KA * 
+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
+P4 *  *  *  *  *  *  *  *  * 
+P5 *  *  *  *  *  *  *  *  * 
+P6 *  *  *  *  *  *  *  *  * 
+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
+P8 *  *  *  *  *  *  * +HI * 
+P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
++
+EOF
+    assert_equal(answer, str)
+  end
+
+  def test_hcrook
+    klass = ShogiServer::Login.handicapped_game_name?("hcrook_hoge-900-0")
+    board = klass.new
+    board.initial
+    str = board.to_s
+    answer = <<EOF
+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+P2 * -HI *  *  *  *  * -KA * 
+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
+P4 *  *  *  *  *  *  *  *  * 
+P5 *  *  *  *  *  *  *  *  * 
+P6 *  *  *  *  *  *  *  *  * 
+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
+P8 * +KA *  *  *  *  *  *  * 
+P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
++
+EOF
+    assert_equal(answer, str)
+  end
+
+  def test_hcrooklance
+    klass = ShogiServer::Login.handicapped_game_name?("hcrooklance_hoge-900-0")
+    board = klass.new
+    board.initial
+    str = board.to_s
+    answer = <<EOF
+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+P2 * -HI *  *  *  *  * -KA * 
+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
+P4 *  *  *  *  *  *  *  *  * 
+P5 *  *  *  *  *  *  *  *  * 
+P6 *  *  *  *  *  *  *  *  * 
+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
+P8 * +KA *  *  *  *  *  *  * 
+P9 * +KE+GI+KI+OU+KI+GI+KE+KY
++
+EOF
+    assert_equal(answer, str)
+  end
+
+  def test_hc2p
+    klass = ShogiServer::Login.handicapped_game_name?("hc2p_hoge-900-0")
+    board = klass.new
+    board.initial
+    str = board.to_s
+    answer = <<EOF
+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+P2 * -HI *  *  *  *  * -KA * 
+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
+P4 *  *  *  *  *  *  *  *  * 
+P5 *  *  *  *  *  *  *  *  * 
+P6 *  *  *  *  *  *  *  *  * 
+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
+P8 *  *  *  *  *  *  *  *  * 
+P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
++
+EOF
+    assert_equal(answer, str)
+  end
+
+  def test_hc4p
+    klass = ShogiServer::Login.handicapped_game_name?("hc4p_hoge-900-0")
+    board = klass.new
+    board.initial
+    str = board.to_s
+    answer = <<EOF
+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+P2 * -HI *  *  *  *  * -KA * 
+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
+P4 *  *  *  *  *  *  *  *  * 
+P5 *  *  *  *  *  *  *  *  * 
+P6 *  *  *  *  *  *  *  *  * 
+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
+P8 *  *  *  *  *  *  *  *  * 
+P9 * +KE+GI+KI+OU+KI+GI+KE * 
++
+EOF
+    assert_equal(answer, str)
+  end
+
+  def test_hc6p
+    klass = ShogiServer::Login.handicapped_game_name?("hc6p_hoge-900-0")
+    board = klass.new
+    board.initial
+    str = board.to_s
+    answer = <<EOF
+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+P2 * -HI *  *  *  *  * -KA * 
+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
+P4 *  *  *  *  *  *  *  *  * 
+P5 *  *  *  *  *  *  *  *  * 
+P6 *  *  *  *  *  *  *  *  * 
+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
+P8 *  *  *  *  *  *  *  *  * 
+P9 *  * +GI+KI+OU+KI+GI *  * 
++
+EOF
+    assert_equal(answer, str)
+  end
+
+  def test_hc8p
+    klass = ShogiServer::Login.handicapped_game_name?("hc8p_hoge-900-0")
+    board = klass.new
+    board.initial
+    str = board.to_s
+    answer = <<EOF
+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+P2 * -HI *  *  *  *  * -KA * 
+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
+P4 *  *  *  *  *  *  *  *  * 
+P5 *  *  *  *  *  *  *  *  * 
+P6 *  *  *  *  *  *  *  *  * 
+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
+P8 *  *  *  *  *  *  *  *  * 
+P9 *  *  * +KI+OU+KI *  *  * 
++
+EOF
+    assert_equal(answer, str)
+  end
+
+  def test_hc10p
+    klass = ShogiServer::Login.handicapped_game_name?("hc10p_hoge-900-0")
+    board = klass.new
+    board.initial
+    str = board.to_s
+    answer = <<EOF
+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+P2 * -HI *  *  *  *  * -KA * 
+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
+P4 *  *  *  *  *  *  *  *  * 
+P5 *  *  *  *  *  *  *  *  * 
+P6 *  *  *  *  *  *  *  *  * 
+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
+P8 *  *  *  *  *  *  *  *  * 
+P9 *  *  *  * +OU *  *  *  * 
++
+EOF
+    assert_equal(answer, str)
+  end
+
+end
+
index ecb76aa..4742753 100644 (file)
@@ -3,6 +3,7 @@ require 'test/unit'
 require 'shogi_server'
 require 'shogi_server/player'
 require 'shogi_server/login'
+require 'shogi_server/handicapped_boards'
 
 class ShogiServer::BasicPlayer
   attr_accessor :protocol
@@ -36,5 +37,5 @@ class TestLogin < Test::Unit::TestCase
     login = ShogiServer::Login::factory("LOGIN hoge floodagate-900-0,xyz", player)
     assert_equal(@p_csa.player_id, player.player_id)
   end
-
 end
+