I was writing some Code in Unity, when i had a very strange phenomenon. The variable "newBoard", wich is declared in some code above byte[] newBoard
keeps its value after it is being changed in the code:
case "1001":
Debug.Log("white pawn");
// pawn
if (i >= 8 && i <= 15 && tiles[i+16] == "0000"&& tiles[i+8] == "0000") {
// make two steps if its a start pawn and then make him an en passant pawn
newBoard = null;
newBoard = movePiece (board, i , i+16);
newBoard = makeEnpassant (newBoard, i);
allBoards.Add(newBoard);
test = newBoard;
}
if (i < 56 && tiles[i+8] == "0000") {
// single steps
newBoard = null;
newBoard = movePiece (board, i, i+8);
allBoards.Add(newBoard);
if (test == newBoard) Debug.Log("test");
}
Assume that in my case both if statements are being met.
I added the
test = newBoard;
and
if (test == newBoard) Debug.Log("test");
are too see if it is actually the variable that keeps its value after i say newBoard = null;
I really dont know what could be my mistake here so i hope someone smarter than me can help me here.
Thank you!