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
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Wed Sep 08, 2004 4:43 pm   

Explore all mapped rooms
 
I changed my auto-mapping script to be able to do auto-exploring. The algorithm used is depth-first search adapted to work with graphs.

#CLASS {mapexplorer} {setdef}
#ALIAS
 explore {
  #priority
 {
    #echo
 exploring
    #noop
 // Is there some unexplored exit in this room?
    #if
 ((@lastroom=%roomnum( )) and (@recovering="false")) {
      #echo
 I am stuck! Trying to recover!
      #stop

      #nodir

      #find

      recovering
=true
      
} {
      #if
 (@recovering="true") {
        unexplored 
= %delitem( @lastroom, @unexplored)
        ignorerooms
=%push( @lastroom|@lastexit, @ignorerooms)
        recovering
=false
        
}
      
}
    explored
=%push( %roomnum( ), @explored)
    counter
=0
    exit
=%item( exits, @counter)
    #forall
 @exits {
      #if
 (%roomlink( , %i) > 0) {
        #if
 (not %ismember( %roomnum( )|%i, @ignorerooms) and not %ismember( %roomlink( , %i), @explored)) {
          exit
=%i
          counter
=%eval( @counter+1)
          
}
        
}
      
}
    #if
 (@exit!=%null) {
      #noop
 // We found an exit. If we have unexplored exits left add this location to the 'unexplored' list.
      #if
 (@counter>1) {unexplored=%push( %roomnum( ), @unexplored)}
      lastroom
=%roomnum( )
      lastexit
=@exit
      #exec
 @exit
      
} {
      #noop
 // No exit found. Do we have any in the 'unexplored' list?
      #if
 (@unexplored!=%null) {
        roomnumber
=%pop( unexplored)
        lastroom
=%roomnum( )
        #echo
 Walking to @roomnumber from %roomnum( )
        #walk
 @roomnumber
        
} {
        #echo
 Exploration Finished
        #t
- autoexplorer
        
}
      
}
    
}
  
}
#VAR
 unexplored {}
#VAR
 exits {north|south|east|west|up|down}
#VAR
 ignorerooms {}
#VAR
 lastexit {west}
#VAR
 lastroom {198}
#VAR
 recovering {false}
#VAR
 explored {}
#ALARM
 "autoexplorer" {-1} {#if (%inwalk( )!="1") {explore}} "" {disable}
#BUTTON
 1 {Auto-map} {
  unexplored
=""
  ignorerooms
=""
  lastexit
=""
  lastroom
=""
  recovering
=false
  explored
=""
  #t
+ autoexplorer
  
} {} {#t- autoexplorer} {%class(autoexplorer)} {1} {} {} {} {} {} {} {} {} {} {} {} "" {} {} {autoexplorerbutton}
#CLASS
 0
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