2016-02-29 83 views
2

是否有內置函數可以詢問海龜的數量?所以如果你問50只海龜,但只有40只,它會問這40只,繼續前進。或者沒有,它會繼續前進。向海龜索要

或者沒有人有任何整潔的代碼來實現這一目標?

回答

2

這將挑選出40種隨機海龜:

ask n-of 40 turtles [ <whatever you want them to do> ] 

如果你想挑選出一個較小的數字時,有沒有40用,你可以這樣做:

let num min (list 40 count turtles) 
ask n-of num turtles [ <whatever you want them to do> ]