logo
down
shadow

A dictionary controls a turtle's movement


A dictionary controls a turtle's movement

By : Ramon Antonio
Date : November 20 2020, 03:01 PM
should help you out Specific problems with your code: The asterisk in front of the cmd argument is incorrect:
code :
def execute(turtle, length, args, *cmd):
execute(bob, 50, 45, 'fdltfd')
map = {'fd': turtle.fd(length), 'lt': turtle.lt(args), 'bk': turtle.bk(length), 'rt': turtle.rt(args), 'nop':None}
commands = {'fd': turtle.fd, 'lt': turtle.lt, 'bk': turtle.bk, 'rt': turtle.rt, 'nop': None}
LENGTH = 50
ANGLE = 45

commands = { \
    'fd': lambda t: t.fd(LENGTH), \
    'lt': lambda t: t.lt(ANGLE), \
    'bk': lambda t: t.bk(LENGTH), \
    'rt': lambda t: t.rt(ANGLE), \
    }
for command in cmd:
# 'fdltfd' -> ['fd', 'lt', 'fd']
for command in [a + b for a, b in zip(cmd[0::2], cmd[1::2])]:
import turtle

LENGTH = 50
ANGLE = 45

commands = { \
    'fd': lambda t: t.fd(LENGTH), \
    'lt': lambda t: t.lt(ANGLE), \
    'bk': lambda t: t.bk(LENGTH), \
    'rt': lambda t: t.rt(ANGLE), \
    }

def execute(my_turtle, cmd):
    for command in [a + b for a, b in zip(cmd[0::2], cmd[1::2])]:
        if command in commands:
            commands[command](my_turtle)

execute(turtle.Turtle(), 'fdltfdltfdltfdltfdltfdltfdltfd')

turtle.mainloop()


Share : facebook icon twitter icon
asking red turtles to avoid other turtles and move to one of its neighbor which is empty and has highest conc

asking red turtles to avoid other turtles and move to one of its neighbor which is empty and has highest conc


By : Pat
Date : March 29 2020, 07:55 AM
Does that help I think your code would read a little nicer if you used let to avoid repetition, like this:
code :
let target max-one-of neighbors [conc]
if [conc] of target > conc [
  face target
  move-to target
]
ask turtles with [color = red] [
  let targets neighbors with [not any? turtles-here]
  let target max-one-of targets [conc]
  if target != nobody and [conc] of target > conc [
    face target
    move-to target
  ]
]
NetLogo asking turtles to hatch based on total number of turtles created during setup

NetLogo asking turtles to hatch based on total number of turtles created during setup


By : Dhanashri Haldankar
Date : March 29 2020, 07:55 AM
Hope that helps If I understood you correctly, all you need is to store the number of preys at setup in a global variable.
You can declare it like this at the top of your program:
code :
globals [ initial-number-of-preys ]
set initial-number-of-preys count preys
if count preys < initial-number-of-preys
How do I make turtles move with ranked movement order based on an owned trait?

How do I make turtles move with ranked movement order based on an owned trait?


By : Neeson
Date : March 29 2020, 07:55 AM
this will help You may want to sort the turtles by their score and iterate over the resulting list asking each turtle to move.
code :
 foreach sort-on [score] turtles [ ask ? [ move]]
Movement of turtles between nodes following the shortest path

Movement of turtles between nodes following the shortest path


By : Sherest Dutt
Date : March 29 2020, 07:55 AM
help you fix your problem You may want to use the nw extension to take advantage of the nw:turtles-on-path-to or nw:turtles-on-weighted-path-to primitives. With these extensions and variables:
code :
extensions [nw]
breed [ nodes node ]
breed [ walkers walker ]
links-own [ weight ]
to setup-example
  ca
  let xs [ 10 -5 -5 -5 -5 2 ]
  let ys [ 0 0 3 6 9 9 ]
  ( foreach xs ys [
    [ x y ] ->
    ask patch x y [
      sprout-nodes 1 [
        set shape "circle"
        set color white
        set size 2.5
      ]
    ]
  ])
  let ind ( range 0 4 )
  foreach ind [
    i ->
    let x item i xs
    let y item i ys
    let xn item ( i + 1 ) xs
    let yn item ( i + 1 ) ys
    ask nodes-on patch x y [
      create-links-with nodes-on patch xn yn
    ]
  ]
  while [ any? nodes with [ count my-links < 2 ] ] [
    ask one-of nodes with [ count my-links < 2 ] [
      let linkable min-one-of other nodes with [ count my-links < 2 ] [distance myself]
      if linkable != nobody [
        create-link-with linkable
      ]
    ] 
  ]
  ask nodes-on patch -5 0 [ set color green ]
  ask nodes-on patch 2 9 [ set color red ]  
end
to fewest-links
  let start one-of nodes-on patch -5 0
  let target one-of nodes-on patch 2 9

  let path nobody 
  ask start [
    set color green
    set path but-first nw:turtles-on-path-to target
    ask turtle-set path [ set color yellow ]
    ask target [ set color red ]
  ]  
end
to shortest-distance
  let start one-of nodes-on patch -5 0
  let target one-of nodes-on patch 2 9
  ask links [ 
    set weight link-length
  ]
  let path nobody 
  ask start [
    set color green
    set path but-first nw:turtles-on-weighted-path-to target weight
    ask turtle-set path [ set color yellow ]
    ask target [ set color red ]
  ]  
