Exemple #1
0
        /// <summary>
        /// The append piece path.
        /// </summary>
        /// <param name="moves">
        /// The moves.
        /// </param>
        /// <param name="piece">
        /// The piece.
        /// </param>
        /// <param name="player">
        /// The player.
        /// </param>
        /// <param name="offset">
        /// The offset.
        /// </param>
        /// <param name="movesType">
        /// The moves type.
        /// </param>
        public static void AppendPiecePath(
            Moves moves, Piece piece, Player player, int offset, Moves.MoveListNames movesType)
        {
            int    intOrdinal = piece.Square.Ordinal;
            Square square;

            intOrdinal += offset;
            while ((square = GetSquare(intOrdinal)) != null)
            {
                if (square.Piece == null)
                {
                    if (movesType == Moves.MoveListNames.All)
                    {
                        moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, square, null, 0, 0);
                    }
                }
                else if (square.Piece.Player.Colour != player.Colour && square.Piece.IsCapturable)
                {
                    moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, square, square.Piece, 0, 0);
                    break;
                }
                else
                {
                    break;
                }

                intOrdinal += offset;
            }
        }
Exemple #2
0
        /// <summary>
        /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check.
        /// </summary>
        /// <param name="moves">
        /// Moves list that will be populated with lazy moves.
        /// </param>
        /// <param name="movesType">
        /// Types of moves to include. e.g. All, or captures-only.
        /// </param>
        public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType)
        {
            Square square;

            switch (movesType)
            {
            case Moves.MoveListNames.All:
                for (int i = 0; i < moveVectors.Length; i++)
                {
                    square = Board.GetSquare(this.Base.Square.Ordinal + moveVectors[i]);
                    if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
                    {
                        moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0);
                    }
                }
                break;

            case Moves.MoveListNames.CapturesPromotions:
                for (int i = 0; i < moveVectors.Length; i++)
                {
                    square = Board.GetSquare(this.Base.Square.Ordinal + moveVectors[i]);
                    if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
                    {
                        moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0);
                    }
                }
                break;
            }
        }
Exemple #3
0
        public void SortByScoreTest()
        {
            Moves moves = new Moves();
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 1));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 4));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 6));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 2));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 8));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 5));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 6));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 7));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 8));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0));

            moves.SortByScore();

            for (int i = 0; i < moves.Count - 1; i++)
            {
                Assert.IsTrue(moves[i].Score >= moves[i + 1].Score);
            }
        }
