Exemple #1
0
Pilot *createPilotFromVertex(Vertex *u)
{
   Pilot *p=createEmptyPilot();
   Vect4D *v=u->e;
   p->pos=createVect(v->x,v->y);
   p->speed=getSpeedFromIndex(v->z);

   return p;
}
Exemple #2
0
Pilot *getPilotFromVertex(Vertex *v)
{
   Vect *speed=getSpeedFromIndex(((Vect4D *)v->e)->z);
   if(speed)
      {
	 return createPilot(createVect(((Vect4D *)v->e)->x,((Vect4D *)v->e)->y),speed);
      }
   else
      {
	 perror("Vitesse (NULL)");
      }
}
Exemple #3
0
Vertex *updateNeighborhood(Graph *g,Vertex *u)
{
   int i,j;
   Vertex *v;
   Pilot *np, *p;
   Vect *nextAcc;
   int boost=((Vect4D *)u->e)->b;
   int l=boost>0?2:1;

   p=createPilotFromVertex(u);

   for(i=-l;i<=l;i++)
      {
	 for(j=-l;j<=l;j++)
	    {  
	       np=createEmptyPilot();
	       nextAcc=createVect(i,j); 
	       np->speed=vectSum(p->speed,nextAcc); 
	       np->pos=vectSum(p->pos,np->speed);
		     
	       if(isValidMove(p,np,g->field))
		  {
		     boost=(i==-2||i==2||j==-2||j==2)?((Vect4D *)u->e)->b-1:((Vect4D *)u->e)->b;
		     
		     v=g->vertices[np->pos->x][np->pos->y][getSpeedIndex(np->speed)][boost];
		     
		     if(v->distance>u->distance+1)
			{
			   v->previous=u;
			   v->distance=u->distance+1;
			   fh_insertkey(g->heap,v->distance,v);
			}

		     if(g->field->cell[np->pos->x][np->pos->y]=='=')
			{
			   return v;
			}
		  }
	       else 
		  {
		     destroyPilot(np);
		     destroyVect(nextAcc);
		     continue;
		  }

	       destroyVect(nextAcc);
	    }
      }

   return NULL;
}
Exemple #4
0
Vect *getSpeedFromIndex(int index)
{
   int i,j;
   int k=0;
   for(i=-5;i<=5;i++)
      {
	 for(j=-5;j<=5;j++)
	    {
	       if(i*i+j*j<=25)
		  {
		     if(k==index) return createVect(i,j);
		     k++;
		  }
	    }
      }
   return NULL;
}
Exemple #5
0
float distance2Points(Point a, Point b)
{
    return distanceVect( createVect(a, b) );
}