views:

133

answers:

5

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.

+1  A: 

Sounds like you want a finite state machine. I've used them to various degrees of success in coding bots. Depending on the game you're botting you could be better off coding an AI that learns, but it sounds like yours is simple enough not to need that complexity.
Don't make a new language, just make a library of functions you can call from your state machine.

Jean-Bernard Pellerin
+3  A: 

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.

Emile
+1  A: 

First of all I must point out that this project(which only serves educational purposes), is too large for a single person to complete within a reasonable amount of time. But if you want the AI to imitate your personal playing style, another alternative that comes to mind are neural networks: You play the game a lot(really a lot) and record all moves you make and feed that data to such a network, and if all goes well, the AI should play roughly the same as you do. But I'm afraid this is just a third idea you won't like, because it would take a tremendeous amount of time to get it perfect.

JBSnorro
Sheesh... a neural network is certainly not the *only* way to accomplish this goal. It is not as easy as you think it is to build or train a NN.
Shaggy Frog
+1  A: 

Most strategy game AIs use a "hierarchical" approach, much in the same way you've already described: define relatively separate domains of action (i.e. deciding what to research is mostly independent from pathfinding), and then create an AI layer to handle just that domain. Then have a "top-level" AI layer that directs the intermediate layers to perform tasks.

How each of those intermediate layers work (and how your "general" layer works) can each determined separately. You might come up with something rather rigid and straightforward for the "What To Research" layer (based on your preferences), but you may need a more complicated approach for the "General" layer (which is likely directing and responding to inputs of the other layers).

Shaggy Frog
+1  A: 

Do you have the sourcecode behind the game? If not, it's going to be kind of hard tracing the positions of each CPU you're (your computer in your case) is battling against. You'll have to develop some sort of plugin that can do it because from the sound of it, you're dealing with some sort of RTS of some sort; That requires the evaluation of a lot of different position scenarios between a lot of different CPUs.

If you want to simulate your movements, you could trace your mouse using some WinAPI quite easily. You can also record your screen as you play (which probably won't help much, but might be of assistance if you're determined enough.).

To be brutally honest, what you're trying to do is damn near impossible for the type of game you're playing with. You didn't seem to think this through yet. Programming is a useful skill, but it's not magic.

Check out some stuff (if you can find any) on MIT Battlecode. It might be up your alley in terms of programming for this sort of thing.

Mr_Spock
Programming can be magic if you do it wrong!
fredley
haha... Touché!
Mr_Spock