Esempio n. 1
0
void TestData_list_uint_test(TestData _test)
{
    uint i = 0;
    ///list _lst;
    List _lst = List_new(Vptr, malloc, free);
    List lst;
    Iterator iter;


    for (; i < _test->count; i++)
    {
        _test->data[i].uint32_var = i;
    }

    printf("push back begin test\n");

    lst = List_Init(_lst, Uint32, malloc, free);
    for (i = 0; i < _test->count; i++)
    {
        Iterator iter = List_push_back(lst, _test->data[i]);
        if (List_get_value(iter).uint32_var != _test->data[i].uint32_var)
        {
#if BIT_WIDTH == 64
            printf("data error! tmp %d data %d i %I64d count %I64d", List_get_value(iter).uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#else
            printf("data error! tmp %d data %d i %d count %d", List_get_value(iter).uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#endif
        }
    }
    i = 0;
    iter = List_begin(lst);
    while (iter)
    {
        var tmp = List_get_value(iter);
        if (tmp.uint32_var != _test->data[i].uint32_var)
        {
#if BIT_WIDTH == 64
            printf("data error! tmp %d data %d i %I64d count %I64d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#else
            printf("data error! tmp %d data %d i %d count %d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#endif
        }
        iter = List_next(iter);
        i++;
    }
    i = _test->count - 1;
    iter = List_end(lst);
    while (iter)
    {
        var tmp = List_get_value(iter);
        if (tmp.uint32_var != _test->data[i].uint32_var)
        {
#if BIT_WIDTH == 64
            printf("data error! tmp %d data %d i %I64d count %I64d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#else
            printf("data error! tmp %d data %d i %d count %d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#endif
        }
        iter = List_prev(iter);
        i--;
    }
    List_Dest(lst);
    printf("push back test end\n");
    ///
    printf("insert after test0 begin\n");
    lst = List_Init(lst, Uint32, malloc, free);
    iter = List_push_back(lst, _test->data[0]);
    for (i = 1; i < _test->count; i++)
    {
        iter = List_insert_after(lst, iter, _test->data[i]);
    }
    i = 0;
    iter = List_begin(lst);
    while (iter)
    {
        var tmp = List_get_value(iter);
        if (tmp.uint32_var != _test->data[i].uint32_var)
        {
#if BIT_WIDTH == 64
            printf("data error! tmp %d data %d i %I64d count %I64d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#else
            printf("data error! tmp %d data %d i %d count %d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#endif
        }
        iter = List_next(iter);
        i++;
    }
    List_Dest(lst);
    printf("insert after test0 end\n");
    ///
    printf("insert after test1 begin\n");
    lst = List_Init(lst, Uint32, malloc, free);
    iter = List_push_back(lst, _test->data[0]);
    List_push_back(lst, _test->data[_test->count - 1]);
    for (i = 1; i < _test->count - 1; i++)
    {
        iter = List_insert_after(lst, iter, _test->data[i]);
    }
    i = 0;
    iter = List_begin(lst);
    while (iter)
    {
        var tmp = List_get_value(iter);
        if (tmp.uint32_var != _test->data[i].uint32_var)
        {
#if BIT_WIDTH == 64
            printf("data error! tmp %d data %d i %I64d count %I64d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#else
            printf("data error! tmp %d data %d i %d count %d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#endif
        }
        iter = List_next(iter);
        i++;
    }
    List_Dest(lst);
    printf("insert after test1 end\n");
    ///
    printf("insert before test0 begin\n");
    lst = List_Init(lst, Uint32, malloc, free);
    iter = List_push_back(lst, _test->data[_test->count - 1]);
    for (i = _test->count - 2; i; i--)
    {
        iter = List_insert_before(lst, iter, _test->data[i]);
    }
    List_insert_before(lst, iter, _test->data[0]);
    i = 0;
    iter = List_begin(lst);
    while (iter)
    {
        var tmp = List_get_value(iter);
        if (tmp.uint32_var != _test->data[i].uint32_var)
        {
#if BIT_WIDTH == 64
            printf("data error! tmp %d data %d i %I64d count %I64d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#else
            printf("data error! tmp %d data %d i %d count %d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#endif
        }
        iter = List_next(iter);
        i++;
    }
    List_Dest(lst);
    printf("insert before test0 end\n");
    ///
    ///
    printf("insert before test1 begin\n");
    lst = List_Init(lst, Uint32, malloc, free);
    iter = List_push_back(lst, _test->data[0]);
    List_push_back(lst, _test->data[_test->count - 1]);
    iter = List_end(lst);
    for (i = _test->count - 2; i; i--)
    {
        iter = List_insert_before(lst, iter, _test->data[i]);
    }
    i = 0;
    iter = List_begin(lst);
    while (iter)
    {
        var tmp = List_get_value(iter);
        if (tmp.uint32_var != _test->data[i].uint32_var)
        {
#if BIT_WIDTH == 64
            printf("data error! tmp %d data %d i %I64d count %I64d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#else
            printf("data error! tmp %d data %d i %d count %d", tmp.uint32_var, _test->data[i].uint32_var, i, _test->count);
            getchar();
            exit(0);
#endif
        }
        iter = List_next(iter);
        i++;
    }
    List_Dest(lst);
    printf("insert before test1 end\n");
    ///

    printf("test succ\n");
}
Esempio n. 2
0
int main(int argc, char* argv[])
{
	Map map;
	Car cars[3] = {NULL, NULL, NULL};
	int x, y, i, rounds = 0, needPathfinding = 0, firstLoop = 1;
	List path;
	Position position;
	Vector acc;
	int fuel;

	srand(time(NULL));

	freopen("pshr4log.txt", "w+", stderr);
	// freopen("map.txt", "r", stdin);

	LOGINFO("Starting");

	initGC();

	map = Map_load(stdin);

	LOGINFO("Map loaded");

	while(!feof(stdin))
	{
		LOGINFO1I("===== Round number %d =====", rounds);

		for(i = 0; i < 3; i++)
		{
			fscanf(stdin, "%d %d", &x, &y);

			LOGINFO3I("Car number %i, position : %d %d", i, x, y);

			if(cars[i] == NULL)
				cars[i] = Car_new(x, y);
			else
				Car_updatePosition(cars[i], x, y);

			if(Car_updateArrivedStatus(cars[i], map))
			{
				recomputeDistances(map, cars);
				LOGINFO("I see you've arrived, let me see where I can park now...");
				needPathfinding = 1;
			}
		}

		if(firstLoop)
		{
			firstLoop = 0;
			path = doPathfinding(map, cars);
			List_tail(path);
			List_prev(path);
		}

		position = List_getCurrent(path);

		for(i = 1; i < 3; i++)
		{
			if(Position_equal(position, Car_getPosition(cars[i])))
			{
				needPathfinding = 1;
				LOGINFO("YOU TOOK MY SPOT JERK");
			}
		}

		if(needPathfinding)
		{
			freePath(path);
			path = doPathfinding(map, cars);
			List_tail(path);
			List_prev(path);
			needPathfinding = 0;
			position = List_getCurrent(path);
		}

		if(position == NULL)
		{
			goRandom();
		}
		else
		{
			LOGINFO2I("Going to %d %d", position->x, position->y);
			acc = Car_getAccelerationToReach(cars[0], position);
			go(acc->x, acc->y);

			if(Vector_squaredLength(acc) > 2)
			{
				Car_useBoost(cars[0]);
				LOGINFO("Using a boost");
			}

			Vector_delete(acc);
		}

		List_prev(path);

		rounds++;
	}

	LOGINFO("End");

	freePath(path);

	for(i = 0; i < 3; i++)
	{
		Car_delete(cars[i]);
	}

	Map_delete(map);
	freeGC();

	return 0;
}