3d Pacman AI Problem

Topics regarding Scripting with Reality Factory
Post Reply
grayjamn
Posts: 3
Joined: Tue May 23, 2006 9:39 pm

3d Pacman AI Problem

Post by grayjamn »

Greetings,

I'm working on a project just to learn more about game design in general, but I'm having a couple problems with the scripting portions. My game is basically a 3d Pacman game (yes, i know its been done before) that basically sets the original Pacman game in 3d, with similar AI.

So as far as the AI goes, I want my game to follow the basic logic that is used in the original pacman game. Such as defined below:

-There are four ghosts that can kill the player by colliding with Pacman.
-Ghosts travel in straight paths, and change direction each time they hit a wall.
-They are able to find their way through the turns of the level to get to Pacman.

Now, my question is, how would I go about implementing this into my level as far as scripting it goes?

I've thought about setting ScriptPoints throughout the intersections of the level and make a pawns somehow "choose" the next point based on were Pacman is currently in the level (maybe put some triggers with an updatePosition attribute associated with them so the ghosts can know where Pacman has been last). But I'm having trouble with this since the scripting language used within RF (simkin I think it's called) doesn't support any data structures or while/for loops like I am familiar with in other programming languages. My original plan was going to use the A* AI strategy (or rather, having the ghosts choose the shortest path to get to Pacman's current position).

Does anything out there have a better idea on how to implement the AI for the ghosts? Thanks, hope to hear back from you guys soon.
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

I think that generally the idea beyond AI dev is this:
more Intelligence = minus random choice = more Humanity
and vice-versa

In games like GTA or Splinter Cell you can see Humans acting like Humans. But in a Pac-Man game I always saw stupid ghosts turning around. So you can implement a 2 layer AI. Basicly you could have a Standard Ai that follow random rules chhosing the path and an Advanced AI with some simple implementation of pathfinding.
Now we can start thinking about the Standard Ai. I created something similar in one of my physics demo. In the demo there are 3 cars that freely go around a crossing.
- Every car is in a different path named with a letter (A1, A2, A3, A4) (B1, B2, B3, B4).
- The last scriptpath before the crossing is reached. This scriptpath has a name like this: 2_B3. The number "2" tells the AI how many possibile road can be choosed. If the junction had three possible way it would be named 3_B3. B3 is the actual path progression.
- A random numer between 0 and "2" is choosed then is reconstructed an output string named xB3, where x is the output of the random script section. Imagine, for example, that x is "1", then the uotput will be 1B3 (it could be 2B3).
- the car goes toward the scriptpath 1B3 that has the NextPath parameter set to the new path sequence (for example C1).
This is the random path script part:

Code: Select all

RANDOMPOINT =0;
debug(StringCopy(RANDOMPOINT));
if((LeftCopy(self.point_name, 2) = ("1_"))or(LeftCopy(self.point_name, 2) = ("2_"))or(LeftCopy(self.point_name, 2) = ("3_")))
{
    if(self.distancetopoint < GAP_DISTANCE )
    {
        RANDOMPOINT = random(1, (LeftCopy(self.point_name, 1)+1));
        self.think="FindPointOrder";
    }
}
else
{
    if(self.distancetopoint < GAP_DISTANCE )
    {
        
        self.think="NextPointOrder";
    }
    
    GAP_COMMAND= LeftCopy(self.point_name, 1);
}    
}]

NextPointOrder[()
{
    NextPoint();
    self.think="GO";
       
}]  
   
FindPointOrder[()
{
    
    NewPoint(StringCopy(RANDOMPOINT # self.point_name));
    
    self.think="GO";
       
}] 
Initially isn't simple to understand but it works. You can see it in action downloading and patching a standard installation of RF (I suggest you to make a fresh installation to avoid any mess) with the Car_AI_Test3.azip archive that you can find here: http://realitychess.altervista.org/physics/

The demo is a early attempt to dev a car Ai for the new RFwithPhysics, so it doesn't work so well...
I hope this helps.
grayjamn
Posts: 3
Joined: Tue May 23, 2006 9:39 pm

Post by grayjamn »

Thank you for your help on this issue. I see from your code that you are generatoring a random number from 1 to the number of available scriptpoints around your player then going to that point.

I'm still a little confused on how to implement this into the game, or rather, how to script this for my "ghost" to act accordingly. For example, suppose I have the following map layout below...

1---------------4
|.......................|
5------------------6
|.......................|
7--------------10

Beautiful huh? Each number represents an intersection of two paths and the red (-) and (|) make up the path that the ghosts are able to take. So, if I understand what you are saying...each number (ie. Scriptpoint) has two or more other script points the ghost can travel once it has arrives at any given scriptpoint. So lets say a ghost is on scriptpoint 1, then it will have choose randomly between 4 and 5 and then move to that next point.

Now, as far as scripting this goes, where I get confused is how does the script know what limits to ask the random number generator to spit out a random number in? Or in other words, how do I make it so if a ghost is at intersection 1...to choose randomly between 4 and 5 and then move to that point?

Thanks for you help in advance.
User avatar
Master
Posts: 81
Joined: Tue Jul 12, 2005 6:58 pm

Post by Master »

You can use the i=random(0,1); then if i=0 go to first available script point and if i=1 go to second available script point.
grayjamn
Posts: 3
Joined: Tue May 23, 2006 9:39 pm

Post by grayjamn »

Ah thanks, got it. Thanks everyone.
Post Reply