depth + thinktime back to AIs, along with a a specific TicTacToeAIRSleep

This commit is contained in:
michiel
2025-12-04 15:11:41 +01:00
parent 134c9a2fd8
commit 4ea458c92e
3 changed files with 30 additions and 4 deletions

View File

@@ -13,7 +13,7 @@ import org.toop.framework.gameFramework.GameState;
* opening or when no clear best move is found.
* </p>
*/
public final class TicTacToeAIR extends AbstractAI<TicTacToeR> {
public class TicTacToeAIR extends AbstractAI<TicTacToeR> {
/**
* Determines the best move for the given Tic-Tac-Toe game state.
@@ -26,7 +26,6 @@ public final class TicTacToeAIR extends AbstractAI<TicTacToeR> {
* @param game the current Tic-Tac-Toe game state
* @param depth the depth of lookahead for evaluating moves (non-negative)
* @return the index of the best move, or -1 if no moves are available
*
*/
private int depth;
@@ -34,6 +33,7 @@ public final class TicTacToeAIR extends AbstractAI<TicTacToeR> {
public TicTacToeAIR(int depth) {
this.depth = depth;
}
public int getMove(TicTacToeR game) {
assert game != null;
final int[] legalMoves = game.getLegalMoves();

View File

@@ -0,0 +1,25 @@
package org.toop.game.games.tictactoe;
import java.util.Random;
public class TicTacToeAIRSleep extends TicTacToeAIR {
private int thinkTime;
public TicTacToeAIRSleep(int depth, int thinkTime) {
super(depth);
this.thinkTime = thinkTime;
}
@Override
public int getMove(TicTacToeR game) {
int score = super.getMove(game);
try {
Random random = new Random();
Thread.sleep(this.thinkTime * 1000L + random.nextInt(1000));
} catch (Exception e) {
e.printStackTrace();
}
return score;
}
}