diff --git a/src/ai/ga.js b/src/ai/ga.js index 655df3d..3e7fc0d 100644 --- a/src/ai/ga.js +++ b/src/ai/ga.js @@ -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) { @@ -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 {