示例#1
0
        private Square?GetFirstMoveSquare(Board board, int moveDirection)
        {
            Square mySquare      = board.FindPiece(this);
            Square?availableMove = null;

            if (!HasEverMoved && BoardQuery.IsWithinBounds(mySquare + new MoveOffset(moveDirection, 0)) &&
                board.GetPiece(mySquare + new MoveOffset(moveDirection, 0)) == null)
            {
                availableMove = mySquare + new MoveOffset(moveDirection * 2, 0);
            }

            return(availableMove);
        }
示例#2
0
        private List <Square> GetSquaresCanAttack(Board board, int moveDirection)
        {
            Square        mySquare       = board.FindPiece(this);
            List <Square> availableMoves = new List <Square>();

            for (int colOffset = -1; colOffset < 2; colOffset += 2)
            {
                Square captureSquare = mySquare + new MoveOffset(moveDirection, colOffset);
                if (BoardQuery.IsWithinBounds(captureSquare) &&
                    BoardQuery.IsOppositeColourOnSquares(board, mySquare, captureSquare))
                {
                    availableMoves.Add(captureSquare);
                }
            }

            return(availableMoves);
        }
示例#3
0
        public static IEnumerable <Square> GetValidMovesInDirection(Board board, Square startingSquare, MoveOffset direction)
        {
            List <Square> validMoves = new List <Square>();
            int           distance   = 1;

            while (BoardQuery.IsWithinBounds(startingSquare + (direction * distance)) && board.GetPiece(startingSquare + (direction * distance)) == null)
            {
                validMoves.Add(startingSquare + (direction * distance));
                distance += 1;
            }

            if (BoardQuery.IsWithinBounds(startingSquare + (direction * distance)) &&
                !BoardQuery.IsSameColourOnSquares(board, startingSquare + (direction * distance), startingSquare))
            {
                validMoves.Add(startingSquare + (direction * distance));
            }

            return(validMoves);
        }
示例#4
0
        private List <Square> GetSquaresEnPassant(Board board, int moveDirection)
        {
            Square        mySquare       = board.FindPiece(this);
            List <Square> availableMoves = new List <Square>();

            for (int colOffset = -1; colOffset < 2; colOffset += 2)
            {
                Square sidewaysSquare = mySquare + new MoveOffset(0, colOffset);
                if (BoardQuery.IsWithinBounds(sidewaysSquare) &&
                    BoardQuery.IsOppositeColourOnSquares(board, mySquare, sidewaysSquare))
                {
                    Square previousSquare = sidewaysSquare + new MoveOffset(moveDirection * 2, 0);
                    if (board.PreviousBoard[previousSquare.Row, previousSquare.Col] == board.GetPiece(sidewaysSquare))
                    {
                        availableMoves.Add(sidewaysSquare + new MoveOffset(moveDirection, 0));
                    }
                }
            }
            return(availableMoves);
        }