Modified control rotor stepping so the next control rotor steps once the previous rotor reaches "O" and added tests

This commit is contained in:
hettysymes committed 2020-06-07 17:45:17 +01:00
1 parent e2b3389da6
commit 3c68ad1302
3 files changed
+56 -32

No files matched your search

+6 -7
View File
@@ -216,7 +216,6 @@ export class ControlBank {
*/
constructor(rotors) {
this.rotors = [...rotors].reverse();
this.numberOfMoves = 1;
}
/**
@@ -258,14 +257,14 @@ export class ControlBank {
*/
step() {
const MRotor = this.rotors[1], FRotor = this.rotors[2], SRotor = this.rotors[3];
this.numberOfMoves ++;
FRotor.step();
if (this.numberOfMoves%26 === 0) {
// 14 is the offset of "O" from "A" - the next rotor steps once the previous rotor reaches "O"
if (FRotor.state === 14) {
if (MRotor.state === 14) {
SRotor.step();
}
MRotor.step();
}
if (this.numberOfMoves%(26*26) === 0) {
SRotor.step();
}
FRotor.step();
}
/**