1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#include "organisms.h"
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
void begin(char temp[], int num, int i);
void calcNextGen(organisms next[], int num);
char aliveOrDead(organism_cell m2, organism_cell m1, organism_cell oc, organism_cell p1, organism_cell p2);
void read();
void print();
const organism_cell alive('*');
const organism_cell dead(' ');
organisms history[10000];
int main( )
{
}
void read()
{
string in;
int num = 0;
cout << "Please enter the path to the file you wish to read:" << endl;
cin >> in;
char temp[50];
char cont;
int i = 0;
ifstream fin(in.c_str());
while(fin >> cont)
{
temp[i] = cont;
if(i == 50) //Just in case the input file is giving mroe then it should.
break;
i++;
}
cout << "How many generations do you want to run? \n\t(No more then 10000)" << endl;
cin >> num;
begin(temp, num, i);
}
void begin(char seed[], int num, int i)
{
for(int j = 0; j < num; num) //Set all the organisms (that are needed to be set)
history[i] = organisms(i);
organisms h = history[0];
for(int j = 0; j < i; j++)
{
organism_cell he = h[j];
if(alive.o_alive == seed[j])
he = alive;
else
he = dead;
}
for(int j = 0; j < num-1; j++)
calcNextGen(history + j, j);
}
void calcNextGen(organisms next, int num)
{
for(int i = 0; i < num; i++)
{
if(i > 1 || i < num-3) //The easy cases
{
organism_cell ocm2 = next[i-2];
organism_cell ocm1 = next[i-1];
organism_cell oc = next[i];
organism_cell ocp1 = next[i+1];
organism_cell ocp2 = next[i+2];
char c = aliveOrDead(ocm2, ocm1, oc, ocp1, ocp2);
organisms work = history[num+1];
organism_cell wo = work[i];
wo = c;
}
}
}
char aliveOrDead(organism_cell ocm2, organism_cell ocm1, organism_cell oc, organism_cell ocp1, organism_cell ocp2)
{
int life = 0;
if(ocm2 == alive)
life++;
if(ocm1 == alive)
life++;
if(ocp1 == alive)
life++;
if(ocp2 == alive)
life++;
if(life < 2)
return dead.o_alive;
if(life == 2)
return alive.o_alive;
if(life == 3)
if(oc == alive)
return dead.o_alive;
else
return alive.o_alive;
if(life == 4)
if(oc == dead)
return dead.o_alive;
else
return alive.o_alive;
}
void print()
{
}
|