Skip to content

Commit 00f3fbc

Browse files
committed
Renamed SearchParameters.getLow to getLowerBound + javadoc
1 parent 9df1615 commit 00f3fbc

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,30 @@ public int getAccuracy() {
7474
*/
7575
public void setAccuracy(int accuracy) {
7676
if (accuracy<0) {
77-
throw new IllegalArgumentException("Accuracy should be strictly positive");
77+
throw new IllegalArgumentException(ACCURACY_SHOULD_BE_POSITIVE);
7878
}
7979
this.accuracy = accuracy;
8080
}
8181

82-
public <M> int getLow(List<EvaluatedMove<M>> moves) {
82+
/** Gets the lower bound score under which moves will not be considered as one of the best moves returned by {@link #getBestMoves(List)}.
83+
* <br>An {@link AI} can returned the lower bound score instead of the real one if it is sure that its real score is lower than the lower bound score.
84+
* <br>This is because such a move is guaranteed not to be among the best {@link #getSize()} moves returned by {@link #getBestMoves(List)}.
85+
* @param moves A ordered (best first) list of moves. If this list is not sorted, the result is unpredictable.
86+
* @return an int
87+
*/
88+
public <M> int getLowerBound(List<EvaluatedMove<M>> moves) {
8389
return moves.size()>=size ? moves.get(size-1).getScore() - accuracy -1 : Integer.MIN_VALUE;
8490
}
8591

92+
/** Gets the best moves of a sorted move list according to the {@link #getSize()} and {@link #getAccuracy()} of this search parameter.
93+
* @param moves The list of moves to cut. This list must be sorted (best first). If it is not sorted, the result is unpredictable.
94+
* @return a list of moves restricted to the size and accuracy of this search parameter.
95+
* <br>Please note that the returned list may have more than {@link #getSize()} elements in case of equivalent moves or almost equivalent moves (according to {@link #getAccuracy()}).
96+
* It can also have less than {@link #getSize()} elements if there's less than {@link #getSize()} legal moves or search was interrupted before it finished.
97+
*/
8698
public <M> List<EvaluatedMove<M>> getBestMoves(List<EvaluatedMove<M>> moves) {
8799
final List<EvaluatedMove<M>> cut = new ArrayList<>(moves.size());
88-
final int low = getLow(moves);
100+
final int low = getLowerBound(moves);
89101
int currentCount = 0;
90102
for (EvaluatedMove<M> ev : moves) {
91103
if (ev.getScore()>low || currentCount<size) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public SearchParameters getSearchParameters() {
2727
}
2828

2929
synchronized int getLow() {
30-
return params.getLow(result);
30+
return params.getLowerBound(result);
3131
}
3232

3333
public synchronized void add(M move, Evaluation value) {

src/main/java/com/fathzer/games/ai/iterativedeepening/DeepeningPolicy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public <M> Optional<SearchResult<M>> mergeInterrupted(SearchHistory<M> history,
191191
return Optional.empty();
192192
}
193193
final List<EvaluatedMove<M>> historyMoves = history.getLastList();
194-
final int previousLow = this.getLow(historyMoves);
194+
final int previousLow = this.getLowerBound(historyMoves);
195195
final boolean trap = partialList.get(partialList.size()-1).getScore()<=previousLow;
196196
final SearchResult<M> mergedResult = new SearchResult<>(this);
197197
if (trap) {

0 commit comments

Comments
 (0)