How can I create territories for several groups of agents in netlogo? - netlogo

I'm very new to Netlogo, and this is my very first post in a forum.
I need to create animal agent groups which move in habitats or territories. The territories can overlap. More precisely I need male agents that move in different territories and several groups of female agents which move in other territories.
This is what I did so far. I created a territory just for one group of females and one group of males. Thats not exactly what I need.
globals [fragments]
breed [preys prey]
breed [femaletigers femaletiger]
breed [kids kid]
breed [maletigers maletiger]
turtles-own
[
energy
age
gender
territory
]
to setup
clear-all
setup-fragments
;setup-habitats
setup-turtles
reset-ticks
end
to setup-fragments
ask patches[set pcolor 67]
repeat 50
[
ask one-of patches
[
set pcolor brown
repeat 30
[
let a random 360
let b random 5
ask patch-at-heading-and-distance a b
[
ask neighbors [ set pcolor brown]
set pcolor brown
]
]
]
]
end
to setup-turtles
set-default-shape femaletigers "default" ; default shape (dreieck)
create-femaletigers 10
[
set color red
set size 1.5
set energy 100
set age random 20
set gender "female"
set territory patches-in-territory patch 10 6 15
move-to one-of territory with [pcolor = 67 ] ; tigers start in territory but not on fragmented areas
]
set-default-shape maletigers "default" ; default shape (dreieck)
create-maletigers 10
[
set color blue
set size 1.5
set energy random 100
set age random 20
set gender "male"
set territory patches-in-territory patch 40 15 10
move-to one-of territory with [pcolor = 67 ] ; tigers start in territory but not on fragmented areas
]
set-default-shape preys "circle"
create-preys 100
[
move-to one-of patches with [pcolor = 67] ;preys don't start in fragmented areas
set color 114
set size 0.75
]
end
to-report patches-in-territory [Center rd]
let ptr []
ask Center [set ptr patches in-radius 20]
report ptr
end
I'm thankful for any help.
Maria

welcome to Stack Overflow. When posting on here, in general you will be better served by restricting your code to just the bare minimum needed to demonstrate your issue (see the MCVE guidelines here); for example you could remove your to-report, prey breeds, etc just to make it very obvious what you're trying to solve.
I'm not following your code exactly as I'm not sure of some of your overall goal- instead I give an alternative example that will hopefully illustrate one way to accomplish what you're after. I'll show an example of territories that can overlap for females in this example and of territories that cannot overlap, for males in this example. Using these variables and setup:
breed [ femaletigers femaletiger ]
breed [ maletigers maletiger ]
turtles-own [ territory ]
patches-own [ maleclaimed? ]
to setup
ca
ask patches [
set maleclaimed? false
]
create-maletigers 3 [
set shape "triangle"
set size 1.5
move-to one-of patches with [ maleclaimed? = false ]
pd
set territory patches in-radius 5 with [ maleclaimed? = false ]
ask territory [
set maleclaimed? true
]
]
create-femaletigers 3 [
set shape "square"
setxy random-xcor random-ycor
pd
set territory patches in-radius 3
hatch 1 + random 3 [
rt random 360
fd 1
]
]
reset-ticks
end
In the setup, the patches-own boolean indicates if a patch has been claimed by a male- set it to false to start so that a male can check, as it sets up its territory, whether a patch is already claimed or not. Tigers then set up their territories similar to how you did, except males will not select territory from another male. Females set up their territory then hatch a few more females that will share the territory of the "mother".
To move within their territory, just restrict turtles such that they can only move to one of their territory patches- here is one way to do that:
to go
ask turtles [
let target one-of territory in-radius 1.5
if target != nobody [
face target
fd 1
]
]
tick
end
If you want to confirm that the turtles stay within a territory, run something like:
to territory-check
ask turtles [
let col color + 2 + random 3
ask territory [
set pcolor col
]
]
end

Thanks again. What is when the tigers reproduce and I want their kids to create a new territoy and the territories should not overlap?
to move-male
ask maletigers [
let target1 one-of territory in-radius 2
if target1 != nobody [
face target1
fd 1]]
end
to reproduce-tiger
if age >= 48 and any? maletigers-on patch-here and pcolor = 67 [
hatch random 1 + random (5 - 1) [
set gender one-of [ "male" "female" ]
set breed kids
fd random-float 2 ]]
end
to search-territory-male
ask maletigers with [ territory = nobody ] [
if maleclaimed? = false [
set territory patches in-radius 18 with [ maleclaimed? = false ]
ask territory [ set maleclaimed? true ]]]
end

Related

How to get turtles to move to the target?

I'm stumped with an issue in my model. I have a model that looks to simulate an office environment, where there are two breeds: employees and citizens. The employees stay in the office, denoted by grey coloured patches, and the citizensstay in the outside world denoted by black colour patches.
In the middle of the world patch 0 0 there is an office, where employees go to pick up money. There are 4 service-desks where both employees and citizens are to meet for a transfer of money to occur. Here is the full code:
globals [ office-space ]
breed [ offices office ]
breed [ service-desks service-desk ]
breed [ employees employee ]
breed [ citizens citizen ]
offices-own [ money ]
employees-own [ money-held ]
citizens-own [ money-received ]
to setup
clear-all
create-offices 1
ask offices [
set shape "building institution"
set size 4
set color yellow
set money num-of-money ]
create-employees num-of-employees
ask employees [
set shape "person"
set size 1.5
set color blue
setxy random-xcor random-ycor ]
create-citizens num-of-citizens
ask citizens [
set shape "person"
set size 1.5
set color white
setxy random-xcor random-ycor ]
;; create four service desks
ask patch 0 8 [
sprout 1 [
set breed service-desks
set shape "building institution"
set color pink
set size 3 ]
]
ask patch 0 -8 [
sprout 1 [
set breed service-desks
set shape "building institution"
set color pink
set size 3 ]
]
ask patch -8 0 [
sprout 1 [
set breed service-desks
set shape "building institution"
set color pink
set size 3 ]
]
ask patch 8 0 [
sprout 1 [
set breed service-desks
set shape "building institution"
set color pink
set size 3 ]
]
;; create office space
set office-space patches with [ pxcor <= 8 and pxcor >= -8 and pycor <= 8 and pycor >= -8 ]
ask office-space [ set pcolor grey]
place-on-color-employees ;; sets all employees randomly within the grey square
place-on-color-citizens ;; sets citizens randomly outside of the grey box
reset-ticks
end
to place-on-color-employees
let _patches (patches with [pcolor = grey])
ask employees [
move-to one-of (_patches with [not any? turtles-here])
]
end
to place-on-color-citizens
let _patches (patches with [pcolor = black])
ask citizens [
move-to one-of (_patches with [not any? turtles-here])
]
end
to go
employee-movement
employee-take-money
citizen-movement
tick
end
to employee-movement
ask employees [
ifelse [pcolor] of patch-ahead 1 = black
[ rt random-float 360]
[ forward 1 ]
let target one-of citizens
if money-held > 0 [
set heading (towards target)
]
]
end
to citizen-movement
;; citizens walk only in the black patches, they do not go into the office area
ask citizens [
ifelse [pcolor] of patch-ahead 1 = grey
[ rt random-float 360]
[ forward 1 ]
;; if they have no money, then the citizens will walk to one of the service-desks
let target one-of service-desks
if money-received = 0 [
set heading (towards target )
]
]
end
to employee-take-money ;; asks employees to go to the main office and get money
ask employees [
if any? turtles-here with [ shape = "building institution" and color = yellow] [
set money-held money-held + 1
set color green ]
]
end
The issue I have is that within the employee-movement function, the employees will not move towards their targets. Whereas, the citizens will move to their targets. The code for both breeds is basically the same. The employees tend to congregate around the central patch, rather than moving to the targets.
Edited after receiving the full code:
The problem lies with how you define target as a local variable (let target one-of service-desks) each time you call the code. However, since there is more than one service-desk, nothing is forcing them to choose the same service-desk each time. This means that the employees, who are standing in the middle of the four service-desks, are basically taking a step in a random direction at each tick. The citizens on the other hand stand outside of the square on which the service-desks are located. Because of that, all of the service-desks are roughly in the same direction for them, so their general movement also goes in that direction.
I see two different options for working around this. The first one is to not use let target one-of service-desks but use let target min-one-of service-desks [distance myself]. This moves them to the closest service-desk rather than to a random service desk.
The other option would be to set target as a turtles-own variable, and not letting them choose a new one all the time.
Finally I streamlined your setup a little bit, reducing the amount of code you needed.
globals [
office-space
num-of-money
num-of-employees
num-of-citizens
]
breed [ offices office ]
breed [ service-desks service-desk ]
breed [ employees employee ]
breed [ citizens citizen ]
offices-own [ money ]
employees-own [ money-held ]
citizens-own [ money-received ]
to setup
clear-all
set num-of-money 100
set num-of-employees 5
set num-of-citizens 5
create-offices 1 [
set shape "building institution"
set size 4
set color yellow
set money num-of-money
]
create-employees num-of-employees [
set shape "person"
set size 1.5
set color blue
setxy random-xcor random-ycor
]
create-citizens num-of-citizens [
set shape "person"
set size 1.5
set color white
setxy random-xcor random-ycor
]
;; create four service desks
let service-desk-patches (patch-set patch 0 8 patch 8 0 patch 0 -8 patch -8 0)
ask service-desk-patches [
sprout-service-desks 1 [
set shape "building institution"
set color pink
set size 3
]
]
;; create office space
set office-space patches with [ pxcor <= 8 and pxcor >= -8 and pycor <= 8 and pycor >= -8 ]
ask office-space [ set pcolor grey]
place-on-color-employees ;; sets all employees randomly within the grey square
place-on-color-citizens ;; sets citizens randomly outside of the grey box
reset-ticks
end
to place-on-color-employees
let _patches (patches with [pcolor = grey])
ask employees [
move-to one-of (_patches with [not any? turtles-here])
]
end
to place-on-color-citizens
let _patches (patches with [pcolor = black])
ask citizens [
move-to one-of (_patches with [not any? turtles-here])
]
end
to go
employee-movement
employee-take-money
citizen-movement
tick
end
to employee-movement
ask employees [
ifelse [pcolor] of patch-ahead 1 = black
[ rt random-float 360]
[ forward 1 ]
let target min-one-of citizens [distance myself]
if money-held > 0 [
set heading (towards target)
]
]
end
to citizen-movement
;; citizens walk only in the black patches, they do not go into the office area
ask citizens [
ifelse [pcolor] of patch-ahead 1 = grey
[ rt random-float 360]
[ forward 1 ]
;; if they have no money, then the citizens will walk to one of the service-desks
let target min-one-of service-desks [distance myself]
if money-received = 0 [
set heading (towards target )
]
]
end
to employee-take-money ;; asks employees to go to the main office and get money
ask employees [
if any? offices-here [
set money-held money-held + 1
set color green ]
]
end