Exemple #4
0
 /// <summary>
 /// Appends a list of moves of all the pieces that are attacking this square.
 /// </summary>
 /// <param name="moves">
 /// Moves of pieces that are attacking this square.
 /// </param>
 /// <param name="player">
 /// Player whose turn it is
 /// </param>
 public void AttackersMoveList(Moves moves, Player player)
 {
     foreach (Piece p in player.Pieces)
     {
         if (p.CanAttackSquare(this))
         {
             moves.Add(0, 0, Move.MoveNames.Standard, p, p.Square, this, this.Piece, 0, 0);
         }
     }
 }
        /*
         * private Move.enmName MoveName(Player.enmColour colourPlayer, Square squareTo)
         * {
         *  if (colourPlayer==Player.enmColour.White && squareTo.Rank==7 || colourPlayer==Player.enmColour.Black && squareTo.Rank==0)
         *  {
         *      return Move.enmName.PawnPromotion;
         *  }
         *  else
         *  {
         *      return Move.enmName.Standard;
         *  }
         * }
         */
        #region Public Methods

        /// <summary>
        /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check.
        /// </summary>
        /// <param name="moves">
        /// Moves list that will be populated with lazy moves.
        /// </param>
        /// <param name="movesType">
        /// Types of moves to include. e.g. All, or captures-only.
        /// </param>
        public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType)
        {
            // Types of promotion to generate. Removed bishop and Rook.
            Move.MoveNames[] promotionTypes =
            {
                Move.MoveNames.PawnPromotionQueen, Move.MoveNames.PawnPromotionKnight

                // Move.MoveNames.PawnPromotionBishop, Move.MoveNames.PawnPromotionRook // Why bother?
            };

            Square square;
            bool   isPromotion = (this.Base.Player.Colour == Player.PlayerColourNames.White && this.Base.Square.Rank == 6)
                                 ||
                                 (this.Base.Player.Colour == Player.PlayerColourNames.Black && this.Base.Square.Rank == 1);

            int intMovesToGenerate = isPromotion ? promotionTypes.Length : 1;

            for (int intIndex = 0; intIndex < intMovesToGenerate; intIndex++)
            {
                // Take right
                if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackRightOffset))
                    != null)
                {
                    if (square.Piece != null && square.Piece.Player.Colour != this.Base.Player.Colour &&
                        square.Piece.IsCapturable)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }

                // Take left
                if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackLeftOffset)) != null)
                {
                    if (square.Piece != null && square.Piece.Player.Colour != this.Base.Player.Colour &&
                        square.Piece.IsCapturable)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }

                // Forward one
                if (movesType == Moves.MoveListNames.All || isPromotion)
                {
                    if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset))
                        != null && square.Piece == null)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }
            }

            // Forward two
            if (movesType == Moves.MoveListNames.All)
            {
                if (!this.Base.HasMoved)
                {
                    // Check one square ahead is not occupied
                    if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset))
                        != null && square.Piece == null)
                    {
                        if (
                            (square =
                                 Board.GetSquare(
                                     this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset
                                     + this.Base.Player.PawnForwardOffset)) != null && square.Piece == null)
                        {
                            moves.Add(
                                0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0);
                        }
                    }
                }
            }

            // En Passent
            if ((this.Base.Square.Rank == 4 && this.Base.Player.Colour == Player.PlayerColourNames.White) ||
                (this.Base.Square.Rank == 3 && this.Base.Player.Colour == Player.PlayerColourNames.Black))
            {
                Piece piecePassed;

                // Left
                if ((piecePassed = Board.GetPiece(this.Base.Square.Ordinal - 1)) != null && piecePassed.NoOfMoves == 1 &&
                    piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.PieceNames.Pawn &&
                    piecePassed.Player.Colour != this.Base.Player.Colour)
                {
                    square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackLeftOffset);
                    moves.Add(0, 0, Move.MoveNames.EnPassent, this.Base, this.Base.Square, square, piecePassed, 0, 0);
                }

                // Right
                if ((piecePassed = Board.GetPiece(this.Base.Square.Ordinal + 1)) != null && piecePassed.NoOfMoves == 1 &&
                    piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.PieceNames.Pawn &&
                    piecePassed.Player.Colour != this.Base.Player.Colour)
                {
                    square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackRightOffset);
                    moves.Add(0, 0, Move.MoveNames.EnPassent, this.Base, this.Base.Square, square, piecePassed, 0, 0);
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// The append piece path.
        /// </summary>
        /// <param name="moves">
        /// The moves.
        /// </param>
        /// <param name="piece">
        /// The piece.
        /// </param>
        /// <param name="player">
        /// The player.
        /// </param>
        /// <param name="offset">
        /// The offset.
        /// </param>
        /// <param name="movesType">
        /// The moves type.
        /// </param>
        public static void AppendPiecePath(
            Moves moves, Piece piece, Player player, int offset, Moves.MoveListNames movesType)
        {
            int intOrdinal = piece.Square.Ordinal;
            Square square;

            intOrdinal += offset;
            while ((square = GetSquare(intOrdinal)) != null)
            {
                if (square.Piece == null)
                {
                    if (movesType == Moves.MoveListNames.All)
                    {
                        moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, square, null, 0, 0);
                    }
                }
                else if (square.Piece.Player.Colour != player.Colour && square.Piece.IsCapturable)
                {
                    moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, square, square.Piece, 0, 0);
                    break;
                }
                else
                {
                    break;
                }

                intOrdinal += offset;
            }
        }
