Exemplo n.º 1
0
/* SetLabSeg: Set st and en for label (sequence) */
void SetLabSeg(Transcription *tr)
{
   LabList *ll = tr->head;    /* use first lab list */
   LLink p,q;
   
   if (tr->numLists > 1)
      HError(-1031,"SetLabSeg: label lists 2 to %d will be ignored",
             tr->numLists);
   if (labName != NULL) {  /* extract labName */
      if (auxLab==0) {
         p = GetCase(ll,labName,labRep);
         st = p->start; en = p->end;
      } else {
         p = GetAuxCase(ll,labName,labRep,auxLab);
         st = p->start; en = AuxLabEndTime(p,auxLab);
      }        
   } else {                /* extract labstidx to labenidx */
      if (auxLab==0){
         FixLabIdxs(CountLabs(ll));
         p = GetLabN(ll,curstidx);
         q = GetLabN(ll,curenidx);
         st = p->start; en = q->end;
      }else{
         FixLabIdxs(CountAuxLabs(ll,auxLab));
         p = GetAuxLabN(ll,curstidx,auxLab);
         q = GetAuxLabN(ll,curenidx,auxLab);
         st = p->start; en = AuxLabEndTime(q,auxLab);
      }
   }  
   if(trace & T_SEGMENT)
      printf("Extracting %8.0f to %8.0f\n",st,en);
}
Exemplo n.º 2
0
	bool Map::CanMove(const Direction & d1, const Point2i & pos) const
	{

		return (_cases[pos.x][pos.y].canDirection(d1)
			&& GetCase(pos.addDirection(d1)).canDirection(directionOpposee(d1))
			&& GetPracticable(pos.addDirection(d1)));

	}