How do you fix a problem with convert probability on a zombie apocalypse simulation on Netlogo [duplicate]

This question already has an answer here:
How do you go about making a convert probability chance for an agent in netlogo?
(1 answer)
Closed 1 year ago.
currently I'm working on a zombie apocalypse simulation on Netlogo, and I'm almost done except that the convertion function is not working. when the zombies collide with humans the humans they either die or convert the human to a zombie according to the global variable convert_probability. For example, if convert probability is set to 80 the human would have an 80% chance of winning the fight and killing the zombie and the zombie would have a 20% chance of converting the human to a zombie.
Also, zombies and humans are not allowed to pass over the brown patches and the function I wrote for that is change_direction, but had to comment those parts because I run to an error.
I have spent hours but couldnt come up with a solution so I would really appreciate any help;
breed [humans human]
humans-own [ humans_speed]
turtles-own [
infected?
]
patches-own [
block
]
breed [zombies zombie]
zombies-own [ zombies_speed]
globals [
student_id
username
nzomb
%infected
]
to setup_world
clear-all
reset-ticks
set student_id 19009670
ask patches [set pcolor green]
set-default-shape zombies "person"
set-default-shape humans "person"
create-zombies 5 [
set color red
set size 4
set zombies_speed 0.5
setxy random-pxcor random-pycor
]
ask zombies[
move-to one-of patches with [pcolor = green]
]
create-humans 15 [
set color blue
set size 4
set humans_speed 1 + random-float 0.1
setxy random-pxcor random-pycor
]
ask humans[
move-to one-of patches with [pcolor = green]
]
set %infected (count turtles with [color = red ] / 20 ) * 100
set nzomb 0
draw_blocks
end
to draw_blocks
ask patches [
set block false
]
ask n-of 100 patches with [pcolor = green][
set pcolor brown
set block true
]
end
to change_direction
if[block] of patch-ahead 2 = true [
right 180
face one-of patches in-radius 2 with [not block]
]
end
to run_model
if ticks >= 10000 [ stop ]
tick
move-turtles
convert
if not any? humans [stop]
end
to move-turtles
ask humans [move-humans]
ask zombies [move-zombies]
end
to move-humans
ask humans [
if any? zombies in-radius (10 + random 20) [rt 180]
set infected? false
set heading (heading + 45 - (random 90))
forward 1 + random-float 1.1
zombiedeath
convert
;;change_direction
]
end
to move-zombies
ask zombies [
chasehuman
convert
zombiedeath
set %infected (count turtles with [color = red ] / 20 ) * 100
set infected? true
set heading (heading + 45 - (random 90))
forward 0.5
; change-direction
]
end
to chasehuman
if any? humans in-radius 10 [
set heading towards one-of humans in-radius 10]
; change_direction
end
to runaway
face min-one-of zombies [distance myself]
rt 180
;change_direction
end
to convert
ask turtles with [ breed = zombies ]
[
ask humans-on patch-here
[
if random 100 < convert_probability [set breed zombies]]
ask humans-on patch-here [if random 100 < convert_probability
[set color red]]
]
end
to zombiedeath
ask zombies-on patch-here [if random 100 > convert_probability
[die]]
end
Okay, the only procedure relevant to this question is this one (same code as above, formatted so you can see the structure logic}:
to convert
ask turtles with [ breed = zombies ]
[ ask humans-on patch-here
[ if random 100 < convert_probability
[ set breed zombies
]
]
ask humans-on patch-here
[ if random 100 < convert_probability
[ set color red
]
]
]
end
You haven't actually told us what the problem is - "convertion function is not working" does not say whether it is generating an error, or what behaviour it is doing compared to what is expected for example. But, look at what this code actually does. First it finds all the zombies then, for each zombie, it:
gets the humans on the same patch to convert to zombies with some probability
gets the humans on the same patch to change colour to red with some probability
Your first problem is that you haven't linked the turning red with becoming a zombie. Is that the problem you were trying to solve? If so, here is some cleaned up code that links zombie and red:
to convert
ask zombies ; note, you can just directly use the breed name
[ ask humans-here ; again, can use the breed name
[ if random 100 < convert_probability
[ set breed zombies
set color red
]
]
]
end