Exemple #7
0
        /// <summary>
        /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check.
        /// </summary>
        /// <param name="moves">
        /// Moves list that will be populated with lazy moves.
        /// </param>
        /// <param name="movesType">
        /// Types of moves to include. e.g. All, or captures-only.
        /// </param>
        public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType)
        {
            // Types of promotion to generate. Removed bishop and Rook.
            Move.MoveNames[] promotionTypes = {
                                                  Move.MoveNames.PawnPromotionQueen, Move.MoveNames.PawnPromotionKnight

                                                  // Move.MoveNames.PawnPromotionBishop, Move.MoveNames.PawnPromotionRook // Why bother?
                                              };

            Square square;
            bool isPromotion = (this.Base.Player.Colour == Player.PlayerColourNames.White && this.Base.Square.Rank == 6)
                               ||
                               (this.Base.Player.Colour == Player.PlayerColourNames.Black && this.Base.Square.Rank == 1);

            int intMovesToGenerate = isPromotion ? promotionTypes.Length : 1;

            for (int intIndex = 0; intIndex < intMovesToGenerate; intIndex++)
            {
                // Take right
                if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackRightOffset))
                    != null)
                {
                    if (square.Piece != null && square.Piece.Player.Colour != this.Base.Player.Colour
                        && square.Piece.IsCapturable)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }

                // Take left
                if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackLeftOffset)) != null)
                {
                    if (square.Piece != null && square.Piece.Player.Colour != this.Base.Player.Colour
                        && square.Piece.IsCapturable)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }

                // Forward one
                if (movesType == Moves.MoveListNames.All || isPromotion)
                {
                    if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset))
                        != null && square.Piece == null)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }
            }

            // Forward two
            if (movesType == Moves.MoveListNames.All)
            {
                if (!this.Base.HasMoved)
                {
                    // Check one square ahead is not occupied
                    if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset))
                        != null && square.Piece == null)
                    {
                        if (
                            (square =
                             Board.GetSquare(
                                 this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset
                                 + this.Base.Player.PawnForwardOffset)) != null && square.Piece == null)
                        {
                            moves.Add(
                                0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0);
                        }
                    }
                }
            }

            // En Passent
            if ((this.Base.Square.Rank == 4 && this.Base.Player.Colour == Player.PlayerColourNames.White)
                || (this.Base.Square.Rank == 3 && this.Base.Player.Colour == Player.PlayerColourNames.Black))
            {
                Piece piecePassed;

                // Left
                if ((piecePassed = Board.GetPiece(this.Base.Square.Ordinal - 1)) != null && piecePassed.NoOfMoves == 1
                    && piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.PieceNames.Pawn
                    && piecePassed.Player.Colour != this.Base.Player.Colour)
                {
                    square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackLeftOffset);
                    moves.Add(0, 0, Move.MoveNames.EnPassent, this.Base, this.Base.Square, square, piecePassed, 0, 0);
                }

                // Right
                if ((piecePassed = Board.GetPiece(this.Base.Square.Ordinal + 1)) != null && piecePassed.NoOfMoves == 1
                    && piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.PieceNames.Pawn
                    && piecePassed.Player.Colour != this.Base.Player.Colour)
                {
                    square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackRightOffset);
                    moves.Add(0, 0, Move.MoveNames.EnPassent, this.Base, this.Base.Square, square, piecePassed, 0, 0);
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Appends a list of moves of all the pieces that are attacking this square.
        /// </summary>
        /// <param name="moves">
        /// Moves of pieces that are attacking this square.
        /// </param>
        /// <param name="player">
        /// Player whose turn it is
        /// </param>
        public void AttackersMoveList(Moves moves, Player player)
        {
            Piece piece;

            // Pawn
            piece = Board.GetPiece(this.Ordinal - player.PawnAttackLeftOffset);
            if (piece != null && piece.Name == Piece.PieceNames.Pawn && piece.Player.Colour == player.Colour)
            {
                moves.Add(
                    0,
                    0,
                    Move.MoveNames.Standard,
                    Board.GetPiece(this.Ordinal - player.PawnAttackLeftOffset),
                    Board.GetSquare(this.Ordinal - player.PawnAttackLeftOffset),
                    this,
                    this.Piece,
                    0,
                    0);
            }

            piece = Board.GetPiece(this.Ordinal - player.PawnAttackRightOffset);
            if (piece != null && piece.Name == Piece.PieceNames.Pawn && piece.Player.Colour == player.Colour)
            {
                moves.Add(
                    0,
                    0,
                    Move.MoveNames.Standard,
                    Board.GetPiece(this.Ordinal - player.PawnAttackRightOffset),
                    Board.GetSquare(this.Ordinal - player.PawnAttackRightOffset),
                    this,
                    this.Piece,
                    0,
                    0);
            }

            // Knight
            piece = Board.GetPiece(this.Ordinal + 33);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 18);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 14);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 31);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 33);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 18);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 14);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 31);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // Bishop & Queen
            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, 15)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, 17)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, -15)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, -17)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // Rook & Queen
            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, 1)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, -1)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, 16)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, -16)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // King!
            piece = Board.GetPiece(this.Ordinal + 16);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 17);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 1);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 15);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 16);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 17);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 1);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 15);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }
        }
