Hi.
My project is using some AI. What mine does is rolls a 1d100, then it
has for each type of opponent sections of that 1 to 100 that tells it to
do certain things. like, if it's less than 15 scan, if it's between 15
and 30 fire this, greater than 30 less than 80 approach, etc etc. The AI
has around 200 chances per try to come up with something that it can do,
but there is no extra delay for each time it tries, because that's the
other part of the trick. When it comes up with something to try, it,
just tries it, it doesn't actually do it. It calls a function that
decides whether it will do it or not. If it has no capability to do
that, then it obviously won't, but if it does have the capability, there
is room to implement the capability to have a chance that it will do it,
and you can set up some numbers to control the chances based on the
likelihood that function is going to actually be useful to the AI,
whether the AI for that particular type of opponent is good enough to be
smart enough to do that, etc etc. For instance this is where it decides
that won't fire the laser, as in a previous example by someone else, if
you're too far away. Basically, the try things either do something and
take away the try, or it does nothing at all and the function that is
trying to decide what to do will still have that try left , and 199
chances now and it goes and rolls 1d100 again and tries the function
that it came up with again based on the rules I first provided. So you
can adjust likelihood to pick things to do in this way, and then you can
adjust likelihood further for each individual decision on specific
basis, and since it doesn't take away the try, just subtracts a chance,
it doesn't mean the computer wasted time if it doesn't decide it will do
what ever it was asked to do. This turned out to be pretty simple code
to understand and mess around with, as it separated all the logic for
each individual possibility and provided a ridiculously simple way to
adjust likelihood that it would pick certain things. And I can add new
AI's for new opponents by copying and pasting from one of the others and
changing numbers around and maybe adding or removing a line or two if I
need to add a special choice for this particular AI or remove one, and
the number changing allows to make it more likely this this opponent
will be scared a lot and want to run away for instance, or that it will
usually just stand there and slug it out, as it were. Continuing with
the slugging it out, if the AI has decided to try to slug it out, the
code would then see if it can slug it out after all, does it have what
it needs to do so. If it can't slug it out, then it doesn't do anything,
the function just runs out without actually doing anything, and the try
function will continue on it's loop. make the try function's loop count
downward so the computer can give up if you totally screw it over and it
literally can't do anything. I suggest 5ms delay for the loop so the
computer will make up it's mind quickly. If you need the computer to
pretend like it's thinking, make the actual decision when it comes up
with something that it is actually going to do, then introduce how ever
much lag you want as it does what it's going to do. In my case, when the
computer does something, it completely eliminates the try function
regardless of chances left, and if the computer gets to go again, then
the try function is called up again and started with 200 chances again.
Also consider this. In the functions that the try function is calling,
you can have them actually call other functions that the try function is
supposed to call and then return themselves back to the try function as
if they did nothing. If the function it called agrees to go through, it
will do it's job and remove the try and shut down the loop, then the
code would return back to the function that called it, who would in turn
return it back to the loop which is not running anymore because the one
function just shut it down. If that function actually didn't do anything
either, it would subtract a chance, return back to the function the try
function originally called, who would either try another function of
it's own or just return back to the try function after subtracting
another chance. It sounds confusing but I'm trying to do this without
giving away too much.
I ended up having to make the AI kind of stupid in my game and just try
random things, otherwise the player wouldn't have a chance at all to win
the game. It does it to a certain limit though, it knows not to do stuff
that absolutely would make no sense, firing weapons while out of range,
for instance.
In summery, using this approach it is a piece of cake if you figure out
that your AI is doing a certain thing too much to tweak how often it's
going to do that, just change a couple of numbers around, that would not
affect whether it decides it can do that, just how likely it is that it
would consider doing that.
Here's another analogy.
try 1:
chance 1:
What do I do?
I'm going to punch!
My left hand is not empty. My right hand is broken (nothing happens)
end of chance 1
chance 2:
what do I do?
I'm going to kick!
my left foot is unprotected. My right foot wears a steel toed boot (kick
with right foot)
end of chance 2
end of try 1
now let's have it try to do something again
try 2:
chance 1:
what do I do?
I'm going to headbutt!
my neck is damaged. am I wearing a neck brace? no (nothing happens)
end of chance 1
chance 2:
what do I do?
I'm going to run away!
my left foot is unprotected. I'm wearing a steel toed boot on my right
foot I'm going to kick! (nothing happens)
end of chance 2
end of try 2
The reason I said nothing happens after I said I'm going to kick! is
because the function itself doesn't do anything, except that it decided
to try to kick. The kick function might kick after all, but the run away
function did nothing except call the kick function. does that explain
things any?
---
Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gamers@audyssey.org.
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.