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

来源:互联网 发布:4g内存吃鸡优化 编辑:程序博客网 时间:2024/06/11 22:25


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).


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






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


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


  

本文转自
http://labs.hexagonstar.com/diceclass/
原创粉丝点击