$SET_INT DEFAULT_MAX_ITERATIONS 50 proc "safe_to_jump": # Optional inputs if: not: exists procvar("max_iterations") then: set procvar("max_iterations"): $GET_INT DEFAULT_MAX_ITERATIONS # Uncomment this here, or set it before calling this proc, to see a # bunch of debug printing... #set procvar("debug"): T # Stuff we "return" to caller # NOTE: the "_reason" is for unit testing purposes! set myvar("safe_to_jump"): F set myvar("_reason"): null # NOTE: we move the location by (1 0) right off the bat, because we # assume that our current location would already be safe to land on! set procvar("location"): myvar(".loc") move procvar("location"): 1 0 if: expr: procvar("debug") then: print: "Checking jump safety..." set procvar("iterations"): 0 while: expr: T do: # Avoid infinite loops inc procvar("iterations") if: expr: >= procvar("iterations") procvar("max_iterations") then: if: expr: procvar("debug") then: print: "INFINITY!" set myvar("_reason"): "infinity" break # Not safe to jump, because we would crash into something? if: coll: any yes at procvar("location") ;; *\*/* ;; - + - ;; */*\* ;; ( ) then: if: expr: procvar("debug") then: print: "CRASH!" set myvar("_reason"): "crash" break # It might or might not be *safe* to jump, but we are not *allowed* # to make this jump! if: exists procvar("not_allowed_colltag") coll: any yes colltag: procvar("not_allowed_colltag") at procvar("location") ;; *\*/* ;; - + - ;; */*\* ;; ( ) then: if: expr: procvar("debug") then: print: "NOT ALLOWED!" set myvar("_reason"): "not_allowed" break # Safe to jump, because we can land here? if: all: # Make sure this isn't the first iteration, because after pressing # jump, we always travel a distance of at least one. expr: > procvar("iterations") 1 coll: all yes at procvar("location") ;; (+)- + then: if: expr: procvar("debug") then: print: "SAFE!" set myvar("safe_to_jump"): T break # Deflected upwards? if: coll: all yes at procvar("location") ;; + ;; ;; ( ) + then: if: expr: procvar("debug") then: print: "DEFLECTED!" move procvar("location"): 1 0 rot procvar("location"): 1 continue # Move forward and repeat! if: expr: procvar("debug") then: print: "FORWARD!" move procvar("location"): 1 0