From 7a159148d7e44abf278bd723de3debce74712959 Mon Sep 17 00:00:00 2001 From: Daigo Moriwaki Date: Sat, 23 Jan 2010 17:35:29 +0900 Subject: [PATCH] * [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_ --- changelog | 17 ++++ shogi_server/command.rb | 6 +- shogi_server/login.rb | 35 ++++++++ test/TC_ALL.rb | 1 + test/TC_handicapped_boards.rb | 190 ++++++++++++++++++++++++++++++++++++++++++ test/TC_login.rb | 3 +- 6 files changed, 248 insertions(+), 4 deletions(-) create mode 100644 test/TC_handicapped_boards.rb diff --git a/changelog b/changelog index 7a9c40c..fb8617c 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,20 @@ +2010-01-22 Daigo Moriwaki + + * [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 * [shogi-server] diff --git a/shogi_server/command.rb b/shogi_server/command.rb index 55b56f1..a63cac2 100644 --- a/shogi_server/command.rb +++ b/shogi_server/command.rb @@ -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 diff --git a/shogi_server/login.rb b/shogi_server/login.rb index 6a08fba..086e14f 100644 --- a/shogi_server/login.rb +++ b/shogi_server/login.rb @@ -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 diff --git a/test/TC_ALL.rb b/test/TC_ALL.rb index a514722..c8463be 100644 --- a/test/TC_ALL.rb +++ b/test/TC_ALL.rb @@ -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 index 0000000..0413ec0 --- /dev/null +++ b/test/TC_handicapped_boards.rb @@ -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 = <