Bombe: tweaks

Twiddle the default rotor sets a bit.
Add a time remaining estimate for the multibombe.
This commit is contained in:
s2224834 2019-01-12 01:35:24 +00:00
parent 49f5c94a75
commit 74eb4cca86
4 changed files with 21 additions and 15 deletions

View file

@ -22,14 +22,14 @@ export const ROTORS = [
{name: "VI", value: "JPGVOUMFYQBENHZRDKASXLICTW<AN"}, {name: "VI", value: "JPGVOUMFYQBENHZRDKASXLICTW<AN"},
{name: "VII", value: "NZJHGRCXMYSWBOUFAIVLPEKQDT<AN"}, {name: "VII", value: "NZJHGRCXMYSWBOUFAIVLPEKQDT<AN"},
{name: "VIII", value: "FKQHTLXOCBJSPDZRAMEWNIUYGV<AN"}, {name: "VIII", value: "FKQHTLXOCBJSPDZRAMEWNIUYGV<AN"},
];
export const ROTORS_FOURTH = [
{name: "None", value: ""},
{name: "Beta", value: "LEYJVCNIXWPBQMDRTAKZGFUHOS"}, {name: "Beta", value: "LEYJVCNIXWPBQMDRTAKZGFUHOS"},
{name: "Gamma", value: "FSOKANUERHMBTIYCWLQPZXVGJD"}, {name: "Gamma", value: "FSOKANUERHMBTIYCWLQPZXVGJD"},
]; ];
export const ROTORS_OPTIONAL = [].concat(ROTORS).concat([
{name: "None", value: ""},
]);
/** /**
* Provided default Enigma reflector set. * Provided default Enigma reflector set.
* These are specified as 13 space-separated transposed pairs covering every letter. * These are specified as 13 space-separated transposed pairs covering every letter.

View file

@ -9,7 +9,7 @@
import Operation from "../Operation"; import Operation from "../Operation";
import OperationError from "../errors/OperationError"; import OperationError from "../errors/OperationError";
import {BombeMachine} from "../lib/Bombe"; import {BombeMachine} from "../lib/Bombe";
import {ROTORS, ROTORS_OPTIONAL, REFLECTORS, Reflector} from "../lib/Enigma"; import {ROTORS, ROTORS_FOURTH, REFLECTORS, Reflector} from "../lib/Enigma";
/** /**
* Bombe operation * Bombe operation
@ -49,7 +49,7 @@ class Bombe extends Operation {
{ {
name: "4th (left-most, only some models) rotor", name: "4th (left-most, only some models) rotor",
type: "editableOption", type: "editableOption",
value: ROTORS_OPTIONAL, value: ROTORS_FOURTH,
defaultIndex: 10 defaultIndex: 10
}, },
{ {

View file

@ -8,7 +8,7 @@
import Operation from "../Operation"; import Operation from "../Operation";
import OperationError from "../errors/OperationError"; import OperationError from "../errors/OperationError";
import {ROTORS, LETTERS, ROTORS_OPTIONAL, REFLECTORS, Rotor, Reflector, Plugboard, EnigmaMachine} from "../lib/Enigma"; import {ROTORS, LETTERS, ROTORS_FOURTH, REFLECTORS, Rotor, Reflector, Plugboard, EnigmaMachine} from "../lib/Enigma";
/** /**
* Enigma operation * Enigma operation
@ -79,8 +79,8 @@ class Enigma extends Operation {
{ {
name: "4th (left-most, only some models) rotor", name: "4th (left-most, only some models) rotor",
type: "editableOption", type: "editableOption",
value: ROTORS_OPTIONAL, value: ROTORS_FOURTH,
defaultIndex: 10 defaultIndex: 0
}, },
{ {
name: "4th rotor ring setting", name: "4th rotor ring setting",

View file

@ -10,7 +10,7 @@
import Operation from "../Operation"; import Operation from "../Operation";
import OperationError from "../errors/OperationError"; import OperationError from "../errors/OperationError";
import {BombeMachine} from "../lib/Bombe"; import {BombeMachine} from "../lib/Bombe";
import {ROTORS, REFLECTORS, Reflector} from "../lib/Enigma"; import {ROTORS, ROTORS_FOURTH, REFLECTORS, Reflector} from "../lib/Enigma";
/** /**
* Convenience method for flattening the preset ROTORS object into a newline-separated string. * Convenience method for flattening the preset ROTORS object into a newline-separated string.
@ -104,11 +104,11 @@ class MultipleBombe extends Operation {
}, },
{ {
name: "German Service Enigma (Third - 4 rotor)", name: "German Service Enigma (Third - 4 rotor)",
value: rotorsFormat(ROTORS, 8, 9) value: rotorsFormat(ROTORS_FOURTH, 1, 2)
}, },
{ {
name: "German Service Enigma (Fourth - 4 rotor)", name: "German Service Enigma (Fourth - 4 rotor)",
value: rotorsFormat(ROTORS, 8, 10) value: rotorsFormat(ROTORS_FOURTH, 1, 3)
}, },
{ {
name: "User defined", name: "User defined",
@ -178,8 +178,13 @@ class MultipleBombe extends Operation {
* @param {number} nStops - How many stops so far * @param {number} nStops - How many stops so far
* @param {number} progress - Progress (as a float in the range 0..1) * @param {number} progress - Progress (as a float in the range 0..1)
*/ */
updateStatus(nLoops, nStops, progress) { updateStatus(nLoops, nStops, progress, start) {
const msg = `Bombe run with ${nLoops} loops in menu (2+ desirable): ${nStops} stops, ${Math.floor(100 * progress)}% done`; const elapsed = new Date().getTime() - start;
const remaining = (elapsed / progress) * (1 - progress) / 1000;
const hours = Math.floor(remaining / 3600);
const minutes = `0${Math.floor((remaining % 3600) / 60)}`.slice(-2);
const seconds = `0${Math.floor(remaining % 60)}`.slice(-2);
const msg = `Bombe run with ${nLoops} loops in menu (2+ desirable): ${nStops} stops, ${Math.floor(100 * progress)}% done, ${hours}:${minutes}:${seconds} remaining`;
self.sendStatusMessage(msg); self.sendStatusMessage(msg);
} }
@ -267,6 +272,7 @@ class MultipleBombe extends Operation {
const totalRuns = choose(rotors.length, 3) * 6 * fourthRotors.length * reflectors.length; const totalRuns = choose(rotors.length, 3) * 6 * fourthRotors.length * reflectors.length;
let nRuns = 0; let nRuns = 0;
let nStops = 0; let nStops = 0;
const start = new Date().getTime();
for (const rotor1 of rotors) { for (const rotor1 of rotors) {
for (const rotor2 of rotors) { for (const rotor2 of rotors) {
if (rotor2 === rotor1) { if (rotor2 === rotor1) {
@ -292,7 +298,7 @@ class MultipleBombe extends Operation {
const result = bombe.run(); const result = bombe.run();
nStops += result.length; nStops += result.length;
if (update !== undefined) { if (update !== undefined) {
update(bombe.nLoops, nStops, nRuns / totalRuns); update(bombe.nLoops, nStops, nRuns / totalRuns, start);
} }
if (result.length > 0) { if (result.length > 0) {
msg += `\nRotors: ${runRotors.join(", ")}\nReflector: ${reflector.pairs}\n`; msg += `\nRotors: ${runRotors.join(", ")}\nReflector: ${reflector.pairs}\n`;