netlogo: how to separate two armies in 4 corners? - netlogo

I have to do a program where two base fields are created for each of the two armies of agents that are going to meet. How do I put every army to its corners? Soldiers and generals are created for each army and have to be born in one of their corners aleatory. In what I have done, soldiers and generals are already created, but they are not being separated by the army. (I wanted to do [army 1] [army 2]).
breed [ soldiers soldier ]
soldiers-own [ army ]
breed [ generals general ]
generals-own [ army ]
globals [ converted-soldiers death-by-energy death-by-combat ]
turtles-own[ energy max-energy ]
to setup
clear-all
setup-patches
setup-turtles
reset-ticks
end
to setup-patches
set-patch-size 15
ask patches[
if (distancexy 20 20) < base-size [set pcolor yellow]
if (distancexy -20 -20) < base-size [set pcolor yellow]
if (distancexy -20 20) < base-size [set pcolor pink]
if (distancexy 20 -20) < base-size [set pcolor pink]
]
end
to setup-turtles
create-soldiers init-soldiers [
set shape "person"
set color red
set energy init-energy
set max-energy 100
setxy random-xcor random-ycor
while [pcolor = black or pcolor = yellow]
[setxy random-xcor random-ycor]
]
create-generals init-generals [
set shape "person"
set color green
set energy init-energy
set max-energy 100
setxy random-xcor random-ycor
while [pcolor = black or pcolor = pink]
[setxy random-xcor random-ycor]
]
end

Related

How to restrict Old vs. Young: in netlogo?

