From 7acc727fbf7788c97a016f8bb2ab629741d6f546 Mon Sep 17 00:00:00 2001
From: Paolo Capriotti
Date: Sun, 12 Jul 2009 16:11:27 +0200
Subject: [PATCH] Disallow dropping a lance on the last row.
---
lib/plugins/shogi/lib/validator.rb | 4 ++++
test/plugins/shogi/test_shogi_validation.rb | 13 +++++++++++++
2 files changed, 17 insertions(+)
diff --git a/lib/plugins/shogi/lib/validator.rb b/lib/plugins/shogi/lib/validator.rb
index 510fbce..8d63d23 100644
--- a/lib/plugins/shogi/lib/validator.rb
+++ b/lib/plugins/shogi/lib/validator.rb
@@ -43,6 +43,10 @@ module Shogi
return false if
move.dst.y == @state.row(@state.board.size.y - 1, piece.color) ||
move.dst.y == @state.row(@state.board.size.y - 2, piece.color)
+ elsif piece.type == :lance
+ # lances cannot be dropped on the last rank
+ return false if
+ move.dst.y == @state.row(@state.board.size.y - 1, piece.color)
end
else
piece = @state.board[move.src]
diff --git a/test/plugins/shogi/test_shogi_validation.rb b/test/plugins/shogi/test_shogi_validation.rb
index 63cd4df..2453ef4 100644
--- a/test/plugins/shogi/test_shogi_validation.rb
+++ b/test/plugins/shogi/test_shogi_validation.rb
@@ -226,6 +226,19 @@ class TestShogiValidation < Test::Unit::TestCase
:promote => true)
end
+ def test_last_row_lance_drop
+ piece = @game.piece.new(:black, :lance)
+ @state.pool(:black).add(piece)
+
+ @state.board[Point.new(0, 0)] = nil
+ @state.board[Point.new(0, 1)] = nil
+ @state.board[Point.new(0, 2)] = nil
+
+ assert_not_valid @game.move.drop(piece, Point.new(0, 0))
+ assert_valid @game.move.drop(piece, Point.new(0, 1))
+ assert_valid @game.move.drop(piece, Point.new(0, 2))
+ end
+
def test_last_row_pawn_drop
piece1 = @state.piece_factory.new(:black, :pawn)
piece2 = @state.piece_factory.new(:black, :horse)
--
2.11.4.GIT