I’d like to write an application, which would imitate a player in an online game.
About the game: it is a strategy, where you can:
- train your army (you have to have enough resources, then click on a unit, click train)
- build buildings (mines, armories, houses,…)
- attack enemies (select a unit, select an enemy, click attack)
- transport resources between buildings
- make researches (economics, military, technologic,…)
This is a simplified list and is just an example. Main thing is, that you have to do a lot of clicking, if you want to advance…
I allready have the ‘navigational’ part of the application (I used Watin library – http://watin.sourceforge.net/). That means, that I can use high level objects and manipulate them, for example:
Soldiers soldiers = Navigator.GetAllSoldiers();
soldiers.Move(someLocation);
Now I’d like to take the next step – write a kind of AI, which would simulate my gaming style. For this I have two ideas (and I don’t like either of them):
- login to the game and then follow a bunch of if statements in a loop (check if someone is attacking me, check if I can build something, check if I can attack somebody, loop)
- design a kind of scripting language and write a compiler for it. This way I could write simple scripts and run them (Login(); CheckForAnAttack(); BuildSomething(); …)
Any other ideas?
PS: some might take this as cheating and it probably is, but I look on this as a learning project and it will never be published or reselled.
A bunch of if statements is the best option if the strategy is not too complicated. However, this solution does not scale very well.
Making a scripting language (or, domain specific language as one would call that nowadays) does not buy you much. You are not going to have other people create AI agents are you? You can better use your programming language for that.
If the strategy gets more involved, you may want to look at Bayesian Belief Networks or Decision Graphs. These are good at looking for the best action in an uncertain environment in a structured and explicit way. If you google on these terms you’ll find plenty of information and libraries to use.