Skip to content

Commit

Permalink
Make ga fitness a mutabe object's accesor
Browse files Browse the repository at this point in the history
  • Loading branch information
U1F30C committed Nov 27, 2020
1 parent b608022 commit b99b70d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ai/ga.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { maxBy, random, times, sample, sampleSize } = require('lodash');

class Individual {
constructor(genome) {
this.fitness = 0;
this._fitness = { value: 0 };
this._genome = genome.map(gene => ({ value: gene }));
}
set genome(genome) {
Expand All @@ -13,6 +13,12 @@ class Individual {
get genome() {
return this._genome.map(gene => gene.value);
}
set fitness(fitness) {
this._fitness.value = fitness;
}
get fitness() {
return this._fitness.value;
}
}

class GeneticAlgorithm {
Expand Down

0 comments on commit b99b70d

Please sign in to comment.