Advertisement

decisions in simple strategy game

Started by April 08, 2011 01:52 AM
3 comments, last by frederiksen 13 years, 10 months ago
Hi,
i've started making a very simple game and i'm trying to implement some kind of ai. The ai has only a few possible options, attack, move armies from one planet to another,build or wait and can only do one thing at a time. link (as i said i only started but i think you can see what would be needed). As i have never done something like this before i wanted to know how you would go about this. Right now i'm trying to calculate the threat level for each planet, to see if any need reinforcement, look for the best planet to attack, if nothing is really urgent wait/built. At least that's the plan but one of the biggest problems i have is turning my data into something the computer can choose from. I know that's a stupid question but how do i "normalize" something like that?
Sounds like you're on the right track :)

As you note, the real trick here is normalizing your input values to get them into some kind of range that you can reason with. This might be [0, 1] or [0, 100) or any other number of intervals depending on how your mechanics work, what kinds of filtering you need to do, possible weighting/combination of considerations, etc. etc.

The best place to start I guess is to get a solid list of what factors the AI wants to think about. What kinds of game situations might it want to take into account? What sort of qualitative aspects are involved in things that might need to be quantified? If you can break down the mechanics of your game design for us, we can probably give you some direct tips on how to handle various aspects of quantification.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Advertisement
thanks, the main thing i'm trying to do now is having the computer decide where to expand to, if to attack or if it should send armies from one planet to another. The armies grow automatically, building things just takes time, so no economy. I'm thinking of just giving it to them randomly or something, at least i'm keeping the problem for later.

The computer player like the player can see everything that is happening. Right now i go through every planet a computer player has and get how many spaceships are in the neighbouring planets and to whom the planet belongs to.
If it's another player the threat level for the planet rises(i.e. threat+=(amount of spaceships in enemy planet+somevalue*total size of enemy),
if it's neutral, it's a planet you would more likely want to attack, depending on how many spaceships there are.

So than i want the computer to decide if it either attacks another planet or reinforces a planet with spaceships from a neighbouring planet with a lesser threat level (or reinforce a planet with low threat level but a good planet to attack if it had more spaceships.)
//Later there will be other factors like defense of the planet, production of a planet, max size of army of the planet, etc.

Now it basically boils down to: own_planet_threat_level = (neighbouring spaceships)/spaceships of that planet;
not_own_neighbouring_planets = spaceships of neighbouring planet*(x<1.0 if its neutral) / spaceships of that planet;
Finding the "best" planet to attack or the planet with the highest threat level even i can do, but how do i compare those two values. I know this is trivial for most of you but i'm just not sure how to go from there.
Well, this is where AI design gets into more of an art than a science, so I wouldn't feel bad about being stuck here :)

The typical approach is to think in terms of win conditions and how likely a given action is to promote the win condition. I don't know how your game rules work as far as victory/loss goes, so it's hard to say for sure what a good technique would be. Basically though you just need some kind of formula that maps both the "attack" and "defense" scores onto another normalized scale, such as [0, 1]. Once those two values are on the same scale, you can easily do a greater-than check to select which move is more useful.

This can get tricky, though, because the utility of making a given move may not be limited to a single turn of scope. For instance, you might want to make a defensive move to shore up a weak planet even several turns before it's under attack. Or you may want to make a preemptive strike on a target planet to weaken it in advance of a more powerful force to finish it off. These kinds of things fall into the category of planning and generally will comprise the strategic level of your AI.

For simplicity's sake, I'd suggest starting with a one-turn lookahead AI and then expanding on that once you see it in action and know where its strengths and weaknesses are. To do that, all you really need is to come up with a way to decide whether to attack or defend on a given turn based on the immediate situation. That just requires, again, normalizing your two attack/defense numbers onto a single range.


After a few games worth of experience, you'll develop a bit of instinct for how to create those mappings, or at least get something rough down to experiment with. But in the absence of that gut feeling, the best you can do is to try and look at the empirical numbers and work out a formula by hand. (This is actually something we have to do fairly routinely in major AI work anyways, even with a little bit of hints/guidance from instinct and experience.) I would suggest a setup like the following:

- Build a debug mode for your AI that shows the attack and defense scores for each potential move, along with the chosen attack and defend moves
- Give the developer/designer (i.e. you) a button to tell the AI to attack or defend in a given round
- Record three data points every turn: the attack score, the defend score, and whether you chose to attack or defend
- After several games worth of doing this, graph the data points and look for patterns

Specifically, you want to plot the ratio between the attack and defense scores, against whether an attack or defense move was selected. This should visually highlight the slope of the curve that maps each score onto the final, normalized range. By plotting a line of best fit through this data (using Excel or whatever) you should be able to get the exact coefficients needed to translate the two scores. Some experimentation may be in order to find a really good result.


Some exercises for future work:

- Think about a nonlinear mapping between attack and defense scores. For instance, what if you square one score post-normalization to the [0, 1] interval? This will proportionally decrease the attractiveness of that option along an interesting curve, making the AI correspondingly more reckless or more conservative. Experiment with different functions and interpolations, such as a logistic (S-curve) interpolation instead of linear, and so on. Most of this will require actually feeding the formula into the game and watching the outcome.

- Look into scoring moves based on more than one turn of lookahead. There are any number of options for how to do this, but I won't spoil the challenge by giving you examples; see what you can come up with.

- Consider doing something more goal-oriented than just selecting the highest-scoring move every turn. For instance, think about how you would build it tactics like hit-and-fade, or honeypots, or luring the enemy into a trap, and so forth. Make your gameplay about accomplishing various goals (conquer this group of planets, etc.) instead of just always trying to hit the win condition.

- Use some random fuzziness to select good-but-not-optimal moves. For instance, suppose you score attacking at 0.94 and defending at 0.93. Instead of always blindly choosing to attack, you could add some "personality" or "flaws" to the AI by selecting the less optimal (but still perfectly valid) decision.


Best of luck, and let us know how it goes! :)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

tldr; can't you just give me some code?
And now seriously: can't thank you enough for that post. It helped a lot. (You even gave me new ideas for gameplay)
I kinda love the idea of graphing the ai/player decisions, it's simple but makes so much sense. With this method i can see getting to some kind of reasonable normalization/mapping. And just to hear that more experienced programmers have some of the same problems helps ;). A lot to think about, now i'm just glad that the game has so few possible actions that i can still see the light at the end of the tunnel and gain some experience instead of just giving up.

This topic is closed to new replies.

Advertisement