예제 #1
0
int cambio(int pos, int carril, int *darpos, int *darcarril)
{
	int i, tpos, tcarril;

	/*En este array la ultima cifra va a ser lo que se le va a añadir (en caso de ser positivo) o lo que se le va a restar (en caso de ser negativo) a 	la posicion pasada como parametro,las dos primera cifras van a ser la maxima posicion en el carril en cuestion hasta donde va a ser posible aplicar 		la cifra anteriormente mencionada*/

	static int inter[2][11] = { { 130,281,600,-621,-652,-673,-684,-1295,-1303,-1342,-1361 },
	{ 150,-281,580,601,622,644,1255,1264,1283,1332,1360 } }; //Ver que hace con esta ultima posicion

	for (i = 0; i<11; i++)
	{
		tpos = inter[carril][i] / 10;
		if (pos <= abs(tpos) && tpos != 136)
		{
			tpos = pos + inter[carril][i] % 10;
			break;
		}
	}

	if (darpos != NULL)
		(*darpos) = tpos;

	tcarril = (carril == 1 ? 0 : 1);

	if (darcarril != NULL)
		(*darcarril) = tcarril;

	/*Ningun coche entra en el cruce cambiando de carril*/
	if (!cruce(tpos, tcarril))
		return 1;
	else
		return 0;
}
예제 #2
0
int main(void)
{
	int size = 100;
	float buffer[size];
	float buffer1[size];
	float buffer2[size];
	int i;

	trayectoriaLR(0, 2, 0, buffer, size,1, 1.2, 0.3);

	printf("Imprimiendo trayectoria izquierda derecha...\n");

	for(i = 0; i<size ; i++){
		printf("El valor de i=%d es: %f\n" ,i, buffer[i]);
	}

	trayectoriaRL(0, 2, 0, buffer1, size,1, 1.2, 0.3);

	printf("Imprimiendo trayectoria derecha izquierda...\n");

	for(i = 0; i<size ; i++){
		printf("El valor de i=%d es: %f\n" ,i, buffer1[i]);
	}

	int c = cruce(buffer,buffer1,buffer2,size);

	printf("Imprimiendo signos de las distancias...\n");

	for(i = 0; i<size ; i++){
		printf("El valor de i=%d es: %f\n" ,i, buffer2[i]);
	}

	printf("El primer cruce ocurrio en el momento %d\n", c);

}
예제 #3
0
DWORD WINAPI fnCoches(LPVOID parametro)
{
	int posicion, carril, color, sum;
	int velocidad, tcarril;

	srand((unsigned int)time(NULL));

	do
	{
		carril = randgen(0, 1);
		sum = carril * 137;
		posicion = randgen(0, 136);
	} while (cruce(posicion, carril) || WaitForSingleObject(IPC.posiciones[posicion + sum], 0) != WAIT_OBJECT_0);

	velocidad = randgen(1, 99);
	color = randgen(0, 7);

	/*Situamos el coche en la posicion y carril calculadas arriba*/
	DLL.inicio_coche(&carril, &posicion, color);

	/*Avisamos que nos hemos creado*/
	SetEvent(IPC.evento_creacion);
	WaitForSingleObject(IPC.semaforo_pistoletazo, INFINITE); //Esperamos por el pistoletazo

	while (1)
	{
		/*Garantizamos que  estando en estas posiciones avanzo o espero que el semaforo cambie*/
		if ((posicion == 20 && carril == 0) || (posicion == 22 && carril == 1))
			WaitForSingleObject(IPC.posiciones[274], INFINITE);
		if ((posicion == 105 && carril == 0) || (posicion == 98 && carril == 1))
			WaitForSingleObject(IPC.posiciones[275], INFINITE);

		tcarril = carril;

		avanzar(&posicion, &carril, color);

		/*Incremento el contador de vueltas si estoy en estas posiciones y no cambio de carril*/
		if (((posicion == 133 && carril == 0) || (posicion == 131 && carril == 1)) && tcarril == carril)
			InterlockedIncrement((long*)(parametro));

		/*Si he cogio los mutex de arriba los libero para que el semaforo pueda cambiar de color*/
		ReleaseMutex(IPC.posiciones[274]);
		ReleaseMutex(IPC.posiciones[275]);

		DLL.velocidad(velocidad, carril, posicion);
	}

	return 1;
}