Ejemplo n.º 1
0
static void
dice_roll_test(void)
{
    struct rnd *always_one = rnd_alloc_fake_fixed(0);
    struct rnd *always_two = rnd_alloc_fake_fixed(1);
    int score;

    score = dice_roll(dice_make(0, 1), always_one, NULL);
    assert(0 == score);

    score = dice_roll(dice_make(3, 1), always_two, NULL);
    assert(3 == score);

    score = dice_roll(dice_make_plus(1, 1, 1), always_one, NULL);
    assert(2 == score);

    score = dice_roll(dice_make_plus(5, 1, -1), always_two, NULL);
    assert(4 == score);

    score = dice_roll(dice_make_plus_times(5, 1, 0, 10), always_one, NULL);
    assert(50 == score);

    score = dice_roll(dice_make_plus(0, 4, 1), always_two, NULL);
    assert(1 == score);

    rnd_free(always_one);
    rnd_free(always_two);
}
Ejemplo n.º 2
0
static void
dice_alloc_description_test(void)
{
    char *description = dice_alloc_description(dice_make(0, 6));
    assert(0 == strcmp("0", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make(5, 1));
    assert(0 == strcmp("5", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make(3, 6));
    assert(0 == strcmp("3d6", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make_plus(2, 8, 1));
    assert(0 == strcmp("2d8+1", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make_plus(2, 4, -1));
    assert(0 == strcmp("2d4-1", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make_plus_times(1, 10, 0, 10));
    assert(0 == strcmp("1d10x10", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make_plus_times(1, 4, 1, 10000));
    assert(0 == strcmp("1d4+1x10000", description));
    free_or_die(description);
}
Ejemplo n.º 3
0
static void
dice_roll_and_drop_lowest_test(void)
{
    struct rnd *ascending = rnd_alloc_fake_ascending(0);
    struct rnd *always_one = rnd_alloc_fake_fixed(0);
    struct rnd *always_two = rnd_alloc_fake_fixed(1);
    int score;
    
    score = dice_roll_and_drop_lowest(dice_make(4, 6), ascending);
    assert(9 == score);
    
    score = dice_roll_and_drop_lowest(dice_make(3, 6), always_one);
    assert(2 == score);
    
    score = dice_roll_and_drop_lowest(dice_make(5, 4), always_two);
    assert(8 == score);
    
    rnd_free(ascending);
    rnd_free(always_one);
    rnd_free(always_two);
}
Ejemplo n.º 4
0
static void
dice_roll_with_average_scoring_test(void)
{
    struct rnd *ascending = rnd_alloc_fake_ascending(0);
    struct rnd *always_one = rnd_alloc_fake_fixed(0);
    struct rnd *always_two = rnd_alloc_fake_fixed(1);
    int score;
    
    score = dice_roll_with_average_scoring(dice_make(3, 6), ascending);
    assert(8 == score);
    
    score = dice_roll_with_average_scoring(dice_make(3, 6), always_one);
    assert(9 == score);
    
    score = dice_roll_with_average_scoring(dice_make(3, 6), always_two);
    assert(6 == score);
    
    rnd_free(ascending);
    rnd_free(always_one);
    rnd_free(always_two);
}
Ejemplo n.º 5
0
static void
dice_alloc_range_description_test(void)
{
    char *description = dice_alloc_range_description(dice_make(0, 6));
    assert(0 == strcmp("0", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus(0, 6, 2));
    assert(0 == strcmp("2", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus_times(0, 4, 4, 10));
    assert(0 == strcmp("40", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make(3, 1));
    assert(0 == strcmp("3", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make(3, 6));
    assert(0 == strcmp("3-18", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus(2, 8, 1));
    assert(0 == strcmp("3-17", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus(2, 4, -1));
    assert(0 == strcmp("1-7", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus_times(1, 10, 0, 10));
    assert(0 == strcmp("10-100", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus_times(1, 4, 1, 10000));
    assert(0 == strcmp("20000-50000", description));
    free_or_die(description);
}
Ejemplo n.º 6
0
static void
generate_monetary_treasure(struct treasure *treasure, struct rnd *rnd)
{
    int multiple_rolls = 0;
    int max_score = 20;
    do {
        int score = dice_roll(dice_make(1, max_score), rnd, NULL);
        if (score <= 2) {
            generate_monetary_treasure_1_to_2_copper_and_silver(treasure, rnd);
            --multiple_rolls;
        } else if (score <= 5) {
            generate_monetary_treasure_3_to_5_electrum(treasure, rnd);
            --multiple_rolls;
        } else if (score <= 10) {
            generate_monetary_treasure_6_to_10_gold(treasure, rnd);
            --multiple_rolls;
        } else if (score <= 12) {
            generate_monetary_treasure_11_to_12_platinum(treasure, rnd);
            --multiple_rolls;
        } else if (score <= 15) {
            generate_monetary_treasure_13_to_15_gems(treasure, rnd);
            --multiple_rolls;
        } else if (score <= 17) {
            generate_monetary_treasure_16_to_17_jewelry(treasure, rnd);
            --multiple_rolls;
        } else if (score <= 18) {
            max_score = 17;
            multiple_rolls = 2;
        } else if (score <= 19) {
            max_score = 17;
            multiple_rolls = 3;
        } else {
            generate_monetary_treasure_1_to_2_copper_and_silver(treasure, rnd);
            generate_monetary_treasure_3_to_5_electrum(treasure, rnd);
            generate_monetary_treasure_6_to_10_gold(treasure, rnd);
            generate_monetary_treasure_11_to_12_platinum(treasure, rnd);
            generate_monetary_treasure_13_to_15_gems(treasure, rnd);
            generate_monetary_treasure_16_to_17_jewelry(treasure, rnd);
        }
    } while (multiple_rolls > 0);
}