summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--genome-list.mjs8
-rw-r--r--index.html2
-rw-r--r--rules.mjs30
3 files changed, 19 insertions, 21 deletions
diff --git a/genome-list.mjs b/genome-list.mjs
index c057d34..8969a8c 100644
--- a/genome-list.mjs
+++ b/genome-list.mjs
@@ -18,14 +18,6 @@ class GenomeList {
return undefined
}
}
-
- get penultimate() {
- if (this.genomes.length > 1) {
- return this.genomes[this.genomes.length - 2]
- } else {
- return undefined
- }
- }
}
export default GenomeList
diff --git a/index.html b/index.html
index 66a62fa..3b41efc 100644
--- a/index.html
+++ b/index.html
@@ -74,7 +74,7 @@
<ul>
<li>If the mutation caused a change in the amino acid
being coded, then <button class='kill' disabled=''>kill</button> it and
- start again with the previous generation.</li>
+ start again with the last successful generation.</li>
<li>Otherwise, <button class='clone' disabled=''>clone</button> this
genome for the next generation.</li>
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