Skip to content

Instantly share code, notes, and snippets.

@EmbeddedLinuxGuy
Created May 4, 2016 01:05
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 EmbeddedLinuxGuy/01685d57b5f7f48f399ba9278980bbd7 to your computer and use it in GitHub Desktop.
Save EmbeddedLinuxGuy/01685d57b5f7f48f399ba9278980bbd7 to your computer and use it in GitHub Desktop.
Armchair Quarterback
#!/usr/bin/env node
var down = 1;
var yards = 10;
var yard_line = 20;
var suffix = ["st", "nd", "rd", "th" ];
process.stdin.setEncoding("utf8");
process.stdin.on("data", (t) => {
var c = t.substr(0,1);
var gain;
if (c === "r") {
var run = Math.random();
if (run > .995) {
console.log("FUMBLE");
process.exit(0);
} else if (run > .955) {
gain = 0;
console.log("Run stopped for 0 yards.");
} else {
if (run > .95) {
gain = 1;
} else if (run > .85) {
gain = 3;
} else {
gain = 2;
}
yards -= gain;
console.log("Run for "+gain+" yards");
}
down += 1;
} else if (c === "p") {
var pass = Math.random();
if (pass > .65) {
console.log("Incomplete");
gain = 0;
} else if (pass > .63) {
console.log("INTERCEPTED!");
process.exit(0);
} else {
gain = 1+Math.floor(10*Math.random());
console.log("Pass complete for "+gain+" yards.");
}
yards -= gain;
down += 1;
} else if (c === "q") {
console.log("Goodbye");
process.exit(0);
} else {
console.log("prq");
return;
}
yard_line += gain;
if (yard_line >= 100) {
console.log("TOUCHDOWN!");
process.exit(0);
yard_line = 20;
yards = 10;
down = 1;
} else if(yards <= 0) {
console.log("First down!");
yards = 100 - yard_line;
if (yards > 10) yards = 10;
down = 1;
} else if (down > 4) {
console.log("TURNOVER");
process.exit(0);
yards = 10;
down = 1;
}
console.log(down + suffix[down-1] + " and " + yards + " at the "+yard_line + " yard line: r[un] or p[ass]>");
});
console.log(down + "st and " + yards + ": r[un] or p[ass]>");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment