From b99b70d36c1fed770ded6bd3a6317a638cbd7617 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 26 Nov 2020 18:40:11 -0600 Subject: [PATCH] Make ga fitness a mutabe object's accesor --- src/ai/ga.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 {