OSDN Git Service

Refactored Player#set_sente_from_str().
authordaigo <beatles@users.sourceforge.jp>
Sat, 4 Sep 2010 08:18:47 +0000 (17:18 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sat, 4 Sep 2010 08:18:47 +0000 (17:18 +0900)
shogi_server/command.rb
shogi_server/player.rb
test/TC_player.rb

index ba4fe1d..fe0ddf4 100644 (file)
@@ -543,13 +543,7 @@ module ShogiServer
         if (@command_name == "GAME")
           @player.status = "game_waiting"
           @player.game_name = @game_name
         if (@command_name == "GAME")
           @player.status = "game_waiting"
           @player.game_name = @game_name
-          if (@my_sente_str == "+")
-            @player.sente = true
-          elsif (@my_sente_str == "-")
-            @player.sente = false
-          else
-            @player.sente = nil
-          end
+          @player.set_sente_from_str(@my_sente_str)
         else                # challenge
           @player.write_safe(sprintf("##[ERROR] can't find rival for %s\n", @game_name))
           @player.status = "connected"
         else                # challenge
           @player.write_safe(sprintf("##[ERROR] can't find rival for %s\n", @game_name))
           @player.status = "connected"
index 3a86c96..7e235f9 100644 (file)
@@ -115,6 +115,16 @@ class BasicPlayer
       @player_id = @password = nil
     end
   end
       @player_id = @password = nil
     end
   end
+
+  def set_sente_from_str(str)
+    case str
+    when "+": @sente = true
+    when "-": @sente = false
+    else
+      # str should be "*"
+      @sente = nil
+    end
+  end
 end
 
 
 end
 
 
index 6858bad..78dd946 100644 (file)
@@ -41,5 +41,11 @@ class TestPlayer < Test::Unit::TestCase
     assert(@p.is_human?)
     assert(!@p.is_computer?)
   end
     assert(@p.is_human?)
     assert(!@p.is_computer?)
   end
+
+  def test_set_sente_from_str
+    assert_equal true,  @p.set_sente_from_str("+")
+    assert_equal false, @p.set_sente_from_str("-")
+    assert_nil          @p.set_sente_from_str("*")
+  end
 end
 
 end