Skip to content Skip to sidebar Skip to footer

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:

  1. add new key-value pair to transpositionTable
  2. play next move
  3. save transpositionTable to 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"