Skip to content

Instantly share code, notes, and snippets.

@Gergling
Created October 20, 2018 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gergling/f2aba1c37182b47500744500a97a2da5 to your computer and use it in GitHub Desktop.
Save Gergling/f2aba1c37182b47500744500a97a2da5 to your computer and use it in GitHub Desktop.
Star Trek Engineering Crisis
const getRandomItem = list => list[Math.floor(Math.random() * list.length)];
const components = [
'matter/antimatter manifold',
'main deflector dish',
'kettle',
'Captain\'s copy of TMNT Issue #1 signed by Roger Moore',
'baffle plate',
'navigational laser',
'secondary plasma relay'
];
const subordinates = [
'Seven',
'Lieutenant Barclay'
];
const actions = [
'rerouting power to',
'realigning',
'synchronising',
'boiling',
'activating',
'reading',
'ejecting',
'deliberating over',
'restarting'
];
const developments = [
'has developed a feedback loop',
'has ruptured',
'has developed a mysterious defect',
'has started showing anomalous readings',
'has disappeared'
];
const getComponent = () => getRandomItem(components);
const getEscalation = () => getRandomItem([
'causing a ' + getComponent() + ' overload',
'flooding decks 1, 2, 3, 5, 8 and 13 with epsilon gas',
'causing an explosion in the mess hall',
'resulting in the Captain being locked in the ready room'
]);
const getAddress = () => Math.random() > 0.5 ? 'I am' : getRandomItem(subordinates) + ', try';
const getInstruction = () => {
const component = getComponent();
return {
sentence: [getRandomItem(actions), 'the', component].join(' '),
component
};
};
// Plan:
// * Address
// * Instruction
// * Action
// * The [Subject]
const getPlan = () => {
const instruction = getInstruction();
return {
sentence: [getAddress(), instruction.sentence].join(' ') + '.',
component: instruction.component
};
};
const getDevelopment = () => getRandomItem(developments);
// Outcome
// * The [Plan subject or random subject]
// * Development
// * Escalation
const getOutcome = (plan) => {
return ['The', plan.component, getDevelopment(), getEscalation()].join(' ') + '.';
}
const fullPlan = getPlan();
console.log(fullPlan.sentence);
console.log(getOutcome(fullPlan))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment