
com.fathzer.games.ai.toys.BasicAI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of games-core Show documentation
Show all versions of games-core Show documentation
A core library to help implement two players games.
The newest version!
package com.fathzer.games.ai.toys;
import java.util.List;
import java.util.function.Predicate;
import com.fathzer.games.MoveGenerator;
import com.fathzer.games.ai.AI;
import com.fathzer.games.ai.SearchParameters;
import com.fathzer.games.ai.SearchResult;
import com.fathzer.games.ai.evaluation.Evaluation;
/** A basic AI
* @param The type of moves
* @param The type of move generator
*/
public abstract class BasicAI> implements AI {
/** The board on which the AI plays */
protected final B board;
/** Constructor.
* @param board The board on which the AI plays
*/
protected BasicAI(B board) {
this.board = board;
}
@Override
public SearchResult getBestMoves(SearchParameters parameters) {
return getBestMoves(null, parameters);
}
@Override
public SearchResult getBestMoves(List possibleMoves, SearchParameters parameters) {
final SearchResult result = new SearchResult<>(parameters);
final List moves = board.getLegalMoves();
final Predicate filter = possibleMoves==null ? m->true : possibleMoves::contains;
moves.stream().filter(filter).forEach(m -> result.add(m, getEvaluation(m)));
return result;
}
/** Gets the evaluation of a move
* @param move The move
* @return The evaluation of the move
*/
protected abstract Evaluation getEvaluation(M move);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy