Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Suggestions ➜ Shortest Path Speedwalking

Shortest Path Speedwalking

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2  3 

Posted by Rojan QDel   USA  (9 posts)  Bio
Date Reply #30 on Mon 11 Sep 2006 10:33 PM (UTC)
Message
I'm wondering if the newest version of this has been posted? And if not, could it be? I'm also wondering how we could automatically get the room name when it's not a specific color scheme...
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #31 on Mon 11 Sep 2006 11:27 PM (UTC)
Message
So far the code has been largely experimental. It works, and nicely too, if you know where the rooms are, and where you are.

However deducing the room name especially if there are no particular colour codes is the tricky bit. Plus, as mentioned earlier, if multiple rooms happen to have the same name.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Rojan QDel   USA  (9 posts)  Bio
Date Reply #32 on Tue 12 Sep 2006 12:49 AM (UTC)
Message
Could you post the most recent version you have of the plugin so I could experiment with it? Thanks :)
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #33 on Tue 12 Sep 2006 02:56 AM (UTC)
Message
I don't have a plugin personally. The code I posted earlier on in this thread is my latest attempts to solve the shortest path analysis, assuming you already have all the room data in memory. I did it, as decribed there, by pulling in the room data from the "rlist" command as a MUD administrator.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #34 on Tue 12 Sep 2006 02:59 AM (UTC)
Message
Whoops! I thought this was another thread:

http://www.gammon.com.au/forum/bbshowpost.php?id=7306

My latest plugin (which I forgot I had) is posted earlier in this thread.

The other thread mentioned above gives a different way of solving the shortest-path problem. Now if you could combine them, you might have a pretty good solution. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #35 on Tue 12 Sep 2006 03:00 AM (UTC)
Message
Unfortunately my plugin (in this thread) is in VBscript, and the shortest path algorithm (in the other thread) is in Lua, but you will be able to take the general ideas and do something with them.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #36 on Tue 12 Sep 2006 03:03 AM (UTC)
Message
Well, this is the version I have on disk, it looks more extensive than the earlier post. I can't say if I know whether it works, I forgot I had it ...


<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, March 22, 2004, 4:43 PM -->
<!-- MuClient version 3.47 -->

<!-- Plugin "Automap" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Automap"
   author="Nick Gammon"
   id="23a544e6b6eeb7ea26c29b7d"
   language="VBscript"
   purpose="Creates speedwalks from one checkpoint to another one"
   save_state="y"
   date_written="2004-03-22 16:38:10"
   requires="3.47"
   version="1.2"
   >
<description trim="y">
<![CDATA[
cp [nr] - add a checkpoint - optional "nr" argument specifies "no return"
cl - list checkpoints from this location
cl x - lists checkpoints, filtered by x (eg. cl tavern)
cg x  - go to checkpoint x (eg. cg 5)
cc - clear current speedwalk - start new checkpoint
cr x - manually define room name (eg. cr Outside East Gate)
ci - checkpoint info - lists all known paths in the database
cdel x - checkpoint delete - deletes a path or node identified in the "ci" list
cdel all - deletes all map info
cn - go to last node (ie. one we just left)
csave - save the database, in case of a crash

chelp - this description


]]>
</description>

</plugin>


<!--  Get our standard constants -->

<include name="constants.vbs"/>

<!--  Triggers  -->

<!-- red = 9, green = 10 -->

<triggers>
  <trigger
   back_colour="8"
   bold="y"
   enabled="y"
   match="*"
   match_back_colour="y"
   match_bold="y"
   match_inverse="y"
   match_italic="y"
   match_text_colour="y"
   sequence="100"
   text_colour="10"
   script="OnRoomFromFirstStyle"
  >
  </trigger>
  <trigger
   enabled="y"
   match="&lt;*&gt;*"
   script="OnGetRoomFromPrompt"
   sequence="100"
  >
  </trigger>
  <trigger
   back_colour="8"
   bold="y"
   enabled="y"
   match="^(The reddish sun sets past the horizon\.|The sun slowly disappears in the west\.|The sun's radiance dims as it sinks in the sky\.|The sky turns a reddish orange as the sun ends its journey\.|You are carrying\:)$"
   match_back_colour="y"
   match_bold="y"
   match_inverse="y"
   match_italic="y"
   match_text_colour="y"
   regexp="y"
   sequence="90"
   text_colour="9"
  >
  </trigger>
</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   script="OnClearcheckpoint"
   match="cc"
   echo_alias="y"
   enabled="y"
   sequence="100"
  >
  </alias>
  <alias
   script="OnCheckpointlist"
   match="^cl( .*)?$"
   echo_alias="y"
   enabled="y"
   regexp="y"
   sequence="100"
  >
  </alias>
  <alias
   script="OnCheckpointinfo"
   match="ci"
   echo_alias="y"
   enabled="y"
   sequence="100"
  >
  </alias>
  <alias
   match="csave"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>SaveState
ColourNote &quot;white&quot;, &quot;green&quot;, &quot;Database saved&quot;</send>
  </alias>
  <alias
   script="OnCheckpointGotoNode"
   match="cn"
   echo_alias="y"
   enabled="y"
   sequence="100"
  >
  </alias>
  <alias
   script="OnCheckpointDelete"
   match="cdel *"
   echo_alias="y"
   enabled="y"
   sequence="100"
  >
  </alias>
  <alias
   script="OnCheckpoint"
   match="^cp( nr)?$"
   echo_alias="y"
   enabled="y"
   regexp="y"
   sequence="100"
  >
  </alias>
 <alias
   script="OnCheckpointRoom"
   match="cr *"
   echo_alias="y"
   enabled="y"
   sequence="100"
  >
  </alias>
  <alias
   script="OnCheckpointgoto"
   match="cg *"
   echo_alias="y"
   enabled="y"
   sequence="100"
  >
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[
'----------------------------------------------------------
'  Load mapping array
'----------------------------------------------------------
Sub OnPluginInstall

  ArrayCreate "map"
  ArrayImport "map", GetVariable ("map"), ","

  ArrayCreate ""  ' work array
  ArrayCreate "dest"  ' destinations array
  ArrayCreate "cl"  ' current listed destinations array
  ArrayCreate "cin"  ' ci - nodes
  ArrayCreate "cip"  ' ci - paths

  SetVariable "known_room", ""
  SetVariable "known_checkpoint", ""
  SetVariable "known_mapstring", ""
 
  SetVariable "clroom", ""

'
' turn auto-mapping on
'  

  EnableMapping vbTrue  

End Sub

'----------------------------------------------------------
' The plugin is saving its state
'----------------------------------------------------------
sub OnPluginSaveState

'
' Save mapping array
'
  SetVariable "map", ArrayExport ("map", ",")

end sub

'----------------------------------------------------------
'  helper routine to add a new path to the array
'----------------------------------------------------------
Sub AddPath (from_location, to_location, speedwalk)
dim currspeedwalk, currpath, newpath
  
  newpath = EvaluateSpeedwalk (RemoveBacktracks (speedwalk))

  ArrayClear ""  ' get rid of previous stuff

'
'  get current entries into work array
'
  ArrayImport "", ArrayGet ("map", from_location), ","

'
'  see what the current path there is
'
  currspeedwalk = RemoveBacktracks (ArrayGet ("", to_location))

  If currspeedwalk <> "" Then
    currpath = EvaluateSpeedwalk (currspeedwalk)
    If Len (newpath) > Len (currpath) Then
      ColourNote "white", "red", "New path is: " & RemoveBacktracks (speedwalk)
      ColourNote "white", "red", "Old path is: " & currspeedwalk
      ColourNote "white", "red", "Retaining older, shorter, path."
      Exit Sub
    End If ' new path longer
  End If  ' have an old path

'
'  note path from last checkpoint
'
  ArraySet "", to_location, speedwalk

  ColourNote "white", "blue", "Path from '[" & _
             from_location & "] to [" & _
             to_location & "] noted as " & _
             speedwalk
'
'  put back new destinations
'
  ArraySet "map", from_location, ArrayExport ("", ",")

End Sub	' AddPath 

'----------------------------------------------------------
'  Make a checkpoint (node)
'----------------------------------------------------------
Sub OnCheckpoint (name, line, wildcards)
Dim room, checkpoint, mapstring


'
'  get into variables to save time and confusion
'
room = trim (GetVariable ("room"))

'
'  if they stumbled across a known node, the "room change" routine
'   clears the map info, however we needed that to checkpoint the room
'
if room = GetVariable ("known_room") Then
  checkpoint = trim (GetVariable ("known_checkpoint"))
  mapstring = GetVariable ("known_mapstring")
Else
  checkpoint = trim (GetVariable ("checkpoint"))
  mapstring = GetMappingString 
End If

If Mapping Then
  If checkpoint <> "" And _
     room  <> "" And _
     mapstring <> "" Then

    AddPath checkpoint, room, mapstring

'
'  now add reverse path - if wanted
'

    If trim (wildcards (1)) <> "nr" Then
      AddPath room, checkpoint, "{auto}" & ReverseSpeedwalk (mapstring)
    End If

  End If  ' already have a checkpoint
'
'  note new checkpoint
'
  OnClearcheckpoint "", "", ""

Else
  ColourNote "white", "red", "Auto-mapper not active"
End If ' mapping 

End Sub  ' OnCheckpoint 

'----------------------------------------------------------
' Clear a checkpoint
'----------------------------------------------------------
Sub OnClearcheckpoint (name, line, wildcards)

'
'  clear checkpoint (start from here)
'
  SetVariable "checkpoint", GetVariable ("room")
'
'  start mapping again from here
'
  DeleteAllMapItems

  ColourNote "white", "blue", "New checkpoint started at: " _
     & GetVariable ("room")

End Sub ' OnClearcheckpoint 


'----------------------------------------------------------
'   Add destinations to "dest" array from location "from"
'----------------------------------------------------------
Sub GetDestinations (orig, from, speedwalk, indent, level)
dim d, k, existing, path

'debug Note indent & "finding destinations from " & from & " prefix " & speedwalk

   ArrayCreate level
   ArrayClear level  ' get rid of previous stuff
   ArrayImport level, ArrayGet ("map", from), ","

'
'  check each one
'
   d = ArrayListKeys (level)

   If IsEmpty (d) Then Exit Sub
  
   For Each k In d

   if k <> orig then

     path = ArrayGet (level, k)
     existing = ArrayGet ("dest", k)

'debug      Note indent & "considering " & k & " path " & path
'debug      Note indent & "existing = " & existing

     If (len (EvaluateSpeedWalk (RemoveBacktracks (existing))) > _
         len (EvaluateSpeedWalk (RemoveBacktracks (speedwalk & path)))) Or _
        (existing = "") Then

       ArraySet "dest", k, speedwalk & path
'debug       Note indent & "** addding destination " & k & " path = " & speedwalk & path

'
'  recurse to get destinations from *this* destination
'
   
       If k <> from Then
'debug         Note indent & "recursing to find walks from " & k & " with prefix " & speedwalk & path
         GetDestinations orig, k, speedwalk & path, indent & "  ", level + 1
       End If 
     End If	' not already having a path there

   End If  ' not going to where we started

   Next	' end of doing each destination

End Sub ' GetDestinations 

'----------------------------------------------------------
' cl -  List available checkpoints
'
' You can specify a filter, eg. cl tavern  
'----------------------------------------------------------
Sub OnCheckpointlist (name, line, wildcards)
Dim room, destinations, count, k, path, filter

  filter = trim (Lcase (wildcards (1)))
  room = trim (GetVariable ("room"))
  SetVariable "clroom", room  ' note what room we were in
  count = 0

  ColourNote "white", "blue", "Current room believed to be [" & _
           room & "]"

'
'  get current entries into work array
'
   ArrayClear "dest"
   GetDestinations room, room, "", "", 1
   ArrayClear "cl"

   destinations = ArrayListKeys ("dest")

   If Not IsEmpty (destinations) Then
  
    For Each k In destinations
      If (filter = "") or (instr (lcase (k), filter) <> 0) Then
        count = count + 1
        path = RemoveBacktracks (ArrayGet ("dest", k))
        world.ColourNote "white", "blue", "  " & _
            CStr (count) & ": " & k & " (" & path & ")"
        ArraySet "cl", count, path
      End If
    Next

    if (count = 0) and (filter <> "") then
      ColourNote "white", "blue", "No destinations matching filter: " & filter
    end if

   Else
     ColourNote "white", "blue", "No known destinations from here"
     If GetVariable ("checkpoint") <> "" And _
        trim (GetMappingString) <> "" Then
       ColourNote "white", "blue", "You were last at [" & _
           GetVariable ("checkpoint") & "] (" & _
           trim (ReverseSpeedwalk (GetMappingString)) & ")"
       ColourNote "white", "blue", "Type 'cn' to go there"
     End If
   End If

End Sub ' OnCheckpointlist 

'----------------------------------------------------------
' go to a checkpoint
'----------------------------------------------------------
Sub OnCheckpointgoto (name, line, wildcards)
Dim room, destinations, which

  if ArraySize ("cl") = 0 then
    ColourNote "white", "red", "You have not done a 'cl' or there were no rooms listed"
    Exit Sub
  end if
    
  room = trim (GetVariable ("room"))

  if room <> GetVariable ("clroom") then
    ColourNote "white", "red", "You have changed rooms since doing a 'cl'"
    ColourNote "white", "red", "You were in    [" & GetVariable ("clroom") & "]"
    ColourNote "white", "red", "You are now in [" & room & "]"
    Exit Sub
  end if

  which = CInt (wildcards (1)) ' which choice

  if not ArrayKeyExists ("cl", which) then
    ColourNote "white", "red", "Destination " & which & _
       " was not on the list"
    exit sub
  end if

'
'  go there :)
'

  Send EvaluateSpeedwalk (RemoveBacktracks (ArrayGet ("cl", which)))

End Sub ' OnCheckpointgoto 


'----------------------------------------------------------
'  Show node info
'----------------------------------------------------------
Sub OnCheckpointinfo (name, line, wildcards)
Dim nodes, k, dests, j, nodenum, destnum
  
   nodenum = 0
   destnum = 0
   ArrayClear "cin"  ' ci - nodes
   ArrayClear "cip"  ' ci - paths

   nodes = ArrayListKeys ("map")

   If IsEmpty (nodes) Then
    ColourNote "white", "blue", "No mapping points known."
   Else
  
    For Each k In nodes
     
      nodenum = nodenum + 1
      ArraySet "cin", "N" & nodenum, k

      ColourNote "white", "darkgreen", "N" & Cstr (nodenum) & ". " & k

'
'  Get destinations from this node
'
      ArrayClear "dest"
      ArrayImport "dest", ArrayGet ("map", k), ","

      dests = ArrayListKeys ("dest")
 
      If Not IsEmpty (dests) Then

      For Each j in dests
      
        destnum = destnum + 1
        ArrayClear ""
        ArraySet "", "node", k
        ArraySet "", "dest", j

        '  save both node and path here
        ArraySet "cip", "P" & destnum, ArrayExport ("", ",")

        ColourNote "limegreen", "black", "  P" & _
                   CStr (destnum) & ". " & _
                   j & " = " & ArrayGet ("dest", j)

      Next ' dest
      End If

    Next  ' next node

   End If

End Sub ' OnCheckpointinfo

'----------------------------------------------------------
' delete a checkpoint node or path
'----------------------------------------------------------
Sub OnCheckpointDelete (name, line, wildcards)
dim which, k, node, nodes

  which = UCase (trim (wildcards (1)))

  if which = "ALL" then
    ArrayClear "map"
    ArrayClear "cin"
    ArrayClear "cip"
    ArrayClear "cl"
    ColourNote "white", "red", "ALL mapping points deleted."
    OnClearcheckpoint "", "", ""
    SetVariable "known_room", ""
    SetVariable "known_checkpoint", ""
    SetVariable "known_mapstring", ""
    Exit Sub
  end if

  If left (which, 1) = "N" Then  ' delete node
    
    If not ArrayKeyExists ("cin", which) Then
       ColourNote "white", "red", "Node number " & which & " does not exist"
       Exit Sub
    End If

    node = ArrayGet ("cin", which)

    if not ArrayKeyExists ("map", node) Then
       ColourNote "white", "red", "Map checkpoint [" & node & "] does not exist"
       Exit Sub
    End If

    ArrayDeleteKey "map", node

    ColourNote "white", "blue", "Map checkpoint [" & node & "] deleted."

    nodes = ArrayListKeys ("map")

    If Not IsEmpty (nodes) Then
  
      For Each k In nodes
     
'
'  Get destinations from this node
'
        ArrayClear ""
        ArrayImport "", ArrayGet ("map", k), ","

        If ArrayKeyExists ("", node) Then
          ArrayDeleteKey "", node
          ColourNote "white", "blue", "Path from [" & k & "] " & _
                     "to [" & node & "] deleted."
          ArraySet "map", k, ArrayExport ("", ",")
        End If
 
      Next  ' next node

    End If

    Exit Sub  ' all done
  End If  ' deleting node

  If left (which, 1) = "P" Then  ' delete path
    
    If not ArrayKeyExists ("cip", which) Then
       ColourNote "white", "red", "Path number " & which & " does not exist"
       Exit Sub
    End If

'
'  we stored the path as a node,destination pair
'
    ArrayClear ""
    ArrayImport "", ArrayGet ("cip", which), ","
    node = ArrayGet ("", "node")
    k = ArrayGet ("", "dest")

    if not ArrayKeyExists ("map", node) Then
       ColourNote "white", "red", "Map node [" & node & "] does not exist"
       Exit Sub
    End If

    ArrayClear ""
    ArrayImport "", ArrayGet ("map", node), ","

    If ArrayKeyExists ("", k) Then
      ArrayDeleteKey "", k
      ColourNote "white", "blue", "Path from [" & node & "] " & _
                 "to [" & k & "] deleted."
      ArraySet "map", node, ArrayExport ("", ",")
    End If

    Exit Sub  ' all done
  End If  ' deleting node

  ColourNote "white", "red", "Node number must start with N or P"

End Sub ' OnCheckpointDelete

'----------------------------------------------------------
' room has changed - are we at an existing node?
'----------------------------------------------------------
Sub RoomChanged
dim room

  room = GetVariable ("room")

  If ArrayKeyExists ("map", room) then
'
'  we are at a known node - delete map items so
'  we do not take some tortuous path from here to here
'  

'
'  first, however, save them in case they re-checkpoint this room
'
    SetVariable "known_room", room
    SetVariable "known_checkpoint", GetVariable ("checkpoint")
    SetVariable "known_mapstring", GetMappingString 
   
    DeleteAllMapItems
    ColourNote "white", "blue", "Now at known map node [" & room & "]"
    SetVariable "checkpoint", room
 
  End If

End Sub ' RoomChanged

dim roomnamestyle 
  roomnamestyle = 6

'----------------------------------------------------------
' deduce room name if on same line as prompt
'----------------------------------------------------------
Sub OnGetRoomFromPrompt (name, line, wildcards)
dim lines, styles, text

  line = GetLinesInBufferCount
  styles = GetLineInfo (line, 11)

'
'  Should be 2 styles, the prompt and the room name
'
  If Styles < roomnamestyle Then Exit Sub

'
'  Room name is bold
'
  If Not GetStyleInfo (line, roomnamestyle, 8) Then Exit Sub

'
'  Room name is red text (2) or green text (3)
'
  If Not GetStyleInfo (line, roomnamestyle, 14) = BoldColour (3) Then Exit Sub

'
'  Room name is black background
'
  If Not GetStyleInfo (line, roomnamestyle, 15) = NormalColour (1) Then Exit Sub

'
'  Get name
'

  SetVariable "room", GetStyleInfo (line, roomnamestyle, 1)
  Call RoomChanged
  

End Sub ' OnGetRoomFromPrompt 

'----------------------------------------------------------
' pull in room name from first style on line
'----------------------------------------------------------
Sub OnRoomFromFirstStyle (name, line, wildcards)
dim lines, styles

  line = GetLinesInBufferCount
  styles = GetLineInfo (line, 11)

'
'  Get name
'

  if (trim (GetStyleInfo (line, 1, 1)) <> "") and _
     (GetStyleInfo (line, 1, 2) = 58) then
    SetVariable "room", trim (GetStyleInfo (line, 1, 1))
    Call RoomChanged
  end if
  
End Sub ' OnRoomFromFirstStyle

'----------------------------------------------------------
' cr (room) - manually set room name
'----------------------------------------------------------
Sub OnCheckpointRoom (name, line, wildcards)

  SetVariable "room", trim (wildcards (1))
  ColourNote "white", "blue", "Room name set to " & GetVariable ("room")
  Call RoomChanged

End Sub	' OnCheckpointRoom 

'----------------------------------------------------------
' room change (from trigger)
'----------------------------------------------------------
Sub OnRoomChange (name, line, wildcards)

  SetVariable "room", trim (wildcards (1))
  Call RoomChanged

End Sub	' OnCheckpointRoom 

'----------------------------------------------------------
' use mapper to backtrack to  last node
'----------------------------------------------------------
Sub OnCheckpointGotoNode (name, line, wildcards)
dim mapstring
  
  mapstring = trim (GetMappingString)

  if mapstring = "" then
    colournote "white", "red", "No map path available"
    exit sub
  end if

'
'  try to go back
'
  ColourNote "white", "blue", "Attempting to go to [" & _
     GetVariable ("checkpoint") & "]"

  Send EvaluateSpeedwalk (ReverseSpeedwalk (mapstring))

End Sub ' OnCheckpointGotoNode

]]>
</script>


<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="chelp"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
Sub OnHelp (sName, sLine, wildcards)
  world.Note world.GetPluginInfo (world.GetPluginID, 3)
End Sub
]]>
</script> 

</muclient>

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


119,038 views.

This is page 3, subject is 3 pages long:  [Previous page]  1  2  3 

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.