2013-12-23 37 views
2

我正在製作比賽模型。其功能是海龜從xcor -13開始水平移動到xcor13,速度爲 不斷變化,當一隻海龜到達xcor = 13時,所有其他海龜(除了先穿過的海龜)死亡如何殺死除一個之外的所有海龜?

to Race 
    wait .3 
    fd random 5 
    if xcor = 13 (this is where i want to tell all other turtles to die) 
end 

我如何要求所有其他海龜死亡? 第一個答案does not幫助我,別人請回應

+1

什麼是沒有幫助的關於第一個答案?如果「問其他海龜[死亡]」,不知道你在找什麼。 –

+0

我真的不知道你到底在找什麼!如果你可以解釋更多,我可能會改變我的答案:) – Marzy

+0

如果你的問題是我的完整例子,這可能使它很難理解,只需使用'if xcor = 13 [ask other turtles [die]]' – Marzy

回答

-1

你想做什麼沒有多大意義。發佈時,請確保該問題爲回答您的問題提供了更好的背景。

我對你的問題的解釋是汽車根本就不重要。所有你想知道的是,當一隻烏龜穿過終點線時,你殺死了所有其他的烏龜。

這樣做我可能會給每隻烏龜一個名稱或標籤的屬性。將它們全部存儲在一個數組中。

然後,如果龜越過終點線,刪除所有來自陣列海龜除了

if turtle.name == turtle[i].name. 

希望有所幫助。請稍後再清楚一點。

+0

我編輯它更有意義。即時通訊不知道如何使用數組,還有沒有其他方法? – user2909199

-1

你需要一種方法來識別活着的烏龜並殺死其他烏龜。要做到這一點,你可以寫很多if語句,但看起來很可怕。

if(larry.coordinates == 13){ 
     kill(tom); 
     kill(harry); 

}

你最好的選擇是閱讀如何創建一個數組。將它存儲在一個數組中。相信我,數組非常簡單。

1

你可以做到這一點,要求獲獎者詢問其他龜類[模具]

to setup 
    clear-all 
    reset-ticks 
    ;resize-world min-pxcor max-pxcor min-pycor max-pycor 
    resize-world -15 20 0 3 
    set-patch-size 15 
    ;set-patch-size size 
    create-turtles 10 
    [setxy -13 1 set heading 90 set shape "car" wait 0.3] 
    ask patch -13 2 [Set plabel "Start" set pcolor 110] ; just for visualization 
    ask patch 13 2 [Set plabel "END" set pcolor 110] 
end 


to go 
    ifelse count turtles > 1 
    [ 
    ask turtles 
    [Race] 
    ] 
    [stop] 

    tick 
end 
to Race 
    fd random 5 
    if xcor >= 13 [ set size 2 ask other turtles [die] ] 
end 

這是一個樣本截圖

Start

END

我真的很低的例子,所以還有另一種方法可以通過使用多行汽車來提高比賽的可視性:

resize-world -15 20 0 5 
    set-patch-size 15 
    create-turtles 20 
    [set xcor -13 set ycor one-of [0 1 2 3 4 ] set heading 90 set shape "car" ] 
    ask patch -13 5 [Set plabel "Start" set pcolor 110] 
    ask patch 13 5 [Set plabel "END" set pcolor 110] 

enter image description here

enter image description here

enter image description here

+0

當你使用xcor = 13時,一些海龜可能跳過並穿過線,所以我認爲它更安全的使用xcor> = 13 – Marzy

相關問題