/* * A valid move for a knight is 1 square along either the X or Y axes, and * 2 squares along the axis that wasn't moved 1 along. Every combination of * adding/subtracting 1 or 2 points along an axis and doing the opposite * mathematical operation to the other number is accounted for. */ /*public override BoardSquare[] getMoveableSquares(short xCoord, short yCoord) { possibleMoves[0] = new BoardSquare(xCoord + 2, yCoord + 1); possibleMoves[1] = new BoardSquare(xCoord + 2, yCoord - 1); possibleMoves[2] = new BoardSquare(xCoord - 2, yCoord + 1); possibleMoves[3] = new BoardSquare(xCoord - 2, yCoord - 1); possibleMoves[4] = new BoardSquare(xCoord - 1, yCoord + 2); possibleMoves[5] = new BoardSquare(xCoord - 1, yCoord - 2); possibleMoves[6] = new BoardSquare(xCoord + 1, yCoord + 2); possibleMoves[7] = new BoardSquare(xCoord + 1, yCoord - 2); return possibleMoves; }*/ /* * Get the bitboard form of all the valid moves for the given board and start position. */ internal override BitBoard getAllMoves(Board b, short xCoord, short yCoord) { BitBoard bit = BitBoard.Empty; BoardSquare ownKing = b.GetKingLocation(this.colour == Piece.NOTATION_W ? Game.Sides.white : Game.Sides.black); BoardSquare potentialPinner = b.ExtrapolateAttack(xCoord, yCoord, (short)ownKing.X, (short)ownKing.Y); // if piece is not pinned if (potentialPinner == BoardSquare.Empty) { if (b.isValidSquare(xCoord+2, yCoord+1) && (b[yCoord + 1, xCoord + 2] == null || b[yCoord + 1, xCoord + 2].Colour != this.colour)) bit.AddPosition(xCoord + 2, yCoord + 1); if (b.isValidSquare(xCoord + 1, yCoord + 2) && (b[yCoord + 2, xCoord + 1] == null || b[yCoord + 2, xCoord + 1].Colour != this.colour)) bit.AddPosition(xCoord + 1, yCoord + 2); if (b.isValidSquare(xCoord - 2, yCoord - 1) && (b[yCoord - 1, xCoord - 2] == null || b[yCoord - 1, xCoord - 2].Colour != this.colour)) bit.AddPosition(xCoord - 2, yCoord - 1); if (b.isValidSquare(xCoord - 1, yCoord - 2) && (b[yCoord - 2, xCoord - 1] == null || b[yCoord - 2, xCoord - 1].Colour != this.colour)) bit.AddPosition(xCoord - 1, yCoord - 2); if (b.isValidSquare(xCoord + 2, yCoord - 1) && (b[yCoord - 1, xCoord + 2] == null || b[yCoord - 1, xCoord + 2].Colour != this.colour)) bit.AddPosition(xCoord +2, yCoord - 1); if (b.isValidSquare(xCoord + 1, yCoord - 2) && (b[yCoord - 2, xCoord + 1] == null || b[yCoord - 2, xCoord + 1].Colour != this.colour)) bit.AddPosition(xCoord + 1, yCoord - 2); if (b.isValidSquare(xCoord - 2, yCoord + 1) && (b[yCoord + 1, xCoord - 2] == null || b[yCoord + 1, xCoord - 2].Colour != this.colour)) bit.AddPosition(xCoord - 2, yCoord + 1); if (b.isValidSquare(xCoord - 1, yCoord + 2) && (b[yCoord + 2, xCoord - 1] == null || b[yCoord + 2, xCoord - 1].Colour != this.colour)) bit.AddPosition(xCoord - 1, yCoord + 2); } return bit; }
/* * Get the bitboard form of all the valid moves for the given board and start position. */ internal override BitBoard getAllMoves(Board b, short xCoord, short yCoord) { BitBoard bit = BitBoard.Empty; BoardSquare ownKing = b.GetKingLocation(this.colour == Piece.NOTATION_W ? Game.Sides.white : Game.Sides.black); BoardSquare potentialPinner = b.ExtrapolateAttack(xCoord, yCoord, (short)ownKing.X, (short)ownKing.Y); int sign = this.colour == Piece.NOTATION_W ? 1 : -1; // if piece is not pinned, check normal movement if (potentialPinner == BoardSquare.Empty || potentialPinner.X == xCoord) { if (b[yCoord + sign, xCoord] == null) { bit.AddPosition(xCoord, yCoord + sign); if (yCoord == this.GetStartRow() && b[yCoord + sign * 2, xCoord] == null) bit.AddPosition(xCoord, yCoord + sign * 2); } } // Check for attacks on either side if (potentialPinner == BoardSquare.Empty || new BoardSquare(xCoord + 1, yCoord + sign).IsBetweenPoints(potentialPinner, ownKing)) { if (b.isValidSquare(xCoord + 1, yCoord + sign) && (b[yCoord + sign, xCoord + 1] == null ? MayEnPassant(b, xCoord, yCoord, (short)(xCoord + 1), (short)(yCoord + sign)) : b[yCoord + sign, xCoord + 1].Colour != this.colour)) bit.AddPosition(xCoord + 1, yCoord + sign); } if (potentialPinner == BoardSquare.Empty || new BoardSquare(xCoord - 1, yCoord + sign).IsBetweenPoints(potentialPinner, ownKing)) { if (b.isValidSquare(xCoord - 1, yCoord + sign) && (b[yCoord + sign, xCoord - 1] == null ? MayEnPassant(b, xCoord, yCoord, (short)(xCoord - 1), (short)(yCoord + sign)) : b[yCoord + sign, xCoord - 1].Colour != this.colour)) bit.AddPosition(xCoord - 1, yCoord + sign); } return bit; }