Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Enemy AI help and suggestions?

Author
Message
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 3rd Oct 2013 02:47
Ok, I'm at the point now where I need some help with AI.

My game is a turn based civ style game, and I thought the AI might be pretty easy for this....however upon reflection, and taking simple pathmapping out of the equation, I think it might actually be harder than a platformer or shooter for numbers of reasons.

So, I've done a bit of thinking and considered this system:
Each CPU "player" can have up to a set number of "goals" (I'm thinking five), and a set number of steps to achieve each (again, thinking five, maybe up to ten for complex moves - this number is largely not important). So, if for example a CPU player decided to attack a city, the goal would be "attack city X", and the steps along the lines of "1)identify/build units to attack with. 2)move units to target. 3)attack city". A more complex set to attack a different island could be "1)identify/builds units to attack with. 2)identify/build transport ships. 3)set rally point for ships and units and move all to there. 4)board units onto ships. 5)move ships to target city. 6)disembark attacking units. 7)attack city".

I've decided one route is to assign a score to each goal, the value of which will correlate to the importance of the goal - this allows me to sort them and stop constant competition for the same thing (say goal one wanted to build soldiers, but goal two wanted to build a city hall - goal 1 would get priority) and also set requirements for the AI changing the goals, one idea being the new goal must be at least 50% higher in value than the current one to make swapping worth while. In the examples above, this value could increase at each step so that once the CPU is "commited" to the attack, only major disasters will see it abandon it. This will allow me to "hardcode" the steps to a huge degree and I suspect it's the quickest (running) and easiest way to do it.

Baring in mind it's turn based, and the entire AI thought process must be saveable with the game, has anyone any better thoughts on this? I've never tried AI outwith pathmapping etc so any experience would help. The above is kind of working with simple combat only units who only need to decide where/when to attack, but for more complex decisions I'm not sure.

Thoughts?
JohnnyMeek
11
Years of Service
User Offline
Joined: 23rd Apr 2013
Location: Slovenia
Posted: 3rd Oct 2013 11:39
Have you checked out MiniMax?

I just implemented it for a turn based board/strategy game and it works very well.

http://en.wikipedia.org/wiki/Minimax
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Oct 2013 12:15 Edited at: 3rd Oct 2013 12:16
Perhaps some chess techniques would be a good start.

You mention assigning each move a score, but I don't think that would provide a convincing opponent. What I would suggest, is making a system that gives the current state a score, like - give each unit type a value, like 2 for a soldier, 5 for a tank, 10 for a bomber plane etc etc. Now, for each unit, you'd check if it's under threat, then decrease it's value, if it's threatening an enemy unit, then increase it's value. So, at any point - you'd have a score for each player, which basically determines who is winning, but in chess AI this is very important.

If you can determine a score for each player, for the current state of play, then you can simply test each possible move and keep a record of that move, and the score. Maybe you'd need a macro language to do it neatly, like to hold the info for the move. Anyway, say you make a list of every possible move, calculate each moves resulting score, then repeat that, adding the most obvious opponent move, then repeat, repeat, repeat. Your still selecting a move from that original list - but all the time you'd look for the best possible move - the move that results in the best score in the long run. If you have a powerful unit, maybe it's value is 10 times what other units have, well the AI would automatically try and get rid of that unit, because it would have the biggest impact on the players score. If 4 moves ahead, the AI can possibly get rid of that unit, then it will. It'll also defend and attack sensibly... looking for the best defensive positions, pieces would move out of harms way if they can, units would even sacrifice themselves if it benefits the cause.

This is a very mechanical and precise way to calculate AI, you might actually have to add in some randomness (even add a random value to the move score to mix it up a bit).

I guess my point is that AI isn't too scary when you consider that it could just be a sum, based on the units in play and how much of a threat they are, or are under. A game like Civ at least allows a grid style and turn based movement, really I think the old chess brute force approach would work pretty well and you'd get results fairly quickly, maybe start with just calculating the first move - that would at least get the enemy AI going, and make the project much more interesting to work on.

I am the one who knocks...
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 3rd Oct 2013 15:52
Johnny, that's gonna take some serious sit down and read time, but it does look really useful, I'll check that out in depth. You sasay your game was a turn based one, as in one on one? Not sure how this would work for my game, where ten civs are playing against each other, and have to consider both offensive and defensive?? Do you have a link to your game so I can see it in action?

Van, your chess idea is a good one, and I can play so I follow it (I think), so that I can look at for combat. My hope is, it will work like civ until you start a fight, then instead of just a stats decision to make some form of mini turn based combat game... To make player strategy more important. That would work there, but again in the main campaign I'm not sure how to fit it in. One big issue is its not really turn based, it's a mix of turn and realise, so I don't really have the ability to stop and "think" for long periods. One thing that annoyed me about civ 5,is even on my 2.6ghz quad core in the later stages a single go could take over a minute..... And I'm aiming for tablets in tier 1. How ow is this kind of method, baring in mind each nation would need to consider moves against up to 9 others, as well as random rogue units?
JohnnyMeek
11
Years of Service
User Offline
Joined: 23rd Apr 2013
Location: Slovenia
Posted: 3rd Oct 2013 16:52
MiniMax is the same principal used for chess etc.

My game is currently up to 4 players, it just means you have to score every opponent's move, rather than just 1.

If I break down the principal into it's simplest form, it would be:

Score a player move
then score every potential opponent move

get highest opponent score and subtract this from the player score for this move.

repeat this for all possible moves.

The highest player score is the best move.

I'm a few weeks away from finishing my game so I don't have a link yet.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Oct 2013 18:01
I was wondering if it would be easier to score the map locations rather than the units. Like, if a map location has a players unit, that players score for that location is set to whatever that unit's strength is. Then, you'd have the map locations set a score depending on the units nearby, or units that can attack that location.

I think that might be a better approach, as say you have 10 battleships, and 10 bi-planes. Well, the battleships would be several magnitudes more powerful, but far less mobile, far slower. Now, in a chess style calculation the battleships would far outweigh the biplanes. But - if you look at the actual process of a war, well the battleships might not be very effective. Especially if they are in the sea, and most of the battle is on land. It would be more accurate to go by map locations occupancy, and threat from other players.

That might even allow for more dynamic moves - like moving to cover more ground, defend, that sort of thing.

I am the one who knocks...
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 3rd Oct 2013 18:10
Hi Santman,

you might find these CIV-III articles useful. They are written from a players point of view to maximize ones chance at winning, but can be helpful in designing or thinking about AI-routines.

Also, it might be useful to have a look at the code from the FreeCIV-project.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 3rd Oct 2013 18:22
You mean like an influence map? I already have one built which allows the cpu to decide on good city locations etc, so that could be pretty easily adapted. That might work quite well actually, I'm Def gonna have a play around with that idea. If I combined the two, used the land value from the influence map, then deduct the strength values of nearby enemy units, that would pretty much be the process of deciding where to attack too, in the sense of taking over a city..... The one with the value greatest when compared to the risk. Excellent thoughts, many thanks.

Zero town, thanks for the links too. I've seen free civ on the market, but admit I've never played it. I'll check it out later...... Don't want to end up cloning it because it's in my mind. Lol. Def will be checking out the links though.... A night of reading ahead for me.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Oct 2013 18:32
Yeah, sounds like your geared up for that stuff. It probably won't take much to get some really cool things happening with the AI.

I am the one who knocks...
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 3rd Oct 2013 19:10
A good MiniMax search takes a LOT of CPU punch. It's really best for zero-sum games like chess. It's also 100% predictive, so all AIs just using that will behave exactly the same - which can be boring. Some AIs could be more defensive-minded and others more attacking.

Small tactical grids can be quick and easy - how much damage can I impose in this (say) 8x8 zone? How much damage will I take? You can sum these for a wider area, and adjust the values for strategy. It's also possible then only to calculate change for small regions rather than iterating the entire map.

-- Jim - When is there going to be a release?

Login to post a reply

Server time is: 2024-05-07 10:50:32
Your offset time is: 2024-05-07 10:50:32