Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dmj12004 committed May 1, 2017
2 parents 77ba547 + 1eb6280 commit 4f8fc70
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/GeneticSimulation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include <fstream>
#include <iostream>

#include "GeneticSimulation.hpp"
#include "Game.hpp"
#include "Specimen.hpp"

void GeneticSimulation::simulate(){

std::cout << dist(gen) << std::endl;


for(int i = 0; i < numSpecimen; i++){

Heuristic h1, h2;
for(int j = 0; j < Heuristic::numFeatures; j++){
h1.set(j, dist(gen));
h2.set(j, dist(gen));
}

Specimen s(h1, h2);
population.push(s);
}
std::cout << numSpecimen;

int cntBlack=0, cntWhite=0, cntTies=0;
int cntTieBlack=0, cntTieWhite=0;

while(population.size() > 1){
Specimen a = population.front();
population.pop();
Specimen b = population.front();
population.pop();

Game game1(a, b);
Game game2(b, a);

int winner = 0;
game1.play(&winner);

if(winner == 0){
game2.play(&winner);

if(winner == 1){
population.push(b);
cntTieBlack++;
}
else if(winner == 2){
population.push(a);
cntTieWhite++;
}
}
else {
if(winner == 1){
population.push(a);
cntBlack++;
}
else if(winner == 2){
population.push(a);
cntWhite++;
}
else cntTies++;

std::cout << population.size() << std::endl;
}
}


std::ofstream s;
s.open("sim_out.txt", std::ios::app);

if(s.is_open()){
s << "Size: \t\t" << numSpecimen << std::endl;
s << "Black Wins: \t" << cntBlack << std::endl;
s << "White Wins: \t" << cntWhite << std::endl;
s << "White Wins(after Tie): " << cntTieBlack << std::endl;
s << "Black Wins(after Tie): " << cntTieWhite << std::endl;
s << "Ties: \t\t" << cntTies << std::endl;
}
s.close();

}

0 comments on commit 4f8fc70

Please sign in to comment.