Transportes do Futuro em C

precisava dumas ajudas num source que ando a desenvolver a nível académico...
fazendo um pequeno resumo do que é pedido: Construir 1 Cidade com Pessoas e Veiculos, alguns dos "quarteirões" são de recarregamento dos Veiculos, e as Pessoas fazem 1 request ao Veiculo mais próximo para satisfazer o seu request... (isto tudo com log's...) Se bem que isto tem de ser mostrado na Console, e correr do modo Step by Step (user a decidir se pretende em Step by Step, N Steps ou RUN)...

a minha dúvida recai sobre este ultimo ponto a metodologia Step by Step...
já tenho algo feito tal como a "movimentação" dos Veiculos, os Inits dos Pedidos, Pessoas, Veiculos e Cidade, já tenho funções de pesquisa de Pessoas e Veiculos, o recarregar os Veiculos, e pouco mais que isso...

Atenciosamente
André Barreto aka NitroBlast
 
Código:
[SIZE=2][COLOR=#008000]
/*Bibliotecas*de*Funcionalidades*/
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#a31515]<stdio.h>
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#a31515]<stdlib.h>
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#a31515]<time.h>
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#a31515]<math.h>
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#a31515]"projecto2.h" [/COLOR][/SIZE]
[SIZE=2][COLOR=#a31515]/*Na biblioteca projecto2.h tão definidas certas funções semelhantes à conio.h da Borland feitas por mim...*/
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]/*Defnição*de*Macros*/
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] LIMPAR system([/COLOR][/SIZE][SIZE=2][COLOR=#a31515]"cls"[/COLOR][/SIZE][SIZE=2][COLOR=#000000]) [/COLOR][/SIZE][SIZE=2][COLOR=#008000]//Definição de Macro de Limpeza
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] PAUSA system([/COLOR][/SIZE][SIZE=2][COLOR=#a31515]"pause"[/COLOR][/SIZE][SIZE=2][COLOR=#000000]) [/COLOR][/SIZE][SIZE=2][COLOR=#008000]//Definição de Macro de Pausa
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] DELAY Sleep(1000) [/COLOR][/SIZE][SIZE=2][COLOR=#008000]//Definição de Macro de Delay
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] MaxCidade 22[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] MaxPessoas MaxCidade*MaxCidade*3[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] MaxVeiculos MaxPessoas[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] MaxPedidos MaxPessoas*3[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] EnergyWasteEmpty 0.5[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] EnergyWastePerPerson 0.1[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] EnergyCell MaxCidade*MaxCidade[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] maxX=0,maxY=0,maxp=0,minp=0,maxv=0,minv=0,maxr=0, numcelulaenergy, nsteps, mediapassos;[/COLOR]
FILE* logfile;
[/SIZE][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][SIZE=2][COLOR=#000000] celula{[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] energy, pessoas[MaxPessoas], veiculos[MaxVeiculos];
};
[/SIZE][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][SIZE=2][COLOR=#000000] celula cidade[MaxCidade][MaxCidade];[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][SIZE=2][COLOR=#000000] posicao{[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] x, y;
};
[/SIZE][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][SIZE=2][COLOR=#000000] posicao posicaoEnergy[EnergyCell];[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][SIZE=2][COLOR=#000000] pedido{[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] x, y, cod, feito;
};
[/SIZE][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][SIZE=2][COLOR=#000000] pedido Pedidos[MaxPedidos];[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][SIZE=2][COLOR=#000000] pessoa{[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] cod, BI, telefone, x, y;
[/SIZE][SIZE=2][COLOR=#0000ff]char[/COLOR][/SIZE][SIZE=2] nome[256],morada[1024];
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] pedido, delaypedido;
};
[/SIZE][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][SIZE=2][COLOR=#000000] pessoa Pessoas[MaxPessoas];[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][SIZE=2][COLOR=#000000] veiculos{[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] cod, x, y, capacidade, lugares[15], energia, pedidos[15], tipo, recharging, destX, destY;
};
[/SIZE][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][SIZE=2][COLOR=#000000] veiculos Veiculos[MaxVeiculos];[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000] initPedidos(){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i;
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<maxr;i++){
Pedidos[i].cod=i+1;
Pedidos[i].feito=0;
Pedidos[i].x=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(maxX*rand()/RAND_MAX+1.0);
Pedidos[i].y=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(maxY*rand()/RAND_MAX+1.0);
}
}
[/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000] initcidade(){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i,x,y;
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<numcelulaenergy;i++){
posicaoEnergy[i].x=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(maxX*rand()/RAND_MAX+1.0);
posicaoEnergy[i].y=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(maxY*rand()/RAND_MAX+1.0);
cidade[posicaoEnergy[i].x][posicaoEnergy[i].y].energy=1;

}
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<maxv;i++){
x=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(maxX*rand()/RAND_MAX+1.0);
y=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(maxY*rand()/RAND_MAX+1.0);
cidade[x][y].veiculos[i]=Veiculos[i].cod;
}
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<maxp;i++){
Pessoas[i].x=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(maxX*rand()/RAND_MAX+1.0);
Pessoas[i].y=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(maxY*rand()/RAND_MAX+1.0);
cidade[Pessoas[i].x][Pessoas[i].y].pessoas[i]=Pessoas[i].cod;

} 
}
[/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000] initPessoas(){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i;
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<maxp;i++){
Pessoas[i].cod=i+1;
Pessoas[i].BI=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(99999999*rand()/RAND_MAX+1.0);
Pessoas[i].delaypedido=5;
Pessoas[i].pedido=-1;
printf([/SIZE][SIZE=2][COLOR=#a31515]"Pessoa %i BI %i Delay %i\n"[/COLOR][/SIZE][SIZE=2],Pessoas[i].cod,Pessoas[i].BI,Pessoas[i].delaypedido);
}
PAUSA;
}
[/SIZE][SIZE=2][COLOR=#008000]/*void writefilestats() {
FILE * stat;
stat = fopen ("Estatística.txt","w");
if (stat==NULL)
return;
else {
fprintf(stat,"",);
}
fclose (stat);
}
*/
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000] LogInit() {[/COLOR]
logfile = fopen ([/SIZE][SIZE=2][COLOR=#a31515]"log.txt"[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#a31515]"w"[/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (logfile==NULL) {
puts([/SIZE][SIZE=2][COLOR=#a31515]"Não foi possivel criar o ficheiro de log."[/COLOR][/SIZE][SIZE=2]);
exit(1);
}
}
[/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000] LogClose() {[/COLOR]
fclose (logfile);
}
[/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000] LogWrite([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]char[/COLOR][/SIZE][SIZE=2][COLOR=#000000]* str) {[/COLOR]
puts(str,logfile);
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] novoPedido([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] i){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] request;
request=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(maxr*rand()/RAND_MAX+1.0);
[/SIZE][SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2](Pedidos[request].feito!=0)
request=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(maxr*rand()/RAND_MAX+1.0);
Pessoas[i].pedido=Pedidos[request].cod;
printf([/SIZE][SIZE=2][COLOR=#a31515]"Pessoa %i Pedido %i Pedido da pessoa %i\n"[/COLOR][/SIZE][SIZE=2],Pessoas[i].cod,Pedidos[request].cod,Pessoas[i].pedido);
PAUSA;
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] pessoastatus([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] pessoa){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] found,i;
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Pessoas[pessoa].pedido==-1){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Pessoas[pessoa].delaypedido!=5)
Pessoas[pessoa].delaypedido++;
[/SIZE][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][SIZE=2]{
Pessoas[pessoa].delaypedido=0;
novoPedido(pessoa);
found=findVeiculoNear(pessoa);
Veiculos[found].destX=Pessoas[pessoa].x;
Veiculos[found].destY=Pessoas[pessoa].y;
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<Veiculos[found].capacidade;i++)
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Veiculos[found].lugares[i]==-1)
Veiculos[found].lugares[i]=Pessoas[pessoa].cod;
}
}
}
[/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000] initVeiculos(){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i, j;
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<maxv;i++){
Veiculos[i].cod=i+1;
Veiculos[i].capacidade=-1+([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2])(15*rand()/RAND_MAX+1.0);
Veiculos[i].energia=100;
Veiculos[i].tipo=1;
Veiculos[i].recharging=0;
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](j=0;j<Veiculos[i].capacidade;j++)
Veiculos[i].lugares[j]=-1;
printf([/SIZE][SIZE=2][COLOR=#a31515]"Veiculo %i - Capacidade %i\n"[/COLOR][/SIZE][SIZE=2],Veiculos[i].cod,Veiculos[i].capacidade);
}
PAUSA;
}
[/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000] mostarCidade(){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i,j,k,flagp=0,flagv=0;
LIMPAR;
setcolor(WHITE);
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<=maxX+1;i++){
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](j=0;j<=maxY+1;j++){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2]((i==0) || (i==maxX+1) || (j==0) || (j==maxY+1)){
gotoxy(i,j);
printf([/SIZE][SIZE=2][COLOR=#a31515]"H"[/COLOR][/SIZE][SIZE=2]);

}
}
}
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<maxX;i++){
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](j=0;j<maxY;j++){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](cidade[i][j].energy==1){
setcolor(CYAN);
gotoxy(i+1,j+1);
printf([/SIZE][SIZE=2][COLOR=#a31515]"E"[/COLOR][/SIZE][SIZE=2]);
}
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](k=0;k<MaxPessoas;k++){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](cidade[i][j].pessoas[k]!=0){
setcolor(GREEN);
gotoxy(i+1,j+1);
printf([/SIZE][SIZE=2][COLOR=#a31515]"P"[/COLOR][/SIZE][SIZE=2]);
}
}
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](k=0;k<MaxVeiculos;k++){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](cidade[i][j].veiculos[k]!=0){
setcolor(RED);
gotoxy(i+1,j+1);
printf([/SIZE][SIZE=2][COLOR=#a31515]"V"[/COLOR][/SIZE][SIZE=2]);
}
}

}
}
setcolor(WHITE);
gotoxy(maxX+2,maxY+1);
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] deslocamentoVeiculos(){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i, j;
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<maxv;i++){[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Veiculos[i].x>Veiculos[i].destX){
Veiculos[i].x--;
}
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Veiculos[i].x<Veiculos[i].destX){
Veiculos[i].x++;
}
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Veiculos[i].x==Veiculos[i].destX){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Veiculos[i].y>Veiculos[i].destY){
Veiculos[i].y--;
}
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Veiculos[i].y<Veiculos[i].destY){
Veiculos[i].y++;
}
}
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](j=0;j<Veiculos[i].capacidade;j++){
Pessoas[Veiculos[i].lugares[j]].x=Veiculos[i].x;
Pessoas[Veiculos[i].lugares[j]].y=Veiculos[i].y;
}

}
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] carregarveiculo([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] i){[/COLOR]
Veiculos[i].energia=Veiculos[i].energia+3;
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Veiculos[i].energia>100)
Veiculos[i].energia=100;
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] verificarEnergy([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] i, [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] energy){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] recarregar;
recarregar=maxX*EnergyWastePerPerson*Veiculos[i].capacidade+maxY*EnergyWastePerPerson*Veiculos[i].capacidade;
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](energy>recarregar)
[/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] 1;
[/SIZE][SIZE=2][COLOR=#0000ff]else
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] 0;
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] verstatuspedido(){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i, flag=0;
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<maxr;i++){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Pedidos[i].feito==1)
flag=1;
[/SIZE][SIZE=2][COLOR=#0000ff]else
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] 0;
}
[/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] flag;
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] largarpessoa([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] veiculo){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i;
Pessoas[Veiculos[veiculo].lugares[0]].pedido=-1;
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<Veiculos[veiculo].capacidade;i++){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Veiculos[veiculo].lugares[i]==(Veiculos[veiculo].capacidade-1))
Veiculos[veiculo].lugares[i]=0;
[/SIZE][SIZE=2][COLOR=#0000ff]else
[/COLOR][/SIZE][SIZE=2]Veiculos[veiculo].lugares[i]=Veiculos[veiculo].lugares[i+1];
}
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] distanciaPessoasVeiculos([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] i, [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] j){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] dist;
dist=(Pessoas[i].x-Veiculos[j].x)+(Pessoas[i].y-Veiculos[j].y);
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](dist<0) dist=dist*-1;
[/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] dist;
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] findVeiculoNear([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] j){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i, max, pos;
max=MaxCidade*2;
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<maxv;i++){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](max>distanciaPessoasVeiculos(i,j)){
max=distanciaPessoasVeiculos(i,j);
pos=j;
}
}
[/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] pos;
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] distanciaVeiculosEnergy([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] i, [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] j){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] dist;
dist=(posicaoEnergy[i].x-Veiculos[j].x)+(posicaoEnergy[i].y-Veiculos[j].y);
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](dist<0) dist=dist*-1;
[/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] dist;
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] findEnergyCell([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] j){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i, max, pos;
max=MaxCidade*2;
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<numcelulaenergy;i++){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](max>distanciaVeiculosEnergy(i,j)){
max=distanciaVeiculosEnergy(i,j);
pos=j;
}
}
[/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] pos;
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] motorCidade([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] opcao){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i, flag=0, steps=0, found;
[/SIZE][SIZE=2][COLOR=#0000ff]switch[/COLOR][/SIZE][SIZE=2](opcao){
[/SIZE][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][SIZE=2] 1:[/SIZE][SIZE=2][COLOR=#008000]//run
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]do[/COLOR][/SIZE][SIZE=2]{
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<maxp;i++){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](Pessoas[i].pedido==-1)
pessoastatus(i);
}
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2](i=0;i<maxv;i++){
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](verificarEnergy(i, Veiculos[i].energia)==0){
found=findEnergyCell(i);
Veiculos[i].destX=posicaoEnergy[found].x;
Veiculos[i].destY=posicaoEnergy[found].y;
}
[/SIZE][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][SIZE=2]{
Veiculos[i].destX=Pedidos[Pessoas[Veiculos[i].lugares[0]].pedido].x;
Veiculos[i].destY=Pedidos[Pessoas[Veiculos[i].lugares[0]].pedido].y;
}
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2]((Veiculos[i].destX==Pedidos[Pessoas[Veiculos[i].lugares[1]].pedido].x) && (Veiculos[i].destY==Pedidos[Pessoas[Veiculos[i].lugares[1]].pedido].y))
largarpessoa(i);
}
deslocamentoVeiculos();
flag=verstatuspedido();
mostarCidade();
DELAY;
}[/SIZE][SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2](flag==0);
[/SIZE][SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][SIZE=2] 2:[/SIZE][SIZE=2][COLOR=#008000]//n step
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]do[/COLOR][/SIZE][SIZE=2]{

flag=verstatuspedido();
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](steps==nsteps){
PAUSA;
steps=-1;
}
DELAY;
mostarCidade();
steps++;
}[/SIZE][SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2](flag==0);
[/SIZE][SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][SIZE=2] 3:[/SIZE][SIZE=2][COLOR=#008000]//step
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]do[/COLOR][/SIZE][SIZE=2]{

flag=verstatuspedido();
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](steps==nsteps){
PAUSA;
steps=0;
}
DELAY;
mostarCidade();
steps++;
}[/SIZE][SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2](flag==0);
[/SIZE][SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][SIZE=2];
}
}
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] main(){[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] op;
printf([/SIZE][SIZE=2][COLOR=#a31515]"Insira o tamanho da cidade (máx:(%i,%i)): "[/COLOR][/SIZE][SIZE=2],MaxCidade,MaxCidade);
scanf([/SIZE][SIZE=2][COLOR=#a31515]"%i%i"[/COLOR][/SIZE][SIZE=2],&maxX,&maxY);
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](maxX==0)
maxX=MaxCidade;
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](maxY==0)
maxY=MaxCidade;
minp=(1/3)*maxX*maxY;
minv=(1/5)*maxX*maxY;
maxp=3*maxX*maxY;
maxr=maxp*3;
numcelulaenergy=floor((maxX*maxY)/62.5);
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (((maxX==0) && (maxY==0)) || ((maxX==MaxCidade) && (maxY==MaxCidade)))
numcelulaenergy++;
printf([/SIZE][SIZE=2][COLOR=#a31515]"Insira o nº de pessoas (min:%i máx:%i): "[/COLOR][/SIZE][SIZE=2],minp,maxp);
scanf([/SIZE][SIZE=2][COLOR=#a31515]"%i"[/COLOR][/SIZE][SIZE=2],&maxp);
maxv=maxp;
maxr=maxp*3;
printf([/SIZE][SIZE=2][COLOR=#a31515]"Insira o nº de veiculos (min:%i máx:%i): "[/COLOR][/SIZE][SIZE=2],minv,maxv);
scanf([/SIZE][SIZE=2][COLOR=#a31515]"%i"[/COLOR][/SIZE][SIZE=2],&maxv);
printf([/SIZE][SIZE=2][COLOR=#a31515]"Insira o nº de pedidos (máx:%i): "[/COLOR][/SIZE][SIZE=2],maxr);
scanf([/SIZE][SIZE=2][COLOR=#a31515]"%i"[/COLOR][/SIZE][SIZE=2],&maxr);
printf([/SIZE][SIZE=2][COLOR=#a31515]"Insira opção (1-RUN 2-N Steps 3-Step by Step): "[/COLOR][/SIZE][SIZE=2]);
scanf([/SIZE][SIZE=2][COLOR=#a31515]"%i"[/COLOR][/SIZE][SIZE=2],&op);
LIMPAR;
srand(time(NULL));
initPedidos();
initVeiculos();
initPessoas();
initcidade();
[/SIZE][SIZE=2][COLOR=#0000ff]switch[/COLOR][/SIZE][SIZE=2](op){
[/SIZE][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][SIZE=2] 1:
motorCidade(1);
[/SIZE][SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][SIZE=2] 2:
printf([/SIZE][SIZE=2][COLOR=#a31515]"Insira a quantidade de Steps: "[/COLOR][/SIZE][SIZE=2]);
scanf([/SIZE][SIZE=2][COLOR=#a31515]"%i"[/COLOR][/SIZE][SIZE=2],&nsteps);
motorCidade(2);
[/SIZE][SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][SIZE=2] 3:
nsteps=1;
motorCidade(3);
[/SIZE][SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][SIZE=2];
}
PAUSA;
[/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] 0;
}
[/SIZE]

e não percebo o porquê disto não funcionar...
 
desculpem... aqui tá ele

Código:
[SIZE=2][COLOR=#0000ff]
#ifndef[/COLOR][/SIZE][SIZE=2][COLOR=#000000] _PROJECTO2_H_[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] _PROJECTO2_H_[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#a31515]<stdio.h>
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#a31515]<stdlib.h>
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#a31515]<windows.h>
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] BLACK 0[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] DARK_BLUE 1[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] DARK_GREEN 2[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] DARK_CYAN 3[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] DARK_RED 4[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] DARK_MAGENT 5[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] DARK_YELLOW 6[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] LIGHT_GRAY 7[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] DARK_GRAY 8[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] BLUE 9[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] GREEN 10[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] CYAN 11[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] RED 12[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] MAGENT 13[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] YELLOW 14[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]#define[/COLOR][/SIZE][SIZE=2][COLOR=#000000] WHITE 15[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000] gotoxy([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] x, [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2][COLOR=#000000] y) {[/COLOR]
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (INVALID_HANDLE_VALUE != hConsole) {
COORD pos = {x,y};
SetConsoleCursorPosition(hConsole,pos);
}
}
[/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000] setcolor([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]unsigned[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]short[/COLOR][/SIZE][SIZE=2][COLOR=#000000] color)[/COLOR]
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](INVALID_HANDLE_VALUE!= hConsole)
SetConsoleTextAttribute(hConsole,color);
}
[/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000] clrscr([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2][COLOR=#000000]){[/COLOR]
COORD coordScreen = {0, 0}; 
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; 
DWORD dwConSize; 
HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

FillConsoleOutputCharacter(hConsole, TEXT([/SIZE][SIZE=2][COLOR=#a31515]' '[/COLOR][/SIZE][SIZE=2]),
dwConSize, coordScreen, &cCharsWritten);

GetConsoleScreenBufferInfo(hConsole, &csbi);

FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten);

SetConsoleCursorPosition(hConsole, coordScreen);
}
 
 
[/SIZE][SIZE=2][COLOR=#0000ff]#endif
[/COLOR][/SIZE]
 
continuamos sem perceber a tua dúvida, se está a dar erra, mosta-o sff, debuging é fácil e aconselhável, a melhor forma de aprender é a cometer erros e a perceber onde erramos, se não sabes usar tools de debugging, podes sempre fazer uns printfs :P, testa função a função e certifica-te que está tudo a fazer o que deve. Que não passas dos limites dos vectores, e que estás a guardar a info certa. mais uma vez testa função a função. :) se tiveres alguma dúvida especifica que não percebas e não consegues apanhar origem do problema, linka aqui a função e o erro :)
boa sorte.
 
é assim não dá-me um erro em especifico, apenas não "corre", seja isso:
o programa executa normalment mas os "veiculos" não vão bucar as "pessoas" mas no entanto sei que as estão a levar...


bug encontrado... thks anyway
 
Última edição:
Back
Topo