I'm making a game played on a GameBoard (like 3 in a row).
I save the gameboard in a int [2]
and like to define the method Move.
In this method, with input which player (1 or 2), row, column and the previous board (Previous), we return a new board (Next).
However, the problem is that after running this method, the object Previous changes with it and this is not my intention. Can someone help me?
public class GameBoard {
public int [] [] board;
public GameBoard(GameBoard G) {
this.Board=G.Board;
}
public static GameBoard Move(int player,int row, int column, GameBoard Previous) {
GameBoard Next = new GameBoard(Previous);
if (player==1) {
Next.setBoard(row,column,-1); ();}
if (player==2) {
Next.setBoard(row,column,1);}
return Next;
}
}