2014-01-13 54 views
1

我有這個安裝和移動龜的基本代碼。 到了這個時候,我只想在安裝過程中出現幾隻烏龜,然後在它們移動時出現。其他海龜將顯示或將變得可見。一次只展示幾隻烏龜?

to setup 
crt 100 
setxy random 19 random 80 
end 

to go 
fd 1 
end 

我嘗試這樣做。但我得到錯誤

to setup 
    clear-all 
    create-turtles random 10 
    reset-ticks 
end 

to go 
    fd 1 
    if count turtles < 100 [ 
    create-turtles min list (random 10) (100 - count turtles) 
    ] 
    tick 
end 
+0

你能更清楚明確地知道你想要發生什麼嗎?我不明白你的描述。 –

+0

就像我開始安裝時,我不希望所有的100只烏龜出現。就像第5只烏龜會出現,然後當它開始出現時,另外5只會出現,接下來的7或8或2等等,直到100出來。 – user3146700

+0

您可能會在示例模型的生物學部分查看Ant Lines模型,該模型有螞蟻逐漸出現。 –

回答

1

你的問題不是很清楚,如果你想能夠設置你應該使用隱藏的龜的可見性?原始設置龜的可見性, 下面的例子顯示了當他們的身份證小於蜱時龜如何出現,在蜱101中,所有的龜都將是可見的。

to setup 
    clear-all 
    reset-ticks 
    crt 100 [ 
    set hidden? true 
    setxy random 19 random 80 
    ] 


end 

to go 
    ask turtles 
    [ 
    if who < ticks 
    [ 
     set hidden? false 
     fd 1 
    ] 
    ] 

    ask patch 0 0 [set plabel ticks] ; just for your info 
    ask patch 1 1 [set plabel "Ticks"] ; just for your info 
    tick 
end 

後1個滴答只有一個烏龜可見:

enter image description here

現在40個龜可見:

enter image description here

更新:

在這個例子中,你可以有你要問龜自己的知名度設置爲true號碼清單:

globals [ number-to-set-visible] 
to setup 
    clear-all 
    reset-ticks 
    set number-to-set-visible [ 5 5 7 8 2 ] 
    crt 100 [ 
    set hidden? true 
    setxy random 19 random 80 
    ] 


end 

to go 
    if visibility-condition and length number-to-set-visible > 0 

    [ 
     ask n-of item 0 number-to-set-visible turtles [ 

     set hidden? false 
     ] 

     set number-to-set-visible remove-item 0 number-to-set-visible 
     ] 

    ask turtles with [not hidden? ] 
    [ 
     fd 1 

    ] 


    tick 
end 

to-report visibility-condition 
report ticks mod 100 = 0 and ticks > 0 
end 
+0

如何隨機數量的海龜不是由一個。如前4個,後9個,然後5個等。 – user3146700

+0

我已經添加了一個列表,例如[5 5 7 8 2 ...],然後你可以有一個條件,如果它是真的,你可以要求列表中的n個項目設置它們的可見性。 – Marzy

+0

在能見度條件下,只需放置任何需要使海龜出現的條件,例如,如果某個補丁的pcolor是特定顏色或蜱大於X或其他任何其他東西 – Marzy

1

馬爾齊的回答涵蓋了如何在setup創造無形的海龜,然後逐漸使他們在go可見。

我不清楚你是否真的需要這種可見/不可見的區別。你是否真的需要所有的烏龜從一開始就存在?可能每次創建更多的海龜都可以嗎?如果是這樣,請嘗試這樣的代碼:

to setup 
    clear-all 
    create-turtles random 10 
    reset-ticks 
end 

to go 
    if count turtles < 100 [ 
    create-turtles min list (random 10) (100 - count turtles) 
    ] 
    tick 
end 
+0

如果我想添加fd 1,該怎麼辦? – user3146700

+0

添加'問龜[fd 1]'。 –