I am coding chess, and have made a class called BoardObject to store board states, so I can have a list of them, making a history of the game. BoardObject has a field called boardValues, which is a 2D array which stores the values of each square on the board.
In my while loop where the game is played, if the user input passes my validity checks, the move they enter is passed into a method called movePieceTrad. During movePieceTrad, the list boardHistory is changed in some way to update with the move just made. Here's the problem: nowhere in movePieceTrad is boardHistory or any boardObject addressed. I have looked through with ctrl+f, every reference to boardHistory is in the main method.
In the code below, when I debug, lastInBoardHistory2 is different from what lastInBoardHistory1 was before movePieceTrad, but lastInBoardHistory1 also changes when I go through movePieceTrad, which makes no sense once again. What is going on?
lastInBoardHistory1 = boardHistory[boardHistory.Count - 1].getBoardValues();
movePieceTrad(arr[0], arr[1]);
lastInBoardHistory2 = boardHistory[boardHistory.Count - 1].getBoardValues();
Here is the code for the BoardObject class
namespace chess_v1
{
class BoardObject
{
private int[,] boardValues;
public int[,] possibleEnPassants;
public int[,] castlePiecesMoved;
public int turn = 0;
public BoardObject(int[,] squareValues, int[,] pep, int[,]castleInfo, int inputTurn)
{
boardValues = squareValues;
possibleEnPassants = pep;
castlePiecesMoved = castleInfo;
turn = inputTurn;
}
public int[,] getBoardValues()
{
return boardValues;
}
}
}