Skip to content

Commit fb086f4

Browse files
committed
Moves AlphaBetaState to transposition package. Adds javadoc
1 parent e44296f commit fb086f4

32 files changed

+455
-128
lines changed

pom.xml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<dependency>
5151
<groupId>org.mockito</groupId>
5252
<artifactId>mockito-junit-jupiter</artifactId>
53-
<version>5.1.1</version>
53+
<version>5.16.0</version>
5454
<scope>test</scope>
5555
</dependency>
5656
<dependency>
@@ -66,4 +66,31 @@
6666
<scope>test</scope>
6767
</dependency>
6868
</dependencies>
69+
70+
<build>
71+
<plugins>
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-javadoc-plugin</artifactId>
75+
<version>3.6.3</version>
76+
<configuration>
77+
<source>8</source>
78+
<docencoding>UTF-8</docencoding>
79+
<overview>${basedir}/overview.html</overview>
80+
<header>${project.version}</header>
81+
<bottom>${project.version}</bottom>
82+
<excludePackageNames>:*.experimental</excludePackageNames>
83+
</configuration>
84+
<executions>
85+
<execution>
86+
<id>javadoc_generation</id>
87+
<phase>package</phase>
88+
<goals>
89+
<goal>jar</goal>
90+
</goals>
91+
</execution>
92+
</executions>
93+
</plugin>
94+
</plugins>
95+
</build>
6996
</project>

