Ejemplo n.º 1
0
Archivo: King.cs Proyecto: hcesar/Chess
        private bool CanCastle(CastleType castleType)
        {
            var castle = this.Board.GetCastleAvailabity(this.Player);

            if (!castle.HasFlag(castleType))
                return false;

            if (this.Board.IsInCheck())
                return false;

            var testSquare = castleType.GetRookSquare(this.Player);
            for (int i = 0; i < castleType.GetRookDistance(); i++)
            {
                testSquare = testSquare.Move(castleType.GetRookMoveDirection()).Value;
                if (this.Board[testSquare] != null || this.Board.IsUnderAttack(testSquare, this.Player.Opponent()))
                    return false;
            }

            return true;
        }