Was ist die Idee des Programms: Wir haben Wachhunde, Schafe, Wölfe. Meine Schafe sind in einer Furt, die Wölfe kommen von draußen, beim Betreten der Furt beginnen sich die Wachhunde zu bewegen. Wölfe essen Schafe, Schafe fressen Gras, Wachhunde sollten Wölfe erschrecken (noch nicht umgesetzt).Lassen Sie mehrere Schildkröten alle zur gleichen Zeit bewegen
Mein Problem: Alle Schildkröten bewegen sich einzeln.
Was ich will: Ich will, dass sie alle auf einmal für jeden Tick bewegen.
-Code:
breed [sheeps sheep]
breed [wolves wolf]
breed [watchdogs watchdog]
turtles-own [attacked?]
globals [counter
attack
sheep-energy
wolf-energy
grass-counter
lifespan
age
num-attacks
death-countdown]
to set-variables-shapes
set lifespan 365 * 10
set-default-shape sheeps "sheep"
set-default-shape watchdogs "dog"
set-default-shape wolves "wolf"
set sheep-energy 200
set wolf-energy 400
set death-countdown 60
end
to setup
clear-all
set-variables-shapes
create-fold
spawn-animals
reset-ticks
end
to go
ask turtles [
move
]
respawn-grass
ask sheeps [
if (pcolor != green or pcolor != brown) [
move-to one-of patches with [ pcolor = green or pcolor = brown] ;; If i change this with turn-around (procedure), all sheeps die at once.
]
eat-grass
reproduce
sheep-status
death
show sheep-energy
]
ask wolves [
attack-sheep
if (xcor < 5 and xcor > -14 and ycor < 15 and ycor > -5) [
ask watchdogs [
move
if (pcolor != green or pcolor != brown) [
move-to one-of patches with [ pcolor = green]
]
]
]
]
tick
end
to create-fold
ask patches [
if (pxcor < 6 and pxcor > -15 and pycor < 16 and pycor > -6)[
set pcolor grey]
if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5) [
set pcolor green]
]
end
to sheep-status
if (pcolor = brown) [
set sheep-energy sheep-energy - (life-from-food/2)]
if attacked?
[set color red]
end
to attack-sheep
ask other sheeps in-radius (size)[
set attacked? true
set color red
]
end
to reproduce
if (age = lifespan/10) [
hatch-sheeps 40 [
hatch-options
]
]
end
to eat-grass
if (pcolor = green)[
set pcolor brown
set sheep-energy sheep-energy + life-from-food
]
end
to respawn-grass
ask patches [
if pcolor = brown [
ifelse grass-counter = 0 [
set pcolor green
set grass-counter grass-respawn-timer
]
[ set grass-counter grass-counter - 1]
]
]
end
to death
sheep-death-timer
if (sheep-energy <= 0)
[die]
;;if (age >= lifespan) [die]
sheep-explode
end
to sheep-death-timer
if (attacked?)[
set death-countdown death-countdown - 1
if (death-countdown <= 30)
[set color black]
if (death-countdown <= 0)
[die]
]
end
to sheep-explode
if (sheep-energy >= 10000)[
hatch-sheeps 20 [
hatch-options]
die
]
end
to hatch-options
set sheep-energy 200
set age 1
set attacked? false
end
to move
fd 1
rt random 90
lt random 90
end
to spawn-animals
create-wolves number-of-wolves [
set color red
setxy 10 -10
set size 1.3
ask patch 10 -10[
Set plabel "Wolves"]
]
create-sheeps number-of-sheeps [
if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5)[
setxy -4.5 5]
ask patch -4.5 15 [
Set plabel "Sheeps"]
set color white
set attacked? false
]
create-watchdogs number-of-dogs [
if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5)[
setxy -4.5 5
set size 1.3]
set color blue
]
end
to turn-around
fd -1
rt 180
end
Sie sollten Ihre Frage über vorzeitigen Schafsterben separat stellen. –