title: NetLogo: ask turtle to set destination and keep walking towards it until reached
body: <p><strong>Goal:</strong> I am attempting to make a turtle pick a destination, then continue walking towards it until the destination is reached. At that point, the turtle returns to its original patch and picks another destination, walks towards it, repeat. </p>
  
  <p><strong>Issue:</strong> The selected destination sometimes changes while the turtle is walking towards it. I need some means of telling the turtle to hold the original destination until it reaches it. </p>
  
  <p><strong>Details:</strong> Here is my relevant code. Turtles are building territories. They have a territory center-point ("start-patch") from which they choose a destination to walk to and claim. Destination is based on the patch with "highest-value" where value should be the patch's benefit ("benefit-to-me") divided by the distance away from the start-patch ("cost-to-me"). I think turtles are constantly reassessing cost-to-me while walking, however. They shouldn't do this--highest-value must be assessed while standing on the start-patch. </p>
  
  <p>How can I fix this so a turtle assesses highest-value while standing on the start-patch, sets a destination, and moves towards it until reached? </p>
  
  <pre><code>patches-own
  [
    owner  ;; once part of a territory, owner becomes the turtle.
    benefit  ;; i.e., food available in a patch; used to assess "highest-value" to the turtle.
  ]
  
  turtles-own
  [
    start-patch  ;; the territory center; turtle returns here after reaching destination.
    destination  ;; the patch turtle wants to claim for its territory. 
    territory  ;; the patches the turtle owns.
  ]
  
  to go
     tick
     ask turtles
      [
       pick-patch
      ]
  end
  
  to pick-patch
       set destination highest-value  ;; calculated in reporters, below.
       ifelse destination != nobody [
         ask destination [set pcolor red]  ;; reveals that destination changes occasionally before original destination is reached.
         travel]  
       [give-up]  ;; (will reposition start-patch to a new site if no destinations available.)
  end
  
  to travel
       face destination forward 1   ;; **should** keep original destination, but it doesn't.
       if patch-here = destination
         [update-territory  
          move-to start-patch ]  ;; return to the start-patch, and should only NOW assess new destination.             
  end
  
  to update-territory
       set owner self ;; and so on....
  end
  
  ;;;---Reporters for highest-value:---
  
  to-report highest-value    ;; this appears to be changing while turtle moves...how fix this?
       let available-destinations edge-patches      
       report max-one-of available-destinations [benefit-to-me / cost-to-me]         
  end
  
  to-report benefit-to-me
       report mean [benefit] of patches in-radius 1  ;; i.e., moving window to find high-benefit cluster
  end
  
  to-report cost-to-me
       report distance myself
  end
  
  to-report edge-patches
       report (patch-set [neighbors4] of territory) with [owner = nobody]
  end
  </code></pre>
  
  <p>(<em>Note:</em> instead of "forward 1," I realize I could just use "move-to." I will eventually build in obstacles, however, and turtles will need to walk towards the destination to check for obstacles.) </p>
  
  <p><strong>Update:</strong> I think the issue could be addressed within the "cost-to-me" reporter? I tried making this change:</p>
  
  <pre><code>to-report cost-to-me
       report distance [start-patch] of myself
  end
  </code></pre>
  
  <p>Should this accomplish what I'm after? It would take away the "distance myself" part so that this cost remains constant. The other idea I've had is that "pick-patch" or "travel" may need something along the lines of "ifelse patch-here != destination [forward 1...]" but that doesn't seem to work either. </p>
  
  <p>I tried the "while" loop idea recommended below (thanks!) and that seems to introduce a new host of odd behavior. I'm not sure how to code that out if I go that route. Something like this doesn't work (they just stop moving):</p>
  
  <pre><code>to travel
       while [distance destination &gt; 1] 
       [face destination forward 1]  
       if patch-here = destination
         [update-territory  
          move-to start-patch ]     
  end
  </code></pre>
  
  <p>I'm new to this; thanks in advance for any help!</p>
  
  <p><strong>Second update:</strong> I think that the change I made in the previous update (<em>report distance [start-patch] of myself</em>) fixed part of my problem (assuming that line makes sense?), but left one issue. If there is a tie among patches with highest-value, the turtle still switches destination midway to its selected patch. So it still goes back to the original problem of having the turtle set and keep a destination until it is reached. Any ideas on how to fix this? </p>