Making an NPC avoid other NPCs

I’m using moveclass.h by Neil James Brown and Alan Trewartha under Inform6. There are several cats wandering around several rooms. How can I make sure that no cat ever walks into a room occupied by another cat?

Try this.

[spoiler][code]“Test”

Include Basic Screen Effects by Emily Short.

A cat is a kind of animal. Cookie, Twix, Steve, Marx and Reagan are cats.

Definition: a room is miaowed rather than unmiaowed:
if it encloses a cat begin;
decide yes;
otherwise;
decide no;
end if.

When play begins (this is the startup rule):
repeat with the chosen cat running through cats begin;
move the chosen cat to a random unmiaowed room;
end repeat;
move the player to a random unmiaowed room, without printing a room description.

Check an actor entering a room (this is the convert enter room into go rule):
let the way be the best route from the location of the actor to the noun;
try the actor going the way instead.

The convert enter room into go rule is listed first in the check entering rulebook.

Every turn (this is the NPC movement rule):
repeat with the chosen cat running through cats begin;
let the current room be the location of the chosen cat;
let next room be a random unmiaowed room which is adjacent to current room;
try the chosen cat entering the next room;
end repeat.

To say (chosen room - a room) status:
if the chosen room is the location of the player and the chosen room is miaowed begin;
say green letters;
otherwise if the chosen room is the location of the player and the chosen room is unmiaowed;
say yellow letters;
otherwise if the chosen room is miaowed;
say blue letters;
otherwise;
say red letters;
end if;
say “@”;
say default letters.

Every turn (this is the show locations rule):
say fixed letter spacing;
say “[room 00 status] [room 01 status] [room 02 status] [room 03 status] [line break]”;
say “[room 04 status] [room 05 status] [room 06 status] [room 07 status] [line break]”;
say “[room 08 status] [room 09 status] [room 10 status] [room 11 status] [line break]”;
say “[room 12 status] [room 13 status] [room 14 status] [room 15 status] [line break]”;
say variable letter spacing.

Room 00 is A Room. Room 01 is east of Room 00. Room 02 is east of Room 01. Room 03 is east of Room 02. Room 04 is south of Room 00 and southwest of Room 01. Room 05 is south of Room 01, southeast of Room 00, southwest of Room 02 and east of Room 04. Room 06 is south of Room 02, southeast of Room 01, southwest of Room 03 and east of Room 05. Room 07 is south of Room 03, southeast of Room 02 and east of Room 06. Room 08 is south of Room 04 and southwest of Room 05. Room 09 is south of Room 05, southeast of Room 04, southwest of Room 06 and east of Room 08. Room 10 is south of Room 06, southeast of Room 05, southwest of Room 07 and east of Room 09. Room 11 is south of Room 07, southeast of Room 06 and east of Room 10. Room 12 is south of Room 08 and southwest of Room 09. Room 13 is south of Room 09, southeast of Room 08, southwest of Room 10 and east of Room 12. Room 14 is south of Room 10, southeast of Room 09, southwest of Room 11 and east of Room 13. Room 15 is south of Room 11, southeast of Room 10 and east of Room 14.

The description of a room is “If it was the player, it would be as good looking as ever!”.[/code][/spoiler]

It has some extra code to help show what’s going on, but the active code can be found in the startup rule, the NPC movement rule and the the definition at the top.

Hope this helps.

Edit: Ignore this, it’s Inform 7 rather than Inform 6!

He said Inform 6.

Yeah, I should learn to be a little more observant to these things. :blush: