Esempio n. 1
0
void remCell(Grid* W,Cell* killMe){/*dead cell is removed from Grid and added to list of dead cells*/
  killMe->alive=0;
  LL* myDeadLL=malloc(sizeof(LL));
  initLL(myDeadLL,killMe);
  remLL(&getSquare(W,killMe->CellPos)->cells,&killMe->mySqElem);
  addLL(&W->deadCells,myDeadLL);
  freeLL(killMe->BondedCells);
  killMe->BondedCells=NULL;};
Esempio n. 2
0
void initCell(Grid* W,Cell* ret,Brain* parent,Brain* childBrain,double* pos, Body* parentBody, int BodyCellI,int keepBonds,Body* myParent,Ecosystem* data,int* Is){/*if cell has a parent brain, then abilities are copied, otherwise brain is initialized randomly*/
  ret->alive=1;
  ret->myBrain=childBrain;
  ret->myBody=parentBody;
  ret->myParent=myParent;
  ret->BodyCellI=BodyCellI;
  ret->BondedCells=NULL;
  ret->numBonds=0;
  if(data){
    setupCellFromData(data,ret,Is,parentBody);//setup bonds, cellpos and brain from data
    setupBrainFromData(data,childBrain,ret,Is);}//init brain from data
  else{
  if(parent){
    initBrain(W,childBrain,parent,ret,NULL,NULL);
    Cell* parentCell=parent->myCell;
    if(keepBonds){
      for(LL* ParentBondedIs=parentCell->BondedCells;ParentBondedIs;ParentBondedIs=ParentBondedIs->next){
        LL* newBondILL=malloc(sizeof(LL));
        initLL(newBondILL,parentBody->cells[((Cell*)ParentBondedIs->val)->BodyCellI]);
        addLL(&ret->BondedCells,newBondILL);}
      ret->numBonds=parentCell->numBonds;}}
  else{initBrain(W,childBrain,NULL,ret,NULL,NULL);}
  ret->CellPos[0]=pos[0];
  ret->CellPos[1]=pos[1];
  ret->CellPos[2]=pos[2];
  }
  calcBehindPoint(ret->behindPoint,ret->CellPos);
  ret->rotAmount=0;
  ret->color[0]=0.2;
  ret->color[1]=0.2;
  ret->color[2]=0.2;
  ret->color[3]=1;
  ret->livingCost=calcLivingCost(childBrain);
  initLL(&ret->mySqElem,ret);
  Square* birthPlace=getSquare(W,ret->CellPos);
  if(!birthPlace){fprintf(stderr,"%lf, %lf attempting to place a Cell outside the world!",ret->CellPos[0],ret->CellPos[1]);}
  addLL(&birthPlace->cells,&ret->mySqElem);};
Esempio n. 3
0
int main(){
  int i=0;
  struct LinkedList* L = (struct LinkedList *)malloc(sizeof(struct LinkedList));
  for(i=0; i< 28; i++)
   {
     if(i%5 ==1)
      addLL(i,L);
   }
  printLL(L);
  printf("Test delete head\n");
  L= deleteLL(0, L);
  printLL(L);

  printf("Test delete middle\n");
  L = deleteLL(16, L);
  printLL(L);
  return 0;
}
Esempio n. 4
0
void moveCell(Grid* W,Cell* moveMe, double* newLoc){/*Cells moved by summing move ability vectors and bumping into other cells (cellBump)*/
  if(insideWorld(newLoc,0)){
  Square* currSq=getSquare(W,moveMe->CellPos);
  Square* nextSq=getSquare(W,newLoc);
  if(!nextSq){
    fprintf(stderr,"cell detected it has moved off the world, this should never happen, the body should catch this first!");

    //fprintf(stderr,"cell trying to move outside of world");
  }
  //addColor(W,moveMe->color,0,.7,0,MOVEMENT);
  if(currSq!=nextSq){
      remLL(&currSq->cells,&moveMe->mySqElem);
      addLL(&nextSq->cells,&moveMe->mySqElem);
  }
  /* cells lose energy based on how far they have moved */
  double moveCost=pow(getDist(moveMe->CellPos,newLoc)/CELLRAD,MOVE_EXP)*MOVE_COST_MULT;
  EnTransfer(&W->SUN,&moveMe->myBody->energy,moveCost*((1-MOVE_COST_DROP_PROP)+(MOVE_COST_DROP_PROP*(1.0/moveMe->myBody->cellSize))));//getTerrain(W,moveMe->CellPos)->moveCost);///log(moveMe->myBody->cellSize+2));//,__func__,__LINE__);
  //EnTransfer(&W->SUN,&moveMe->myBody->energy,pow(getDist(moveMe->CellPos,newLoc)/CELLRAD,MOVE_EXP)*getTerrain(W,moveMe->CellPos)->moveCost/moveMe->myBody->cellSize);//,__func__,__LINE__);
  moveMe->CellPos[0]=newLoc[0];
  moveMe->CellPos[1]=newLoc[1];
  }
  moveMe->CellPos[2]=wrapAngle(newLoc[2]);
  calcBehindPoint(moveMe->behindPoint,moveMe->CellPos);
};
Esempio n. 5
0
/* -------------------------------------------------------------------- */
void ReadExternalCit(void)
	{
	FILE *fBuf;
	char line[257];
	char *words[256];
	int count;

	if ((fBuf = fopen(externalCit, "r")) == NULL)       /* ASCII mode */
		{
		printf("Cannot find %s!", externalCit);
		exit(69);
		}
	else
		{
		int i, lineNo = 0;

		while (fgets(line, 256, fBuf) != NULL)
			{
			lineNo++;

			if (line[0] != '#')
				{
				continue;
				}

			count = parse_it(words, line);

			if (SameString(words[0], "#PROTOCOL"))
				{
				protocols *theProt;

				theProt = (protocols *) addLL((void **) &protList,
							sizeof(*theProt));

				if (theProt)
					{
					CopyStringToBuffer(theProt->name, words[1], LABELSIZE);
					theProt->batch = !!atoi(words[2]);
					theProt->block = atoi(words[3]);
					CopyStringToBuffer(theProt->rcv, words[4], 127);
					CopyStringToBuffer(theProt->snd, words[5], 127);

					if (count <= 6 || words[6][0] == '\0')
						{
						theProt->autoDown[0] = '\0';
						}
					else
						{
						CopyStringToBuffer(theProt->autoDown, words[6], LABELSIZE);
						}

					if (count > 7)
						{
						CopyStringToBuffer(theProt->respDown, words[7], 127);
						}
					}
				else
					{
					printf("Not enough memory for #PROTOCOL \"%s\"",
							words[1]);
					printf("\n");
					}
				}
			}

		fclose(fBuf);
		}
	}