Пример #1
0
static void test_dragon_attacks_the_rich(CuTest * tc)
{
    faction *f, *f2;
    unit *u, *m;
    const item_type *i_silver;

    create_monsters(&f, &f2, &u, &m);
    init_resources();

    setguard(m, true);
    set_level(m, SK_WEAPONLESS, 10);

    rsetmoney(findregion(0, 0), 1);
    rsetmoney(findregion(1, 0), 0);
    i_silver = it_find("money");
    assert(i_silver);
    i_change(&u->items, i_silver, 5000);

    config_set("rules.monsters.attack_chance", "0.00001");

    plan_monsters(f2);

    CuAssertPtrNotNull(tc, find_order("attack 1", m));
    CuAssertPtrNotNull(tc, find_order("loot", m));
    test_cleanup();
}
Пример #2
0
static void test_dragon_attacks_the_rich(CuTest * tc)
{
    faction *f, *f2;
    region *r;
    unit *u, *m;
    const item_type *i_silver;

    init_language();
    create_monsters(&f, &f2, &r, &u, &m);

    guard(m, GUARD_TAX);
    set_level(m, SK_WEAPONLESS, 10);

    rsetmoney(r, 1);
    rsetmoney(findregion(1, 0), 0);
    i_silver = it_find("money");
    assert(i_silver);
    i_change(&u->items, i_silver, 5000);

    config_set("rules.monsters.attack_chance", "0.00001");

    plan_monsters(f2);

    CuAssertPtrNotNull(tc, find_order("ATTACKIERE 1", m));
    CuAssertPtrNotNull(tc, find_order("PLUENDERE", m));
    test_cleanup();
}
Пример #3
0
static void test_dragon_moves(CuTest * tc)
{
    faction *f, *f2;
    region *r;
    unit *u, *m;
    struct message *msg;

    create_monsters(&f, &f2, &u, &m);
    rsetmoney(findregion(1, 0), 1000);
    r = findregion(0, 0); // plain
    rsetpeasants(r, 0);
    rsetmoney(r, 0);

    set_level(m, SK_WEAPONLESS, 10);
    config_set("rules.monsters.attack_chance", ".0");
    plan_monsters(f2);

    CuAssertPtrNotNull(tc, find_order("move east", m));

    mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", 0));

    random_growl(m, findregion(1, 0), 3);

    msg = test_get_last_message(r->msgs);
    assert_message(tc, msg, "dragon_growl", 4);
    assert_pointer_parameter(tc, msg, 0, m);
    assert_int_parameter(tc, msg, 1, 1);
    assert_pointer_parameter(tc, msg, 2, findregion(1,0));
    assert_string_parameter(tc, msg, 3, "growl3");

    test_cleanup();
}
Пример #4
0
ull ShiftHashTable::calc_hash(ull key)
{
  ull res = key;
  unsigned order = find_order(res);
  unsigned half_order;
  do
  {
    if ( order < package_count_order * 2 )
      res = (res % ten_in_package_count_order) + (res / ten_in_package_count_order);
    else
    {
      half_order = (order + 1) / 2;
      res = (res % (ull) pow(10, half_order)) + (res / (ull) pow(10, half_order));
    }
    order = find_order(res);
  } while ( order > package_count_order );
  return res;
}
Пример #5
0
static void test_monsters_waiting(CuTest * tc)
{
    faction *f, *f2;
    unit *u, *m;

    create_monsters(&f, &f2, &u, &m);
    setguard(m, true);
    fset(m, UFL_ISNEW);
    monster_attacks(m, false, false);
    CuAssertPtrEquals(tc, 0, find_order("attack 1", m));
    test_cleanup();
}
Пример #6
0
static void test_monsters_waiting(CuTest * tc)
{
    faction *f, *f2;
    region *r;
    unit *u, *m;

    create_monsters(&f, &f2, &r, &u, &m);
    guard(m, GUARD_TAX);
    fset(m, UFL_ISNEW);
    monster_attacks(m, false, false);
    CuAssertPtrEquals(tc, 0, find_order("ATTACKIERE 1", m));
    test_cleanup();
}
Пример #7
0
static void test_seaserpent_piracy(CuTest * tc)
{
    faction *f, *f2;
    region *r;
    unit *u, *m;
    race *rc;

    create_monsters(&f, &f2, &u, &m);
    r = findregion(-1, 0); // ocean
    u = test_create_unit(u->faction, r);
    unit_setid(u, 2);
    m = test_create_unit(m->faction, r);
    u_setrace(m, rc = test_create_race("seaserpent"));
    assert(!m->region->land);
    fset(m, UFL_MOVED);
    fset(rc, RCF_ATTACK_MOVED);

    config_set("rules.monsters.attack_chance", "1");

    plan_monsters(f2);
    CuAssertPtrNotNull(tc, find_order("piracy", m));
    CuAssertPtrNotNull(tc, find_order("attack 2", m));
    test_cleanup();
}
Commitment Commiter::commit(const unsigned K, const vector<bool> &m) {
    unsigned available_primes;
    Integer g, h;
    Integer a0, a, u;
    vector<bool> S;
    vector<Integer> W;
    unsigned l;

    // sanity check on m
    for(bool b: m) {
        if (b != 0 && b != 1) {
            throw SanityException("not binary m");
        }
    }
    l = m.size();

    h = Integer(common::rng(), 2, n-1);
    g = get_g(n, h);
    order = find_order(p, q, g);

    a0 = a_exp_b_mod_c(2, Integer::Power2(K) - l, phi);
    a = a_exp_b_mod_c(2, Integer::Power2(K), phi);
    u = a_exp_b_mod_c(g, a0, n);

    S.resize(l);
    for(unsigned i = 0; i < l; ++i) {
        S[i] = m[i] ^ u.GetBit(0);
        u = a_times_b_mod_c(u, u, n);
    }

    // sanity check on u
    if (u != a_exp_b_mod_c(g, a, n)) {
        throw SanityException("u != g ** a");
    }

    W.resize(K+1);
    for(unsigned i = 0; i <= K; ++i) {
        Integer exp = a_exp_b_mod_c(2, Integer::Power2(i) , phi);
        W[i] = a_exp_b_mod_c(g, exp, n);
    }

    // sanity check on W
    if (W[0] != (g*g % n) || W[1] != (g*g*g*g % n) || W[K] != u) {
        throw SanityException("invalid W");
    }
    com = Commitment(K, n, h, g, u, S, W, m.size());
    return com;
}
Пример #9
0
static void test_monsters_attack(CuTest * tc)
{
    faction *f, *f2;
    unit *u, *m;

    create_monsters(&f, &f2, &u, &m);

    setguard(m, true);

    config_set("rules.monsters.attack_chance", "1");

    plan_monsters(f2);

    CuAssertPtrNotNull(tc, find_order("attack 1", m));
    test_cleanup();
}
Пример #10
0
static void test_monsters_attack(CuTest * tc)
{
    faction *f, *f2;
    region *r;
    unit *u, *m;

    create_monsters(&f, &f2, &r, &u, &m);

    guard(m, GUARD_TAX);

    config_set("rules.monsters.attack_chance", "1");

    plan_monsters(f2);

    CuAssertPtrNotNull(tc, find_order("ATTACKIERE 1", m));
    test_cleanup();
}
Пример #11
0
static void test_dragon_moves(CuTest * tc)
{
    faction *f, *f2;
    region *r;
    unit *u, *m;

    create_monsters(&f, &f2, &r, &u, &m);
    rsetpeasants(r, 0);
    rsetmoney(r, 0);
    rsetmoney(findregion(1, 0), 1000);

    set_level(m, SK_WEAPONLESS, 10);
    config_set("rules.monsters.attack_chance", ".0");
    plan_monsters(f2);

    CuAssertPtrNotNull(tc, find_order("NACH O", m));
    test_cleanup();
}
Пример #12
0
static void test_monsters_attack_ocean(CuTest * tc)
{
    faction *f, *f2;
    region *r;
    unit *u, *m;

    create_monsters(&f, &f2, &u, &m);
    r = findregion(-1, 0); // ocean
    u = test_create_unit(u->faction, r);
    unit_setid(u, 2);
    m = test_create_unit(m->faction, r);
    assert(!m->region->land);

    config_set("rules.monsters.attack_chance", "1");

    plan_monsters(f2);

    CuAssertPtrNotNull(tc, find_order("attack 2", m));
    test_cleanup();
}
Пример #13
0
/**
 * Allocate a memory block.
 *
 * On a memory request, the allocator returns the head of a free-list of the
 * matching size (i.e., smallest block that satisfies the request). If the
 * free-list of the matching block size is empty, then a larger block size will
 * be selected. The selected (large) block is then splitted into two smaller
 * blocks. Among the two blocks, left block will be used for allocation or be
 * further splitted while the right block will be added to the appropriate
 * free-list.
 *
 * @param size size in bytes
 * @return memory block address
 */
