Whilst there have been numerous other questions on cloning, I've been reading their answers and as far as I'm aware I seem to have done most of what people have been saying.
In my Chequers Java game the board state is represented as a 2D Array containing objects of the Chequer class. In order to implement a MiniMax AI you need to create a search tree in order to traverse possible game states & evaluate them. For some reason my cloning technique has not worked.
What currently happens is that the MiniMax algorithm keeps moving Chequers around the primary game array, so once it decides on the best move to make, the Chequer is not there any more to move and a null pointer error is thrown.
I was wondering if any of you could take a look at my cloning and tell me where I'm going wrong:
Game Board Constructor:
public PlaySpace(Chequer[][] chequerBoard)
{
setState(chequerBoard);
}
Set state method:
public void setState(Chequer[][] state)
{
Chequer[][] newBoard = new Chequer[8][8];
for(int i = 0; i < state.length; i++){
newBoard[i] = state[i];
}
chequerBoard = newBoard;
}
Creating a new game board & cloning the current state's values to it:
PlaySpace child = new PlaySpace(board.returnState());
child.setState(board.returnState());
child.moveChequer(move.returnCurrentX(),move.returnCurrentY(),move.returnDestX(),move.returnDestY());
Thank you very much in advance! Please let me know if I can give any more information.
Cheers, Louis