Skip to content

Commit

Permalink
Update Dna.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
cppnuts-yt committed Aug 23, 2016
1 parent ba0aa1f commit 1260b19
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Dna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class Dna{
}

char getNewChar(){
char r = (char)rand()%(122-63+1)+63;
if(r == 63) r=' ';
if(r == 64) r='.';
return r;
int r = rand()%(122-63+1)+63;
if(r == 63) r=32;
if(r == 64) r=46;
return (char)r;
}
void calFitness(Dna& target){
float score=0;
Expand All @@ -44,10 +44,11 @@ class Dna{
}
void mutate(float mutationRate){
for(int i=0; i<gens.length(); i++){
float r = floor(rand()%100+1);
if(mutationRate>r)
float r = floor(rand()%100+1)/100;
if(mutationRate>r){
gens[i] = getNewChar();
}
}
//cout << "gens: " << gens << endl;
cout << "gens: " << gens << endl;
}
};

0 comments on commit 1260b19

Please sign in to comment.