mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
better human/ai selector with bot selection and depth on TicTacToeAIR
This commit is contained in:
@@ -25,10 +25,10 @@ public final class ReversiR extends AbstractGame<ReversiR> {
|
||||
// TODO: Don't hardcore for two players :)
|
||||
public record Score(int player1Score, int player2Score) {}
|
||||
|
||||
public ReversiR(Player<ReversiR>[] players) {
|
||||
super(8, 8, 2, players);
|
||||
public ReversiR(Player<ReversiR>[] players) {
|
||||
super(8, 8, 2, players);
|
||||
addStartPieces();
|
||||
}
|
||||
}
|
||||
|
||||
public ReversiR(ReversiR other) {
|
||||
super(other);
|
||||
@@ -53,8 +53,8 @@ public final class ReversiR extends AbstractGame<ReversiR> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getLegalMoves() {
|
||||
@Override
|
||||
public int[] getLegalMoves() {
|
||||
final ArrayList<Integer> legalMoves = new ArrayList<>();
|
||||
int[][] boardGrid = makeBoardAGrid();
|
||||
int currentPlayer = this.getCurrentTurn();
|
||||
@@ -67,7 +67,7 @@ public final class ReversiR extends AbstractGame<ReversiR> {
|
||||
}
|
||||
}
|
||||
return legalMoves.stream().mapToInt(Integer::intValue).toArray();
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Point> getAdjacentCells(int[][] boardGrid) {
|
||||
Set<Point> possibleCells = new HashSet<>();
|
||||
@@ -76,7 +76,7 @@ public final class ReversiR extends AbstractGame<ReversiR> {
|
||||
for (int deltaRow = -1; deltaRow <= 1; deltaRow++){ //orthogonally and diagonally
|
||||
int newX = point.x + deltaColumn, newY = point.y + deltaRow;
|
||||
if (deltaColumn == 0 && deltaRow == 0 //continue if out of bounds
|
||||
|| !isOnBoard(newX, newY)) {
|
||||
|| !isOnBoard(newX, newY)) {
|
||||
continue;
|
||||
}
|
||||
if (boardGrid[newY][newX] == EMPTY) { //check if the cell is empty
|
||||
|
||||
@@ -26,9 +26,15 @@ 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;
|
||||
|
||||
public TicTacToeAIR(int depth) {
|
||||
this.depth = depth;
|
||||
}
|
||||
public int getMove(TicTacToeR game) {
|
||||
int depth = 9;
|
||||
assert game != null;
|
||||
final int[] legalMoves = game.getLegalMoves();
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
final class TicTacToeAIRTest {
|
||||
|
||||
private final TicTacToeAIR ai = new TicTacToeAIR();
|
||||
private final TicTacToeAIR ai = new TicTacToeAIR(9);
|
||||
|
||||
// Helper: play multiple moves in sequence on a fresh board
|
||||
private TicTacToeR playSequence(int... moves) {
|
||||
|
||||
Reference in New Issue
Block a user