本文整理汇总了Java中com.google.common.math.BigIntegerMath.factorial方法的典型用法代码示例。如果您正苦于以下问题:Java BigIntegerMath.factorial方法的具体用法?Java BigIntegerMath.factorial怎么用?Java BigIntegerMath.factorial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.math.BigIntegerMath
的用法示例。
在下文中一共展示了BigIntegerMath.factorial方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.google.common.math.BigIntegerMath; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public Context build(final Context<Object> context) {
System.out.println("Running builder");
context.setId("prisonersdilemma");
final GameAdministrator gameAdministrator = new GameAdministrator();
context.add(gameAdministrator);
final Parameters params = RunEnvironment.getInstance().getParameters();
final int playerCount = (Integer) params.getValue("player_count");
if (playerCount % 2 != 0)
throw new CsfRuntimeException(
"The CSF only supports an even number of players for now.");
final int numberOfRounds = (Integer) params.getValue("number_of_rounds");
assert (playerCount % 2 == 0); // Only even numbers supported
for (int i = 0; i < playerCount; i++) {
final Player player = new Player(gameAdministrator);
player.setPlayerNumber(i);
context.add(player);
}
// Calculate the number of combinations
final BigInteger nFact = BigIntegerMath.factorial(playerCount);
final BigInteger nMinusRfact = BigIntegerMath.factorial(playerCount - 2);
final BigInteger rFact = BigIntegerMath.factorial(2);
final Number denominator = LongMath.multiply(nMinusRfact, rFact);
final Number numCombinations = LongMath.divide(nFact, denominator);
final int numbCombinationsInt = numCombinations.intValue();
RunEnvironment.getInstance().endAt(numbCombinationsInt * numberOfRounds);
return context;
}