Saving Data Internally In Android Messes Up My Data
I'm currently working on a game, where I need to create a transposition table for my AI. I implemented Hashtable so that the key to the Hashtable is a state under consideration and
Solution 1:
My serializing and hashing was completely fine. My program went something like this:
- add new key-value pair to
transpositionTable - play next move
- save
transpositionTableto internal storage
However, after meticulous logging, I found that my transpositionTable changed after step 2). This was because during step 1), I used
BoardState newKey = currentData.getBoardState();
and saved it to my transpositionTable. Then in step 2), when my currentData changed, my transpositionTable changed accordingly. I tried using
BoardState newKey = currentData.getBoardState().clone();
but that didn't work either. Finally I had to assign each field of currentData.getBoardState() to newKey manually, which worked.
Post a Comment for "Saving Data Internally In Android Messes Up My Data"