Version 2 (modified by 10 years ago) ( diff ) | ,
---|
Hannibal
Intro
The Hannibal AI/Bot is a new approach to reduce the complexity of programming a bot for 0 A.D. It was started in February 2014 by agentx. This page will document the development process and parts of the source, explains major concepts and provides tips & tricks. The forum has already a few posts discussing the bot's features. Little Query Language, AI Tournaments
In particular the bot will use:
- a state machine to handle game phases
like village, town, city, attack, defense, reconstruction, etc.
- a triple store to link features of the cultures
like who can gather fields, can a healer melee?
- a simple query language to retrieve information from the triple store
"food.grain GATHEREDBY WITH costs.metal = 0, costs.stone = 0, costs.wood = 0 SORT < costs.food"
- a plugin system describing behavior of groups of units
(grain-picker, hunter, warrior, miner, etc)
- a domain specific language used for the plugins
to allow non programmer to define a group's behavior
State Machine
The state machines relies on clearly distinguishable states. They are connected and have entry and exit conditions. The game starts in the whiteflag state, which it tries to exit. If that is not possible the game is either lost or the map is unplayable.
example code
states: { "ai:ai": { entry: "whiteflag", whiteflag: ["village"], village: ["populate", "town", "victory"], town: ["expand", "defense", "city", "victory"], city: ["attack", "defense", "attack", "victory"], victory: [], }, "ai:ai:1": { village: ["populate", "technology", "town", "victory"], } }
If the village state's entry conditions like enough resources are met the machine switches and processes all states or sub states mentioned in the list. Victor is checked every turn, to make sure that doesn't happen unrecognized :) "ai:ai:1" indicates a state set for a higher difficulty and basically overwrites the lower ones (adding technology) if chosen by the user. This hierarchy allows easy editing and provides fine tuned set of game difficulties. The states are defined in config.js and the function getBehaviour() applies the difficulty.
Triple Store
Query Language
Plugins
Domain Specific Language
Scratchpad
(just a section for thoughts and experiments)
Attachments (3)
- 0 A.D. Language(1).png (49.8 KB ) - added by 10 years ago.
- hcq.png (49.8 KB ) - added by 10 years ago.
- hcq.jpg (49.3 KB ) - added by 10 years ago.
Download all attachments as: .zip