Ejemplo n.º 1
0
        public static void AppendPiecePath(Moves moves, Piece piece, Player player, int Offset, Moves.enmMovesType movesType)
        {
            int    intOrdinal = piece.Square.Ordinal;
            Square square;

            intOrdinal += Offset;
            while ((square = Board.GetSquare(intOrdinal)) != null)
            {
                if (square.Piece == null)
                {
                    if (movesType == Moves.enmMovesType.All)
                    {
                        moves.Add(0, 0, Move.enmName.Standard, piece, piece.Square, square, null, 0, 0);
                    }
                }
                else if (square.Piece.Player.Colour != player.Colour && square.Piece.CanBeTaken)
                {
                    moves.Add(0, 0, Move.enmName.Standard, piece, piece.Square, square, square.Piece, 0, 0);
                    break;
                }
                else
                {
                    break;
                }
                intOrdinal += Offset;
            }
        }
Ejemplo n.º 2
0
        public void AttackerMoveList(Moves moves, Player player)
        {
            Piece piece;

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

            // Knights
            if (player.QueensKnight.IsInPlay && m_aintMinorAttackers[m_intOrdinal - player.QueensKnight.Square.Ordinal + 128] == 'N')
            {
                moves.Add(0, 0, Move.enmName.Standard, player.QueensKnight, player.QueensKnight.Square, this, this.Piece, 0, 0);
            }
            if (player.KingsKnight.IsInPlay && m_aintMinorAttackers[m_intOrdinal - player.KingsKnight.Square.Ordinal + 128] == 'N')
            {
                moves.Add(0, 0, Move.enmName.Standard, player.KingsKnight, player.KingsKnight.Square, this, this.Piece, 0, 0);
            }

            // Bishops
            if (player.QueensBishop.IsInPlay && m_aintMinorAttackers[m_intOrdinal - player.QueensBishop.Square.Ordinal + 128] == 'B' && CanSlideToHereFrom(player.QueensBishop.Square, m_aintVectors[m_intOrdinal - player.QueensBishop.Square.Ordinal + 128]))
            {
                moves.Add(0, 0, Move.enmName.Standard, player.QueensBishop, player.QueensBishop.Square, this, this.Piece, 0, 0);
            }
            if (player.KingsBishop.IsInPlay && m_aintMinorAttackers[m_intOrdinal - player.KingsBishop.Square.Ordinal + 128] == 'B' && CanSlideToHereFrom(player.KingsBishop.Square, m_aintVectors[m_intOrdinal - player.KingsBishop.Square.Ordinal + 128]))
            {
                moves.Add(0, 0, Move.enmName.Standard, player.KingsBishop, player.KingsBishop.Square, this, this.Piece, 0, 0);
            }

            // Rooks
            if (player.QueensRook.IsInPlay && m_aintMinorAttackers[m_intOrdinal - player.QueensRook.Square.Ordinal + 128] == 'R' && CanSlideToHereFrom(player.QueensRook.Square, m_aintVectors[m_intOrdinal - player.QueensRook.Square.Ordinal + 128]))
            {
                moves.Add(0, 0, Move.enmName.Standard, player.QueensRook, player.QueensRook.Square, this, this.Piece, 0, 0);
            }
            if (player.KingsRook.IsInPlay && m_aintMinorAttackers[m_intOrdinal - player.KingsRook.Square.Ordinal + 128] == 'R' && CanSlideToHereFrom(player.KingsRook.Square, m_aintVectors[m_intOrdinal - player.KingsRook.Square.Ordinal + 128]))
            {
                moves.Add(0, 0, Move.enmName.Standard, player.KingsRook, player.KingsRook.Square, this, this.Piece, 0, 0);
            }

            // Queen
            if (player.Queen.IsInPlay && m_aintQueenAttackers[m_intOrdinal - player.Queen.Square.Ordinal + 128] == 'Q' && CanSlideToHereFrom(player.Queen.Square, m_aintVectors[m_intOrdinal - player.Queen.Square.Ordinal + 128]))
            {
                moves.Add(0, 0, Move.enmName.Standard, player.Queen, player.Queen.Square, this, this.Piece, 0, 0);
            }

            // King
            if (m_aintKingAttackers[m_intOrdinal - player.King.Square.Ordinal + 128] == 'K')
            {
                moves.Add(0, 0, Move.enmName.Standard, player.King, player.King.Square, this, this.Piece, 0, 0);
            }
        }
Ejemplo n.º 3
0
 public static void UndoMove()
 {
     if (m_movesHistory.Count > 0)
     {
         Move moveUndo = m_movesHistory.Item(m_movesHistory.Count - 1);
         m_playerToPlay.Clock.Revert();
         m_movesRedoList.Add(moveUndo);
         Move.Undo(moveUndo);
         m_playerToPlay = m_playerToPlay.OtherPlayer;
         if (m_movesHistory.Count > 1)
         {
             Move movePenultimate = m_movesHistory.Item(m_movesHistory.Count - 2);
             m_playerToPlay.Clock.TimeElapsed = movePenultimate.TimeStamp;
         }
         else
         {
             m_playerToPlay.Clock.TimeElapsed = new TimeSpan(0);
         }
         m_playerToPlay.Clock.Start();
     }
 }
