tourney ready

This commit is contained in:
Ticho Hidding
2025-10-27 17:14:36 +01:00
parent b506afdade
commit c115fb91af
8 changed files with 116 additions and 29 deletions

View File

@@ -6,6 +6,8 @@ import org.toop.game.Game;
public final class ReversiAI extends AI<Reversi> {
@Override
public Game.Move findBestMove(Reversi game, int depth) {
return game.getLegalMoves()[0];
Game.Move[] moves = game.getLegalMoves();
int inty = (int)(Math.random() * moves.length-.5f);
return moves[inty];
}
}

View File

@@ -11,7 +11,7 @@ public final class TicTacToeAI extends AI<TicTacToe> {
final Game.Move[] legalMoves = game.getLegalMoves();
if (legalMoves.length <= 0) {
if (legalMoves.length == 0) {
return null;
}
@@ -38,6 +38,24 @@ public final class TicTacToeAI extends AI<TicTacToe> {
return bestMove != null? bestMove : legalMoves[(int)(Math.random() * legalMoves.length)];
}
public Game.Move findWorstMove(TicTacToe game, int depth){
Game.Move[] legalMoves = game.getLegalMoves();
int bestScore = -depth;
Game.Move bestMove = null;
for (final Game.Move move : legalMoves) {
final int score = getMoveScore(game, depth, move, false);
if (score > bestScore) {
bestMove = move;
bestScore = score;
}
}
return bestMove;
}
private int getMoveScore(TicTacToe game, int depth, Game.Move move, boolean maximizing) {
final TicTacToe copy = new TicTacToe(game);