void *buddy_alloc(int size)
{
	if(size > (1<<MAX_ORDER))
	{
		printf("Size too big for memory space\n");
		return NULL;
	}

	int newOrder = MIN_ORDER;
	while(size > (1<<newOrder))
	{
		newOrder++;
	}
	// printf("Received request of order: %d\n", newOrder);

	int splits = 0;
	Node* temp = find_order(newOrder);
	while(temp == 0)
	{
		newOrder++;
		temp = find_order(newOrder);
		splits++;
	}
	if(splits == 0)
	{
		temp->free = 0;
		return PAGE_TO_ADDR(temp->pageIndex);
	}
	while(splits > 0)
	{
		// printf("Splitting node of order: %d\n", temp->order);
		Node* tempLeft = init_node(temp, temp->pageIndex);
		int pageRight = ADDR_TO_PAGE(BUDDY_ADDR(PAGE_TO_ADDR((unsigned long)temp->pageIndex), (temp->order-1)));
		Node* tempRight = init_node(temp, pageRight);
		temp->left = tempLeft;
		temp->right = tempRight;
		temp->free = 0;
		temp = temp->left;
		splits--;
	}
	temp->free = 0;
	return PAGE_TO_ADDR(temp->pageIndex);



	/*old code
	int index = MIN_ORDER;
	while(size > (1<<index))
	{
		index++;
	}
	struct list_head head = free_area[index];
	if(!list_empty(&head))
	{
		page_t* page = list_entry(head.next, page_t, list);
		page->order = index;
		return PAGE_TO_ADDR((unsigned long) (g_pages - page));
	}
	else
	{
		int splits = 1;
		index++;
		while(index <= MAX_ORDER && list_empty(&(free_area[index])))
		{
			splits++;
			index++;
		}
		head = free_area[index];
		page_t* page =  list_entry(head.next, page_t, list);
		while(splits > 0)
		{
			page_t buddy = g_pages[ADDR_TO_PAGE(BUDDY_ADDR(PAGE_TO_ADDR((unsigned long) (page - g_pages)), (index-1)))];
			buddy.order = index - 1;
			list_add(&buddy.list, &free_area[index-1]);
			splits--;
			index--;
		}
		page->order = index;
		return PAGE_TO_ADDR((unsigned long) (g_pages - page));
	}*/

	return NULL;
}