Skip to content

Commit

Permalink
Adds a queen side castling test in AbstractMoveDataTest + better javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
fathzer committed Dec 11, 2024
1 parent 0e6ffcd commit b2c0f10
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>1.0.8</version>
</parent>
<artifactId>chess-utils</artifactId>
<version>0.0.3-SNAPSHOT</version>
<version>0.0.4-SNAPSHOT</version>

<name>chess-utils</name>
<description>Some helpful piece of code to implement chess engines.</description>
Expand Down Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>com.fathzer</groupId>
<artifactId>games-core</artifactId>
<version>0.0.10-SNAPSHOT</version>
<version>0.0.12-SNAPSHOT</version>
</dependency>
<dependency>
<!-- This dependency is used to compile the com.fathzer.chess.utils.test package.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fathzer.games.ai.evaluation.QuiesceEvaluator;

/** A basic quiescence search evaluator.
* @see #evaluate(SearchContext, int, int, int)
*/
public abstract class AbstractBasicQuiesceEvaluator<M, B extends MoveGenerator<M>> implements QuiesceEvaluator<M,B> {
/** Constructor.
Expand All @@ -17,6 +18,21 @@ protected AbstractBasicQuiesceEvaluator() {
super();
}

/**
* {@inheritDoc}
* <br>The quiesce search is recursive algorithm.
* <br>At each depth:<ul>
* <li>If there's no check:<ul>
* <li>if current position evaluation is &gt;= beta it returns beta</li>
* <li>if current position evaluation is &gt; alpha alpha is replaced by the evaluation</li>
* </ul>
* <li>The method calls {@link #getMoves(SearchContext, int)}: <ul>
* <li>If the move list is empty, it returns the evaluation of current position.</li>
* <li>Otherwise, for each move, it plays the move and performs the same algorithm on this new position.
* </ul>
* </li>
* </ul>
*/
@Override
public int evaluate(SearchContext<M, B> context, int depth, int alpha, int beta) {
return quiesce(context, alpha, beta, depth, 0);
Expand Down Expand Up @@ -55,12 +71,16 @@ private int quiesce(SearchContext<M, B> context, int alpha, int beta, int rootDe
return mate ? -context.getEvaluator().getWinScore(rootDepth+quiesceDepth) : alpha;
}

/** Tests whether the current position is a check.
* @param context The current context (you can find current position with {@link SearchContext#getGamePosition()})
* @return true if the position is a check
*/
protected abstract boolean isCheck(SearchContext<M, B> context);

/** Gets the list of quiesce moves.
* @param context The search context (can be used to get the board)
* @param quiesceDepth The quiesce depth. 0 for the first level
* @return A list of moves to analyze deeper, an empty list to stop deepening.
* @return A list of moves to analyze deeper (usually, this list should contain moves to escape a check, captures and check moves), an empty list to stop deepening.
*/
protected abstract List<M> getMoves(SearchContext<M, B> context, int quiesceDepth);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Evaluator<M, B> fork() {

/** Creates a new instance initialized with current state that will become the initial state of created instance.
* @param state The initial state.
* @return a new evaluator of the same class as this, this the same view point, and initialized with the state.
* @return a new evaluator of the same class as this, from the same view point, and initialized with the state.
*/
protected abstract AbstractIncrementalSimplifiedEvaluator<M, B> fork(IncrementalState state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean update(Move move, ChessLibMoveGenerator board) {
final Side side = board.getBoard().getSideToMove();
this.captured = null;
this.movingDestination = move.getTo();
final Move rookMove = context.getRookCastleMove(side, context.isCastleMove(move) ? KING_SIDE :
final Move rookMove = context.getRookCastleMove(side, context.isKingSideCastle(move) ? KING_SIDE :
QUEEN_SIDE);
this.castlingRookIndex = rookMove.getFrom();
this.castlingRookDestinationIndex = rookMove.getTo();
Expand Down

0 comments on commit b2c0f10

Please sign in to comment.