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

@@ -6,6 +6,7 @@ import org.toop.app.gameControllers.AbstractGameController;
import org.toop.app.gameControllers.ReversiController;
import org.toop.app.gameControllers.TicTacToeController;
import org.toop.framework.gameFramework.model.player.Player;
import org.toop.game.games.tictactoe.TicTacToeAIRSleep;
import org.toop.game.players.ArtificialPlayer;
import org.toop.game.players.LocalPlayer;
import org.toop.app.widget.Primitive;
@@ -52,12 +53,12 @@ public class LocalMultiplayerView extends ViewWidget {
if (information.players[0].isHuman) {
players[0] = new LocalPlayer<>(information.players[0].name);
} else {
players[0] = new ArtificialPlayer<>(new TicTacToeAIR(information.players[0].computerDifficulty), information.players[0].name);
players[0] = new ArtificialPlayer<>(new TicTacToeAIRSleep(information.players[0].computerDifficulty, information.players[1].computerThinkTime), information.players[0].name);
}
if (information.players[1].isHuman) {
players[1] = new LocalPlayer<>(information.players[1].name);
} else {
players[1] = new ArtificialPlayer<>(new TicTacToeAIR(information.players[1].computerDifficulty), information.players[1].name);
players[1] = new ArtificialPlayer<>(new TicTacToeAIRSleep(information.players[1].computerDifficulty, information.players[1].computerThinkTime), information.players[1].name);
}
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstTTT()) {
new ShowEnableTutorialWidget(

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;
}
}