Beispiel #1
0
Z32
dice2_roll_mean(DiceRep dice)
{
    Z16u die = 0;
    Z16 numdice = 0, offset = 0;

    dice2(dice, numdice, die, offset);
    return (Z32)offset + numdice + ((die - 1)/2)*numdice;
}
Beispiel #2
0
Z32
dice2_roll_max(DiceRep dice)
{
    Z16u die = 0;
    Z16 numdice = 0, offset = 0;

    dice2(dice, numdice, die, offset);
    return (Z32)offset + numdice*die;
}
Beispiel #3
0
int main(){
	
	/*
	DiceT dice(0,6);
	
	
	//roll test
	for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); std::cout << dice << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	dice.Roll(); for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	std::cout << "same??" << std::endl;
	for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	for (auto die: dice.Get()){std::cout << die.Value() << " ";} std::cout << '\n';
	
	std::cout << "min" << std::endl;
	std::cout << dice.Min() << std::endl;
	std::cout << "max" << std::endl;
	std::cout << dice.Max() << std::endl;
	std::cout << "sum" << std::endl;
	std::cout << dice.Sum() << std::endl;
	*/
	
	DiceT dice(4,6);
	std::cout << dice << std::endl;
	std::cout << dice.Str() << std::endl;
	std::cout << dice.Str() << std::endl << std::endl;
	
	DiceT dice2(dice.Str());
	std::cout << dice2 << std::endl;
	std::cout << dice2.Str() << std::endl;
	std::cout << dice2.Str() << std::endl << std::endl;
	
	
	
	return EXIT_SUCCESS;
}
Beispiel #4
0
Z32
roll_dice2(DiceRep dice)
{
    Z16u die = 0, i = 0;
    Z16 numdice = 0, offset = 0;
    Z32 rslt = 0;

    dice2(dice, numdice, die, offset);
    if (!numdice)
	return offset;
    rslt = offset;
    for (i = 0; i < numdice; ++i)
	rslt += (1 + xrandom(die));
    return rslt;
}
Beispiel #5
0
DiceRep
multiply_dice2(DiceRep dice, int mult)
{
    Z16u die = 0;
    Z16 numdice = 0, offset = 0;

    dice2(dice, numdice, die, offset);
    if (!numdice) {
	offset = (offset * mult) / 100;
	if (0x4000 & offset)
	    run_warning("Scaled fixed dice value, %d, is out-of-range",
			offset);
	offset = max(-16384, offset);
	offset = min(16383, offset);
	return offset;
    }
    die = (die * mult) / 100;
    if (!between(2, die, 17))
	run_warning("Scaled die has %d spots. Must be between 2 and 17", die);
    die = max(2, die);
    die = min(17, die);
    offset = (offset * mult) / 100;
    if (0 < numdice) {
	if (!between(0, offset, 127))
	    run_warning("Scaled dice offset is %d. Must be between 0 and 127",
			offset);
	offset = max(0, offset);
	offset = min(127, offset);
    }
    else {
	if (!between(-127, offset, 0))
	    run_warning("Scaled dice offset is %d. Must be between -127 and 0",
			offset);
	offset = max(-127, offset);
	offset = min(0, offset);
    }
    return 
	(DiceRep)(
	    (((0 < offset) ? 0 : 1) << 15) | (1 << 14)
	    | (((0 < offset) ? numdice - 1 : -numdice - 1) << 11) 
	    | ((die - 2) << 7) 
	    | (((0 < offset) ? offset : -offset) & 0x7f));
}