|
@@ -29,25 +29,55 @@ typename PawnPushGenerator<side>::MoveIterator PawnPushGenerator<side>::end(void
|
|
|
|
|
|
|
|
|
template<Side side>
|
|
|
+void PromotionGenerator<side>::MoveIterator::next(void)
|
|
|
+{
|
|
|
+ if (direction != 1) {
|
|
|
+ direction++;
|
|
|
+ }
|
|
|
+ else if (promotionType != QUEEN) {
|
|
|
+ promotionType = static_cast<PieceType>(promotionType + 1);
|
|
|
+ direction = -1;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ promotionType = PieceType::KNIGHT;
|
|
|
+ direction = -1;
|
|
|
+ ++pawns;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+template<Side side>
|
|
|
+bool PromotionGenerator<side>::MoveIterator::valid(void) const
|
|
|
+{
|
|
|
+ if (pawns.bitboard == Bitboard{ 0 })
|
|
|
+ return true;
|
|
|
+ if (direction == 0)
|
|
|
+ return !(Bitboard::fromIndex(*pawns +
|
|
|
+ (side == WHITE_SIDE ? 8 : -8)) &
|
|
|
+ chessGame.getBoard().get<otherSide(side)>());
|
|
|
+ else
|
|
|
+ return (Bitboard::fromIndex(*pawns +
|
|
|
+ (side == WHITE_SIDE ? 8 : -8) + direction) &
|
|
|
+ Bitboard(~(Bitboard::aFile | Bitboard::hFile)) &
|
|
|
+ chessGame.getBoard().get<otherSide(side)>());
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+template<Side side>
|
|
|
typename PromotionGenerator<side>::MoveIterator PromotionGenerator<side>::begin(void) const
|
|
|
{
|
|
|
const Board& board = chessGame.getBoard();
|
|
|
- Bitboard movedPieces = board.getPawns<side>();
|
|
|
- movedPieces.pushOne<side>();
|
|
|
+ Bitboard pawns = board.getPawns<side>();
|
|
|
+ pawns &= Bitboard(0xFF000000000000FFULL);
|
|
|
|
|
|
- // can't promote into occupied squares
|
|
|
- movedPieces &= ~board.getOccupied();
|
|
|
- // use different move generator for promotions
|
|
|
- movedPieces &= Bitboard(0xFF000000000000FFULL);
|
|
|
-
|
|
|
- return MoveIterator{ movedPieces, PieceType::KNIGHT };
|
|
|
+ return MoveIterator{ chessGame, pawns, PieceType::KNIGHT, -1 };
|
|
|
}
|
|
|
|
|
|
|
|
|
template<Side side>
|
|
|
typename PromotionGenerator<side>::MoveIterator PromotionGenerator<side>::end(void) const
|
|
|
{
|
|
|
- return MoveIterator{ 0 };
|
|
|
+ return MoveIterator{ chessGame, 0, PieceType::PAWN, 0 };
|
|
|
}
|
|
|
|
|
|
|
|
@@ -99,7 +129,7 @@ typename PawnCaptureGenerator<side, leftright>::MoveIterator
|
|
|
movedPieces.moveWestOne();
|
|
|
|
|
|
movedPieces &= (side == BLACK_SIDE ? board.getWhites() : board.getBlacks());
|
|
|
- //movedPieces &= Bitboard(~0xFF000000000000FFULL);
|
|
|
+ movedPieces &= Bitboard(~0xFF000000000000FFULL);
|
|
|
|
|
|
return MoveIterator{ movedPieces };
|
|
|
}
|
|
@@ -281,7 +311,7 @@ void chessy::generateQueenMoves(const ChessGame& cg, std::vector<Move>& moves)
|
|
|
{
|
|
|
const Board& b = cg.getBoard();
|
|
|
generateMoves<side, PrimitiveQueenMoveGenerator>(
|
|
|
- b.getKnights<side>(), b.get<otherSide(side)>(), b.get<side>(), moves
|
|
|
+ b.getQueens<side>(), b.get<otherSide(side)>(), b.get<side>(), moves
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -291,7 +321,7 @@ void chessy::generateRookMoves(const ChessGame& cg, std::vector<Move>& moves)
|
|
|
{
|
|
|
const Board& b = cg.getBoard();
|
|
|
generateMoves<side, PrimitiveRookMoveGenerator>(
|
|
|
- b.getKnights<side>(), b.get<otherSide(side)>(), b.get<side>(), moves
|
|
|
+ b.getRooks<side>(), b.get<otherSide(side)>(), b.get<side>(), moves
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -301,7 +331,7 @@ void chessy::generateBishopMoves(const ChessGame& cg, std::vector<Move>& moves)
|
|
|
{
|
|
|
const Board& b = cg.getBoard();
|
|
|
generateMoves<side,PrimitiveBishopMoveGenerator>(
|
|
|
- b.getKnights<side>(), b.get<otherSide(side)>(), b.get<side>(), moves
|
|
|
+ b.getBishops<side>(), b.get<otherSide(side)>(), b.get<side>(), moves
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -361,10 +391,11 @@ void chessy::generateAllMoves(const ChessGame& cg, std::vector<Move>& moves)
|
|
|
generateCastling<side>(cg, moves);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// explicit instatiations
|
|
|
namespace chessy
|
|
|
{
|
|
|
- /*template class PawnPushGenerator<WHITE_SIDE>;
|
|
|
+ template class PawnPushGenerator<WHITE_SIDE>;
|
|
|
template class PawnPushGenerator<BLACK_SIDE>;
|
|
|
|
|
|
template class PromotionGenerator<WHITE_SIDE>;
|
|
@@ -379,7 +410,7 @@ namespace chessy
|
|
|
template class PawnCaptureGenerator<BLACK_SIDE, RIGHT>;
|
|
|
|
|
|
template class CastlingGenerator<WHITE_SIDE>;
|
|
|
- template class CastlingGenerator<BLACK_SIDE>;*/
|
|
|
+ template class CastlingGenerator<BLACK_SIDE>;
|
|
|
|
|
|
template void generateAllMoves<WHITE_SIDE>(const ChessGame&, std::vector<Move>&);
|
|
|
template void generateAllMoves<BLACK_SIDE>(const ChessGame&, std::vector<Move>&);
|