Game turn Loop
So, after a bit of reflection today, i decided on the initial draft of the game loop (ie: what happens on every turn of the arena match), so here is what i have thought of so far:
- The timeline is discreet, ie: the player units and AI see the world in steps (read: turns). They examine the game world every turn and then act upon their AI and code. I figure this way, it would be easier to implement such things as speed (allowing each bot to move a certain distance during each turn) and also be easier to implement code wise. I also think that if the timeline steps, or turns, are small enough, then the arena will seem to unfold in close to real time, and not so jerky
- When the bots submit their actions, they do so in an ordered queue (so say, moving to point A and then shooting, is not the same as shooting and THEN moving to point A). However, some actions might not be exclusive, and maybe we can provide a way for them to be grouped together into more complex actions (such as moving AND firing at the same time, or harvesting resources AND shooting one of the guns)
- In any case, I guess the main event loop will be something like:
- Units get their Unit::think() called every turn, and then they return an array of actions to be done in an ordered queue
- Actions are then passed to a Referee Engine, which disqualifies illegal actions (moving too much, shooting many times, etc)
- Legal actions are then applied (units moved, shots fired, health decresed, etc) using the referee engine, with the physics engine verifying outcome (colliding units stopped, hit units shaken or moved by impact, etc)
- A script is generated of what happened in the turn detailing all the actions and events
- The turn script is sent to the Gfx & sound engines to produce output to user
- The script generated should be complete enough to allow it to be some sort of recording mechanism, allowing the user to break down the work, which might allow later a dedicated AI server, where players can upload their AI teams and just download the script then and allow match servers to only focus on the AI part, with the competitors able to download the results and playback of their matches to examine how their AI behaved, ie:
- The engine can run in AI-only mode, only producing a script of the match, without any visualisation of the game itself
- The engine can run in Playback-Only mode, where the input is a match script, and the engine just renders the match script as it unfolds to the player
- The engine can run in Live mode, where the complete process is implemented as mentioned above, with the script being updated every turn and the results presented to the user “on-air”
That is all for now, keep you updated as usual
Advertisement