Is there a way to create impassable barriers in NetLogo?

I am attempting to code a path-finding behavior wherein agents will locate an optimal patch in the environment and navigate their way around fences to reach said patch. I've created a patch variable 'f', which is set to 1 to indicate fences and 0 for any other patch.
I want to make these fences impassable (i.e. I want them to be patches the agents will not use for movement), but agents still seem to be able to travel on them to some extent and in some cases are even able to fully cross them.
Here is a picture of an agent crossing a barrier I don't want it to cross
Relevant decision-making code for the agents is as follows:
{let moveset patches in-radius 30 with [f = 0 and n > 0]
let target max-one-of moveset [n]
ifelse patch-here != target
[
set heading towards target
]
[]
let chance random-float 10
if chance >= 5 [let pick -145]
if chance < 5 [let pick 145]
ask patches in-radius 1
[if f = 1
[ask myself
[set heading towards min-one-of patches [distance myself] + 180 - random 10 + random 10 ]
]
]
fd 1}
For clarity, 'n' is simply a variable to denote the patch I want my agent to locate and venture to.
Is anyone aware of a simple way in NetLogo to exclude certain patches as viable zones for movement in the decision making process (i.e. hard barriers)?
If you haven't yet, have a look at the "Look Ahead" example in the Models Library- it's a simple demonstration of using patch color to control turtle movement. Some code based on that model is below. With this setup:
breed [ seekers seeker ]
breed [ goals goal ]
patches-own [ steps-from-goal ]
to setup
ca
ask patches [
set steps-from-goal 999
]
ask patches with [ pxcor mod 10 = 0 ] [
set pcolor red
]
ask patches with [ pycor mod 10 = 0 ] [
set pcolor black
]
ask one-of patches with [ pcolor = black ] [
sprout-seekers 1 [
set color blue
pd
]
]
ask one-of patches with [ pcolor = black ] [
sprout-goals 1 [
set color white
set shape "circle"
]
]
reset-ticks
end
You can have the seekers breed wander around the black squares until they share a patch with a goal turtle:
to random-wander
ask seekers [
if any? goals-here [
stop
]
rt random 61 - 30
ifelse can-move? 1 and [pcolor] of patch-ahead 1 = black [
fd 1
] [
rt one-of [ 90 -90 ]
]
]
tick
end
However, note that turtles can still 'jump' corners of patches using this method, because they are able to assess the patch-ahead 1 at any angle- so, a patch one space ahead of a turtle may be assessed across the corner of another patch. The turtle should never actually land on the forbidden patch, but you may notice that their path can cross those blocked patches.
Edit:
See simplified code that "traps" a turtle in a square cage:
to setup
ca
crt 1 [
setxy 5 5
set heading 180
repeat 4 [
repeat 10 [
ask patch-here [ set pcolor red ]
fd 1
]
rt 90
]
die
]
crt 1 [ pd ]
reset-ticks
end
to go
ask turtles [
rt random 61 - 30
ifelse can-move? 1 and [pcolor] of patch-ahead 1 = black [
fd 1
] [
rt one-of [ 90 -90 ]
]
]
tick
end
After 1100 ticks:
After 13300 ticks:

