summaryrefslogtreecommitdiffstats
path: root/rules.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2021-02-19 16:21:22 -0500
committerBrian Cully <bjc@kublai.com>2021-02-19 16:21:22 -0500
commitbdf1d88883256c0d2731600d604af22d27d8ee7f (patch)
treea5bbd5a2c99106111aee6defc1a5eaf00fef417d /rules.mjs
parent4ead5e928b49e78e2071f7486530359acdab0bcc (diff)
downloadmolsim2-bdf1d88883256c0d2731600d604af22d27d8ee7f.tar.gz
molsim2-bdf1d88883256c0d2731600d604af22d27d8ee7f.zip
Remove penultimate genome slot
I need the last "good" genome, not the second to last one, so instead thread the original genome (before any mutations) through the required states so it can be reverted to if a lethal change is made.
Diffstat (limited to 'rules.mjs')
-rw-r--r--rules.mjs30
1 files changed, 18 insertions, 12 deletions
diff --git a/rules.mjs b/rules.mjs
index c019de8..9543ee2 100644
--- a/rules.mjs
+++ b/rules.mjs
@@ -73,8 +73,13 @@ class NucleotideSelect {
return
}
- this.rules.genomeList.push(this.rules.currentGenome.clone())
- this.rules.next(new RollForNucleotide(this.rules))
+ this.rules.iterations--
+ if (this.rules.iterations === 0) {
+ this.rules.next(new PrintResults(this.rules))
+ } else {
+ this.rules.genomeList.push(this.rules.currentGenome.clone())
+ this.rules.next(new RollForNucleotide(this.rules))
+ }
}
handleSelectionChanged(nucleotide, i) {
@@ -126,6 +131,7 @@ class PerformMutation {
this.rules = rules
this.id = 'perform-mutation'
+ this.originalGenome = this.rules.currentGenome.clone()
}
enter() {
@@ -183,13 +189,15 @@ class PerformMutation {
return
}
- this.rules.next(new SelectAminoAcid(this.rules))
+ this.selectedNucleotide.value = base
+ this.rules.next(new SelectAminoAcid(this.rules, this.originalGenome))
}
}
class SelectAminoAcid {
- constructor(rules) {
+ constructor(rules, originalGenome) {
this.rules = rules
+ this.originalGenome = originalGenome
this.id ='amino-acid-select'
}
@@ -199,6 +207,7 @@ class SelectAminoAcid {
const selector = this.rules.aminoAcidSelector
this.codon = this.rules.currentGenome.selectedCodon
this.expected = AminoAcid.codonMap[this.codon.value]
+ console.debug('expected: ', this.expected)
let x = selector.elt.querySelector('#amino-acid-selector .codon').innerHTML =
this.codon.value
@@ -227,13 +236,14 @@ class SelectAminoAcid {
const newAminoAcid = new AminoAcid(...this.codon.value.split(''))
const isLethal = this.codon.aminoAcid.value !== newAminoAcid.value
this.codon.aminoAcid = newAminoAcid
- this.rules.next(new MarkAsLethal(this.rules, isLethal))
+ this.rules.next(new MarkAsLethal(this.rules, this.originalGenome, isLethal))
}
}
class MarkAsLethal {
- constructor(rules, isLethal) {
+ constructor(rules, originalGenome, isLethal) {
this.rules = rules
+ this.originalGenome = originalGenome
this.isLethal = isLethal
this.id = 'mark-as-lethal'
@@ -288,7 +298,7 @@ class MarkAsLethal {
this.rules.next(new ShowError(this.rules, this))
return
}
- this.nextGoodState(this.rules.previousGenome)
+ this.nextGoodState(this.originalGenome)
}
nextGoodState(genome) {
@@ -421,7 +431,7 @@ class Rules {
}
_debugStartAtSelectLethality() {
- this.currentState = new MarkAsLethal(this, true)
+ this.currentState = new MarkAsLethal(this, this.currentGenome.clone(), true)
this.die.value = 15
const nucleotide = this.currentGenome.nucleotides[15]
nucleotide.value = 'A'
@@ -438,10 +448,6 @@ class Rules {
return this.genomeList.last
}
- get previousGenome() {
- return this.genomeList.penultimate
- }
-
showCurrent() {
if (this.currentState.id === undefined) {
return