Exemple #9
0
        /// <summary>
        /// Appends a list of moves of all the pieces that are attacking this square.
        /// </summary>
        /// <param name="moves">
        /// Moves of pieces that are attacking this square.
        /// </param>
        /// <param name="player">
        /// Player whose turn it is
        /// </param>
        public void AttackersMoveList(Moves moves, Player player)
        {
            Piece piece;

            // Pawn
            piece = Board.GetPiece(this.Ordinal - player.PawnAttackLeftOffset);
            if (piece != null && piece.Name == Piece.PieceNames.Pawn && piece.Player.Colour == player.Colour)
            {
                moves.Add(
                    0,
                    0,
                    Move.MoveNames.Standard,
                    Board.GetPiece(this.Ordinal - player.PawnAttackLeftOffset),
                    Board.GetSquare(this.Ordinal - player.PawnAttackLeftOffset),
                    this,
                    this.Piece,
                    0,
                    0);
            }

            piece = Board.GetPiece(this.Ordinal - player.PawnAttackRightOffset);
            if (piece != null && piece.Name == Piece.PieceNames.Pawn && piece.Player.Colour == player.Colour)
            {
                moves.Add(
                    0,
                    0,
                    Move.MoveNames.Standard,
                    Board.GetPiece(this.Ordinal - player.PawnAttackRightOffset),
                    Board.GetSquare(this.Ordinal - player.PawnAttackRightOffset),
                    this,
                    this.Piece,
                    0,
                    0);
            }

            // Knight
            piece = Board.GetPiece(this.Ordinal + 33);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 18);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 14);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 31);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 33);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 18);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 14);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 31);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // Bishop & Queen
            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, 15)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, 17)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, -15)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, -17)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // Rook & Queen
            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, 1)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, -1)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, 16)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, -16)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // King!
            piece = Board.GetPiece(this.Ordinal + 16);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 17);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 1);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 15);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 16);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 17);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 1);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 15);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }
        }
Exemple #10
0
 /// <summary>
 /// Appends a list of moves of all the pieces that are attacking this square.
 /// </summary>
 /// <param name="moves">
 /// Moves of pieces that are attacking this square.
 /// </param>
 /// <param name="player">
 /// Player whose turn it is
 /// </param>
 public void AttackersMoveList(Moves moves, Player player)
 {
     foreach (Piece p in player.Pieces)
     {
         if (p.CanAttackSquare(this))
             moves.Add(0, 0, Move.MoveNames.Standard, p, p.Square, this, this.Piece, 0, 0);
     }
 }
Exemple #11
0
        /// <summary>
        /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check.
        /// </summary>
        /// <param name="moves">
        /// Moves list that will be populated with lazy moves.
        /// </param>
        /// <param name="movesType">
        /// Types of moves to include. e.g. All, or captures-only.
        /// </param>
        public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType)
        {
            Square square;

            switch (movesType)
            {
                case Moves.MoveListNames.All:
                    for (int i = 0; i < moveVectors.Length; i++) //Sil
                    {
                        square = Board.GetSquare(this.Base.Square.Ordinal + moveVectors[i]);

                        if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
                        {
                            moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0);
                        }
                    }
                    break;

                case Moves.MoveListNames.CapturesPromotions:
                    for (int i = 0; i < moveVectors.Length; i++)
                    {
                        square = Board.GetSquare(this.Base.Square.Ordinal + moveVectors[i]);

                        if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
                        {
                            moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0);
                        }
                    }
                    break;
            }
        }