From 0b25b0c7e24405dcbd0af495c2ca1d7afdd2b7e5 Mon Sep 17 00:00:00 2001
From: Paolo Capriotti
Date: Sat, 20 Jun 2009 15:32:35 +0200
Subject: [PATCH] Pieces are demoted when captured.
---
lib/games/shogi/state.rb | 8 +++++++-
test/games/shogi/test_shogi_perform_moves.rb | 8 ++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/lib/games/shogi/state.rb b/lib/games/shogi/state.rb
index 5c0ea59..03dee3a 100644
--- a/lib/games/shogi/state.rb
+++ b/lib/games/shogi/state.rb
@@ -78,7 +78,7 @@ module Shogi
end
if captured
piece = piece_factory.new(turn, captured.type)
- pool(turn).add(piece)
+ pool(turn).add(demoted(piece))
end
switch_turn!
end
@@ -98,6 +98,12 @@ module Shogi
('promoted_' + piece.type.to_s).to_sym)
end
+ def demoted(piece)
+ piece_factory.new(
+ piece.color,
+ piece.type.to_s.gsub(/^promoted_/, '').to_sym)
+ end
+
def promoted_type?(type)
type.to_s =~ /^promoted_/
end
diff --git a/test/games/shogi/test_shogi_perform_moves.rb b/test/games/shogi/test_shogi_perform_moves.rb
index 1fe1a65..3c22015 100644
--- a/test/games/shogi/test_shogi_perform_moves.rb
+++ b/test/games/shogi/test_shogi_perform_moves.rb
@@ -39,4 +39,12 @@ class TestShogiPerformMoves < Test::Unit::TestCase
assert_equal 1, @state.pool(:white).size
assert @state.pool(:black).empty?
end
+
+ def test_promoted_capture
+ @board[Point.new(2, 5)] = @state.promoted(@game.piece.new(:white, :rook))
+
+ execute 2, 6, 2, 5
+
+ assert_pool :black, :rook, 1
+ end
end
--
2.11.4.GIT