From 4ea458c92ee18471fe42d1af18010efd1703ee35 Mon Sep 17 00:00:00 2001
From: michiel
Date: Thu, 4 Dec 2025 15:11:41 +0100
Subject: [PATCH] depth + thinktime back to AIs, along with a a specific
TicTacToeAIRSleep
---
.../app/widget/view/LocalMultiplayerView.java | 5 ++--
.../game/games/tictactoe/TicTacToeAIR.java | 4 +--
.../games/tictactoe/TicTacToeAIRSleep.java | 25 +++++++++++++++++++
3 files changed, 30 insertions(+), 4 deletions(-)
create mode 100644 game/src/main/java/org/toop/game/games/tictactoe/TicTacToeAIRSleep.java
diff --git a/app/src/main/java/org/toop/app/widget/view/LocalMultiplayerView.java b/app/src/main/java/org/toop/app/widget/view/LocalMultiplayerView.java
index 4e5cc3a..aa9cefe 100644
--- a/app/src/main/java/org/toop/app/widget/view/LocalMultiplayerView.java
+++ b/app/src/main/java/org/toop/app/widget/view/LocalMultiplayerView.java
@@ -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(
diff --git a/game/src/main/java/org/toop/game/games/tictactoe/TicTacToeAIR.java b/game/src/main/java/org/toop/game/games/tictactoe/TicTacToeAIR.java
index faeba18..dc0a285 100644
--- a/game/src/main/java/org/toop/game/games/tictactoe/TicTacToeAIR.java
+++ b/game/src/main/java/org/toop/game/games/tictactoe/TicTacToeAIR.java
@@ -13,7 +13,7 @@ import org.toop.framework.gameFramework.GameState;
* opening or when no clear best move is found.
*
*/
-public final class TicTacToeAIR extends AbstractAI {
+public class TicTacToeAIR extends AbstractAI {
/**
* Determines the best move for the given Tic-Tac-Toe game state.
@@ -26,7 +26,6 @@ public final class TicTacToeAIR extends AbstractAI {
* @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 {
public TicTacToeAIR(int depth) {
this.depth = depth;
}
+
public int getMove(TicTacToeR game) {
assert game != null;
final int[] legalMoves = game.getLegalMoves();
diff --git a/game/src/main/java/org/toop/game/games/tictactoe/TicTacToeAIRSleep.java b/game/src/main/java/org/toop/game/games/tictactoe/TicTacToeAIRSleep.java
new file mode 100644
index 0000000..bdd21cf
--- /dev/null
+++ b/game/src/main/java/org/toop/game/games/tictactoe/TicTacToeAIRSleep.java
@@ -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;
+ }
+}