Turtles, patches and their moving sequentially from one patch to the next

邮差的信 提交于 2019-12-19 11:58:30

问题


Platfrom : NetLogo

  • Question

I want to move my flag specific 3 point

  • A(-12 8)
  • B(-5 12)
  • C(6 4)

-While travelling this point plot energy/time randomly decrease.

-When reach C flag will die.

I asked before and found this solution for moving. ( When turtle reached 2. point it will not stop ) - LINES1 -

breed [cities city]
breed [flag person]
flag-own [target]
to setup
  clear-all

  create-flag 1
  [ set size 6
    set shape "by"
    setxy -5 3
    set target patch -10 5
    face target
  ]

  < other commands >
end

to go
  ask flag-on patch -10 5
  [ set target patch <next place you want it to go>
    face target
  ]
  ask flag with [ shape = "by" ]
  [ forward 1 ]
end

People suggest this code for towarding any target.

    to go
      ask people [
        ;; if at target, choose a new random target
        if distance target = 0
          [ set target one-of houses
            face target ]
        ;; move towards target.  once the distance is less than 1,
        ;; use move-to to land exactly on the target.
        ifelse distance target < 1
          [ move-to target ]
          [ fd 1 ]
      ]
      tick
    end

In this code they will travel randomly and i dont want this. I cant implement this part at -LINES1-

I'm try to explain this with an image.

Well, this is the question : How can i move turtle along these points and connect the graph for energy/time or energy/distance.

CC : @Seth Tisue @JenB @yacc

UPDATE 1

-Guys i finished my movement part of my program aid of community. In this code your turtle will move specific point and it will die when it reach last point. While travel it is plotting the number of turtle

    breed [cities city]
    breed [flag person]
    flag-own [target]   ;;set features flag only


    to setup
     clear-all
     reset-ticks
     print "Setting up model."
     set-default-shape cities "house"  ;; set all cities shape by house

      create-flag 1
      [ 
        set SIZE 2
        set shape "turtle"
        setxy -11 13
        set target patch -3 12
        face target

      ]

     create-cities 1
        [set color yellow set SIZE 2 setxy 8 2]
    create-cities 1
        [ set color yellow set SIZE 2 setxy -3 12]
      create-cities 1
        [ set color yellow set SIZE 2 setxy 3 3]


    ask patch 3 3 [set pcolor red]
    end
    to go
      ask flag-on patch -3 12 [
        set target patch 8 2
        face target
      ]

      ask flag-on patch 8 2 [
       set target patch 3 3

        face target
      ]

      ask flag-on patch 3 3 [
       if distance target < 1    ;; check distance for last point
            [die]]




      ask flag with [ shape = "turtle" ]
      [fd 1]

 tick
end

回答1:


Have you tried to understand the answers you have already been given? In the setup, replace -10 5 with the first place you want to go to (which is -12 8). Then update the go code accordingly.

to go
  ask flag-on patch -12 8
  [ set target patch -5 12
    face target
  ]
  ask flag-on patch -5 12
  [ set target patch 6 4
    face target
  ]
  ask flag with [ shape = "by" ]
  [ forward 1 ]
end

This is just the direction and moving. You need to try and do some code for the energy and dying etc. But do things gradually, get something working and then add the next piece.



来源:https://stackoverflow.com/questions/47521102/turtles-patches-and-their-moving-sequentially-from-one-patch-to-the-next

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!