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.

Newcomers DBPro Corner / Simple AI decision making

Author
Message
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Oct 2011 18:06
I was trying to work out a few ways of making AI - in a simple text based game - make a decision about what to do next.
Its options would be based on 3 different tactics and it would increase the % of what decision it made based on what tactic it employs.
The tactics in my little text based demo are simple.
1 = Aggressive (will send troops out often and use more money to buy troops rather than defence)
2 = Balanced
3 = Defensive (spends more on defence and keeps most of the troops at home in case of attack)

(There is no user input its just watching 5 factions fight each other to see what they will do and who lasts)

So every cycle of the Do loop its thinking about what to do next based on what tactic it was assigned at the beginning. "Should i spend more money on troops, buy more defence or something in the middle.", "Should i attack something now or wait."

Of course i dont want it making hundreds of decisions a second so it has to be realistically slowed down and i just cant think of how to do any of this based around a counter. I came up with a few ideas but i could only say them and not actually write them down let alone code them as i dont know where to begin.
So i suppose i need algorithms perhaps for making it increase the percentage that it will do something on each turn till it gets to the point where it decides to make that decision. And have it based on a priority system on what it wants to do (defend more, attack more etc).

Anyone got any good guides to read for making simple AI. I really cant handle AI books at the moment or tutorials that are talking about making stuff walk around and more complex 3d decision making so i want to avoid most of the tutorials i know are out there, they start off too complex. I just need a theory to go off. Something very simple that i can build on.
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 6th Oct 2011 12:09
This is just something simple I concocted to point you in the right direction. Implementation will require some understanding first. The best way to think about AI is to think of it in terms of CONDITIONS. Using numbers and ranges is obviously the best way to approach this. Below is my example. I really hope it works and that it is easy to understand. Simply copy and paste it to your editor and run.



<a href="http://roundphoenix.wordpress.com">Round Phoenix Software Studios</a>
No matter how much you know, you'll always have far more left to learn... (My head hurts)
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 6th Oct 2011 13:06
Thank you very much for taking the time to code that example. It runs well. I am just picking through it trying to get which peices i understand as a few things are difficult for me to follow down to my experience with coding so far, but it certainly has pointed me in the right direction. Particularly the turn based (or time based) decision making which i think i can incorporate into my little demo.
If anyone has any other ideas/simple examples i would love to see them as i am very interested in this subject at the moment for making my demo work.

Once again nonZero, thank you.
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 6th Oct 2011 21:23
No problem at all. And good luck with your game.

Da_Rhyno
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 6th Oct 2011 21:33
Quote: "In fact a senior member will no doubt find over 9000 oversights in my code."


Vegeta! What does your scouter say about his oversights level?

It's over... NINE-THOUSAAAAAAAAAAAAAAND!

NINE-THOUSAND!? There's no way that can be right!
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 8th Oct 2011 23:19
Quote: "Vegeta! What does your scouter say about his oversights level?

It's over... NINE-THOUSAAAAAAAAAAAAAAND!"


I thought this too

I think i have a nice simple decision maker based on percent. If the logic is wrong can someone point it out because ive not had time to test this yet and it may be flawed.

A) I have a decision counter that is a random number between say 2 seconds and 5 seconds (so every 2-5 seconds it will make a decision).
Once its made a decision this is reset for that particular faction.

B) So now its time for that faction to make a decision. There are only 5 states it can be in (or 5 decisions it can pick).
1) Build a tower (for defence)
2) Build a knight (for attack)
3) Repair a damaged turrent (based on an if statement for if a turret is damaged otherwise it can only pick 4 options)
4) Attack another faction
5) Do nothing (possibly the most common so it is not always constantly battering out commands)

C) For it to pick one it rolls a random number between 1 - 100.

D) Depending on its tactic the number it lands on is ranged for a decision. For example a defensive tactic will not attack as much as repairing turrets and building them.

