diff --git a/src/GeneticSimulation.cpp b/src/GeneticSimulation.cpp new file mode 100644 index 0000000..25e13c8 --- /dev/null +++ b/src/GeneticSimulation.cpp @@ -0,0 +1,82 @@ +#include +#include + +#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(); + +}