Package game
Class MoveGenerator
java.lang.Object
game.MoveGenerator
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()static StringconvertAllMoves(Map<Integer, List<Integer>> possibleMoves) Converts a map of possible combined integer moves to a formatted FEN string representation.static StringconvertMoveToFEN(int move) Convert a combined integer move to FEN notation.static StringconvertPosToString(int rowAndColInt) Convert a combined integer position to a string representation.static intconvertStringToPos(String pos) Convert a string position to a combined integer position.int[]convertStringToPosWrapper(String position_string) Convert a FEN move to an array of two combined integer positions.booleandoesBaseRowContainColor(Color color, int rowToCheck) Checks if a specific row on the board contains any pieces of a given color.generateAllPossibleMoves(Color color) Generates all possible moves for a specific color.Generates all possible capturing moves for a specific color.Generates a maximum of one possible move for a given color.getColor(char c) Get the color from a character representation.getColorAtPosition(int position) Get the piece color at a specific position on the board.Color[][]Get the FEN string representation of the current board state.getMovesWrapper(String fen) Retrieves all possible moves for a given board FEN string.getPieceAtPosition(int position) Get the piece at a specific position on the board.Piece[][]intgetRandomMove(LinkedHashMap<Integer, List<Integer>> moves) Retrieves a random move from a map of possible moves.intgetRandomMoveInt(LinkedHashMap<Integer, List<Integer>> moves) Generates a random move from the given possible moves.intbooleanDetermines the winner for the Monte Carlo Tree Search (MCTS) strategy (only use when confirmed that game is over).voidInitialize the board(s) with starting position.voidinitializeBoard(String fen) Initialize the board based on the provided FEN string.booleanisGameOver(Color color) Checks if the game is over for a specific color based on current board state.booleanisGameOver(String move, Color color) Checks if the game is over for a specific color after a given move.booleanisGameOver(LinkedHashMap<Integer, List<Integer>> moves, Color color) Checks if the game is over for a specific color based on available moves.intisGameOverMCTS(LinkedHashMap<Integer, List<Integer>> moves, Color color) Checks if the game is over for the Monte Carlo Tree Search (MCTS) strategy and returns the result.booleanisGameOverMCTS_lib(LinkedHashMap<Integer, List<Integer>> moves) Checks if the game is over for the Monte Carlo Tree Search (MCTS) strategy.booleanisValidMove(int move, Color pieceColor) Checks if a move is valid for a piece of the given color.booleanisWinForMCTS(Color color) Checks if the game is a win for the Monte Carlo Tree Search (MCTS) strategy.voidmovePiece(int startEnd) Moves a piece from a combined integer start end position.voidmovePiece(int start, int end) Moves a piece from the combined integer start position to the end position on the board.voidprintBoard(boolean fen) Prints the current state of the board to the console.voidsetColorBoard(Color[][] givenColorBoard) Set the color board.voidsetPieceBoard(Piece[][] givenPieceBoard) Set the piece board.
-
Field Details
-
capturingHM
-
-
Constructor Details
-
MoveGenerator
public MoveGenerator()
-
-
Method Details
-
getPieceBoard
-
getColorBoard
-
getTotalPossibleMoves
public int getTotalPossibleMoves() -
getProtectedPieces
public int getProtectedPieces() -
clone
-
setPieceBoard
Set the piece board.- Parameters:
givenPieceBoard- The piece board to set.
-
setColorBoard
Set the color board.- Parameters:
givenColorBoard- The color board to set.
-
initializeBoard
public void initializeBoard()Initialize the board(s) with starting position. -
initializeBoard
Initialize the board based on the provided FEN string.- Parameters:
fen- The FEN string representing the board state.
-
getFenFromBoard
Get the FEN string representation of the current board state.- Returns:
- The FEN string.
-
getColor
Get the color from a character representation.- Parameters:
c- The character representing the color ('r' for RED, 'b' for BLUE).- Returns:
- The corresponding Color enum value.
-
getColorAtPosition
Get the piece color at a specific position on the board.- Parameters:
position- The position (row * 10 + column) on the board.- Returns:
- The piece color at the specified position.
-
getPieceAtPosition
Get the piece at a specific position on the board.- Parameters:
position- The position (row * 10 + column) on the board.- Returns:
- The piece at the specified position.
-
convertPosToString
Convert a combined integer position to a string representation.- Parameters:
rowAndColInt- The combined integer position (row * 10 + column).- Returns:
- The string representation of the position.
-
convertMoveToFEN
Convert a combined integer move to FEN notation.- Parameters:
move- The move as a combined integer (from * 100 + to).- Returns:
- The move in FEN notation.
-
convertStringToPos
Convert a string position to a combined integer position.- Parameters:
pos- The string position.- Returns:
- The combined integer position (row * 10 + column).
-
convertStringToPosWrapper
Convert a FEN move to an array of two combined integer positions.- Parameters:
position_string- The FEN move.- Returns:
- An array of two combined integer positions representing the start and end positions.
-
isValidMove
Checks if a move is valid for a piece of the given color.- Parameters:
move- The combined integer move to validate (position as row * 10 + column).pieceColor- The color of the piece making the move (RED or BLUE).- Returns:
- True if the move is valid, false otherwise.
-
convertAllMoves
Converts a map of possible combined integer moves to a formatted FEN string representation.- Parameters:
possibleMoves- A map where keys are positions and values are lists of possible target positions.- Returns:
- A FEN string listing all moves.
-
getRandomMove
Retrieves a random move from a map of possible moves.- Parameters:
moves- A map where keys are combined integer starting positions and values are lists of possible target positions.- Returns:
- A random FEN string move.
-
getRandomMoveInt
Generates a random move from the given possible moves.- Parameters:
moves- Contains all possible moves to pick from.- Returns:
- An integer representing a randomly selected move.
-
getMovesWrapper
Retrieves all possible moves for a given board FEN string.- Parameters:
fen- The FEN string representing the given board state.- Returns:
- A map where keys are combined integer starting positions and values are lists of possible target positions.
-
movePiece
public void movePiece(int start, int end) Moves a piece from the combined integer start position to the end position on the board. Adjusts the state of the piece and its surroundings accordingly.- Parameters:
start- The combined integer starting position of the piece to be moved (row * 10 + column).end- The combined integer ending position where the piece will be moved (row * 10 + column).
-
movePiece
public void movePiece(int startEnd) Moves a piece from a combined integer start end position. Adjusts the state of the piece and its surroundings accordingly.- Parameters:
startEnd- Combined integer representing both start and end positions (start * 100 + end).
-
generateAllPossibleMoves
Generates all possible moves for a specific color.- Parameters:
color- The color of pieces for which moves are to be generated (RED or BLUE).- Returns:
- A map where keys are piece combined integer positions and values are lists of possible target positions.
-
generateAllPossibleMovesCaptures
Generates all possible capturing moves for a specific color.- Parameters:
color- The color of pieces for which moves are to be generated (RED or BLUE).- Returns:
- A map where keys are piece combined integer positions and values are lists of possible target positions.
-
generateMaxOnePossibleMoveForAI
Generates a maximum of one possible move for a given color.- Parameters:
color- The color of pieces for which moves are to be generated (RED or BLUE).- Returns:
- A map containing one piece combined integer position and its corresponding list of possible target positions.
-
isGameOver
Checks if the game is over for a specific color based on current board state.- Parameters:
color- The color of the pieces to check (RED or BLUE).- Returns:
- True if the game is over for the specified color, false otherwise.
-
isGameOver
-
isGameOver
Checks if the game is over for a specific color based on available moves.- Parameters:
moves- A map of possible moves where keys are combined integer positions and values are lists of target positions.color- The color of the pieces to check (RED or BLUE).- Returns:
- True if the game is over for the specified color, false otherwise.
-
isGameOverMCTS_lib
Checks if the game is over for the Monte Carlo Tree Search (MCTS) strategy.- Parameters:
moves- A map of possible moves where keys are combined integer positions and values are lists of target positions.- Returns:
- True if the game is over for either color, false otherwise.
-
getWinner
Determines the winner for the Monte Carlo Tree Search (MCTS) strategy (only use when confirmed that game is over).- Parameters:
moves- A map of possible moves where keys are combined integer positions and values are lists of target positions.currPlayer- The current player color to determine the winner (RED or BLUE).- Returns:
- True if BLUE (currPlayer) is the winner, false if RED is the winner.
-
isWinForMCTS
Checks if the game is a win for the Monte Carlo Tree Search (MCTS) strategy.- Parameters:
color- The color of the pieces to check (RED or BLUE).- Returns:
- True if the game is a win for the specified color, false otherwise.
-
isGameOverMCTS
Checks if the game is over for the Monte Carlo Tree Search (MCTS) strategy and returns the result.- Parameters:
moves- A map of possible moves where keys are combined integer positions and values are lists of target positions.color- The color of the pieces to check (RED or BLUE).- Returns:
- 1 if BLUE (color) wins, -1 if RED wins, 0 if the game is not over yet.
-
doesBaseRowContainColor
Checks if a specific row on the board contains any pieces of a given color.- Parameters:
color- The color of the pieces to check (RED or BLUE).rowToCheck- The row number to check (0 to 7).- Returns:
- True if the specified row contains at least one piece of the specified color, false otherwise.
-
printBoard
public void printBoard(boolean fen) Prints the current state of the board to the console. This can be done in FEN or numeric notation.- Parameters:
fen- Indicates whether to print the board in FEN notation format.
-