I am trying to simulate the following situation. Young and old agents.
The old have few social contacts, slower and at the same time have a greater chance of dying.
Young people have more contacts .
Which group should be vaccinated first ?
I created two groups, assigned an infection algorithm, and assigned a social distance. But at the same time I do not see the relationship, the agents behave identically, where is the error?
I'm a beginner and don't want to complicate the model. please don't answer difficult I'm just learning
my code
;;breed [humans human]
;;humans-own [ old young ]
breed [young p-young]
breed [old p-old]
young-own [
days-after-infected
days-of-sick
]
old-own [
days-after-infected
days-of-sick ]
to setup
clear-all
setup-old
setup-young
setup-patches
reset-ticks
end
to setup-old
create-old population-old
[
setxy random-xcor random-ycor
set color 4
set shape "person"
]
end
to setup-young
create-young population-young
[
setxy random-xcor random-ycor
set shape "person"
set color 96
]
end
to setup-patches
ask patches [set pcolor 61]
end
;:ask old [random 360]
;;ask young [forward 1]
to go
move-old
move-young
transmission-old
transmission-young
incubation
sickness
tick
end
to move-old
ask old [
right random 360
forward 1
]
end
to move-young
ask young [
right random 360
forward 3
]
end
to add-carrier
ask one-of young
[set color orange]
end
to transmission-old
ask young with [color = orange]
[let susceptible-person one-of old in-radius 3 with [color = 4]
if susceptible-person != nobody
[ask susceptible-person
[if random 100 < transmission_rate
[set color orange]
]
]
]
end
to transmission-young
ask young with [color = orange]
[let susceptible-person one-of young in-radius 2 with [color = 96]
if susceptible-person != nobody
[ask susceptible-person
[if random 100 < transmission_rate
[set color orange]
]
]
]
end
to incubation
ask old with [color = orange]
[ ifelse days-after-infected < incubation_period
[set days-after-infected days-after-infected + 1]
[set color red]
]
ask young with [color = orange]
[ ifelse days-after-infected < incubation_period
[set days-after-infected days-after-infected + 1]
[set color red ]
]
end
to sickness
ask old with [ color = red ]
[ifelse days-of-sick < 14
[set days-of-sick days-of-sick + 1]
[ifelse random 100 < mortality
[die]
[ set color blue ]
]
]
ask young with [ color = red ]
[ifelse days-of-sick < 14
[set days-of-sick days-of-sick + 1]
[ifelse random 100 < mortality
[die]
[ set color blue ]
]
]
end
I am trying to infect some agents from others, while I am not interested in the incubation period and trying to link age (less movement and less contact) with morbidity.
But I see that the result is not presentable, there is no dependence on age and morbidity.
The transmission-old is your problem. You copypasted from transmission-young but forgot to replace ask young with ask old
to transmission-old
ask old with [color = orange]
[let susceptible-person one-of old in-radius 3 with [color = 4]
if susceptible-person != nobody
[ask susceptible-person
[if random 100 < transmission_rate
[set color orange]
]
]
]
end
I've been fighting for a week, I changed the concept, I think it's easier. How to describe the last block. If there is one infectious neighbor, he will transmit his infection with faithfulness....
breed [olds humanA]
breed [youngs humanB]
globals
[
humans
]
to setup
clear-all
create-olds humans_number * shareA
[
set color 64
set xcor random-xcor
set ycor random-ycor
set shape "person"
]
create-youngs humans_number * (1 - shareA)
[
set color 45
set xcor random-xcor
set ycor random-ycor
set shape "person"
]
set humans (turtle-set olds youngs)
ask olds
[
create-links-with (up-to-n-of (links_number_old * homophily_old) (other olds))
create-links-with (up-to-n-of (links_number_old * ( 1 - homophily_old)) (other
humans))
]
ask youngs
[
create-links-with (up-to-n-of (links_number_young * homophily_young) (other
youngs))
create-links-with (up-to-n-of (links_number_young * ( 1 - homophily_young))
(other humans))
ask patches
[
]
ask n-of 1 humans
[
set infected 1
set color red
]
reset-ticks
end
*to go
ask humans
[
if any? link-neighbors != red ]
[
set humans ......*
end

how to create turtles in a specific area on the patch in Ntelogo

I am making and assignment. The assignment is to make a model of Democracy. I have made a parliament house with coordinates (4, 6). I have made 3 political parties. Now, I want to make the people who will vote. I make them randomly using random-xcor and random-ycor in setxy, but they some of them are made on the parliament house. How can I stop this from happening. I want the turtles to be made everywhere except in the parliament house. Here is the code. Please help me.
breed [people p]
breed [party1 p1]
breed [party2 p2]
breed [party3 p3]
party1-own [vote]
party2-own [vote]
party3-own [vote]
to setup
clear-all
setup-patches
setup-people
setup-parties
reset-ticks
end
to setup-patches
ask patches [
ifelse pxcor >= 4 and pycor >= 6
[set pcolor white]
[set pcolor brown]
]
end
to setup-people
set-default-shape people "person"
create-people 100
ask people [setxy random-xcor random-ycor]
end
to setup-parties
set-default-shape party1 "person"
set-default-shape party2 "person"
set-default-shape party3 "person"
create-party1 1
create-party2 1
create-party3 1
ask party1 [setxy 15 -1]
ask party2 [setxy 15 -3]
ask party3 [setxy 15 -5]
ask party1 [set color blue]
ask party2 [set color green]
ask party3 [set color yellow]
end
to setup-people
set-default-shape people "person"
ask n-of 100 (patches with [pcolor != white]) [sprout-people 1]
end

Setting turtles energy diminishing differently in different areas

In NetLogo I've got 3 areas:
to setup-patches
ask patches [ if pxcor > 6
[set pcolor yellow
]
]
ask patches [ if pxcor <= 6
[set pcolor green
]
]
ask patches [ if pxcor < -6
[set pcolor blue
]
]
end
I'd like 2 of my 3 different kinds of turtles to lose energy faster as they go (tick) in one of the areas, for example in ycor > 6.
set energy energy - 1 [ -6 if xcor <= 6]
But this does not work.
Try:
ask patches with [pxcor > 6] [set pcolor yellow]
ask patches with [pxcor <= 6] [set pcolor green]
ask patches with [pxcolor < -6] [set pcolor blue]
Then, if energy is a turtle variable.
ask turtles
[
if yellow = pcolor [set energy energy - 1]
if green = pcolor [set energy energy - 2]
if blue = pcolor [set energy energy - 3]
]

Initial proportion of three different patches with only two sliders

i am trying to create a predation model in netlogo with foxes and rabbits. foxes eat rabbits and waste (left from people) und rabbits eat grass in a special pleasure ground.
the initial proportion of patches fixed in the setup should be: 65% green patches (grass), 35 % brown patches (eaten grass), 10 % margenta patches (waste from people). they can be distributed randomly.
at the moment it looks like that :
globals [grass waste]
breed [rabbits rabbit]
breed [foxes fox]
turtles-own [energy]
patches-own [countdown]
to setup
clear-all
ask patches [ set pcolor green ]
if grass? [
ask patches [
set pcolor one-of [green brown]
if-else pcolor = green
[ set countdown grass-regrowth-time ]
[ set countdown random grass-regrowth-time ]
]
]
ask patches [ set pcolor magenta ]
if waste? [
ask patches [
set pcolor one-of [ green brown magenta ]
if-else pcolor = [ green brown ]
[ set countdown waste-regeneration-time ]
[ set countdown random waste-regeneration-time ]
]
]
set-default-shape rabbits "rabbit"
create-rabbits initial-number-rabbits
[
set color white
set size 2.2
set label-color gray + 1
set energy random ( 2 * rabbit-gain-from-food)
setxy random-xcor random-ycor
]
set-default-shape foxes "fox"
create-foxes initial-number-foxes
[
set color red
set label-color gray + 1
set size 2.2
set energy random ( fox-gain-from-food )
setxy random-xcor random-ycor
]
display-labels
set grass count patches with [pcolor = green]
set waste count patches with [pcolor = magenta]
reset-ticks
end

Development of turtles from one breed to another

I dont know much about netlogo so this may be a really simple solution but I have multiple breeds of turtles where each breed is a different age range (eggs, hatchlings, juveniles, hawksbills (adults)) and i need them to be able to go from one breed to the next after a certain amount of ticks (in my model one tick = one day). Is this possible to code for?
Here's my code so far
globals [island]
Breed [eggs egg]
Breed [hatchlings hatchling]
Breed [juveniles juvenile]
Breed [hawksbills hawksbill]
turtles-own [
age
z
]
to setup
clear-all
set-default-shape eggs "circle"
create-eggs 80
[ set color 49.5
set size 0.5
setxy random-xcor random-ycor ]
set-default-shape hatchlings "turtle"
create-hatchlings 70
[ set color 57
set size 1.5
setxy random-xcor random-ycor ]
set-default-shape juveniles "turtle"
create-juveniles 10
[ set color 55
set size 2
setxy random-xcor random-ycor ]
set-default-shape hawksbills "turtle"
create-hawksbills 9
[ set color 53
set size 3
setxy random-xcor random-ycor ]
clear-output
setup-environment
setup-birthdays
reset-ticks
end
to setup-environment
ask patches [set pcolor cyan]
ask patches with [abs(pxcor) < 5 and abs(pycor) < 5] [set pcolor yellow]
ask patches with [abs(pxcor) < 2 and abs(pycor) < 2] [set pcolor brown]
end
to setup-birthdays
end
to go
ask eggs
[ kill-eggs ]
ask hatchlings
[ move-hatchlings
kill-hatchlings]
ask juveniles
[ move-juveniles
kill-juveniles]
ask hawksbills
[ move-hawksbills
kill-hawksbills
reproduce-hawksbills ]
tick
if not any? turtles [stop]
end
to kill-eggs
set z random 100
if z > 50
[die]
end
to kill-hatchlings
set z random 100
if z > 10
[die]
end
to kill-juveniles
set z random 20
if z > 18
[die]
end
to kill-hawksbills
set z random 5
if z > 4
[die]
end
to move-hatchlings
rt random 360
fd 1
end
to move-juveniles
rt random 360
fd 1
end
to move-hawksbills
rt random 360
fd 1
end
to reproduce-hawksbills
if pcolor = yellow
[set z random 100
if z > 75
[hatch-eggs 5[
set color 49.5
set size 0.5]
]]
end
To turn a turtle into a hatchling, just do set breed hatchlings! So, your code will probably look something like:
if age > 10 [
set breed hatchlings
]