X-Git-Url: http://git.sourceforge.jp/view?p=shogi-server%2Fshogi-server.git;a=blobdiff_plain;f=shogi_server%2Fpiece.rb;h=8717dff765a1938504323bf519866c287d2a49f0;hp=4275c0bcd8902599be75fd8c1d893df7b39fd44a;hb=ce94a8dae6ddceb9b3af0b43d56da3d11062335e;hpb=c81f26d9288d31bedec7e9cbc97ba0e8d90a32d7 diff --git a/shogi_server/piece.rb b/shogi_server/piece.rb index 4275c0b..8717dff 100644 --- a/shogi_server/piece.rb +++ b/shogi_server/piece.rb @@ -1,7 +1,7 @@ ## $Id$ ## Copyright (C) 2004 NABEYA Kenichi (aka nanami@2ch) -## Copyright (C) 2007-2008 Daigo Moriwaki (daigo at debian dot org) +## Copyright (C) 2007-2012 Daigo Moriwaki (daigo at debian dot org) ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -154,18 +154,17 @@ class Piece @promoted_name end + def current_name + return @promoted ? @promoted_name : @name + end + def to_s if (@sente) sg = "+" else sg = "-" end - if (@promoted) - n = @promoted_name - else - n = @name - end - return sg + n + return sg + current_name end end @@ -203,6 +202,52 @@ class PieceFU < Piece end end +class PieceKY < Piece + def initialize(*arg) + @point = 1 + @normal_moves = [] + @promoted_moves = [[0, +1], [+1, +1], [-1, +1], [+1, +0], [-1, +0], [0, -1]] + @name = "KY" + @promoted_name = "NY" + super + end + def room_of_head?(x, y, name) + if (name == "KY") + if (@sente) + return false if (y == 1) + else + return false if (y == 9) + end + end + return true + end + def far_movable_grids + grids = Array::new + if (@promoted) + return [] + else + if (@sente) # up + cand_x = @x + cand_y = @y - 1 + while (jump_to?(cand_x, cand_y)) + grids.push([cand_x, cand_y]) + break if (! put_to?(cand_x, cand_y)) + cand_y = cand_y - 1 + end + else # down + cand_x = @x + cand_y = @y + 1 + while (jump_to?(cand_x, cand_y)) + grids.push([cand_x, cand_y]) + break if (! put_to?(cand_x, cand_y)) + cand_y = cand_y + 1 + end + end + return grids + end + end +end + class PieceKE < Piece def initialize(*arg) @point = 1 @@ -347,6 +392,7 @@ class PieceOU < Piece @name = "OU" @promoted_name = nil super + @board.add_ou(self) end end