Java - Changing GameState class

Hi,

I’m working in Java. Looking at the sample Bot, I need to change the ShipType enum (enhance the enums, not add new enums).

I see the enum is used in GameState. I assume we’d get an updated copy of GameState at the beginning of every turn. If this GameState is coming in from an external source, will it still have my changes?

Thanks!

from my understanding the Game State class is used in the extraction process where the data in the “state.json” is mapped to the relative member variables in the class in itself using the “Gson” library.

I’m guessing that for each variable in the Game State class Gson runs a search in the json data for a field that might match the identifier for this variable and this sadly might be a case sensitive search.

The moral of the story is that if you change that enum… Gson might fail to map the data correctly and your program might fail but don’t take my word for it there might be a way around it or most likely your program might not rely on this data to run successfully at all :grinning:

Personally, I use the standard set of GameState classes for reading the json file only. Once that object is populated from json, I copy all the relevant data into my own game state classes.

It probably sounds cumbersome, but in my experience it’s really not that bad and it affords you a lot more flexibility in how you store and manipulate the game state internally. You can also easily make changes to your internal game state representation without worrying that you would break the parsing of the json file.

Thanks Paradox and bgh,

So I tried enhancing my enum and setting it loose in a match. I probably should’ve done this 1st before creating this thread. Surprisingly, it worked. Even more surprising is I think I know why it worked.

My Bot gets the name of the enum as a String in sate.json, and Google’s Gson maps that String to the name of my enum on steroids. It doesn’t matter that I have extra data attached to the enum :+1::+1: