
These commands let the turtle change the tile to black and increase the turtle's energy by 10. If the tile is green, return true, and then execute the command in (otherwise skip).
The variable name is energy: turtles-own To add a new turtle variable, you need to be at the top of the routine pageĪdd a turbines own declaration, which must precede all routines.
You've seen some built-in turtle variables, such as color. To do this, you need to add a new turtle variable. We track how much energy the turtles haveĭecision. We need a way to control turtle breeding and death. The grass should gradually recover after being eaten. We let turtles eat "grass" (green tiles), reproduce and die. Now add some interaction between the turtle and the tile. The routine setup patches defines all tile colors as green at the beginning.Īt present, turtles can move on the surface, but they do nothing. The new setup refers to two new routines and defines setup patches: to setup-patches Let's give the turtle a better background and make the model a little more interesting. They move aimlessly and have no awareness of the things around them. First, select a random integer between 0 and 359 (random will not return the number you give it), and then turn the degree right.
right random 360 is a command to use the reporter. ask turbines each turbine runs the commands in. So far, you have two routines added by yourself: setup and goĪdd the move turns routine after the go routine: to go Move turbines is not a primitive like clear all (embedded in NetLogo), but a routine you need to add. enter go in the command section instead of setup. The steps are the same as those of the setup button, except for the following: end ends the definition of the "setup" routine. Finally, each turtle uses the first two numbers as input parameters to run the setxy command, which makes the turtle move to the corresponding coordinates. First, each turtle runs reporter random Xcor, which returns a random number in the X coordinate range, and then each turtle runs reporter random ycor, which returns a random number in the Y coordinate range. Unlike the command, the reporter reports only one result. setxy random Xcor random ycor is a command using "reporters". This command causes the turtle to run the command) ask turtles tells each turtle to run the commands in square brackets independently (each command in NetLogo is executed by some subjects. These turtles are at the origin, the center of tile 0,0.
create turtles 100 create 100 turtles. All the tiles turn black and the turtles you have created disappear.īasically, the past is written off to prepare for the operation of the new model. clear all resets the world to the initial, all empty state. to setup starts to define a routine called "setup". All routines begin and end with these two words. The routine starts with to and ends with end. #Netlogo random number code#
Define routines on the code page: to setupĪsk turtles