src/main/java/com/fathzer/games/Status.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
/** The status of a game (playing, draw, white or black won).
44
*/
55
public enum Status {
6-
PLAYING, DRAW, WHITE_WON, BLACK_WON;
6+
/** The game is still playing */
7+
PLAYING,
8+
/** The game ends with a draw */
9+
DRAW,
10+
/** The white player has won */
11+
WHITE_WON,
12+
/** The black player has won */
13+
BLACK_WON;
714

815
/** Gets the winner's color.
916
* @return A color or null if there's no winner

src/main/java/com/fathzer/games/ai/AlphaBetaState.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/main/java/com/fathzer/games/ai/Negamax.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.fathzer.games.ai.evaluation.EvaluatedMove;
1010
import com.fathzer.games.ai.evaluation.Evaluator;
1111
import com.fathzer.games.ai.evaluation.QuiesceEvaluator;
12+
import com.fathzer.games.ai.transposition.AlphaBetaState;
1213
import com.fathzer.games.ai.transposition.EntryType;
1314
import com.fathzer.games.ai.transposition.TTAi;
1415
import com.fathzer.games.ai.transposition.TranspositionTable;
@@ -24,6 +25,9 @@ public class Negamax<M,B extends MoveGenerator<M>> extends AbstractAI<M,B> imple
2425
private TranspositionTable<M, B> transpositionTable;
2526
private QuiesceEvaluator<M,B> quiesceEvaluator;
2627

28+
/** Constructor
29+
* @param exec The execution context
30+
*/
2731
public Negamax(ExecutionContext<SearchContext<M,B>> exec) {
2832
super(exec);
2933
quiesceEvaluator = (ctx, depth, alpha, beta) -> {

src/main/java/com/fathzer/games/ai/SearchContext.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,32 @@ private SearchContext(B gamePosition, Evaluator<M, B> evaluator, SearchStatistic
2222
this.statistics = statistics;
2323
}
2424

25+
/** Gets the game position.
26+
* @return a {@link MoveGenerator} instance
27+
*/
2528
public B getGamePosition() {
2629
return gamePosition;
2730
}
2831

32+
/** Gets the evaluator.
33+
* @return an evaluator instance
34+
*/
2935
public Evaluator<M, B> getEvaluator() {
3036
return evaluator;
3137
}
3238

39+
/** Gets the search statistics.
40+
* @return a {@link SearchStatistics} instance
41+
*/
3342
public SearchStatistics getStatistics() {
3443
return statistics;
3544
}
3645

46+
/** Makes a move.
47+
* @param move The move to make
48+
* @param confidence The confidence of the move
49+
* @return true if the move was made, false otherwise (if it was illegal)
50+
*/
3751
public boolean makeMove(M move, MoveGenerator.MoveConfidence confidence) {
3852
evaluator.prepareMove(gamePosition, move);
3953
if (gamePosition.makeMove(move, confidence)) {
@@ -43,6 +57,7 @@ public boolean makeMove(M move, MoveGenerator.MoveConfidence confidence) {
4357
return false;
4458
}
4559

60+
/** Unmakes the last move. */
4661
public void unmakeMove() {
4762
evaluator.unmakeMove();
4863
gamePosition.unmakeMove();
@@ -56,6 +71,13 @@ public SearchContext<M, B> fork() {
5671
return new SearchContext<>(mg, ev, statistics);
5772
}
5873

74+
/** Gets a new search context.
75+
* @param board The game position
76+
* @param evaluatorBuilder A supplier that can create an evaluator
77+
* @param <M> The type of moves
78+
* @param <B> The type of the move generator
79+
* @return a new search context
80+
*/
5981
public static <M, B extends MoveGenerator<M>> SearchContext<M, B> get(B board, Supplier<Evaluator<M, B>> evaluatorBuilder) {
6082
@SuppressWarnings("unchecked")
6183
final B b = (B) board.fork();

src/main/java/com/fathzer/games/ai/SearchResult.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.fathzer.games.util.SortedUtils;
99

1010
/** The result of a best move search.
11+
* @param <M> The type of moves
1112
*/
1213
public final class SearchResult<M> {
1314
private final LinkedList<EvaluatedMove<M>> result;

src/main/java/com/fathzer/games/ai/experimental/KeyBasedNegaMaxSpyFilter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
import com.fathzer.games.MoveGenerator;
88

9+
/**
10+
* A spy that can be used to monitor the search process of {@link Negamax3}.
11+
* <br>It is called by the search process at various points.
12+
* @param <M> The type of the moves
13+
* @param <B> The type of the {@link MoveGenerator} to use
14+
*/
915
public abstract class KeyBasedNegaMaxSpyFilter<M,B extends MoveGenerator<M>> {
1016
private int enteringDepth=-1;
1117
private final long searchedKey;

src/main/java/com/fathzer/games/ai/experimental/Negamax3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import com.fathzer.games.MoveGenerator.MoveConfidence;
99
import com.fathzer.games.HashProvider;
1010
import com.fathzer.games.MoveGenerator;
11-
import com.fathzer.games.ai.AlphaBetaState;
1211
import com.fathzer.games.ai.Negamax;
1312
import com.fathzer.games.ai.SearchContext;
1413
import com.fathzer.games.ai.DepthFirstSearchParameters;
1514
import com.fathzer.games.ai.SearchResult;
1615
import com.fathzer.games.ai.evaluation.EvaluatedMove;
1716
import com.fathzer.games.ai.evaluation.Evaluator;
17+
import com.fathzer.games.ai.transposition.AlphaBetaState;
1818
import com.fathzer.games.ai.transposition.EntryType;
1919
import com.fathzer.games.ai.transposition.TranspositionTableEntry;
2020
import com.fathzer.games.util.exec.ExecutionContext;

src/main/java/com/fathzer/games/ai/experimental/Spy.java

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,73 @@
33
import java.util.List;
44

55
import com.fathzer.games.MoveGenerator;
6-
import com.fathzer.games.ai.AlphaBetaState;
6+
import com.fathzer.games.ai.transposition.AlphaBetaState;
7+
import com.fathzer.games.ai.transposition.TranspositionTablePolicy;
78

9+
/** A spy that can be used to monitor the search process of {@link Negamax3}.
10+
* <br>It is called by the search process at various points.
11+
* @param <M> The type of the moves
12+
* @param <B> The type of the {@link MoveGenerator} to use
13+
*/
814
public interface Spy<M, B extends MoveGenerator<M>> {
9-
public enum Event {EVAL, END_GAME, EXIT, TT}
15+
/** The events that triggers the end of search at a depth. */
16+
public enum Event {
17+
/** The search process reached the max depth and computed a new evaluation. */
18+
EVAL,
19+
/** The search process has reached a terminal game state. */
20+
END_GAME,
21+
/** The search process has exited because there are no more moves to play. */
22+
EXIT,
23+
/** The search process has found an evaluation from the transposition table. */
24+
TT
25+
}
1026

27+
/** Called when the search process enters a new depth.
28+
* @param state The state of the search process
29+
*/
1130
default void enter(TreeSearchStateStack<M,B> state) {}
31+
32+
/** Called when alpha/beta value is found in the transposition table.
33+
* @param state The state of the search process
34+
* @param abState The alpha/beta state
35+
*/
1236
default void alphaBetaFromTT(TreeSearchStateStack<M,B> state, AlphaBetaState<M> abState) {}
37+
38+
/** Called when a state was sent to the transposition table (even if it is rejected by its {@link TranspositionTablePolicy}
39+
* @param state The state of the search process
40+
* @param abState The alpha/beta state
41+
* @param store true if the state is stored, false if it is rejected by the policy
42+
*/
1343
default void storeTT(TreeSearchStateStack<M,B> state, AlphaBetaState<M> abState, boolean store) {}
44+
45+
/** Called when a tree cut occurs.
46+
* @param state The state of the search process
47+
* @param move The move that triggered the cut
48+
*/
1449
default void cut(TreeSearchStateStack<M,B> state, M move) {}
50+
51+
/** Called when the search process exits a depth.
52+
* @param state The state of the search process
53+
* @param evt The event that triggered the exit
54+
*/
1555
default void exit(TreeSearchStateStack<M,B> state, Event evt) {}
56+
57+
/** Called when a move is unmade.
58+
* @param state The state of the search process
59+
* @param moves The list of moves
60+
* @param move The move that was unmade
61+
*/
1662
default void moveUnmade(TreeSearchStateStack<M, B> state, List<M> moves, M move) {}
63+
64+
/** Called when the moves are computed.
65+
* @param searchStack The search stack
66+
* @param moves The list of moves
67+
*/
1768
default void movesComputed(TreeSearchStateStack<M, B> searchStack, List<M> moves) {}
69+
70+
/** Called when an exception is thrown.
71+
* @param searchStack The search stack
72+
* @param e The exception
73+
*/
1874
default void exception(TreeSearchStateStack<M, B> searchStack, RuntimeException e) {}
1975
}

0 commit comments

Comments
 (0)