end
to setup
  ca
  create-nodes 10 [ 
    set shape "circle" 
    set color white 
    set size 2.5
  ]
  layout-circle nodes 10
  while [ any? nodes with [ count my-links < 2 ] ] [
    ask one-of nodes with [ count my-links < 2 ] [
      let linkable min-one-of other nodes with [ count my-links < 2 ] [distance myself]
      if linkable != nobody [
        create-link-with linkable
      ]
    ] 
  ]
  ask one-of nodes [ 
   set color green + 1
   hatch-walkers 1 [
      set color blue
      set size 1.5
    ]
  ] 
  reset-ticks
end
to go
  ask walkers [
    ; Randomly choose a target node to walk to
    let target one-of nodes with [ color = white ]
    if target != nobody [
      ; Remember the starting node
      let current one-of nodes-here 
      ; Define a path variable from the current node- take all but
      ; the first item (as first item is current node)
      let path nobody
      ask links [ set weight link-length ]
      ask current [ 
        set path but-first nw:turtles-on-weighted-path-to target weight
      ]
      ; Indicate the end node
      ask last path [ 
        set color red
        set size 2.5
      ]
      ; Move along the path node-to-node 
      foreach path [
        next-target ->
        face next-target
        move-to next-target
        wait 0.25
        ask next-target [
        set color yellow
        ]
      ]
    ]
    wait 1
    ; Reset
    ask nodes [ set color white ]
    ask one-of nodes-here [ set color green ]
  ]
end
How to ask turtles to turn at the intersection point of patches where turtles are arriving from three direction

How to ask turtles to turn at the intersection point of patches where turtles are arriving from three direction


By : Ms Ahmed
Date : March 29 2020, 07:55 AM
I hope this helps . I ran your code with the speed slowed down and a single person created. I don't think the problem is your random direction creation - it is that the speed means that the person spends multiple ticks on the intersection and only leaves when the random direction generated moves them down again. For example, the agent enters the intersection with a heading of 0 and gets random heading 90 so moves to the right by some distance < 1 (from speed) and IS STILL IN THE INTERSECTION, so gets a new random heading say 90, still in intersection, then gets 270 so still in intersection and then gets 180 so leaves.
One way to fix this is to create a counter / flag. It gets set on reaching the intersection and the intersection is not checked if the flag is still set.
Related Posts Related Posts :
  • Element disappears when I add an {% include %} tag inside my for loop
  • Django Rest Framework with either a slug or a pk lookup field for the DetailAPIView
  • Flask doesn't stream on Lambda
  • Generate all permutations of fixed length where the elements come from two different sets
  • Making function for calculating distance
  • How to handle multiprocessing based on the limit of CPU's
  • Django - static files is not working
  • Remove x axis and y axis black lines with matplotlib
  • tkinter: assigning multiple functions to one button
  • flask-jwt-extended: Fake Authorization Header during testing (pytest)
  • Setting pandas dataframe value based on row and column conditions
  • swig char ** as a pointer to a char *
  • Confusion over `a` and `b` attributes from scipy.stats.uniform
  • How can I do groupy.apply() without sort my index?
  • Querying Google Cloud datastore with ancestor not returning anything
  • Read value from one thread in Python: queue or global variable?
  • Django - context process query being repeated 102 times
  • Convert a list of images and labels to np array to train tensorflow
  • Lambda not supporting NLTK file size
  • Numpy ndarray image pixel mean for pixel values greater than zero: Normalizing image
  • Understanding output of np.corrcoef for two matrices of different sizes
  • Finding longest perfect match between two strings
  • what is wrong with my cosine similarity? Tensorflow
  • How to manage user content in django?
  • Receiving unsupported operand error while comparing random number and user input.
  • How to wrap the process of creating start_urls in scrapy?
  • How to mark 'duplicated sequence' in pandas?
  • Boolean indexing on multidimensionnal array
  • Unmodified column name index in patsy
  • Cleaner way to unpack nested dictionaries
  • Importing a python module to enable a script to be run from command line
  • Maya Python read and set optionMenu value via variable
  • How can I bind a property to another property in Kivy?
  • Python extracting specific line in text file
  • How to implement n-body simulation with pymunk?
  • Python / matplotlib: print to resolution and without white space / borders / margins
  • Sum up the second value from one dictionary with all values from another dictionary
  • Robot Framework: Open a chrome browser without launching URL
  • Generate inline Bokeh scatterplots in Jupyter using a for loop
  • Group list of dictionaries python
  • Efficient way to apply multiple Boolean mask to set values in a column using pandas
  • Lazy evaluation of a Python dictionary
  • id of xpath is getting changed every time in selenium python 2.7 chrome
  • Matplotlib RuntimeWarning displaying a 3D plot
  • Cannot install pyqt5 for python3.4 on windows 10
  • Gravity Problems
  • Where to position `import` modules inside an class?
  • Python OpenCV: Cannot resize image
  • Print on the same spot in IPython console
  • Disable logging except in tests
  • Writing json to file in s3 bucket
  • Sorting numpy array created by laspy
  • Open an XML file through URL and save it
  • How to build a 2-level dictionary?
  • error installing scipy using pip on windows 10
  • __str__ from my own matrix, python
  • python re how to Extract fields use findall()?
  • how to read a value from text HI file using python?
  • How to use horizontal scrolling in treeview,here i use tree view to make a table
  • Dependant widgets in tkinter
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org