TBS Engine Tutorials

Started by
6 comments, last by RobAU78 18 years, 10 months ago
Hey everyone, Are there any online tutorials for creating turn-based strategy game engines? It seems like there's a qualitative difference between this type of game and typical action games, but I could be wrong. Thanks, Rob
Advertisement
Beyond TBS' lesser performance requirements, the actual approach isn't much different. You might want to look into some gui-making tutorials, as they tend to mirror TBS' needs [displaying information efficiently and handling user input].
Well, what's the easiest way to handle the turn increments themselves? Should there just be some kind of flag to tell when the turn is incremented, as opposed to the main game loop?

- Rob
Generally, the turn processing is triggered by some input [usually a player ending their turn]. In the process of turn processing, there's usually some sort of state variable that's changed to indicate that processing is going on and/or that it's someone else's turn. It depends greatly on how much processing is being done, how player communication is being done, how the rest of the engine is arranged... There's many ways to do it even then.
I'd like to have a multi-threaded system where each player has its own thread in which it makes decisions, then those decisions are executed when the user clicks on the "Next Turn" button. (Actually, something I could do is have all the players end their turns, but the turn doesn't increment until everyone is done.) Then the program goes through and updates all of the player's states (and thus the game state) based on the decisions they made in the last turn. The whole process obviously repeats until there's a winner. Granted this is just pseudocode, but do you find anything wrong here?

Thanks for your help so far. :)

- Rob
*shrug* Ask me once I've actually finished a game :]

Yeah, your trigger would just be some "is everyone done their turn?". You'd then reset the "done" flag for everyone, compute the turn results, send the turn results to the players, and finally message that it's a new turn. It's pretty straightforward.
For the system you stated I would recommend you have a counter that gets incremented each time a player says “hey, I’m done”. Then the game would periodically test to see if the counter has reached the number of players (this could be done when any player indicates an end of their turn).

If you instead make this over a network, then a likely way to implement this it to have the host computer check for a message from the other computers saying that they are done with their turn, and keep a tally of these computers (also store the decisions made by each computer for processing when all are done). When the last computer gives you the “yep, all done here” message you may then start processing the information.

If you chose to go with the hot-seat game using the all play then change state model, you would just increment a player counter (stating who’s turn it is) and when that reaches the max number of players you then would update the world and loop back to player 1.

These are by no means the only way to go about this, but I hope they at least give you some ideas.


Thanks, guys, for your responses.

Right now my game is only single-player. The AI player threads will increment a counter right before they finish executing. There's also a nextTurn flag which is set to "true" once all the AI players finish their turns and the human player clicks on the "Next Turn" button. In the main game loop, the update() function is called only when nextTurn equals "true". Once update() is called, nextTurn is set to "false".

What do y'all think?

- Rob

This topic is closed to new replies.

Advertisement