Legal Move Generator
Functions
-
void generateLegalMoves(std::stack<std::pair<int, int>> *legal_moves, int *board, bool color)
Generates all legal moves on the board for the given color
Loops through every piece on the board and returns all possible legal moves for the given color.
- Parameters:
legal_moves – A list of moves to add to
board – List of all pieces and their locations on the board
color – The color of pieces to generate legal moves for
- Returns:
All possible legal moves for the given color
-
void generateLegalMoves(std::stack<int> *legal_moves, const int *board, int piece)
Generates all legal moves on the board for the given piece
Determines which function to call based on the piece type, it may be more efficient to call the appropriate function directly.
- Parameters:
legal_moves – A list of moves to add to
board – List of all pieces and their locations on the board
piece – The piece to generate legal moves for
- Returns:
All possible legal moves for the given piece
-
void legalPawnMoves(std::stack<int> *legalMoves, const int *board, int piece, int kingLoc, int enPassantSquare)
Generate the legal moves for a given pawn
The pawn can move forward one square if it is not blocked, and it can capture an enemy piece one space forward to its left or right. It can also move forward two spaces if on its starting square. Though it isn’t handled here, a pawn can also promote at the end of the board.
- Parameters:
legalMoves – A list of moves to add to
board – List of all pieces and their locations on the board
piece – The piece to generate legal moves for
kingLoc – The location of the King (optional)
enPassantSquare – Square where en passant is possible (optional)
- Returns:
A stack of all legal moves for the given piece
-
void legalKnightMoves(std::stack<int> *legalMoves, const int *board, int piece, int kingLoc)
Generate the legal moves for a given knight
The knight can move in an L shape in any direction, jumping over pieces as it goes.
- Parameters:
legalMoves – A list of moves to add to
board – List of all pieces and their locations on the board
piece – The piece to generate legal moves for
kingLoc – The location of the King (optional)
- Returns:
A stack of all legal moves for the given piece
-
void legalBishopMoves(std::stack<int> *legalMoves, const int *board, int piece, int kingLoc)
Generate the legal moves for a given bishop
The bishop can move diagonally in all four directions; for legal moves, the direction must be checked. For right, left, top and bottom, the bishop will not be able to move. Any other pins will require going in that direction.
- Parameters:
legalMoves – A list of moves to add to
board – List of all pieces and their locations on the board
piece – The piece to generate legal moves for
kingLoc – The location of the King (optional)
- Returns:
A stack of all legal moves for the given piece
-
void legalRookMoves(std::stack<int> *legalMoves, const int *board, int piece, int kingLoc)
Generate the legal moves for a given rook
The rook can move horizontally or vertically in any direction
- Parameters:
legalMoves – A list of moves to add to
board – List of all pieces and their locations on the board
piece – The piece to generate legal moves for
kingLoc – The location of the King (optional)
- Returns:
A stack of all legal moves for the given piece
-
void legalQueenMoves(std::stack<int> *legalMoves, const int *board, int piece, int kingLoc)
Generate the legal moves for a given queen
The queen can move in the combined directions of a rook and a bishop
- Parameters:
legalMoves – A list of moves to add to
board – List of all pieces and their locations on the board
piece – The piece to generate legal moves for
kingLoc – The location of the King (optional)
- Returns:
A stack of all legal moves for the given piece
-
void legalKingMoves(std::stack<int> *legalMoves, const int *board, int piece, int kingLoc)
Generate the legal moves for a given king
The king can move one square in any direction
- Parameters:
legalMoves – A list of moves to add to
board – List of all pieces and their locations on the board
piece – The piece to generate legal moves for
kingLoc – The location of the King (optional)
- Returns:
A stack of all legal moves for the given piece