Package Search
Class DomineeringSearch
- java.lang.Object
-
- Search.DomineeringSearch
-
- All Implemented Interfaces:
GameSearch
public class DomineeringSearch extends java.lang.Object implements GameSearch
The DomineeringSearch class implements the GameSearch interface for the Domineering game. It utilizes the Singleton pattern to ensure a single instance of the class.- Since:
- 2023-12-01
- Version:
- 1.0
- Author:
- Laamiri Ouail & Hajar Sadik
-
-
Field Summary
Fields Modifier and Type Field Description private static DomineeringSearch
domineeringSearchInstance
Singleton instance
-
Constructor Summary
Constructors Modifier Constructor Description private
DomineeringSearch()
Private constructor for Singleton pattern.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DomineeringSearch
getInstance()
Get the instance of DomineeringSearch using the Singleton pattern.byte
getNextPlayer()
Get the next player to make a move.byte
getNumberOfPosibleMove(byte player)
Get the number of possible moves for the specified player.byte
getNumbreOfMoveByPlayer(byte player)
Get the number of moves made by the specified player.java.util.List<Board>
getValideStates(byte player)
Get a list of valid game states for the specified player.java.util.List<int[]>
getValidMoves(java.lang.String[][] state, byte player)
Get a list of valid moves for the specified player based on the current state.java.util.List<Move>
getValidMovesi(byte player)
Get a list of valid moves for the specified player.int
heuristic(int[] move)
Calculate the heuristic value for a move.void
makeHelpMove(int x, int y, byte player)
Make a helper move on the game board.void
makeMove(int x, int y, byte player)
Make a move on the game board.int[]
maxValue(java.lang.String[][] state, int depth, int alpha, int beta, int[] move)
Get the maximum value for a state in a minimax search.int[]
minmax(java.lang.String[][] state, int depth, boolean myMove, int[] alpha, int[] beta)
Perform a minimax search on the game state.int[]
minValue(java.lang.String[][] state, int depth, int alpha, int beta, int[] move)
Get the minimum value for a state in a minimax search.byte
playerWin()
Check if a player has won the game.boolean
playHelpMove(int x, int y)
Play a move on the game board for a helper move.boolean
playMove(int x, int y)
Play a move on the game board.
-
-
-
Field Detail
-
domineeringSearchInstance
private static DomineeringSearch domineeringSearchInstance
Singleton instance
-
-
Method Detail
-
getInstance
public static DomineeringSearch getInstance()
Get the instance of DomineeringSearch using the Singleton pattern.- Returns:
- The DomineeringSearch instance.
-
getNumbreOfMoveByPlayer
public byte getNumbreOfMoveByPlayer(byte player)
Get the number of moves made by the specified player.- Specified by:
getNumbreOfMoveByPlayer
in interfaceGameSearch
- Parameters:
player
- The player for whom to get the number of moves.- Returns:
- The number of moves made by the player.
-
getValidMovesi
public java.util.List<Move> getValidMovesi(byte player)
Get a list of valid moves for the specified player.- Specified by:
getValidMovesi
in interfaceGameSearch
- Parameters:
player
- The player for whom to get valid moves.- Returns:
- A list of valid moves for the player.
-
getValidMoves
public java.util.List<int[]> getValidMoves(java.lang.String[][] state, byte player)
Get a list of valid moves for the specified player based on the current state.- Specified by:
getValidMoves
in interfaceGameSearch
- Parameters:
state
- The current state of the game.player
- The player for whom to get valid moves.- Returns:
- A list of valid moves for the player.
-
getValideStates
public java.util.List<Board> getValideStates(byte player)
Get a list of valid game states for the specified player.- Specified by:
getValideStates
in interfaceGameSearch
- Parameters:
player
- The player for whom to get valid game states.- Returns:
- A list of valid game states for the player.
-
getNextPlayer
public byte getNextPlayer()
Get the next player to make a move.- Specified by:
getNextPlayer
in interfaceGameSearch
- Returns:
- The next player to make a move.
-
getNumberOfPosibleMove
public byte getNumberOfPosibleMove(byte player)
Get the number of possible moves for the specified player.- Specified by:
getNumberOfPosibleMove
in interfaceGameSearch
- Parameters:
player
- The player for whom to get the number of possible moves.- Returns:
- The number of possible moves for the player.
-
playerWin
public byte playerWin()
Check if a player has won the game.- Specified by:
playerWin
in interfaceGameSearch
- Returns:
- The winning player or 0 if no player has won.
-
makeMove
public void makeMove(int x, int y, byte player)
Make a move on the game board.- Specified by:
makeMove
in interfaceGameSearch
- Parameters:
x
- The y-coordinate of the move.y
- The x-coordinate of the move.player
- The player making the move.
-
makeHelpMove
public void makeHelpMove(int x, int y, byte player)
Make a helper move on the game board.- Specified by:
makeHelpMove
in interfaceGameSearch
- Parameters:
x
- The x-coordinate of the helper move.y
- The y-coordinate of the helper move.player
- The player making the helper move.
-
playHelpMove
public boolean playHelpMove(int x, int y)
Play a move on the game board for a helper move.- Specified by:
playHelpMove
in interfaceGameSearch
- Parameters:
x
- The x-coordinate of the helper move.y
- The y-coordinate of the helper move.- Returns:
- True if the helper move was played successfully, false otherwise.
-
playMove
public boolean playMove(int x, int y)
Play a move on the game board.- Specified by:
playMove
in interfaceGameSearch
- Parameters:
x
- The x-coordinate of the move.y
- The y-coordinate of the move.- Returns:
- True if the move was played successfully, false otherwise.
-
heuristic
public int heuristic(int[] move)
Calculate the heuristic value for a move.- Specified by:
heuristic
in interfaceGameSearch
- Parameters:
move
- An array containing the move coordinates and value.- Returns:
- The heuristic value for the move.
-
maxValue
public int[] maxValue(java.lang.String[][] state, int depth, int alpha, int beta, int[] move)
Get the maximum value for a state in a minimax search.- Specified by:
maxValue
in interfaceGameSearch
- Parameters:
state
- The current state of the game.depth
- The depth of the search.alpha
- The alpha value for pruning.beta
- The beta value for pruning.move
- The best move found so far.- Returns:
- An array containing the best move and its value.
-
minValue
public int[] minValue(java.lang.String[][] state, int depth, int alpha, int beta, int[] move)
Get the minimum value for a state in a minimax search.- Specified by:
minValue
in interfaceGameSearch
- Parameters:
state
- The current state of the game.depth
- The depth of the search.alpha
- The alpha value for pruning.beta
- The beta value for pruning.move
- The best move found so far.- Returns:
- An array containing the best move and its value.
-
minmax
public int[] minmax(java.lang.String[][] state, int depth, boolean myMove, int[] alpha, int[] beta)
Perform a minimax search on the game state.- Specified by:
minmax
in interfaceGameSearch
- Parameters:
state
- The current state of the game.depth
- The depth of the search.myMove
- True if it's the current player's move, false otherwise.alpha
- The alpha value for pruning.beta
- The beta value for pruning.- Returns:
- An array containing the best move and its value.
-
-