Ejemplo n.º 4
0
        public void GenerateLazyMoves(Moves moves, Moves.enmMovesType movesType)
        {
            Square square;

            switch (movesType)
            {
            case Moves.enmMovesType.All:
                square = Board.GetSquare(m_Base.Square.Ordinal - 1); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 15); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 16); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 17); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 1); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 15); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 16); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 17); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }

                if (this.CanCastleKingSide)
                {
                    moves.Add(0, 0, Move.enmName.CastleKingSide, m_Base, m_Base.Square, Board.GetSquare(m_Base.Square.Ordinal + 2), null, 0, 0);
                }
                if (this.CanCastleQueenSide)
                {
                    moves.Add(Game.TurnNo, m_Base.LastMoveTurnNo, Move.enmName.CastleQueenSide, m_Base, m_Base.Square, Board.GetSquare(m_Base.Square.Ordinal - 2), null, 0, 0);
                }

                break;

            case Moves.enmMovesType.Recaptures_Promotions:
            case Moves.enmMovesType.CapturesChecksPromotions:
                square = Board.GetSquare(m_Base.Square.Ordinal - 1); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 15); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 16); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 17); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 1); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 15); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 16); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 17); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                break;
            }
        }
Ejemplo n.º 5
0
        public void GenerateLazyMoves(Moves moves, Moves.enmMovesType movesType)
        {
            Square square;
            bool   blnIsPromotion = this.m_Base.Player.Colour == Player.enmColour.White && this.m_Base.Square.Rank == 6
                                    ||
                                    this.m_Base.Player.Colour == Player.enmColour.Black && this.m_Base.Square.Rank == 1;

            // Forward one
            if (movesType == Moves.enmMovesType.All || blnIsPromotion)
            {
                if ((square = Board.GetSquare(m_Base.Square.Ordinal + m_Base.Player.PawnForwardOffset)) != null && square.Piece == null)
                {
                    moves.Add(0, 0, (blnIsPromotion ? Move.enmName.PawnPromotion : Move.enmName.Standard), this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
            }

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

            // Take right
            if ((square = Board.GetSquare(m_Base.Square.Ordinal + m_Base.Player.PawnAttackRightOffset)) != null)
            {
                if (square.Piece != null && square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
            }

            // Take left
            if ((square = Board.GetSquare(m_Base.Square.Ordinal + m_Base.Player.PawnAttackLeftOffset)) != null)
            {
                if (square.Piece != null && square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
            }

            // En Passent
            if (
                this.m_Base.Square.Rank == 4 && this.m_Base.Player.Colour == Player.enmColour.White
                ||
                this.m_Base.Square.Rank == 3 && this.m_Base.Player.Colour == Player.enmColour.Black
                )
            {
                Piece piecePassed;
                // Left
                if ((piecePassed = Board.GetPiece(m_Base.Square.Ordinal - 1)) != null && piecePassed.NoOfMoves == 1 && piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.enmName.Pawn && piecePassed.Player.Colour != m_Base.Player.Colour)
                {
                    square = Board.GetSquare(m_Base.Square.Ordinal + m_Base.Player.PawnAttackLeftOffset);
                    moves.Add(0, 0, Move.enmName.EnPassent, this.m_Base, this.m_Base.Square, square, piecePassed, 0, 0);
                }
                // Right
                if ((piecePassed = Board.GetPiece(m_Base.Square.Ordinal + 1)) != null && piecePassed.NoOfMoves == 1 && piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.enmName.Pawn && piecePassed.Player.Colour != m_Base.Player.Colour)
                {
                    square = Board.GetSquare(m_Base.Square.Ordinal + m_Base.Player.PawnAttackRightOffset);
                    moves.Add(0, 0, Move.enmName.EnPassent, this.m_Base, this.m_Base.Square, square, piecePassed, 0, 0);
                }
            }
        }
Ejemplo n.º 6
0
        public void GenerateLazyMoves(Moves moves, Moves.enmMovesType movesType)
        {
            Square square;

            switch (movesType)
            {
            case Moves.enmMovesType.All:
                square = Board.GetSquare(m_Base.Square.Ordinal + 33); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 18); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 14); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 31); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 33); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 18); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 14); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 31); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                break;

            case Moves.enmMovesType.Recaptures_Promotions:
            case Moves.enmMovesType.CapturesChecksPromotions:
                square = Board.GetSquare(m_Base.Square.Ordinal + 33); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 18); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 14); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 31); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 33); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal - 18); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 14); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                square = Board.GetSquare(m_Base.Square.Ordinal + 31); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != m_Base.Player.Colour && square.Piece.CanBeTaken)))
                {
                    moves.Add(0, 0, Move.enmName.Standard, this.m_Base, this.m_Base.Square, square, square.Piece, 0, 0);
                }
                break;
            }
        }