[from now] 2012/12/16 15:23:50

diff --git a/README.org b/README.org
index 153715b..4083d97 100644
--- a/README.org
+++ b/README.org
@@ -206,6 +206,7 @@
     - 寺川唯子先生の将棋レッスン －棋譜の読み方－ ‐ ニコニコ動画:Q http://www.nicovideo.jp/watch/sm1452194
     - 将棋を英語表記するときにblackは何故先手なのか？ - やねうらお－よっちゃんイカを食べながら、息子語録を書き綴る http://d.hatena.ne.jp/yaneurao/20101128
     - 二歩 - Wikipedia http://ja.wikipedia.org/wiki/%E4%BA%8C%E6%AD%A9#cite_note-4
+    - せっき～のゲーム屋さん 個性を持った将棋プログラムを目指してー強くするという目標を達成した後にー http://sekigames.gg-blog.com/Entry/242/

     - Rubyist Magazine - cairo: 2 次元画像描画ライブラリ http://jp.rubyist.net/magazine/?0019-cairo
     - Emacs LispとRubyを使ってGoogle Chromeを操作する - saito’s blog http://d.hatena.ne.jp/saitodevel01/20110925/1316962117
diff --git a/lib/bushido/field.rb b/lib/bushido/field.rb
index d0a40b5..0b58a4d 100644
--- a/lib/bushido/field.rb
+++ b/lib/bushido/field.rb
@@ -24,10 +24,10 @@ module Bushido

       @matrix[point.to_xy] = soldier

-      # # FIXME: 無限ループ
-      # if soldier.moveable_points(:ignore_the_other_pieces_on_the_board => true, :point => point).empty?
-      #   raise NotPutInPlaceNotBeMoved, "#{soldier.name}を#{point.name}に置いてもそれ以上動かせないので反則になります"
-      # end
+      # FIXME: 無限ループ
+      if soldier.moveable_points(:ignore_the_other_pieces_on_the_board => true, :point => point).empty?
+        raise NotPutInPlaceNotBeMoved, "#{soldier.name}を#{point.name}に置いてもそれ以上動かせないので反則になります"
+      end
     end

     def [](point)
diff --git a/lib/bushido/player.rb b/lib/bushido/player.rb
index 52448c7..e90c30d 100644
--- a/lib/bushido/player.rb
+++ b/lib/bushido/player.rb
@@ -44,8 +44,8 @@ module Bushido

     def initial_put_on(arg)
       info = parse_arg(arg)
-      v = Soldier.new(self, pick_out(info[:piece]), info[:promoted])
-      @field.put_on_at(info[:point], v)
+      soldier = Soldier.new(self, pick_out(info[:piece]), info[:promoted])
+      @field.put_on_at(info[:point], soldier)
     end

     def parse_arg(arg)
@@ -148,6 +148,11 @@ module Bushido
       end
     end

