mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
depth + thinktime back to AIs, along with a a specific TicTacToeAIRSleep
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user