我对Netlogo很新,这是我在论坛中的第一篇文章。 我需要创建在栖息地或地区移动的动物代理人群。领土可以重叠。更准确地说,我需要在不同地区移动的男性代理人和在其他地区移动的几组女性代理人。
这是我到目前为止所做的。我为一组女性和一组男性创建了一个领域。这不完全是我需要的。
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
我感谢任何帮助。 玛利亚
答案 0 :(得分:2)
欢迎使用Stack Overflow。在此处发帖时,一般情况下,将代码限制为证明问题所需的最低限度(参见MCVE指南here),您将获得更好的服务;例如,您可以移除to-report
,prey
品种等,以便明确了解您尝试解决的问题。
我没有完全遵循您的代码,因为我不确定您的总体目标 - 而是我提供了一个替代示例,希望能够说明一种方法来实现您的目标。对于本例中的男性,我将展示本示例中可能与女性重叠的区域以及不能重叠的区域的示例。使用这些变量和设置:
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
在设置中,patches-own
布尔值表示男性是否已声明补丁 - 将其设置为false以启动,以便男性在设置其区域时可以检查补丁是否已经是否声称。然后老虎队建立他们的领土,类似于你的方式,除了男性不会从另一个男性选择领土。女性建立了他们的领土,然后hatch
更多的女性将分享"母亲"的领土。
要在他们的领土内移动,只要限制他们只能移动到他们的领土补丁之一 - 这是一种方法:
to go
ask turtles [
let target one-of territory in-radius 1.5
if target != nobody [
face target
fd 1
]
]
tick
end
如果您想确认海龟是否在某个地区内,请执行以下操作:
to territory-check
ask turtles [
let col color + 2 + random 3
ask territory [
set pcolor col
]
]
end
答案 1 :(得分:0)
再次感谢。什么时候老虎繁殖,我希望他们的孩子创造一个新的territoy和领土不应重叠?
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