Marwa
Marwa

Reputation: 159

How to move turtles between neighbors on a hex grid?

I want to ask how to move turtles to their neighbors. ( the houses are hex cells) I tried to make it but give me an error.

;;;;;;;;;;;;;to make houses or the hex cells

 to setup-cells
 set-default-shape cells "hex"
 ask patches
 [ sprout-cells 1
 [ set color grey
  set size 1.2
  ;; shift even columns down
  if pxcor mod 2 = 0
  [ set ycor ycor - 0.5 ] ] ]
  ask cells
  [ ifelse pxcor mod 2 = 0
  [ create-links-with cells-on patches at-points [[0 1] [1 0] [1 -1]] ]
  [ create-links-with cells-on patches at-points [[0 1] [1 1] [1 0]] ] ]
  ask links [ hide-link ]
  end

;;;;; I add turtles to their houses

to setup-population
ask patches [
 sprout 2 
    if pxcor mod 2 = 0
    [ set ycor ycor - 0.5 ]]
end 

my question is how to move this turtle to the link neighbors

I tried to do this

to move 
 ask turtles[
   if ( random-float 1) < 0.03  [
 move-to one-of link-neighbors
fd 1 ]]
 end

but this always give me an error

move-to expected input to be agent but got nobody instead

Upvotes: 0

Views: 506

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30453

Great question. It's too bad this isn't covered in Hex Cells Example (the code example you seem to be working from). Or maybe we should have a separate Hex Cells With Turtles Example.

First, you should make a separate breed for the turtles that live in the houses, so you can refer to them separately from the cell turtles. Suppose you call them people:

breed [people person]

then you should change sprout 2 to sprout-people 2.

As for implementing movement, the code you tried doesn't work because people don't have link-neighbors. It's the cells that have link-neighbors.

So instead of:

move-to one-of link-neighbors

you must write:

move-to [one-of link-neighbors] of one-of cells-here

If you want the people to face in the direction of movement, then it's:

let target [one-of link-neighbors] of one-of cells-here
face target
move-to target

Upvotes: 1

Related Questions