void CellBump(Grid* W,Cell* c){/* cells with overlapping radii get force vectors applied to them to bounce off each other*/ double usageColor=c->myBody->usageB/(BINSIZE*NUMBINS*0.7); //usageColor=0.7<usageColor?0.7:usageColor; addColor(W,c->color,usageColor,usageColor,usageColor,EVOLUTIONVIEW); LL* touching=withinRad(W,c->CellPos,CELLRAD,c,0); if(touching){ for(LL* curr=touching;curr!=NULL;curr=curr->next){ //AddNeuron(&c->myBrain->inputs[1],0.5,__func__); Cell* touching=curr->val; double dist=getDist(c->CellPos,touching->CellPos); //double forceMag=(1-(dist/pow((2*CELLRAD),3)))*0.1;//function to bounce cells with differing severity double forceMag=(1-(pow(dist/(2.0*CELLRAD),BUMP_FUNCTION_EXPONENT))); /*BUMP_FUNCTION_EXPONENT combined with BUMP_FORCE_MULT dictate how strongly bumping cells repel each other*/ double diff[]={touching->CellPos[0]-c->CellPos[0],touching->CellPos[1]-c->CellPos[1]}; double touchLoc[]={c->CellPos[0]+diff[0]/2,c->CellPos[1]+diff[1]/2}; double scale=(forceMag*BUMP_FORCE_MULT)/dist; double xyComp[]={-(touching->CellPos[0]-c->CellPos[0])*scale,-(touching->CellPos[1]-c->CellPos[1])*scale}; /*Force is applied from the touching location to the center of the cell (for single cells exerts no torque)*/ FORCE_FUN(W,c->myBody,touchLoc,xyComp,0); //here we force closest cells to separate instantly! no matter what, by rewinding time until they are fully apart //applyImpulse(W,c,touching); c->myBody->touching=1; //c->dxy[0]-=distx*(forceMag/dist); //c->dxy[1]-=disty*(forceMag/dist); } freeLL(touching); } else{ //AddNeuron(&c->myBrain->inputs[1],-0.5,__func__); } }
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;};
void freeHash(hashtable *table, int freeWords){ //todo int i; for(i = 0; i < table->size; i++){ freeLL(table->buckets[i], freeWords); } free(table->buckets); free(table); }
//recursively frees a linked list void freeLL(node *n, int freeWords){ if(n == 0){ return; } else{ freeLL(n->next, freeWords); if(freeWords){ free(n->data->word); free(n->data); } free(n); } }
int main() { srand(time(NULL)); unsigned char arrCharDevice[MAX_DEVICE][DEVICE_SIZE]; unsigned char chDevice[] = {0xb,0x0,'F','S','o','f','\0',0x0,0x1,0x0,0x0}; int i,j; device **ppd; device *tmp; linkedlist ll; initializeLL(&ll); //initialize linkedlist initArrayDeviceData(arrCharDevice, MAX_DEVICE, DEVICE_SIZE); //create data array of device ppd = initArrayDevice(arrCharDevice, MAX_DEVICE, DEVICE_SIZE); //create array of device for(i=0; i<MAX_DEVICE; i++) { printDevice(*(ppd+i)); addFirst(&ll, *(ppd+i)); //insert device into linkedlist } FL; printLL(&ll); tmp = (device*)chDevice; FL;printDevice(tmp); insertElement(&ll, tmp, 5); //insert above device into linkedlist FL;printLL(&ll); rmElement(&ll,4); //remove element from linkedlist FL;printLL(&ll); free(tmp); freeLL(&ll); freeArrayDevice(&ppd, MAX_DEVICE); unsigned short asdf = 0xF0AA; unsigned char *asda = (char*)malloc(sizeof(asdf)); FL; PRINT_HEX(asdf); EL; printf("%X", asdf&0xff); EL; convertToChar(asda, &asdf, 0, sizeof(short)); FL; PRINT_HEX(*asda); SP; PRINT_HEX(*(asda+1)); EL; PRINT_UINT(sizeof(aaa)); EL; return 0; }