Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
benny1564
Novice


Joined: 22 Jun 2004
Posts: 48

PostPosted: Tue Aug 10, 2004 8:28 pm   

Auto visit every mapped room?
 
Is there any way to make the mapper automatically visit every mapped room?
And a bonus would be if the mapper could choose the shortest path...

I also want to be able to change the time between commands are sent when using speedwalk.
Usually I walk with 600 ms, but sometimes I want to walk faster, can that be arranged?
_________________


Last edited by benny1564 on Wed Aug 11, 2004 6:18 pm; edited 1 time in total
Reply with quote
hykou
Wanderer


Joined: 29 Apr 2004
Posts: 63
Location: USA

PostPosted: Tue Aug 10, 2004 11:13 pm   
 
i think it does take the shortest path from point 1 to point b
Reply with quote
thargy
Beginner


Joined: 10 Aug 2004
Posts: 20
Location: UK, Uganda

PostPosted: Wed Aug 11, 2004 1:34 am   
 
OK,

I read your request as asking zMud to visit every room you've already mapped, I was bored so spent a quick hour and here's one solution, hope you like it

Code:
#CLASS {WalkEverywhere}
#ALIAS WalkEverywhere {#VAR RoomsVisited %array( );#VAR RoomMap %array( );#VAR RoomCount 0;#VAR RoomVNum 0;#CALL %roommode(0);#SAY "Filtering map";#CALL %mapfilter("");#CALL %mapfilter(%concat("ZoneID = ",%zonenum()));#VAR RoomTotal {%numrooms};#IF (@RoomTotal<2) {#SAY "Not enough rooms!"} {#SAY {Creating arrays for @RoomTotal rooms};#VAR RoomMin %mapvnum( 1);#LOOP @RoomTotal {#VAR RoomVNum %mapvnum( %i);#CALL %arrset(RoomsVisited, %i, @RoomVNum);#IF (@RoomVNum<@RoomMin) {#VAR RoomMin @RoomVNum}};#LOOP @RoomTotal {#CALL %arrset(RoomMap,%arrget(RoomsVisited,%i)-@RoomMin,%i)};#SAY Walking;#VAR RoomCurrent %roomnum;onroomenter}}
#ALIAS onroomenter {#VAR RoomFNum %arrget( RoomMap, %roomnum-@RoomMin);#VAR RoomVNum {%arrget( RoomsVisited, @RoomFNum)};#IF (@RoomVNum) {#CALL %arrset(RoomsVisited,@RoomFNum,"");#ADD RoomCount 1};#IF (%roomnum==@RoomVNum) {WalkNext}}
#ALIAS WalkNext {#VAR RoomCurrent 0;#VAR RoomVnum {};#IF (@RoomCount < @RoomTotal) {#WHILE (!@RoomVNum) {#ADD RoomCurrent 1;#VAR RoomVNum {%arrget( RoomsVisited, @RoomCurrent)}};#WALK @RoomVNum} {#SAY All rooms visited}}
#VAR RoomsVisited {<Array>}
#VAR RoomCount {0}
#VAR RoomCurrent {0}
#VAR RoomMap {<Array>}
#VAR RoomMin {0}
#VAR RoomVNum {0}
#VAR RoomTotal {0}
#VAR RoomFNum {0}
#CLASS 0


Notes

Run by using the WalkEverywhere Alias

My map is huge and so I added a filter to reduce the number of rooms to walk to the current zone only (I tested with a 97 zone room and the startup took about 5 secs, this should be linear so it should take about 1min per 1000 rooms to create the startup variables)

To walk in all rooms in the map remove the following:

Code:
#CALL %mapfilter(%concat("ZoneID = ",%zonenum()))


This programme is written to be safe, and not be tripped up by missing vnums etc. I couldn't find any documentation to say whether this is possible, but I suspect it is. It also doesn't assume anything about the way the %mapvnum function works. In practice I found that the %mapvnum function works like this

Quote:
%mapvnum(%i) = %i+VNum_First_Room_In_Zone


However, only zuggs could prove this. If true the code could be speeded up somewhat. In the absence of this proof the WalkEverywhere alias first creates two arrays the first (RoomsVisited) maps filter room numbers to vnums, array lookup seems to be much quicker than using the %mapvnum function and so this speeds up the running code was complete. The RoomsVisited array also works as a record of which rooms have been visited, so that they're not visited (deliberately) again. The second array is a reverse lookup for the %mapvnum function, allowing the current room vnum to be converted into a filter room number. I couldn't find a built in equivalent, and suspect that it would be slower anyway.

Once these two arrays are present the %mapvnum function is not used again, this sped up the execution dramatically. The penalty is paid before walking and is scalable.

With the arrays present the alias sets the first destination room to the current room (therefore it's important that you start in a room in the zone you are walking) and executes the onroomenter alias for the first time, so that the current room is recorded as visited.

Having reached the correct destination (you're already there) the onroomenter alias executes the WalkNext alias. This could be included directly in the onroomenter alias, but it makes the code a little less readable.

The WalkNext alias searches for the next unvisited room and tells zMud to walk there by the shortest route.

The OnRoomEnter alias is then fired as you enter each room, this in turn sets each entered room as visited. When the destination room is reached it fires WalkNext again and a route to the next room is selected.

This doesn't technically move around rooms by the shortest possible path, but in practice works very well, this is because when you create rooms in a MUD you tend to follow a reasonable pattern of expansion anyway (new rooms are connected to existing rooms), this code generally walks the rooms approximately in the order you created them in, but if you do make any big jumps it walks to them as quickly as possible. After the initial set up cost in time, the decision to move tends to be pretty instantaneous.

Would love to see other peoples solutions.

Craig
Reply with quote
benny1564
Novice


Joined: 22 Jun 2004
Posts: 48

PostPosted: Wed Aug 11, 2004 1:34 pm   
 
Awesome Craig! It seems to work fine in offline mode and I shall test it online very soon.
By the way, 279 rooms took less than a second to "prepare", AthlonXP 1800.

Is there any way to pause the process and continue later?

When I am not using this program, should I disable the class in case the onroomenter
alias sips cpu-power?

It does require all rooms to be connected, otherwise it stops but that is not a problem since my rooms are connected, I just had to find something negative :D
_________________
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net