Hi guys,
I am using triple nested dictionarys in order to store a large amount of data. the dictionary looks as follows:
(have used “(” instead of less than as less than doesn’t print here)
public Dictionary(string, Dictionary(int[,], Dictionary(Vector2,NestedWinInfo>>> condensedData;
so the keys are as follows:
string playerName;
int[,] boardData;
vector2 originAndTargetTilePositions;
the nestedwininfo contains 3 variables: #of times move has been made. #of times move won. %winrate.
I then try to condense data into this dictionary by going through the nested dictionaries, checking if the key in the current move data exists, if it doesn’t then it needs to be created.
it first checks to see if the player who made the move is registered as a key in the top level dictionary. Given that there is two players this will fire false twice and then true after. This works as expected.
However in the second level dictionary, it checks if the board data exists as a key, this is perpetually firing false regardless of if it should exist or not. I will assume the same problem is reiterating in the third level dictionary but I can sort that once I understand the problem.
my first thought is that the problem comes from the key being an int[,] (comparing 2 arrays that aren’t necessarily the same?) but i’m not sure.
I will try and provide relevant code snippets:
//foreach move data to save
foreach(MoveData MD in moveDataToSave){
#region if player key doesnt exist
//if the key doesn't already exist
if(!condensedData.ContainsKey(MD.playerMakingMove)){
//initialise board data dictionary
Dictionary <int[,], Dictionary<Vector2[],NestedWinInfo>> tempBoardData = new Dictionary<int[,], Dictionary<Vector2[], NestedWinInfo>>();
//initialise move data dictionary
Dictionary < Vector2[], NestedWinInfo> tempMoveData = new Dictionary<Vector2[], NestedWinInfo>();
//initialise move data vector2
Vector2[] moveTileData = new Vector2[2];
moveTileData[0] = MD.posOfOriginTile;
moveTileData[1] = MD.posOfTargetTile;
//create win info
NestedWinInfo wininfo = new NestedWinInfo();
//update the win info data
wininfo.updateMovesMade(MD.winningMove);
//add data to tempmovedata dictionary
tempMoveData.Add( moveTileData, wininfo);
//add temp move data to tempBoardData
tempBoardData.Add (MD.gameBoardData, tempMoveData);
//add tempboard data to condensed data
condensedData.Add (MD.playerMakingMove, tempBoardData);
}
#endregion
#region if player key does exist
else{
//get the "value" dictionary at the player key
Dictionary <int[,], Dictionary<Vector2[],NestedWinInfo>> tempBoardData = condensedData[MD.playerMakingMove];
#region if board data doesn't exist
//if board data key doesn't already exist
if(!tempBoardData.ContainsKey(MD.gameBoardData)){
//this for some reason always returns false
}
so you can see the first section, if the player hasn’t stored a move before this one then dictionaries are created and populated with the MD data before being stored in condensed data. If the player has already moved it essentially does the same process but checks one link lower in the chain until it finds a broken link, creates a new item with the appropriate data. But as I have commented above, the second link (and most likely the third as well) are always firing false. What am i missing here? Is it a really obvious brain fart or is there a deeper misunderstanding going on?
thanks in advance guys and gals!