doc, fin
All checks were successful
Linux arm64 / Build (push) Successful in 34s

This commit is contained in:
2025-05-18 23:30:30 +02:00
parent 97950403a5
commit c741044469
18 changed files with 465 additions and 45 deletions

View File

@@ -38,19 +38,24 @@ public class Game {
return playerTurn;
}
/**
* Reset the game
*/
public void reset() {
resetPlayerTurn();
this.traitsPos.clear();
}
/**
* Reset the player turn.
* Aka: white for the win
*/
public void resetPlayerTurn() {
this.playerTurn = Color.White;
}
/**
*
* @param color the current player turn
* @return true if a draw should be declared
* Save the current board configuration
*/
public void saveTraitPiecesPos() {
int piecesHash = this.board.hashCode();
@@ -67,14 +72,16 @@ public class Game {
}
/**
*
* @return true if a draw should occur
* Switch player turn
*/
public void switchPlayerTurn() {
playerTurn = Color.getEnemy(playerTurn);
}
// this is the bottleneck of algorithms using this chess engine
/**
* Check the status of the game ofr the specified player
* @return a GameStatus enum
*/
public GameStatus checkGameStatus(Color color) {
if (checkDraw())
return GameStatus.Draw;
@@ -91,20 +98,32 @@ public class Game {
return GameStatus.OnGoing;
}
/**
* Check the status of the gamere
*/
public GameStatus checkGameStatus() {
return checkGameStatus(Color.getEnemy(getPlayerTurn()));
}
/**
* Add a player move (basic move, castling, ...) to the game history.
*/
public void addAction(PlayerCommand command) {
this.movesHistory.add(command);
}
/**
* @return the last player action
*/
public PlayerCommand getLastAction() {
if (this.movesHistory.isEmpty())
return null;
return this.movesHistory.pop();
}
/**
* Update the last board move ater an undo.
*/
public void updateLastMove() {
if (this.movesHistory.isEmpty())
return;
@@ -115,6 +134,9 @@ public class Game {
}
}
/**
* Remove the board configuration occurence from the game history
*/
public void undoTraitPiecesPos() {
int piecesHash = this.board.hashCode();
Integer count = this.traitsPos.get(piecesHash);
@@ -126,6 +148,9 @@ public class Game {
return this.movesHistory;
}
/**
* @return wether a pawn should be promoted
*/
public boolean pawnShouldBePromoted() {
return this.board.pawnShouldBePromoted();
}