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
MrTickle
Newbie


Joined: 03 May 2003
Posts: 9
Location: New Zealand

PostPosted: Sun Aug 31, 2003 3:46 am   

How to calculate the nearest room of 'X' type
 
Solution required: from a list of set room numbers, select the one closest to your current position

Goal: one button click to take you to the nearest room of a certain type (eg - healing, shop, huntbreak...)

Hi guys,

I have mapped a large portion of the MUD I play, and now am trying to figure out if zmud can calculate the closest room to a current position. Sorry if this has been covered before but I couldn't track anything down on the forums (here are some keywords for others searching on the same topic - closest, close, nearest, near, proximity).

Has anyone had any experience with this? I imagine there must be a query that can work out the path to various rooms and calculate which is the shortest.

I think it would be a great tool in large muds have buttons that filters through a list of known rooms numbers (vnum) of a certain type that you might list, then walk (#WAL) you to the closest one.
Some actions (such as healing when you're rapidly dying of poison or breaking off a Player Killer) would benefit from a quick decision like this. It would go beyond having to manually filter through a list of favorites which might take up those critical few extra seconds. I suppose it could also work really well in a trigger.

Thanks for any feedback or similar ideas you can share.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sun Aug 31, 2003 4:57 am   
 
Is there some reason not to use the built-in method?
#WALK temple
Speedwalks you to the room marked as the temple within the current zone no matter where you are in the zone.

%roomid(vNum, s)
Return or set the short name (ID) of the room to string s. If room is omitted, the current room is used.
Reply with quote
MrTickle
Newbie


Joined: 03 May 2003
Posts: 9
Location: New Zealand

PostPosted: Sun Aug 31, 2003 7:17 am   
 
Thanks Lightbulb,

My key objective is to automatically find the closest temple when there might be several temples to choose from. It might sound a bit lazy, but would be very usefull when you have several options spread over a large map. Especially when an extra 8 squares, or the time taken to work out which is closer, could be the difference between dying or getting healed.

#Walk will definately come in to it, after a suitable script (is that the right word?) has determined the best choice to walk to.

I'm way out of my league with this concept, so perhaps i'm asking for something that just can't be done...
Reply with quote
MrTickle
Newbie


Joined: 03 May 2003
Posts: 9
Location: New Zealand

PostPosted: Sun Aug 31, 2003 7:28 am   
 
To give a further example which shows how varied the destinations could be:
In the MUD I play, other players may 'hunt' you, and the only way to shake them off your tail is by moving through a square that has a non-standard exit (huntbreak). There might be hundreds of these through the game, and you could be attacked at any point on the 'map', so knowing the closest huntbreak reduces your chances of being killed before you can escape.
Every huntbreak is unique in description, but with a mapped out MUD each one then has a unique room number.
So a way to calculate the path from current room to each huntbreak, and then walk you to the one which offers the shortest path, would reduce the chance of getting killed no matter where you get attacked.

I suppose I need a way to calculate distance, repeat this for all options, and then some way to auto pick the one with the smallest result as the #wal destination. It's the calculating and the auto picking that has me stumped.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Aug 31, 2003 10:47 am   
 
Since you already have lists with room numbers it is rather easy to do. Something like this:
Lets suppose the hunt list is in the variable hunt...
#CLASS ProximityCalculator
#VAR CloseRec {} {}
#VAR Distance 0 0
#AL FindClosest {CloseRec="";#ADDKEY CloseRec short 1000;#FORALL @{%1} {Distance=%numitems(%pathexpand(%walk(%i)));#ADDKEY CloseRec {%i} {@Distance};#IF (@Distance<@CloseRec.short) {#ADDKEY CloseRec {short=@Distance|near=%i}}};#ECHO Closest room is @CloseRec.near at a distance of @CloseRec.short;#ECHO You might want to make this into the "#WALK" once you verify it is working right.}
#CLASS 0

Now all you do "FindClosest hunt" or if you have your shop list named 'BuddhasFamousGroceryStoreList' then it would be "FindClosest BuddhasFamousGroceryStoreList". Of course you want to do that within a macro or button. If speed isn't fast enough there is a highly convoluted way to eliminate the #FORALL; but I don't think much would be gained, and the alias would become nearly unreadable.
Reply with quote
MrTickle
Newbie


Joined: 03 May 2003
Posts: 9
Location: New Zealand

PostPosted: Mon Sep 01, 2003 11:46 am   
 
YOWZA!

Thanks heaps Vijilante. It looks like what i'm after, but as I suspected i'm way out of my league.
If anyone can spare me some handholding, i'm not sure how to impliment this. I've done lot's of experimenting and reading the help files but cannot find a way to return a good solution.

1) What data do I need to input into the formula and where? (I was thinking I had to put the string of room numbers into a new variable called 'hunt', or perhaps add them between brackets in "#VAR CloseRec {} {}")
2) Does the entire sequence you've supplied get loaded into a new alias? (or button, or pasted straight into the Zmud input screen?)

At the moment I can get an echo showing me only the first value from a string in a variable I created called 'hunt, when I use "findclosest hunt". I feel as if i'm telling zmud to look into a list, but not sort through it and run the beautiful distance calculation you have worked out.

It's frustrating because I can see you've put in the effort to help me out, and you've got the idea of what i'm after... it's just these damn undersized synapses not being able to pump through enough signals through my brain to work out the soloution. Curse whoever it was that gave me extra long tickley arms instead of superior brainpower! Damn you extra long tickley arms!

Okay, enough ranting...
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Sep 01, 2003 7:40 pm   
 
