Exemplo n.º 1
0
int main()
{
    Post_t post = Post_new(0, 0);
    Post_addWantedCar(post, "007");
    Person_t carOwner = Person_new("Nikita", "Silchenko");
    Car_t car = Car_new("007");
    Car_setOwner(car, carOwner);
    char buff[128];
    Transist_t transist = Transist_new(car, TRANSIST_DEST_TO);
    Post_subscribeWantedCarTransist(post, carOwner, wantedCarPassed_Person, NULL );
    Post_pass(post, transist);
    List_t carsTo = Post_getCars(post, TRANSIST_DEST_TO);
    printf("%d\n", Post_getTransistsNum(post));
    int lSize = List_getSize(carsTo);
    for(int i = 0; i < lSize; i++){
        char buff[128];
        puts(Person_toString(Car_getOwner(List_get(carsTo, i, NULL)), buff));
    }

    Post_delete(post);
    Transist_delete(transist);
    Person_delete(carOwner);
    Car_delete(car);
    return 0;
}
Exemplo 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;
}
Exemplo n.º 3
0
Transist_delete(Transist_t self){
    Car_delete(self->car);
    free(self);
}