Netlogo 只要看看代码就可以了。您需要尽可能地消除复杂性,然后使用形状、颜色和大量打印语句来查看每个命令是否都在执行您认为应该执行的操作。复杂的工作代码几乎总是从简单的工作代码演变而来
因此,完全摆脱PlayersB(注释掉代码),只创建5个playersa,并在处理每个步骤时更改颜色和形状,以确认其工作正常。编辑器允许您使用ctrl-;注释掉整个代码块,或者立即取消注释它们,所以在开始一个步骤时,尽可能注释掉所有内容,然后取消注释下一部分,让它开始工作,等等 当您最终使一切正常工作时,您可以注释掉您在开发中使用的所有打印语句 无论如何,我重构了您的代码,添加了许多注释,添加了许多打印语句,最后让它运行起来。如果您运行justsetup并查看视图,您将看到我所说的网络。(我关闭了视图中的换行,以便网络看起来正确。) 这是我对你的代码的修改。它会在每一步后打印出每个玩家的“我的列表”中的内容,这样你就可以一眼看出它是否在做你想做的事情。(事实并非如此。) 我将who编号作为标签添加到视图中的每个玩家,以便您可以了解我的意思 它会产生有用的输出,如: 让我们确认列表已更新。这是我的名单 播放者a[[5 5 5 10][0 0 0 0 0][0 8 8 8][0 0][0 9]] 在您尝试修复“go部分”之前,请先执行设置步骤以正确运行并生成所需的网络Netlogo 只要看看代码就可以了。您需要尽可能地消除复杂性,然后使用形状、颜色和大量打印语句来查看每个命令是否都在执行您认为应该执行的操作。复杂的工作代码几乎总是从简单的工作代码演变而来,netlogo,Netlogo,因此,完全摆脱PlayersB(注释掉代码),只创建5个playersa,并在处理每个步骤时更改颜色和形状,以确认其工作正常。编辑器允许您使用ctrl-;注释掉整个代码块,或者立即取消注释它们,所以在开始一个步骤时,尽可能注释掉所有内容,然后取消注释下一部分,让它开始工作,等等 当您最终使一切正常工作时,您可以注释掉您在开发中使用的所有打印语句 无论如何,我重构了您的代码,添加了许多注释,添加了许多打印语句,最后让它运行起来。如果您运行justsetup并查看视图,您将看到我所说的网络。(我关闭
breed [playersA playerA]
breed [playersB playerB]
breed [balls ball]
playersA-own[
my-list
new_ball
score
]
playersB-own[
my-list
new_ball
score
]
to setup
clear-all
;; for debugging, only create 3 players and inspect the results to confirm it's working as you intended
;; use labels to see player numbers in the view
create-playersA 5 [ set size 1 set color blue set shape "square" setxy random-xcor random-ycor set label who]
ask playerA 0 [ create-links-with other playersA [set color blue]]
ask playerA 2 [ create-link-with playerA 1 [set color red]]
create-playersB 5 [ set size 2 set color yellow set shape "person" setxy random-xcor random-ycor set label who]
; comment out this code until create-playersA is working properly
; ask playerB 0 [ create-links-with other playersB ]
; ask playerB 2 [ create-link-with playerA 1 ] ;; copy-and-paste error? link with playerB intended?
ask playersA[
set my-list []
set score 0
]
ask playersB[
set my-list []
set score 0
]
reset-ticks
end
to go
let selected nobody
let team-players nobody
let hot-ball nobody
set selected one-of turtles with [
breed = playersA
;; or breed = playersB ;; always select one of playersA for debugging this code
]
print ( word "At point 1, we selected turtle " [who] of selected " with breed " [breed] of selected)
;; we're still in the observer context here
ifelse [breed = playersA] of selected [ ;; by mentioning breed, we shift into a turtle context silently
print ( word " entering the TRUE part of the if-else statement " )
ask selected [
set size [count link-neighbors] of self
print ( word "at point 2 we set selected player's size to " size )
]
create-balls 1 [
set shape "circle" set size 3 set color blue set label who
set hot-ball who
; hide-turtle ;; for debugging show it so you can click on it and inspect it
print ( word "at point 3 we set created a blue hot-ball with who= " hot-ball )
]
;; it seems you want to update the selected turtle's my-ball variable here with a reference to the ball just created??
print " at point 4 we should set selected agent's my-ball to the ball we just made..."
ask selected [
set new_ball hot-ball
]
print (word " Confirming that selected player got the hot-ball " [new_ball] of selected )
;; ask ball hot-ball [ set hidden? true ]
;; this set of code seems to apply only when selected turtle is one of playersA, so it was moved INSIDE that ask-selected code
;; and put inside another ask selected [ ] context
ask selected [
set team-players link-neighbors with [breed = playersA]
print (word "At point 5, For selected player " who ", here is the team-players agent set :" )
print (sort team-players) ;; using "sort" here just to convert an agent set to a list for display
]
print " ------------- about to ask team-players to update their my-lists and change to triangles ---"
ask team-players [
set shape "triangle" set size 3 ;; to see at a glance that everyone was processed
set my-list lput new_ball my-list
print "... updated one my-list"
]
print " let's confirm that the lists have been updated. Here's the my-lists for playersA "
print map [ i -> [my-list] of i ] sort playersA ;; using "sort" to convert agent-set to a list
print (word "At the end of the go step, we have this many balls: " count balls)
]
;; else we should have breed != playersA
[
error " we should only be looking at one of playersA here for testing" ;; for debugging
]
;; tick
end
有一件事-没有两只海龟可以有相同的who编号,即使它们是不同的品种:问playerA 0会影响同一只海龟问playerB 0,我相信。谢谢韦德。不幸的是,我不太熟悉使用who。我想做的是,当球员在网络内传球并追踪气球的路径时,给一个分数——没有两只乌龟可以有相同的who号码,即使它们是不同的品种:问playerA 0会影响同一只乌龟a问playerB 0,我相信。谢谢韦德。不幸的是,我不太熟悉使用who。我想做的是,当球员在网络内传球并追踪球的路径时,给一个分数
create-playersA 10
ask playerA 0 [ create-links-with other playersA ]
ask playerA 2 [ create-link-with playerA 1 ]
breed [playersA playerA]
breed [playersB playerB]
breed [balls ball]
playersA-own[
my-list
new_ball
score
]
playersB-own[
my-list
new_ball
score
]
to setup
clear-all
;; for debugging, only create 3 players and inspect the results to confirm it's working as you intended
;; use labels to see player numbers in the view
create-playersA 5 [ set size 1 set color blue set shape "square" setxy random-xcor random-ycor set label who]
ask playerA 0 [ create-links-with other playersA [set color blue]]
ask playerA 2 [ create-link-with playerA 1 [set color red]]
create-playersB 5 [ set size 2 set color yellow set shape "person" setxy random-xcor random-ycor set label who]
; comment out this code until create-playersA is working properly
; ask playerB 0 [ create-links-with other playersB ]
; ask playerB 2 [ create-link-with playerA 1 ] ;; copy-and-paste error? link with playerB intended?
ask playersA[
set my-list []
set score 0
]
ask playersB[
set my-list []
set score 0
]
reset-ticks
end
to go
let selected nobody
let team-players nobody
let hot-ball nobody
set selected one-of turtles with [
breed = playersA
;; or breed = playersB ;; always select one of playersA for debugging this code
]
print ( word "At point 1, we selected turtle " [who] of selected " with breed " [breed] of selected)
;; we're still in the observer context here
ifelse [breed = playersA] of selected [ ;; by mentioning breed, we shift into a turtle context silently
print ( word " entering the TRUE part of the if-else statement " )
ask selected [
set size [count link-neighbors] of self
print ( word "at point 2 we set selected player's size to " size )
]
create-balls 1 [
set shape "circle" set size 3 set color blue set label who
set hot-ball who
; hide-turtle ;; for debugging show it so you can click on it and inspect it
print ( word "at point 3 we set created a blue hot-ball with who= " hot-ball )
]
;; it seems you want to update the selected turtle's my-ball variable here with a reference to the ball just created??
print " at point 4 we should set selected agent's my-ball to the ball we just made..."
ask selected [
set new_ball hot-ball
]
print (word " Confirming that selected player got the hot-ball " [new_ball] of selected )
;; ask ball hot-ball [ set hidden? true ]
;; this set of code seems to apply only when selected turtle is one of playersA, so it was moved INSIDE that ask-selected code
;; and put inside another ask selected [ ] context
ask selected [
set team-players link-neighbors with [breed = playersA]
print (word "At point 5, For selected player " who ", here is the team-players agent set :" )
print (sort team-players) ;; using "sort" here just to convert an agent set to a list for display
]
print " ------------- about to ask team-players to update their my-lists and change to triangles ---"
ask team-players [
set shape "triangle" set size 3 ;; to see at a glance that everyone was processed
set my-list lput new_ball my-list
print "... updated one my-list"
]
print " let's confirm that the lists have been updated. Here's the my-lists for playersA "
print map [ i -> [my-list] of i ] sort playersA ;; using "sort" to convert agent-set to a list
print (word "At the end of the go step, we have this many balls: " count balls)
]
;; else we should have breed != playersA
[
error " we should only be looking at one of playersA here for testing" ;; for debugging
]
;; tick
end