询问最多n只海龟 [英] Ask up to n-of turtles

查看:114
本文介绍了询问最多n只海龟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个内置功能可以查询多达n个海龟?因此,如果您询问50只海龟,但只有40只,它将询问那40只,然后继续前进.还是没有,它会继续前进.

Is there a built in function that will ask up to n-of turtles? So if you ask 50 turtles but there are only 40 it will ask those 40 and move on. Or there aren't any, it will just move on.

或者,有没有人能提供整洁的代码来实现这一目标?

Alternatively does anyone have any neat code for achieving this?

推荐答案

这将挑选出40只随机龟:

This will pick out 40 random turtles:

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

如果要在没有40个可用数字的情况下选择较小的数字,可以执行以下操作:

If you want to pick out a smaller number when there are not 40 available, you could do something like:

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

这篇关于询问最多n只海龟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