OSDN Git Service

- shogi_server/player.rb: Added new methods: is_human? and is_computer?.
authorbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Sat, 26 Dec 2009 01:40:15 +0000 (01:40 +0000)
committerbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Sat, 26 Dec 2009 01:40:15 +0000 (01:40 +0000)
  A human player is recommened to use a name ending with '_human'.
  ex. 'hoge_human', 'hoge_human@p1'

changelog
shogi_server/player.rb
test/TC_player.rb

index 9de6c6e..b0b0dab 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,4 +1,13 @@
+2009-12-20 Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - shogi_server/player.rb: Added new methods: is_human? and
+           is_computer?. 
+           A human player is recommened to use a name ending with '_human'.  
+           ex. 'hoge_human', 'hoge_human@p1'
+
 2009-12-04 Daigo Moriwaki <daigo at debian dot org>
+
        * [shogi-server]
          - The HUP signal is not supported by Ruby on Windows.
 
index f893c6f..7d5f91f 100644 (file)
@@ -60,6 +60,16 @@ class BasicPlayer
   # true for Sente; false for Gote
   attr_accessor :sente
 
+  def is_human?
+    return [%r!_human$!, %r!_human@!].any? do |re|
+      re.match(@name)
+    end
+  end
+
+  def is_computer?
+    return !is_human?
+  end
+
   def modified_at
     @modified_at || Time.now
   end
index d41a829..6858bad 100644 (file)
@@ -29,5 +29,17 @@ class TestPlayer < Test::Unit::TestCase
   def test_rating_group
     assert_nothing_raised {@p.rating_group = 1}
   end
+
+  def test_human1
+    @p.name = "hoge_human"
+    assert(@p.is_human?)
+    assert(!@p.is_computer?)
+  end
+
+  def test_human2
+    @p.name = "hoge_human@p1"
+    assert(@p.is_human?)
+    assert(!@p.is_computer?)
+  end
 end