Wanna simulate the next move for my AI in my othello game, but instead of just returning the next move, it makes all the moves on the original board instead of just simulating on a clone and the game ends.
public class GameState implements Cloneable{
private Node[][] board; // Game board
private int scorePlayer, scoreAI; // Player scores ( will start at 0 )
private ArrayList<Node> validNodes; // List holding all nodes possible to add pieces to
/**
* Creates the game state
*/
public GameState(){
// create size x size board
this.board = new Node[Setting.BOARD_SIZE][Setting.BOARD_SIZE];
validNodes = new ArrayList<>();
scorePlayer = 0;
scoreAI = 0;
protected GameState clone() {
return new GameState(this);
}------------------------ CLONE METHOD----------------
public int search(GameState board, Player player, int alpha, int beta, int depth, ScoreEval function) {
int record = Integer.MIN_VALUE;
Node maxMove = null;
int result;
GameState subBoard = board.clone();
if (depth <= 0 || board.getValidMoves().size()==0) {
record = function.evaluate(board, player);
} else {
ArrayList<Node> possibleMoves = board.getValidMoves();
if (!possibleMoves.isEmpty()) {
for (int i =0; i<possibleMoves.size();i++) {
Node nod = possibleMoves.get(i);
subBoard = board.clone();
subBoard.setPiece(nod.x,nod.y, player.type);
if(player.type==Setting.TILE_AI){
result = -search(subBoard, aiAss1.Controller.pHum, alpha, beta, depth - 1, function);
}
else{
result = -search(subBoard, aiAss1.Controller.pAI, alpha, beta, depth - 1, function);
}
if (result > record) {
record = result;
maxMove = nod;
}
}
} else {
record = -search(subBoard, player, alpha, beta, depth - 1, function);
}
}
bestMove = maxMove;
return record;
}