You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
675 B
34 lines
675 B
package de.tims.tictactoe.ai;
|
|
|
|
import de.tims.tictactoe.GameLogic;
|
|
|
|
import java.util.Random;
|
|
|
|
public class AIEasy implements TicTacToeAI {
|
|
private static final char AI_CHAR = 'o';
|
|
private static final char EMPTY_CHAR = '-';
|
|
|
|
private Random rand;
|
|
private GameLogic gl;
|
|
private int boardSize;
|
|
|
|
public AIEasy(GameLogic gl) {
|
|
this.gl = gl;
|
|
boardSize = gl.getBoard().length;
|
|
rand = new Random();
|
|
}
|
|
|
|
@Override
|
|
public void calculateNextMove() {
|
|
char[][] board = gl.getBoard();
|
|
int row;
|
|
int col;
|
|
do {
|
|
row = rand.nextInt(boardSize);
|
|
col = rand.nextInt(boardSize);
|
|
} while (board[row][col] != EMPTY_CHAR);
|
|
|
|
gl.setField(row, col, AI_CHAR);
|
|
}
|
|
|
|
}
|