Step 1 is take the entire script and paste it into the zMud command line.
Step 2 press enter. The script is designed to create an entire class within your settings.
Step 3 create list style variables containing the room numbers for a given type or room.
Step 4 Use the alias. As my previous post said usage is 'FindClosest variableName'. The alias does not preform any validation to make sure you provided an accurate variable name.
Reply with quote
parrotslave
Wanderer


Joined: 01 Jul 2002
Posts: 81
Location: USA

PostPosted: Tue Sep 02, 2003 12:11 am   
 
I am so glad you asked this question. I have been trying to figure out how to do this for a while to be able to walk to the nearest general store.

I made a list of all the general stores in the mud. The problem I have run into is that some general stores are in zones you can't walk to. For these stores the distance calculated is 0 so those are the ones that come up as being the closest. How would I list the closest store with the distance value greater than 0?

Thanks!
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Tue Sep 02, 2003 2:18 am   
 
Simply change the test condition "(@Distance<@CloseRec.short)" to "((@Distance>0)&(@Distance<@CloseRec.short))".
Reply with quote
MrTickle
Newbie


Joined: 03 May 2003
Posts: 9
Location: New Zealand

PostPosted: Tue Sep 02, 2003 11:32 am   
 
Vijilante, thanks heaps for your support! Very Happy
Not sure what I was doing wrong last time, (maybe setting up the variable outside of the class folder?) but it works a charm now (even across zones that I can walk to). So thanks for the step by step. And i've developed a better understanding of the components involved too.
Much respect!
Reply with quote
Iceclaw
Apprentice


Joined: 11 Sep 2005
Posts: 124

PostPosted: Sat Dec 10, 2005 5:59 am   
 
How would I speed up processing by breaking the loop if it comes upon something with distance=1, and having that be the 'nearest'?
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Sun Dec 11, 2005 2:30 pm   
 
You could do a #WHILE (!%null(@list)) and when distance=1 make the list equal to %null
Reply with quote
Iceclaw
Apprentice


Joined: 11 Sep 2005
Posts: 124

PostPosted: Sun Dec 11, 2005 3:35 pm   
 
Where would I put this while condition so as to not interfere with it if there is never a result that =1?
Reply with quote
Iceclaw
Apprentice


Joined: 11 Sep 2005
Posts: 124

PostPosted: Sun Dec 11, 2005 3:36 pm   
 
Also, is there a way to get this to take the following into account?
Costs for entering Rooms?
2. Ignore Do Not Enter Rooms and remove them from the list?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Dec 12, 2005 1:36 am   
 
The %walk function takes cost of entering rooms into account. "Do Not Enter" room have a cost set equivalent to max integer. So the script I provided over 2 years ago should handle both situation by virtue of zMud's intelligent design.

The use of #FORALL in the script does hinder breaking out of it when an extremely short value has been found. I would suggest you rewrite it such that a #WHILE loop is used instead, to produce the type of short launch that you want.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Iceclaw
Apprentice


Joined: 11 Sep 2005
Posts: 124

PostPosted: Sat Dec 31, 2005 7:06 am   
 
Redone to break on an extreamly short room

"CloseRec=""
#var shortest_found 0
#var notgoingtofindshortest 0
#ADDKEY CloseRec short 1000
#while (@shortest_found=0)&(@notgoingtofindshortest=0)=1 {
#FORALL @{%1} {
#if @shortest_found=1 {#noop} {
Distance=%numitems( %pathexpand( %walk( %i)))
#ADDKEY CloseRec {%i} {@Distance}
#if @distance=1 {
#ADDKEY CloseRec {short=@Distance|near=%i}
#var shortest_found 1
#abort
} {#noop}
#IF ((@Distance>0)&(@Distance<@CloseRec.short)) {#ADDKEY CloseRec {short=@Distance|near=%i}}
}
}
#var notgoingtofindshortest 1
#if @closeRec.near="" {#ECHO Closest room is @CloseRec.near at a distance of @CloseRec.short} {#NOOP}
}
// #ECHO You might want to make this into the "#WALK" once you verify it is working right.
Reply with quote
Iceclaw
Apprentice


Joined: 11 Sep 2005
Posts: 124

PostPosted: Sat Dec 31, 2005 7:09 am   
 
Now i'd like to use this to store the shortest route between all of these rooms, for even more speed improvements (This way, I can load a 'sorted' @Path, and it will find the shortest potential room faster.)
Basic Concept

1. #find shortest from present location, Add that key to a new path variable (Path2?), remove 'shortest' from @Path 1.
2. #tel to shortest room, repeat

Help appreciated
Reply with quote
Iceclaw
Apprentice


Joined: 11 Sep 2005
Posts: 124

PostPosted: Fri Jan 06, 2006 7:20 am   
 
Correct me if i'm wrong, but doesnt the walk take into account the most efficient path for your final choice, not the cost when checking distance? Its checking the #er of rooms away it is, with %numitems()? Anyone know how to incorporate cost?
Reply with quote
Dodgester
Wanderer


Joined: 17 Nov 2005
Posts: 65

PostPosted: Sun Jan 08, 2006 6:47 am   
 
Interesting topic as it's similar but a little more of what I been after myself. The distance part has been answered, but still need to be able to set the kind part first before the distance part can become of use. I been wanting to know how can I set the type of rooms that each room is, which within the room properties, I don't see that as being possible, but when I open the MDB file in Access, I see the "KindID" field in "ObjectTbl", and I also see the "KindTbl", and was just wondering if this was something that was intended to be used for rooms or for something else? Of course, I could setup a script, but I also want to check to be sure if I'm going to mess something else up down the road or not.

Sincerely,

Dodgester
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