Netlogo: simulation of cellular differentiation pattern?

I am trying to simulate the differentiation pattern of a simple organism. This is how I'd like my breeds and variables to work:
Breeds: vegetatives and heterocysts. Vegetatives can divide, heterocysts can't. Vegetatives can become heterocysts. Ideally, once a heterocyst is formed, the closer a vegetative is to it, the less likely it is for it to become a heterocyst in turn.
Variables:
age: + 1 per tick, - 1 for newly-hatched turtles
bump: A means by which to displace all the turtles located 'ahead' of a newly-hatched turtle, so they don't overlap. I imagined the system a bit like a Newton's Cradle (http://s.hswstatic.com/gif/newtons-cradle-1.jpg)
pro: promoter. Accumulates partially randomly. Once it reaches a certain value ('concentration'), a vegetative would change breed to become a heterocyst. Value decreased by inh.
proL: label for pro, with rounded values.
inh: inhibitor. Ideally this value should form a 'gradient' (highest in turtles near heterocysts, lowest further away).
The obvious problem that I can see is that I get a lot of contiguous heterocysts. Which is sort of what I've been trying to avoid. But I can't see what went wrong...Please help?
to setup
clear-all
setup-turtles
reset-ticks
ask turtles [ set size 1 ]
end
to setup-turtles
create-vegetatives 1
ask turtles [
setxy random-xcor random-ycor
set shape "circle"
set color 65]
end
to go
divide
add-age
move
differentiate
tick
end
turtles-own [age
bump
inh
pro
proL]
breed [vegetatives vegetative]
breed [heterocysts heterocyst]
to add-age
ask turtles [
set age age + 1
ifelse show-age?
[ set label age ]
[ set label "" ]
]
end
to divide
ask vegetatives [
if random 100 < 2 [
hatch 1[
set bump 1
set age age - 1
set inh 0
]
]]
end
;;Trying to get only one turtle per patch, making the others move
to move
ask turtles[
while [bump = 1] [
ifelse not any? turtles-on patch-right-and-ahead 180 1[
rt 180
fd 1
set bump 0
if any? other turtles-here[
ask other turtles-here
[set bump 1]
]
]
[fd 1
set bump 0
if any? other turtles-here[
ask other turtles-here[
set bump 1]
]
]
]]
end
to differentiate
ask turtles[
set pro (pro - inh + (random 2))
set proL round pro
ifelse show-proL?
[ set label proL ]
[ set label "" ]
create-links-with other turtles-on patch-ahead 1
create-links-with other turtles-on patch-right-and-ahead 180 1
if breed = vegetatives [
if any? link-neighbors[
ifelse any? link-neighbors with [breed = heterocysts]
[]
[set inh mean [inh] of link-neighbors]
]
if any? vegetatives with [pro > 50]
[ask vegetatives with [pro > 50]
[set breed heterocysts
set color brown
set shape "circle"
if any? link-neighbors[
ask link-neighbors with [breed != heterocysts]
[set inh 2]]
]]
]]
clear-links
end

Define home area-turtles?

I am very new to netlogo. I have searched every question here before I posted this.
I have the following code which sprouts a given number of horses:
ask n-of Number-horses patches with [grass? = "Yes"]
[sprout-horses 1 [set color 25 ]]
The person can change the number of horses using the slider but I would like each horse to have its own area/range/radius.
They can only move within this radius/area and they cannot meet each other.
From what I've read it's got something to do with the distance function?
You can find a similar problem here which has examples too :
Spacing agents in NetLogo based on territory size
There are several ways that you can assign a territory zone to each horse, but all methods that I know have two steps, first step is in order to make sure initial home area of horses are separated from each other , So we need to create horses only in patches which has a certain distance from another patch which has a horse on it,I did not follow your method that asked patches to sprout horses and instead I created them without asking patches.
I was not sure how you defined grass? Variable for each patch but I have assigned a number of patches with grass? = true and others false.
Second step is to set home-area property of each horse. If initially you moved them far away from each other they will have separate territories.
I have included a few examples here :
First to use in-radius for both steps:
Breed [Horses horse]
Horses-own [home-area]
patches-own [grass?]
globals [Zone-Radius]
to setup
clear-all
reset-ticks
set Zone-Radius 2
ask patches
[
ifelse pxcor mod 5 = 3
[ set Grass? true ]
[ set Grass? false ]
]
create-horses Number-horses
[ Move-to one-of patches with [Grass? and not any? other horses in-radius (Zone-Radius + 1)]
set home-area patches in-radius Zone-Radius
set color 25
]
end
to go
ask horses [
ifelse member? patch-ahead 1 home-area
[rt random 10 fd 1 ] ; move if next patch is in their zone
[rt random 180]
]
tick
end
In this example horses only move in the patches in their radius 2. But you can change that base on your model requirements.
In the second method you can use distance for the first step (finding empty patches with enough distance to current patch) and radius for second one (assigning home-area to each horse).
Move-to one-of patches with [Grass? and not any? other horses with [distance myself < (Zone-Radius + 1)]]
set home-area patches in-radius Zone-Radius
If you use higher distance for finding empty patches you will have completely seprated zones. Finally , you can use distance for both steps:
Move-to one-of patches with [Grass? and not any? other horses with [distance myself < (Zone-Radius + 1)]]
set home-area patches with [distance myself < Zone-Radius]
I just did it another way:
Breed [Horses horse]
Horses-own [home-area]
patches-own [ concession? forest? parks?]
globals [Zone-Radius]
to setup
clear-all
reset-ticks
set Zone-Radius 2
ask n-of 500 patches [ set concession? "No" ]
ask n-of 500 patches[ set forest? "Yes" ]
ask n-of 500 patches[ set parks? "Yes"]
let i 0
while [i < Number-horses]
[
ask one-of patches with [(concession? = "No" or forest? = "YES" or parks? = "YES" ) and (not any? horses in-radius (Zone-Radius + 2) )]
[
sprout-horses 1 [
set home-area patches with [distance myself < Zone-Radius]
let w who
ask home-area [set pcolor red]
set color 25 ]
]
set i (i + 1)
]
end
to go
ask horses [
ifelse member? patch-ahead 1 home-area [rt random 10 fd 1 ] [rt random 180]
]
tick
end
As you can see I used while and a condition to ask patches one by one, I might be mistaken but when I ask all the n-of Number-of-horses patches with [YourCondition][...] I get the wrong results and distance between horses is not effective, maybe they are created all at the same time and therefore upon creating a horse there was no horse nearby!? I am new to these concepts and might be wrong.
This is the code and view for the one which asks patches to create horses at once here :
Breed [Horses horse]
Horses-own [home-area]
patches-own [ concession? forest? parks?]
globals [Zone-Radius]
to setup
clear-all
reset-ticks
set Zone-Radius 2
ask n-of 500 patches [ set concession? "No" ]
ask n-of 500 patches[ set forest? "Yes" ]
ask n-of 500 patches[ set parks? "Yes"]
ask n-of number-horses patches with [(concession? = "No" or forest? = "YES" or parks? = "YES" ) and (not any? horses in-radius (Zone-Radius + 2) )]
[
sprout-horses 1 [
set home-area patches with [distance myself < Zone-Radius]
let w who
ask home-area [set pcolor red]
set color 25 ]
]
end
to go
ask horses [
ifelse member? patch-ahead 1 home-area [rt random 10 fd 1 ] [rt random 180]
]
tick
end