Patrolling Attackers

Thanks, that works an awful lot better, but it’s still taking about ten seconds longer than it should to print a room. With even two of those it is going to bog down the game to an unplayable level. Thanks a lot for your help, but unless I can trim down a lot of the bloat, I think it’s best if I just have a reset script of some sort that puts them in a random room and leaves them there. I doubt the player would notice them moving much anyway. :stuck_out_tongue:

That’s probably the best thing to do.

However, you can speed up route-finding by including this line:

Use fast route-finding.

which as I understand it calculates all the routes at the beginning of the game and stores them. So you would get a big slowdown the first time but you could avoid slowdowns thereafter.

Also, if you’re just trying to get NPCs to move to adjacent rooms, using route-finding seems like swatting a fly with a howitzer. Maybe this would be faster:

A room can be patrollable. A room is usually patrollable.

Egress relates a room (called the place) to a direction (called the way) when the room the way from the place is a patrollable room. [This is a bit tricky to parse, but it means that the relation will hold between The Lab and east when there's a room east of the lab; then the verb declaration below means that The Lab is open to the east.]

The verb to be open to means the egress relation. The verb to be accessible from means the reversed egress relation.

[a map]
Lab is a room. Observatory is north of Lab. Safety Shower is west of Lab. Foyer is west of Safety Shower. Safety Shower is southwest of Observatory. Cold Room is south of Lab. Repository is east of Cold Room and southeast of Lab. Repository is not patrollable.

[let's have Alice start where the player is so we can follow her around to make sure it works]

Alice is a woman in the Lab.

Alice has a room called the previous location.
First carry out Alice going from a room (called the place):
	now the previous location of Alice is the place.

Definition: a room is explorable if it is patrollable and it is not the previous location of Alice.

Every turn (this is the move patrol rule):
	let the place be the location of Alice;
	if an explorable room is adjacent to the place:
		let the way be a random direction that is accessible from the place;
		while the room the way from the place is not explorable:
			let the way be a random direction that is accessible from the place; [this will terminate eventually because there must be an explorable room adjacent to the place, and eventually we'll find its direction]
		try Alice going way;
	otherwise: [if no explorable room is adjacent to the place, which means that the only possibility is that the previous location of Alice is adjacent to the place] 
		if the place is open to a direction (called the way out): [note that this will only be true if the previous location of Alice is the only patrollable room next to the place; if there was another patrollable room then "if an exporable room is adjacent to the place" would've ben true, and if the previous location isn't patrollable then the place won't be open to that direction.]
			try Alice going the way out.

…and if that isn’t faster, maybe you can get rid of the egress relation and just have those tests check to see whether you’ve picked a direction that goes to an explorable room. Yeah, it seems wasteful to randomly pick directions until you find the right one, but as long as you check that you don’t enter any interminable loops it shouldn’t loop more than sixteen times per character or so (checking directions randomly), which I expect is a lot less inefficient than finding routes.

OTOH if you don’t have something to tell the player that they’re then you’re right that it might be better (as well as easier) to ditch the movement–if it doesn’t add anything and it confuses the player, you don’t need it.