+    # soldier_names # => ["▽5五飛↓"]
+    def soldier_names
+      soldiers.collect(&:to_text)
+    end
+
     def execute(str)
       md = str.match(/\A(?<point>..|同)(?<piece>#{Piece.names.join("|")})(?<options>成|打)?(\((?<from>.*)\))?/)
       md or raise SyntaxError, "表記が間違っています : #{str.inspect}"
diff --git a/lib/bushido/soldier.rb b/lib/bushido/soldier.rb
index 1dcf1fb..42a8619 100644
--- a/lib/bushido/soldier.rb
+++ b/lib/bushido/soldier.rb
@@ -51,16 +51,20 @@ module Bushido
       list.uniq{|e|e.to_xy}     # FIXME: ブロックを取る
     end

+    def normalized_vectors(vectors)
+      vectors.uniq.compact.collect do |vector|
+        if player.location == :upper
+          vector = Vector.new(vector).reverse
+        else
+          vector
+        end
+      end
+    end
+
     def __moveable_points(vectors, loop, options = {})
-      vectors.uniq.compact.each_with_object([]) do |vector, list|
+      normalized_vectors(vectors).each_with_object([]) do |vector, list|
         point = current_point
-
         loop do
-          # binding.pry
-          if player.location == :upper
-            vector = Vector.new(vector).reverse
-          end
-
           point = point.add_vector(vector)
           unless point.valid?
             break
diff --git a/spec/player_spec.rb b/spec/player_spec.rb
index c3a841b..d116125 100644
--- a/spec/player_spec.rb
+++ b/spec/player_spec.rb
@@ -4,28 +4,33 @@ require "spec_helper"

 module Bushido
   describe Player do
-    let(:field)  { Field.new }
+    let(:field) { Field.new }

-    describe "#side_soldiers_put_on" do
-      subject { Player.new(:black, field, :lower) }
+    describe "#initial_put_on" do
+      let(:player) { Player.new(:black, field, :lower) }
       it "歩を相手の陣地に配置" do
-        subject.initial_put_on("5三歩")
-        subject.soldiers.collect(&:to_text).should == ["▲5三歩"]
+        player.initial_put_on("5三歩")
+        player.soldier_names.should == ["▲5三歩"]
       end
       it "成っている歩を相手の陣地に配置" do
-        subject.initial_put_on("5三と")
-        subject.soldiers.collect(&:to_text).should == ["▲5三と"]
+        player.initial_put_on("5三と")
+        player.soldier_names.should == ["▲5三と"]
       end
       it "成っている金を相手の陣地に配置" do
-        expect { subject.initial_put_on("5三成金") }.to raise_error(SyntaxError)
+        expect { player.initial_put_on("5三成金") }.to raise_error(SyntaxError)
       end
       it "すでに駒があるところに駒を配置できない" do
-        subject.initial_put_on("5三歩")
-        expect { subject.initial_put_on("5三歩") }.to raise_error(PieceAlredyExist)
+        player.initial_put_on("5三歩")
+        expect { player.initial_put_on("5三歩") }.to raise_error(PieceAlredyExist)
       end
       it "飛車は二枚持ってないので二枚配置できない" do
-        subject.initial_put_on("5二飛")
-        expect { subject.initial_put_on("5二飛") }.to raise_error(PieceNotFound)
+        player.initial_put_on("5二飛")
+        expect { player.initial_put_on("5二飛") }.to raise_error(PieceNotFound)
+      end
+      it "後手が置ける" do
+        player = Player.new(:white, field, :upper)
+        player.initial_put_on("５五飛")
+        player.soldier_names.should == ["▽5五飛↓"]
       end
     end

@@ -58,37 +63,29 @@ FIELD
         it "「７六歩」は７七の歩が上に上がる" do
           player = Player.new(:black, field, :lower)
           player.initial_put_on("７七歩")
-          soldier = field["７七"]
           player.execute("７六歩")
-          field["７六"].should == soldier
-          field["７七"].should == nil
+          player.soldier_names.should == ["▲7六歩"]
         end

         it "後手の「３四歩」は３三の歩が上に上がる(画面上で下がることに注意)" do
           player = Player.new(:white, field, :upper)
           player.initial_put_on("３三歩")
-          soldier = field["３三"]
           player.execute("３四歩")
-          field["３四"].should == soldier
-          field["３三"].should == nil
+          player.soldier_names.should == ["▽3四歩↓"]
         end

         it "成銀を動かす" do
           player = Player.new(:black, field, :lower)
           player.initial_put_on("４二成銀")
-          soldier = field["４二"]
           player.execute("３二成銀")
-          field["３二"].should == soldier
-          field["４二"].should == nil
+          player.soldier_names.should == ["▲3二成銀"]
         end

         it "龍を動かす" do
           player = Player.new(:black, field, :lower)
           player.initial_put_on("４二龍")
-          soldier = field["４二"]
           player.execute("３二龍")
-          field["３二"].should == soldier
-          field["４二"].should == nil
+          player.soldier_names.should == ["▲3二龍"]
         end

         it "駒の指定なしで動かす" do
@@ -100,7 +97,7 @@ FIELD
           player.initial_put_on("６九金")
           player.initial_put_on("４九金")
           player.execute("５九金(49)")
-          field["４九"].should == nil
+          player.soldier_names.should == ["▲6九金", "▲5九金"]
         end
       end

@@ -125,7 +122,7 @@ FIELD
         it "相手陣地に入るときに成る" do
           player.initial_put_on("２四歩")
           player.execute("２三歩成")
-          field["２三"].promoted.should == true
+          player.soldier_names.should == ["▲2三と"]
         end

         it "相手陣地から出るときに成る" do
@@ -264,7 +261,7 @@ FIELD
           it "相手の駒の上にも" do
             white_player = Player.new(:white, field, :upper)
             white_player.initial_put_on("５五飛")
-            # expect { player.execute("５五角打") }.to raise_error(PieceAlredyExist)
+            expect { player.execute("５五角打") }.to raise_error(PieceAlredyExist)
           end

           it "卍なんて駒はないので" do
テストのリファクタリング