筛子类和筛子测试类(翻译转贴)

介绍了AS3中用于模拟真实骰子投掷的Dice类及其使用方法。该类支持多种类型的骰子,如四面、六面等,并采用线性同余算法确保随机数的质量。此外,还提供了一个测试应用程序来验证骰子投掷的概率分布。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



AS3 Dice Class & Dice Tester



In game development randomness is often necessary for certain tasks, be it the random distribution of graphic tiles, a random factor in NPC AI or random stats in a roleplaying game. Especially for the latter purpose the static Dice class provides a set of methods to roll dice as it is common in a RPG, to be exact four-, six-, eight-, ten-, twelve-, twenty-sided and percentile dice.


在游戏开发环节中,随机的应用对于某些任务来说总是必要的,象随机的布局,NPC角色的随机表现,特别是想骰子这样的类,提供一系列的投掷方法。



The Dice class (and it’s supporting classes) are rather elaborated, using for example the Linear Congruential algorithm in the process of generating ‘true’ random numbers so it might not be the most speed-optimized method for calculating random numbers. For absolute performance the LCA and rounding routines can be removed to speed up calculations.


筛子类(以及它的一些支撑类)经过了一系列的提炼,我们采用了线性算法来产生真正的随机数,因此也许这是速度最优化的随机数产生算法了。为了获得更好的性能,可以将一些圆整的过程去掉来加快计算速度


Using the Dice class is very simple! For example rolling two ten-sided dice can be done with the following call …


使用骰子类非常简单,例如投掷两个十面的骰子只要这样:


var result:int = Dice.tenSided(2);


… rolling the percentile die is even simpler as it does not need any arguments. It always returns a value between 1 and 100 …


var result:int = Dice.percentile();


… the class also provides the roll method with that any x-sided die could be rolled, 3 sixteen-sided dice for instance …这个类还提供了N面的骰子投掷


var result:int = Dice.roll(16, 3);


The following application uses the Dice class and can be used to test dice throw probability according to the bell curve (the more dice are used the lower the probability to roll boundary results).


下面的应用程序采用了骰子类,并且给出了概率测试(根据贝尔曲线)





//
var so_1804141555 = new SWFObject("http://files.hexagonstar.com/labs/diceclass/dicetester.swf","fm_dicetester_1804141555","660","420","9","","","","","");
so_1804141555.addParam("wmode", "transparent");
so_1804141555.write("so_targ_dicetester_1804141555");

// ]]>


DOWNLOAD
The Dice class and Dice Tester sources can be downloaded from here.


可以从以上给出的链接去下载这个应用的哦源代码。


  

本文转自
http://labs.hexagonstar.com/diceclass/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值