I want to hack together a roguelike. Now I thought about entity and world representation and got to a quite big problem.

If you want all the AI to act simultaneously you would normally(in cellular automa for examble) just copy the cell buffer and let all action of indiviual cells depend on the copy. Actions which are not valid anymore after some cell before the cell you are currently operating on changed the original enviourment(blocking the path) are just ignored or reapplied with the "current"(between turns) environment. After all cells have acted you copy the current map to the buffer again.

Now for an environment with complex AI and big(datawise) entities the copying would take too long. So I thought you could put every action and entity makes into a que(make no changes to the environment) and execute the whole que after everyone took their move. Every interaction on this que are realy interacting entities, so if a entity tries to attack another entity it sends a message to it, the consequences of the attack would be visible next turn, either by just examining the entity or asking the entity for data. This would remove problems like what happens if an entity dies middle in the cue but got actions or is messaged later on(all messages would go to null, and the messages from the entity would either just be sent or deleted(haven't decided yet)

But what would happen if a monster spawns a fireball which by itself tracks the player(in the same turn). Should I add the fireball to the enviourment beforehand, so make a change to the environment before executing the action list or just add the ball to the "need updated" list as a special case so it doesn't exist in the environment and still operates on it, spawing after evaluating the action list?

Are there any solutions or papers on this subject which I can take a look at?

EDIT: I don't need information on writing a roguelike I need information on turn based ai in respective to a complex enviourment.

  • 2
    \$\begingroup\$ You should really attempt to clarify your question. Your title is kind of an oxymoron isn't it? \$\endgroup\$
    – House
    Apr 19, 2012 at 18:54
  • \$\begingroup\$ I will updated the question to be a bit more understandable, but the title isn't oxymoron(real time games are turn based games, with a high turn per secound rate) \$\endgroup\$ Apr 19, 2012 at 18:57
  • \$\begingroup\$ There's a ton of roguelike source code available to study. \$\endgroup\$ Apr 19, 2012 at 18:58
  • \$\begingroup\$ Check out Brogue comes with source code and is a fun game :) \$\endgroup\$
    – House
    Apr 19, 2012 at 19:08

1 Answer 1


One game I remember dealt with the problem in a similar fashion of what you described:

  • Each agent had a "preferred" action (if a player was controlling it, the action the player chose) and a list of alternative actions in descending order or priority (automated but configurable);
  • The choice of the next action, when applicable, would be constrained by the current state only;
  • After all agents made their choice, the game would sort them in "speed" order, to determine who would act first;
  • The first one would then act, and the consequences would apply immediatly;
  • When it's time for the next one to act, the preferred action would check if it's preconditions still hold and, if not, would move to the next action in the priority list; if there is no action with valid preconditions, the agent skips its turn;
  • Repeat until all agents acted or skipped, then begin next turn.

One thing interesting to note is that agents might be added or removed from the list mid-turn: for instance, if a character that still hasn't acted died, but before its time to act another one had "revive any dead character in my party" as its preferred action, that action would execute and the once-dead character would still be able to perform normally in the same turn. In your example, you could treat the fireball as just another agent, and add it to the list when the monster would normally act (after checking the corresponding preconditions: monster is alive, monster has mana, monster is not silenced/paralyzed, etc).

Likewise, some actions would have "character alive" as a precondition, while others would not: for instance, a physical attack on multiple enemies would be interrupted if one of them retaliates and kill the agent before all targets are affected; a magic attack that is supposed to happen simultaneously (a thunderstorm for instance) would continue to affect other enemies even if one of them reflected it and killed the caster mid-action. So, even though the action was split in multiple steps (attack one, attack other, etc) by the implementation, the resulting effect would be that of a simultaneous event.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .