it is definitely a newbie question, but I couldn’t find an answer anywhere.
Can we modify game_state (or anything in gamelib folder) or such modifications will not work when algo will be run on server? In particular, I want to add a few functions in GameState, for more functionality.
I am coding in python.
Not only can you, but I would highly recommend it.
The algo is started by the run.sh, which creates a call to start your algo in a separate process (called by the C1 engine). This new process communicates with the engine using stdout/stdin, which is called by
sys.write, etc in python (different in other languages). This is why you cannot use
print and must use the
debug_write function to display data. If you use
print it thinks you are sending data to the engine, which is probably not what you want (will almost certainly crash your algo, resulting in an immediate loss).
The takeaway from this is that you can modify the code completely, the only requirement is that it communicates properly with the engine, which is why using the existing libraries can be helpful in facilitating that process.
In terms of the game_state, this means the “important” parts are
gamelib.GameState(self.config, round_state_str) where it converts the information from the engine and creates the
game_state object. Then, to communicate with the engine (write to stdout)
You can read more about how the engine and your algo communicate and how these classes work in a forum post I wrote a while back here.
You can also see a couple of examples where myself and another member wrote algos in a single line, so obviously not using any of the code from the starter kit as part of those algos. This was just for fun but demonstrates the concept that no “logic” is technically necessary, to talk with the engine, all you need to do is print to stdout.