This topic is now archived and is closed to further replies.


Message Passing Between AI

Recommended Posts

We designed and implemented a script between a Player(human), customer AI, Pizza and Pirate AI. The code was pretty messy as it was. We used a document / view design, where CGLView handled the windowing, and CGameLogic kept track of players, map, etc. The basic idea of the script is to have a customer get served a pizza, and then a pirate steals the pizza. The player has to stop the pirate, which he can do before the pirate steals the pizza, or after the pirate steals the pizza. Here's the game 1. Cutomer Spawns 2. Customer Wanders to his seat by navagating waypoints. 3. Customer Makes it to a table, and spawns a pizza. 4. Pizza moves a conveyer belt until it reaches the bottom of the conveyer belt, then stops it. 5. Player Picks up Pizza 6. If customer's delvery timer runs out, Customer & pizza is killed. else Pizza is on table, start an eating pizza timer. 7. If customer eating timer runs out, goto 12 else If the pizza on the table event fails to spawn a pirate, goto 7. 8. Pirate is spawned, and claims pizza. Only 1 pirate can try to steal 1 pizza. 9. Pirate makes his way to the pizza, in attempt to steal the pizza. 10. If Pirate is Killed before getting pizza, pirate gives up claim to pizza. goto 6. else Pirate steal pizza, stopping eating timer. 11. If Pirate is killed before leaving the resturant, goto 3. 11. If Pirate makes it to his final waypoint, customer leaves, pirate leaves, pizza leaves. End. 12. Customer finishes eating. Pizza disappears, Customer disappears, Pirate disappears. Macro event: If at any time, the customer is killed by the player, the pizza, any pirate that claimed that pizza and the customer are all killed. Question : How would you implement this script and keep messaging the different AI cleanly? My friend implemented this by passing pointers to everyone involved, the player, the pizza, the pirate, the customer. And then sending 'die()' or Idied() messages to keep pointers from becoming null. It was rather hacky and messy, but it worked. We've been discussing new ways to implement the message passing between AI. The only other way we can design this, is to have a large global structure that keeps track of everything, and the AI polls and updates this global structure. All the AI are assigned unique IDs, so it wouldn't be too difficult to tell them appart. ~~~~~ "One Reality is worth one thousand dreams" Download and play Slime King I. [edited by - dede on January 7, 2004 3:05:59 AM]

Share this post

Link to post
Share on other sites
Well I assume you have a class for pizzas, pirates etc.
Pointers is a good way to go. You could pass a pointer to the others once when the class is constructed. Thus:
class CPizza
CPizza(CPirate *lppirate, CPlayer *lpplayer) : pirate(lppirate), player(lpplayer){}
CPirate *pirate;
CPlayer *player;

Then create it:
CPizza *pizza = new CPizza(&player, &pirate);

Or you could have a class where they all come together like CMain. There you do all the code relevant to them cooperating. The rest is defined generally in the class like for the pirate have a function like:
void StealPizza(int posx, int posy);
Then call that in CMain as
pirate->StealPizza(pizza.GetPosX(), pizza.GetPosY);

Well its late I cant think of more right now.

Great Game by the way. Nicely done.


[edited by - CProgrammer on January 7, 2004 9:44:42 AM]

Share this post

Link to post
Share on other sites
That is our 72 hour game programming entry. We may win, but there is an infitive loop bug if you make it to level 4.

We did use pointers, but we had a hard time managing dangling pointers. Maybe if we manage pointers first, then do game logic as the second step, it would work out alright.

All of the object classes need a total rewrite. The rendering class actually also handles the score and the conveyer belt.

"One Reality is worth one thousand dreams"
Download and play Slime King I.

Share this post

Link to post
Share on other sites