void Human::interact(Organism* o){ if( isA<Human>(o) ){ Human* partner = (Human*)o; if( offspringCount < Human::maxOffspring && partner->offspringCount < Human::maxOffspring ){ offspringCount ++; partner->offspringCount ++; copulate(); } } }
int main(int argc, char** argv) { //Iniatialize random srand(time(NULL)); //Initialize all parent boards initParentBoards(); //Initialize child board initStructBoard(&childBoard); //Tmps for function call int tmpChildPID; int tmpToChildID; int tmpFromChildID; //Child counter int i; //Create children for(i=0; i< M_CHILDREN; i++) { //Children end up calling birth() and run from there //Parent returns from copulate copulate(&tmpChildPID,&tmpToChildID,&tmpFromChildID); //Kept track of new child sendIDs[i] = tmpToChildID; receiveIDs[i] = tmpFromChildID; childrenPIDs[i] = tmpChildPID; } //Children have been born and are running //Now parent needs to do its thing //Parent is always first move //Make first move for all children //Keep making moves followed by waiting for //child to make move - gameOver is called //and proper action will be taken from there while(1) { if(allChildrenDead()) { //Parents turn to die exit(0); } int i; //Make a move for each child for(i=0; i< M_CHILDREN; i++) { if(childAlive[i]) { parentPlayChild(i); } } if(allChildrenDead()) { //Parents turn to die exit(0); } //Wait for a move from each child for(i=0; i< M_CHILDREN; i++) { if(childAlive[i]) { waitForChildMove(i); } } if(allChildrenDead()) { //Parents turn to die exit(0); } } return 0; }