SimMainWindow::SimMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::SimMainWindow) { ui->setupUi(this); mEngine = new LifeEngine(100,100); mView = new LifeEngineView(mEngine); mLifeFileView = new LifeFileView; mLifesView = new LifesView(mEngine); mUndoStack = new QUndoStack(this); mOldLifeCount = 0; ui->dock1->setWidget(mLifeFileView); ui->dock2->setWidget(mLifesView); ui->dock1->setWindowTitle(mLifeFileView->windowTitle()); ui->dock2->setWindowTitle(mLifesView->windowTitle()); setCentralWidget(mView); ui->menuEdit->addActions(mLifeFileView->actions()); ui->menuEdit->addSeparator(); ui->menuEdit->addActions(mLifesView->actions()); connect(mView->gridView()->grid(),SIGNAL(squareClicked(QPoint)),this,SLOT(clicked(QPoint))); connect(ui->actionRun,SIGNAL(triggered()),this,SLOT(startSimulation())); connect(ui->actionNew,SIGNAL(triggered()),this,SLOT(newSim())); connect(ui->actionSave,SIGNAL(triggered()),this,SLOT(saveSim())); connect(ui->actionSaveAs,SIGNAL(triggered()),this,SLOT(saveAsSim())); connect(ui->actionOpen,SIGNAL(triggered()),this,SLOT(openSim())); connect(ui->actionClear,SIGNAL(triggered()),this,SLOT(clear())); connect(ui->actionAnimator,SIGNAL(triggered()),this,SLOT(showAnimator())); connect(ui->actionLifeEditor,SIGNAL(triggered()),this,SLOT(showLifeEditor())); connect(mLifesView,SIGNAL(changed()),this,SLOT(refresh())); connect(mLifesView,SIGNAL(clicked()),this,SLOT(setGridSelection())); connect(ui->actionAboutQt,SIGNAL(triggered()),this,SLOT(showAboutQt())); connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout())); connect(ui->actionUndo,SIGNAL(triggered()),mUndoStack,SLOT(undo())); connect(ui->actionRedo,SIGNAL(triggered()),mUndoStack,SLOT(redo())); connect(mUndoStack,SIGNAL(canUndoChanged(bool)),ui->actionUndo,SLOT(setEnabled(bool))); connect(mUndoStack,SIGNAL(canRedoChanged(bool)),ui->actionRedo,SLOT(setEnabled(bool))); ui->actionSave->setEnabled(false); newSim(); }
/********************************* main **************************************** int main (int argc, char *argv[]) Purpose: This the main functions of the program, it calls the command switch processing function to register the alternative choosen and wether verbose mode has been choosen or not, it creates the LinkedList and Simulation, calls the appropriate functions to populate both, then calls the function to run the simulation and to free all of our allocs. Parameters: I int argc Number of command line argument. I char *argv[] Command line arguments. Returns: Functionally: Integer representing the success of the operation or error encountered. 0 - normal 900 - command line argument syntax error 903 - algorithm error (see message for details) 503 - bad input Notes: *******************************************************************************/ int main(int argc, char *argv[]) { //command switches int bVerbose; char cRunType; processCommandSwitches(argc, argv, &bVerbose, &cRunType); //create the simulation LinkedList list; Simulation sim; list = newListFromInput(); sim = newSim(list, bVerbose, cRunType); //run the simulation and terminate runSimulation(sim, TIME_LIMIT); freeSim(sim); fclose(pInputFile); return 0; }
CSimulation CSimulation::operator*(const CSimulation &rhs) { CSolarSystem newSS(rhs.m_SS); CSimulation newSim(rhs); newSim.m_SS.m_sats.clear(); newSim.m_genNum++; CCoordSet tempSet; vector<CSatellite> loserList; cout << "-----------------------------\n"; for (unsigned int i = 0; i < m_deadList.size(); i++) { loserList.push_back(m_deadList[i]); } for (unsigned int i = 0; i < rhs.m_SS.m_sats.size(); i++) { loserList.push_back(rhs.m_SS.m_sats[i]); } unsigned seed = chrono::high_resolution_clock::now().time_since_epoch().count() + m_coreNum; default_random_engine gen(seed); //fill the success portion unsigned int succUses = 0; sort(m_succList.begin(), m_succList.end(), fuelLesserCompare); if (m_succList.size() >= m_par->breedingNum - m_par->randomBreedingNum) { //enough successes succUses = m_par->breedingNum - m_par->randomBreedingNum; } else { //not enough successes succUses = m_succList.size(); } if(m_succList.size() < .1){ CSolarSystem newSS2(rhs.m_SS); CSimulation newSim2(newSS2, rhs.m_par, rhs.m_name, 666, rhs.m_genNum+1); return newSim2; } else{ for (unsigned int i = 0; i < succUses; i++) { m_breedList.push_back(m_succList[i]); } for (unsigned int i = succUses; i < m_succList.size(); i++) { loserList.push_back(m_succList[i]); } uniform_int_distribution<int> dist(0, loserList.size() - 1); for (unsigned int i = 0; i < m_par->randomBreedingNum; i++) { int r = dist(gen); m_breedList.push_back(loserList[r]); } uniform_int_distribution<int> dist2(0, m_breedList.size() - 1); for (unsigned int x = 0; x < (m_par->satsPerCore-m_par->randSatsPerGen); x++) { newSim.m_SS.m_sats.push_back( m_breedList[dist2(gen)] * m_breedList[dist2(gen)]); } for(unsigned int x = 0; x < m_par->randSatsPerGen; x++){ CCoordSet tempSet; SatName name; name.coreNum = 666; name.genNum = 1+rhs.m_genNum; name.momID = 0; name.dadID = 0; CSatellite a(m_par, &newSS, name); tempSet = m_SS.getPlanetDynamics(a.m_homePlanetName); tempSet.m_position.m_y = -tempSet.m_position.m_y + m_SS.getPlanetRadius(a.m_homePlanetName); tempSet = m_SS.getPlanetDynamics(a.m_homePlanetName); tempSet.m_position.m_y = -tempSet.m_position.m_y + m_SS.getPlanetRadius(a.m_homePlanetName); a.setDynamics(tempSet); a.m_startDynamics = tempSet; a.m_thrusts[a.m_thrusts.size() - 1].m_t[0] = 0; newSim.m_SS.m_sats.push_back(a); } return newSim; } }