I currently tend to implement behaviours like this: C.behaviour = { start: "whiteflag", whiteflag: ["economy", "attack", "defense", "victory"], economy: ["populate", "gather", "hunt", "expand", "research", "fortify", "mobilize", "defense", "victory"], mobilize: ["parade", "analyze"], attack: [...], defense: [...], victory: [], };The AI initializes on the start frame and on each call it checks the frames listed for their entry conditions. If at least one frame qualifies the AI switches to this new frame. The frames also have exit conditions, which let it fall back to the calling frame. So, for example if economy has an entry conditions like canTrain it directly changes on startup, the exit conditions are e.g. noPopulation && noBuilding. If the enemy destroys all, the AI falls back to whiteflag and the game is over. Or there is nothing left to fight and the AI enters victory. Some frames have tasks listed having no behaviour entry, e.g. fortify, these just get executed. The idea is each difficulty has its own behaviour with certain features. That way the AI does what it does in a convincing way. Maybe on an easy level the AI doesn't build towers, but on a hard level I don't want the towers placed in a random fashion.