Example #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);
}
Example #2
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);
}
Example #3
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);
}
Example #4
0
static void
check(FILE *out, uint32_t constant)
{
    struct rnd *fake_rnd = rnd_alloc_fake_fixed(constant);
    
    generate_treasure_type_table(out);
    generate_map(fake_rnd, out);
    generate_each_treasure(fake_rnd, out);
    generate_sample_dungeon(fake_rnd, out);
    generate_random_dungeon(fake_rnd, out);
    generate_character(fake_rnd, out, characteristic_generation_method_simple);
    generate_character(fake_rnd, out, characteristic_generation_method_1);
    generate_character(fake_rnd, out, characteristic_generation_method_2);
    generate_character(fake_rnd, out, characteristic_generation_method_3);
    generate_character(fake_rnd, out, characteristic_generation_method_4);
    generate_character(fake_rnd, out, characteristic_generation_method_general_NPC);
    generate_character(fake_rnd, out, characteristic_generation_method_special_NPC);
    
    rnd_free(fake_rnd);
}
static void
treasure_type_generate_for_A_with_fake_fixed_test(void)
{
    struct rnd *rnd = rnd_alloc_fake_fixed(25);
    struct treasure treasure;
    treasure_initialize(&treasure);
    struct treasure_type *treasure_type = treasure_type_by_letter('A');

    treasure_type_generate(treasure_type, rnd, &treasure);

    assert(0 == treasure.coins.cp);
    assert(2000 == treasure.coins.sp);
    assert(2000 == treasure.coins.ep);
    assert(6000 == treasure.coins.gp);
    assert(0 == treasure.coins.pp);
    assert(24 == treasure.gems_count);
    assert(18 == treasure.jewelry_count);
    assert(3 == treasure.magic_items_count);
    assert(0 == treasure.maps_count);

    treasure_finalize(&treasure);
    rnd_free(rnd);
}
Example #6
0
static void
roll_test(void)
{
    struct rnd *always_one = rnd_alloc_fake_fixed(0);
    struct rnd *always_two = rnd_alloc_fake_fixed(1);
    int score;
    
    /* "roll" a constant number */
    score = roll("0", always_one);
    assert(0 == score);
    
    score = roll("3", always_one);
    assert(3 == score);
    
    score = roll("1+1", always_two);
    assert(2 == score);
    
    score = roll("5-1", always_two);
    assert(4 == score);
    
    score = roll("5*10", always_two);
    assert(50 == score);
    
    /* roll dice that always roll 1's */
    score = roll("0d4+1", always_one);
    assert(1 == score);
    
    score = roll("1D6+2", always_one);
    assert(3 == score);
    
    score = roll("2d10+1", always_one);
    assert(3 == score);
    
    score = roll("3d4+5", always_one);
    assert(8 == score);
    
    score = roll("1d12*5", always_one);
    assert(5 == score);
    
    score = roll("2d20+1*10", always_one);
    assert(30 == score);
    
    /* roll dice that always roll 2's */
    score = roll("1D6-2", always_two);
    assert(0 == score);
    
    score = roll("2d10-2", always_two);
    assert(2 == score);
    
    score = roll("3d4-3", always_two);
    assert(3 == score);
    
    score = roll("2d8*5", always_two);
    assert(20 == score);
    
    score = roll("2d20+1*10", always_two);
    assert(50 == score);
    
    rnd_free(always_one);
    rnd_free(always_two);
}