void ShowMovie(char*** world, int maxTicks, int rows, int columns, SDL_Surface* screen, SDL_Rect *Rect, int rectH, int rectW)
{
	//primitives
	
	//n will equal the size of the inputted world
		//which is basically the maximum columns
	//m is therefore the maxiumum rows.
	//m,n come from printworld
	//NB this will change when reading in a file
	//m and n will be the first row of textfile
	//There needs to be a 3d world variable.
	//char newWorld[rows][columns];
    int i, j;
	
	//actually draw the 'movie'
	//will use the defined delay
			
			//i have made i = 1 because the example windows exe
			//has this. it runs from 1 to 9 meaningh it skips 1
	for (i = 0; i<maxTicks; i++)
	{
		//print the world
		PrintWorld(world[i], rows, columns, screen, *Rect, rectH, rectW);
		//copy the new world
		//CopyWorld(world, newWorld, m, n, rows, columns, i);
		//animate ie clear the world thats all it does
		Animate(i);
		//get next generation of the world and store it
		NextGeneration(world[i], world[i+1], rows, columns);
		//check its status
        if(compareWorld(world[i], world[i-1], rows, columns) == TRUE)
        {
        	// stable....
            printf("The World is Stable.\n");	
        }
		else
		{
			for(j = 0; j < i - 1; j++)
			{
				if(compareWorld(world[i], world[j], rows, columns) == TRUE)
				{
					// print osc period is i-j....
					printf("The Worlds are Osciallting at a period of %d.\n", (i-j));
				}
                
			}
		}  
	}		
}
Exemple #2
0
void World::Activity()
{
    auto now = std::chrono::duration_cast<milliseconds>(
        std::chrono::system_clock::now().time_since_epoch());

    if (paused)
        lastTick = now; // if paused then synchornize so next generation won't be generated

    // if enough time has passed since last update
    if (now - lastTick > tickCount)
    {
        lastTick = now;
        NextGeneration();
        AddGeneration();
    }

}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    Phenotype::OpenWeightFile();

    srand(time(NULL));

    connect(this->ui->hsSpeed, SIGNAL(valueChanged(int)), this, SLOT(SpeedChanged(int)));
    connect(this->ui->bStart, SIGNAL(clicked()), this, SLOT(LaunchTraining()));

    //connect(this->ui->bShowFitnessGraph, SIGNAL(clicked()), this, SLOT(ShowFitnessGraph()));

    ui->lSpeed->setText(QString::number(this->ui->hsSpeed->value()) + "ms");

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(NextGeneration()));
    connect(this->ui->bReset, SIGNAL(clicked()), this, SLOT(Reset()));

    m_GenerationNumber = 0;

//    m_ResultTableDialog = new ResultTable(this);
//    m_FitnessGraphDialog = new FitnessGraphDialog(this);

    statusLabel = new QLabel(this);



    statusLabel->setText("Ready");

    ui->statusBar->addPermanentWidget(statusLabel,0);

    InitResultTable();

    ui->tableXOR->setItem(0,0,new QTableWidgetItem("0"));
    ui->tableXOR->setItem(0,1,new QTableWidgetItem("0"));
    ui->tableXOR->setItem(1,0,new QTableWidgetItem("0"));
    ui->tableXOR->setItem(1,1,new QTableWidgetItem("1"));
    ui->tableXOR->setItem(2,0,new QTableWidgetItem("1"));
    ui->tableXOR->setItem(2,1,new QTableWidgetItem("0"));
    ui->tableXOR->setItem(3,0,new QTableWidgetItem("1"));
    ui->tableXOR->setItem(3,1,new QTableWidgetItem("1"));
}
void OBConformerSearch::Search()
{
    int identicalGenerations = 0;
    double last_score = 0.0;
    for (int i = 0; i < 1000; i++) {
        std::cout << "Generation #" << i + 1 << "  " << last_score << std::endl;
        // keep copy of rotor keys if next generation is less fit
        RotorKeys rotorKeys = m_rotorKeys;
        // create the children
        NextGeneration();
        // make the selection
        double score = MakeSelection();

        if (IsNear(last_score, score)) {
            identicalGenerations++;
            last_score = score;
        } else {
            if (score < last_score) {
                m_rotorKeys = rotorKeys;
                identicalGenerations++;
            } else {
                last_score = score;
                identicalGenerations = 0;
            }
        }

//      if (i)
        //      std::cerr << ";";
        //  std::cerr << last_score;

        if (identicalGenerations > m_convergence)
            break;
    }
//    std::cerr << std::endl;


    for (unsigned int i = 0; i < m_rotorKeys.size(); ++i) {
        for (unsigned int j = 1; j < m_rotorKeys[i].size(); ++j)
            std::cout << m_rotorKeys[i][j] << " ";
        std::cout << std::endl;
    }


}