Defensive Tactics
1 - 20 = Build turret (this should be a 20% chance of happening)
21 - 30 = Build knight (this is a 10% chance of happening)
31 - 35 = Attack a faction (5% chance)
36 - 90 = Do nothing (most chance of happening)
If turret is damaged
91 - 100 = Repair turret otherwise 36 - 100 Do nothing.

Versus an Agressive AI tactics
1 - 5 = Build Turret
6 - 30 = Build Knight
31 - 45 = Attack a faction

etc etc

Does this make sense. Im sure this would technically allow me to control things based on percent chance of it happening.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 9th Oct 2011 00:35 Edited at: 9th Oct 2011 00:36
@ Somarl, that's making pretty good sense to me. I have two tips to give.

1: When randomizing 1-100 you'll need to do this RND(99)+1 because rnd(99) returns 0-99. By adding 1 outside of the random functions makes it's range 1-100.

2: You don't have to limit your range from 1-100, you could take it higher if you add more options etc. If you need the equivalent of fractional percentages e.g 1.5% then take it up a notch such as 1-1000.

Quote: "In fact a senior member will no doubt find over 9000 oversights in my code."

Where do I even begin? *grumpy mumble*Randomize Timer() inside the do loop? *more grumpy mumbling* no sync? *8998 grumpy mumbles later* not using char(0) at all? What kind of code is this?! Over 9000 power lev...er I mean inconsistencies?

I'm just kidding nonZero, it's pretty good code.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 9th Oct 2011 02:25
Thanks for the tips hodgey. I got number 1 a while back and it took me ages to figure out what was going on. Another one that stumped me was randomising between a range of numbers like 30 to 100, its so simple it made me feel very daft when i got it worked out

As for tip 2, i was thinking about how i might do something a little more specific, thats a good tip.

Oh and i noticed the randomize timer inside the do loop and just presumed it was to make it even more random seeming perhaps? As it runs the rnd off a different seed each time, but on the other hand i couldnt think why that would matter so still just put mine near the top of the code but i guess either way works right?

Now if i can just get a text based real time combat system off the ground my demo will be damn near complete
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 9th Oct 2011 02:50
Quote: "I got number 1 a while back"

I thought you might have, you're a smart person Somarl.

Quote: "Oh and i noticed the randomize timer inside the do loop and just presumed it was to make it even more random seeming perhaps?"

From an end user's perspective I don't think that they'd be able to tell (well not in this case anyway). I just mentioned it because I've been designing and programming games for netbooks and mobile devices (with AGK) lately where you always need to think about optimisation. Having RANDOMIZE TIMER() inside the do-loop is two extra function calls each loop. So if performance is a problem then I'd take it out but if not, you can leave it in because it'll give you the most 'random' numbers.

Quote: "Now if i can just get a text based real time combat system off the ground my demo will be damn near complete "

I'll keep an eye on the WIP board.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 9th Oct 2011 03:08
Quote: "I'll keep an eye on the WIP board. "

Lol it wont be good enough to grace the halls of the WIP board. Its not even a game. Just wanted to test some really simple AI and see if i can make something make decisions based on a simple personality.
The end goal of course is to add more and more to it to see if it remains fun to watch and relitivly balanced, then the main goal is to introduce an overseeing AI that makes sure nothing gets too out of hand, like if one of the AI's seem to be unbeatable for too long it will make it suffer some fate that will set it back a little and give the others a chance to catch up. If i can do all that id like to take it to a much larger game world and have a perpetual RPG FPS style world where the factions spawned would all just 'get on with it' and leave the player to make their own choices, but no one faction would just sweep all the rest out and reign supreme for more than a short while, just to keep the world sort of constantly moving about. Is hard to explain but for now, im just taking it all one very small step at a time.

Though i would like to make a slightly more graphical version of what i am building in the not to distant future but ill come to that when i am satisfied with the text version
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 9th Oct 2011 14:31
Well, good luck Somarl!

Login to post a reply

Server time is: 2024-11-22 11:59:45
Your offset time is: 2024-11-22 11:59:45