/* LoadFile: load whole file or segments and accumulate variance */
static void LoadFile(char *fn)
{
   ParmBuf pbuf;
   BufferInfo info;
   char labfn[80];
   Transcription *trans;
   long segStIdx,segEnIdx;  
   int i,j,ncas,nObs;
   LLink p;
   
   if (segId == NULL)  {   /* load whole parameter file */
      if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL)
         HError(2050,"LoadFile: Config parameters invalid");
      GetBufferInfo(pbuf,&info);
      CheckData(fn,info);
      nObs = ObsInBuffer(pbuf);
      for (i=0; i<nObs; i++){
         ReadAsTable(pbuf,i,&obs);
         AccVar(obs);  
      }
      if (trace&T_LOAD) {
         printf(" %d observations loaded from %s\n",nObs,fn);
         fflush(stdout);
      }        
      CloseBuffer(pbuf);
   }
   else {                  /* load segment of parameter file */
      MakeFN(fn,labDir,labExt,labfn);
      trans = LOpen(&iStack,labfn,lff);
      ncas = NumCases(trans->head,segId);
      if ( ncas > 0) {
         if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL)
            HError(2050,"LoadFile: Config parameters invalid");
         GetBufferInfo(pbuf,&info);
         CheckData(fn,info);
         for (i=1,nObs=0; i<=ncas; i++) {
            p = GetCase(trans->head,segId,i);
            segStIdx= (long) (p->start/info.tgtSampRate);
            segEnIdx  = (long) (p->end/info.tgtSampRate);
            if (trace&T_SEGS)
               printf(" loading seg %s [%ld->%ld]\n",
                      segId->name,segStIdx,segEnIdx);
            if (segEnIdx >= ObsInBuffer(pbuf))
               segEnIdx = ObsInBuffer(pbuf)-1;
            if (segEnIdx >= segStIdx) {
               for (j=segStIdx;j<=segEnIdx;j++) {
                  ReadAsTable(pbuf,j,&obs);
                  AccVar(obs); ++nObs;
               }
            }
         }        
         CloseBuffer(pbuf);
         if (trace&T_LOAD)
            printf(" %d observations loaded from %s\n",nObs,fn);
      }  
   }
   ResetHeap(&iStack);
}
void Scan(char** map,QUEUE *q,ROBOT *robot,int feu,char carac){

int i;
//le vecteur va permettre le deplacement a droite {1,0} a gauche {0,-1} en bas {-1,0} en haut {0,1}
//c'est l'ordre du pathfinding donc des fois pour les checkpoints le robot a un deplacement bizarre
int vec[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};

//remet la queue au debut

q->front = q->back = 0;

//envoit les coordonnees dans le Tab de queue
PushBack(q,robot->pos);
//tant que le back est plus petit ou egale que le front
// == si il n'a plus rien a checker (ref popfront et pushback)
while(!(q->back <= q->front)){
	//conserve l'indice du Tab pour apres le mettre dans le from si l'indice est bon
    int from = q->front;
	//recupere les dernieres coordonnees du Tab
    COORDONNEES current = PopFront(q);
    for(i=0;i<4;i++){
        COORDONNEES sonde;
        sonde.x = current.x + vec[i][0];
        sonde.y = current.y + vec[i][1];
		//les cases dispo de passage sont ' ', '1','2','3' et 'i'
        if ((GetCase(map,sonde) == ' '||GetCase(map,sonde) == 'i'||GetCase(map,sonde) == '1'||GetCase(map,sonde) == carac||GetCase(map,sonde) == 			'2'||GetCase(map,sonde) == '3')&&!feu){

			//garde les bons indices pour afficher le chemin
			q->from[q->back] = from;
			//rentre la coordonnee dans le tableau
       		PushBack(q,sonde);	
			if (GetCase(map,sonde) == carac){
				return;//carac choisi arrive
			}
			//marque la case pour ne pas revenir dessus
			SetCase(map,sonde,'.');
		}
		//si le robot connait la config du feu alors il prend les 2 et les 3 comme des murs
		//donc carac de passage ' ','i'et '1'
		else if ((GetCase(map,sonde) == ' '||GetCase(map,sonde) == 'i'||GetCase(map,sonde) == '1'||GetCase(map,sonde) == carac)&&feu){
			
			//garde les bons indices pour afficher le chemin
			q->from[q->back] = from;
			//rentre la coordonnee dans le tableau
        	PushBack(q,sonde);	
			if (GetCase(map,sonde) == carac){
				return;//carac choisi arrive
			}
		//marque la case pour ne pas revenir dessus
		SetCase(map,sonde,'.');
        }
    }
}
return;
}
Exemplo n.º 5
0
void QuickBucket::GenerateCases()
{
	xyLoc o(100,100);
	
	for (int x = o.x-3; x <= o.x+3; x++)
	{
		for (int y = o.y-3; y <= o.y+3; y++)
		{
			xyLoc l(x,y);
			int baseCase = GetBaseCase(l,o);
			
			for (direction d = 0; d < 8; d++)
			{
				xyLoc l2(x+X[d], y+Y[d]);
				cases[baseCase] = GetCase(l,l2,o);
				baseCase ++;
			}
		}
	}
}
Exemplo n.º 6
0
/* LoadFile: load whole file or segments into segStore */
void LoadFile(char *fn)
{
   BufferInfo info;
   char labfn[80];
   Transcription *trans;
   long segStIdx,segEnIdx;
   static int segIdx=1;  /* Between call handle on latest seg in segStore */  
   static int prevSegIdx=1;
   HTime tStart, tEnd;
   int i,k,s,ncas,nObs=0,segLen;
   LLink p;
   Observation obs;

   if((pbuf=OpenBuffer(&bufferStack, fn, 10, dff, FALSE_dup, FALSE_dup))==NULL)
      HError(2150,"LoadFile: Config parameters invalid");
   GetBufferInfo(pbuf,&info);
   CheckData(fn,info);
   if (firstTime) InitSegStore(&info);

   if (segId == NULL)  {   /* load whole parameter file */
      nObs = ObsInBuffer(pbuf);
      tStart = 0.0;
      tEnd = (info.tgtSampRate * nObs);
      LoadSegment(segStore, tStart, tEnd, pbuf);
      segIdx++;
   }
   else {                  /* load segment of parameter file */
      MakeFN(fn,labDir,labExt,labfn);
      trans = LOpen(&transStack,labfn,lff);
      ncas = NumCases(trans->head,segId);
      if ( ncas > 0) {
         for (i=1,nObs=0; i<=ncas; i++) {
            p = GetCase(trans->head,segId,i);
            segStIdx = (long)(p->start/info.tgtSampRate);
            segEnIdx = (long)(p->end/info.tgtSampRate);
            if (segEnIdx >= ObsInBuffer(pbuf))
               segEnIdx = ObsInBuffer(pbuf)-1;
            if (segEnIdx - segStIdx + 1 >= nStates-2) {
               LoadSegment(segStore, p->start, p->end, pbuf);
               if (trace&T_LD1)
                  printf("  loading seg %s %f[%ld]->%f[%ld]\n",segId->name,
                         p->start,segStIdx,p->end,segEnIdx);
               nObs += SegLength(segStore, segIdx);
               segIdx++;
            }else if (trace&T_LD1)
               printf("   seg %s %f->%f ignored\n",segId->name,
                      p->start,p->end);
         }        
      }  
   }
   if (hset.hsKind == DISCRETEHS){
      for (k=prevSegIdx; k<segIdx; k++){
         segLen = SegLength(segStore, k);
         for (i=1; i<=segLen; i++){
            obs = GetSegObs(segStore, k, i);
            for (s=1; s<=nStreams; s++){
               if( (obs.vq[s] < 1) || (obs.vq[s] > maxMixInS[s]))
                  HError(2150,"LoadFile: Discrete data value [ %d ] out of range in stream [ %d ] in file %s",obs.vq[s],s,fn);
            }
         }
      }
      prevSegIdx=segIdx;
   }

   if (trace&T_LD0)
      printf(" %d observations loaded from %s\n",nObs,fn);
   CloseBuffer(pbuf);
   ResetHeap(&transStack);
}
Exemplo n.º 7
0
/* LoadFile: load whole file or segments and accumulate variance */
void LoadFile(char *fn)
{
   ParmBuf pbuf;
   BufferInfo info;
   char labfn[80];
   Transcription *trans;
   long segStIdx,segEnIdx;  
   int i,s,j,ncas,nObs=0;
   LLink p;

   if (segId == NULL)  {   /* load whole parameter file */
      if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL)
         HError(2550,"LoadFile: Config parameters invalid");
      GetBufferInfo(pbuf,&info);
      CheckData(fn,info);
      nObs = ObsInBuffer(pbuf);
      
      for (i=0; i<nObs; i++) {
         for(s=1;s<=swidth[0];s++)
            obs.fv[s] = CreateVector(&dStack,swidth[s]);
         ReadAsTable(pbuf,i,&obs);
         for(s=1;s<=swidth[0];s++)
            StoreItem(dSeq[s],(Ptr)obs.fv[s]);
      }
      CloseBuffer(pbuf);
   }
   else { /* load segment of parameter file */
      MakeFN(fn,labDir,labExt,labfn);
      trans = LOpen(&iStack,labfn,lff);
      ncas = NumCases(trans->head,segId);
      if ( ncas > 0) {
         if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL)
            HError(2550,"LoadFile: Config parameters invalid");
         GetBufferInfo(pbuf,&info);
         CheckData(fn,info);
         for (i=1,nObs=0; i<=ncas; i++) {
            p = GetCase(trans->head,segId,i);
            segStIdx= (long) (p->start/info.tgtSampRate);
            segEnIdx  = (long) (p->end/info.tgtSampRate);
            if (trace&T_SEGS)
               printf(" loading seg %s [%ld->%ld]\n",
                      segId->name,segStIdx,segEnIdx);
            if (segEnIdx >= ObsInBuffer(pbuf))
               segEnIdx = ObsInBuffer(pbuf)-1;
            if (segEnIdx >= segStIdx) {
               for (j=segStIdx;j<=segEnIdx;j++) {
                  /* SJY: The HInit code I copied this from had no */
                  /* SJY: CreateVector call here -- a bug? */
                  for(s=1;s<=swidth[0];s++)
                     obs.fv[s] = CreateVector(&dStack,swidth[s]);
                  ReadAsTable(pbuf,j,&obs);
                  for(s=1;s<=swidth[0];s++)
                     StoreItem(dSeq[s],(Ptr)obs.fv[s]);
                  ++nObs;
               }
            }
         }        
         CloseBuffer(pbuf);
      }  
   }
   ResetHeap(&iStack);
   if (trace&T_LOAD) {
      printf(" %5d obs loaded from %s, streams: ",nObs,fn);
      for(s=1;s<=swidth[0];s++) printf("[%d]" ,swidth[s]);
      printf("\n"); fflush(stdout);
   }        
}
void Deplacement(int hauteur,int largeur,ROBOT *robot,char **map,FEU *feu,QUEUE *q, char *type_affichage,GRAPH *graph,char arrive,char chemin,int stop){

int i;
char type_feu='0';
int continuer=1;

while(continuer){

	//conserve les dernieres coordonnees du robots avec le type de la case
    robot->pos_old=robot->pos;
	//suit le chemin du craractere envoyé en parametre et arrive au caractere de parametre envoyé
	
	if(map[robot->pos.y-1][robot->pos.x]==chemin||map[robot->pos.y-1][robot->pos.x]==arrive){
		robot->pos.y--;//NORD
	}
	else if(map[robot->pos.y][robot->pos.x-1]==chemin||map[robot->pos.y][robot->pos.x-1]==arrive){
		robot->pos.x--;//GAUCHE
	}
	else if(map[robot->pos.y+1][robot->pos.x]==chemin||map[robot->pos.y+1][robot->pos.x]==arrive){
		robot->pos.y++;//SUD
	}
	else if(map[robot->pos.y][robot->pos.x+1]==chemin||map[robot->pos.y][robot->pos.x+1]==arrive){
		robot->pos.x++;//DROITE
	}
	//arrive sur le caracteres envoye en parametre
	if(GetCase(map,robot->pos)==arrive){
		continuer=0;
	}
	//regarde si on est dans un feu quelle valeur du feu
	for(i=0;i<feu->pos;i++){
		if(robot->pos.y==feu->Tab[i].y&&robot->pos.x==feu->Tab[i].x){
			type_feu=feu->Tab[i].type;
		}
	}
	//si il est passé dans un feu il garde en memoire la derniere coordonnee et calcul le chemin le plus court
	if(type_feu=='1'){

		robot->vie--;
		//conserve les coordonnees du feu
		robot->feu=robot->pos;
		//si il arrive a un 1 pour la recherche du feu il se stop
		if(!stop){
			continuer=0;		
		}
	}
	//si il arrive dans le 2 il lance l'algo de pathfinding v2 pour reprendre le chemin le plus court tout en esquivant les 2 et 3
	if(type_feu=='2'){
			
		robot->vie-=2;
		//conserve les coordonnees du feu
		robot->feu=robot->pos;
		//netoit la map
		CleanMap(map,largeur,hauteur);
		//rajoute le feu pour le pathfinding
		AddFire (map,feu);
		//scan la map avec comme parametre de ne pas pouvoir aller dans le feu
		Scan(map,q,robot,1,'E');
		//trace le chemin le plus court
		Trace(map,q);
	}
	//regarde si on a 0 pdv
	if(robot->vie==0){

		system(CLEARSCREEN);
		printf("GAME OVER");
		exit(1);
	}
	//trace le passage du robot
	SetCase(map,robot->pos_old,'i');
	//si le robot est en mode pompier alors on ecrit p sinon r
	if(robot->pompier==0){
		SetCase(map,robot->pos,'R');
	}
	else{
		SetCase(map,robot->pos,'P');
	}
	
	//augemente le nb de deplacement
	robot->dep++;
	//affiche
	Affichage(map,hauteur,largeur,robot,type_affichage,graph,feu);
	type_feu='0';
}
return;
}
Exemplo n.º 9
0
int ods_formula_node::EvaluateGT(IODSCellEvaluator* poEvaluator)
{
    CPLAssert( eNodeType == SNT_OPERATION );
    CPLAssert( eOp == ODS_GT );

    CPLAssert(nSubExprCount == 2);
    if (!(papoSubExpr[0]->Evaluate(poEvaluator)))
        return FALSE;
    if (!(papoSubExpr[1]->Evaluate(poEvaluator)))
        return FALSE;

    CPLAssert(papoSubExpr[0]->eNodeType == SNT_CONSTANT );
    CPLAssert(papoSubExpr[1]->eNodeType == SNT_CONSTANT );

    int bVal = FALSE;
    if (papoSubExpr[0]->field_type == ODS_FIELD_TYPE_INTEGER)
    {
        if (papoSubExpr[1]->field_type == ODS_FIELD_TYPE_INTEGER)
        {
            bVal = (papoSubExpr[0]->int_value > papoSubExpr[1]->int_value);
        }
        else if (papoSubExpr[1]->field_type == ODS_FIELD_TYPE_FLOAT)
        {
            bVal = (papoSubExpr[0]->int_value > papoSubExpr[1]->float_value);
        }
    }
    else if (papoSubExpr[0]->field_type == ODS_FIELD_TYPE_FLOAT)
    {
        if (papoSubExpr[1]->field_type == ODS_FIELD_TYPE_INTEGER)
        {
            bVal = (papoSubExpr[0]->float_value > papoSubExpr[1]->int_value);
        }
        else if (papoSubExpr[1]->field_type == ODS_FIELD_TYPE_FLOAT)
        {
            bVal = (papoSubExpr[0]->float_value > papoSubExpr[1]->float_value);
        }
    }
    else if (papoSubExpr[0]->field_type == ODS_FIELD_TYPE_STRING)
    {
        if (papoSubExpr[1]->field_type == ODS_FIELD_TYPE_STRING)
        {
            if (GetCase(papoSubExpr[0]->string_value) ==
                GetCase(papoSubExpr[1]->string_value))
                bVal = (strcmp(papoSubExpr[0]->string_value,
                               papoSubExpr[1]->string_value) > 0);
            else
                bVal = (strcasecmp(papoSubExpr[0]->string_value,
                                   papoSubExpr[1]->string_value) > 0);
        }
        else
            bVal = TRUE;
    }
    else
    {
        CPLError(CE_Failure, CPLE_NotSupported,
                 "Bad argument type for %s", ODSGetOperatorName(eOp));
        return FALSE;
    }

    eNodeType = SNT_CONSTANT;
    field_type = ODS_FIELD_TYPE_INTEGER;
    int_value = bVal;

    FreeSubExpr();

    return TRUE;
}