Código:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void carrera(int recorrido[]);
void movimiento(int recorrido[]);
int main()
{
int recorrido[71] = {0};
int tortuga = 1;
int liebre = 2;
int i;
int x;
srand(time(NULL));
recorrido[1] = 4;
carrera(recorrido);
while(recorrido[70] == 0){
system("cls");
movimiento(recorrido);
carrera(recorrido);
}
if(recorrido[70] == 1){
printf("\n\nGANO LA TORTUGA!!! VIVA!!!");
}
if(recorrido[70] == 2){
printf("\n\nGano La Liebre. Yupi!");
}
if(recorrido[70] == 3){
printf("\n\nEsto es un empate! (Aunque la Tortuga mordio a la Liebre xD)");
}
getchar();
return 0;
}
void carrera(int recorrido[])
{
int i;
for(i = 1; i <= 70; i++){
if(recorrido[i] == 0)
printf(" ");
if(recorrido[i] == 1)
printf("T");
if(recorrido[i] == 2)
printf("L");
if(recorrido[i] == 3 && i != 1)
printf("OUCH!!!");
if(recorrido[i] == 4)
printf("START");
}
printf("\n\n");
}
void movimiento(int recorrido[])
{
int i;
int azar;
int temporal;
int switch1 = 0;
int switch2 = 0;
if(recorrido[1] == 4){
if(switch1 == 0){
recorrido[1] = 0;
azar = (rand() % 10) + 1;
switch(azar){
case 1:
case 2:
case 3:
case 4:
case 5:
recorrido[4] += 1;
switch1 = 1;
break;
case 6:
case 7:
recorrido[1] += 1;
switch1 = 1;
break;
case 8:
case 9:
case 10:
recorrido[2] += 1;
switch1 = 1;
break;
}
}
if(switch2 == 0){
azar = (rand() % 10) + 1;
switch(azar){
case 1:
case 2:
recorrido[1] += 2;
break;
case 3:
case 4:
recorrido[10] += 2;
break;
case 5:
recorrido[1] += 2;
break;
case 6:
case 7:
case 8:
recorrido[2] += 2;
break;
case 9:
case 10:
recorrido[1] += 2;
break;
}
}
}
else{
for(i = 1; i <= 70; i++){
if(recorrido[i] == 1){
if(switch1 == 0){
azar = (rand() % 10) + 1;
switch(azar){
case 1:
case 2:
case 3:
case 4:
case 5:
if(i+3 > 70){
recorrido[70] += 1;
recorrido[i] -= 1;
switch1 = 1;
}
else{
recorrido[i+3] += 1;
recorrido[i] -= 1;
switch1 = 1;
}
break;
case 6:
case 7:
if(i-6 < 1){
recorrido[1] += 1;
recorrido[i] -= 1;
switch1 = 1;
}
else{
recorrido[i-6] += 1;
recorrido[i] -= 1;
switch1 = 1;
}
break;
case 8:
case 9:
case 10:
recorrido[i+1] += 1;
recorrido[i] -= 1;
switch1 = 1;
break;
}
}
}
if(recorrido[i] == 2){
if(switch2 == 0){
azar = (rand() % 10) + 1;
switch(azar){
case 1:
case 2:
switch2 = 1;
break;
case 3:
case 4:
if(i+9 > 70){
recorrido[70] += 2;
recorrido[i] -= 2;
}
else{
recorrido[i+9] += 2;
recorrido[i] -= 2;
}
switch2 = 1;
break;
case 5:
if(i-12 < 1){
recorrido[1] += 2;
recorrido[i] -= 2;
}
else{
recorrido[i-12] += 2;
recorrido[i] -= 2;
}
switch2 = 1;
break;
case 6:
case 7:
case 8:
recorrido[i+1] += 2; // Talvez en esta parte haga falta una condición de switch2
recorrido[i] -= 2;
switch2 = 1;
break;
case 9:
case 10:
if(i-2 < 1){
recorrido[1] += 2;
recorrido[i] -= 2;
}
else{
recorrido[i-2] += 2;
recorrido[i] -= 2;
}
switch2 = 1;
break;
}
}
}
if(recorrido[i] == 3){
if(switch1 == 0){
azar = (rand() % 10) + 1;
switch(azar){
case 1:
case 2:
case 3:
case 4:
case 5:
if(i+3 > 70){
recorrido[70] += 1;
recorrido[i] -= 1;
}
else{
recorrido[i+3] += 1;
recorrido[i] -= 1;
}
switch1 = 1;
break;
case 6:
case 7:
if(i - 6 < 1){
recorrido[1] += 1;
recorrido[i] -= 1;
}
else{
recorrido[i-6] += 1;
recorrido[i] -= 1;
}
switch1 = 1;
break;
case 8:
case 9:
case 10:
recorrido[i+1] += 1; //Talvez necesite condicion de switch1
recorrido[i] -= 1;
switch1 = 1;
break;
}
}
if(switch2 == 0){
azar = (rand() % 10) + 1;
switch(azar){
case 1:
case 2:
switch2 = 1;
break;
case 3:
case 4:
if(i+9 > 70){
recorrido[70] += 2;
recorrido[i] -= 2;
}
else{
recorrido[i+9] += 2;
recorrido[i] -= 2;
}
switch2 = 1;
break;
case 5:
if(i - 12 < 1){
recorrido[1] += 2;
recorrido[i] -= 2;
}
else{
recorrido[i-12] += 2;
recorrido[i] -= 2;
}
switch2 = 1;
break;
case 6:
case 7:
case 8:
recorrido[i+1] += 2;
recorrido[i] -= 2;
switch2 = 1;
break;
case 9:
case 10:
if(i-2 < 1){
recorrido[1] += 2;
recorrido[i] -= 2;
}
else{
recorrido[i-2] += 2;
recorrido[i] -= 2;
}
switch2 = 1;
break;
}
}
}
}
}
}
Saludos!