Skip to content

Instantly share code, notes, and snippets.

@bluepichu

bluepichu/client.ts

Created Sep 24, 2019
Embed
What would you like to do?
CPU Adventure Solve Script (DragonCTF 2019)
import { Socket } from "net";
import * as readline from "readline";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function wait() {
return new Promise<string>((resolve) => {
rl.question(">", resolve);
});
}
let log = true;
let allData = "";
let socket = new Socket();
socket.connect(1234, "cpuadventure.hackable.software");
socket.on("close", () => process.exit(1));
socket.on("data", (data) => {
allData += data.toString();
});
async function send(data: string) {
if (log) {
process.stdout.write("\x1b[34m");
process.stdout.write(data);
process.stdout.write("\x1b[0m\n");
}
socket.write(data);
}
function readUntil(delim: string) {
return new Promise<string>((resolve) => {
let index = allData.indexOf(delim);
if (index >= 0) {
let result = allData.substring(0, index + delim.length);
allData = allData.substring(index + delim.length);
if (log) {
process.stdout.write("\x1b[31m");
process.stdout.write(result);
process.stdout.write("\x1b[0m\n");
}
resolve(result);
} else {
socket.once("data", async () => {
resolve(await readUntil(delim));
});
}
});
}
let makeArray = <T>(n: number, fn: (i: number) => T) => Array.from(new Array(n), (_, i) => fn(i));
let ENEMIES = [
"VALIS",
"REDFORD",
"THE RED BULL",
"THE YELLOW DRAGON",
"THE BLUE DRAGON",
"THE CRYSTAL DRAGON",
"THE GREEN DRAGON",
"THE BEIGE DRAGON",
"THE BLACK DRAGON",
"THE GRAY DRAGON",
"THE ORANGE DRAGON",
"THE RED DRAGON",
"THE WHITE DRAGON",
"THE DRUNK DRAGON",
]
// Setup
const EOM = "CHOICE: ";
let grid = makeArray(8, () => makeArray<string | undefined>(8, () => undefined));
function shouldShield() {
// console.log(stateString.substring(index, index + 50), stateString[index%stateString.length], stateString[(index+1)%stateString.length]);
return stateString[index%stateString.length] === "0" || stateString[(index+1)%stateString.length] === "1";
}
// dumped from a previous run
let stateString = `0110110100100110011001110010101010011101101000010000010101100100000001111010100000110110011011101100101101110001001000100110000010110001001100111111101111010010001100000111111110110111000111110101110011000111101101001101011111000001011011110001110100111011000000111000100010000011001000100010010001111001111111010001010011100000110110111011011100111111100111011110001000100010011011011100101111111111010111000011101001001100001100111010110111011111001011101011101011111011100011101010100001101010111101101101111000110000111000110000110010010101100010111011100110011000111001101111101001101010111001101011111010100010001010000101000110010000110000111001100100011000010000010010011111111101100110000011101111000011101010110001110010110100100110110011100111101000100101111010011101101010111001000001101111100000110010010111001011101111101101111001110001011000010100011110111000111111111010110010111000011001001111100011110101100100001110001101011000001111011101011110011101111101110000100001111010110000101110010010100111100110100110011000110011001010111001000100111101001000100101010101011010000000010110010001110011110000010100111111011100000111101001010100110010100010011011001001100101011110001011001010101111110011100010011010111101111111001001101101111000011010101101110010001010000111101111000100111011011000101100101111101101100110011110101001100110010011011101011111100011000010110111101001001100100110101111110101100111011001100110010100100110100011111111100001101110110001001010111010101100001001100111101000110000110000111100110110110000000111010000001110010010011101101011101101101011101010010000010110001100110101010101101101010011110001010000001101010000111100000110011000011100001101010011101011101101010100110101110011110010010111111110010101011110110011101110110000001011011010001000100101001010110101110001100100011100010110010000001101001111010011110111101010010001101000110011110010011101011011000101110000110111001101101111111100001010001101110101001011110110111000010100111011011010000101111011100110000111010110011110011011100111011100001011100011010010000101110101000101010101101010101000001101001100101110001001100100000000000100011111110001010011011010111011110000101111100110111101110001000000101010000110010100101001010100000111011000101000000011111010110110010100001110011111101001010010011101110100000010011010011000011101110011101100101100100101100010100011110010010101010111000001010101010010100110000111110110101110001001110001001010100101000011111000010101100101010101010000100101000110111111110111010011001011001000001100000010111001010101110001101011101011101110101001001011111101100011111011010010010110010000110010010000110000010011110001011010101000000000010010000010111011000011111010000011101110111101010101110110111010000010110000110010000000101000011010111010010001111111010000000111001010110011001011111000100100011001100100001000001000011011010100110110110001010011111010001011100010111001110000010011010001101010111010010110000100101100011011101001101010010011111110111000011010011000001000111001001101110000101100100100011100011100110101011101100001010111010100110101100110111000110110100010011100011000001100000000010000000001111010001010100011011001010100111111111100110111111011000010100100001100111011100011110101001110011011001111100000011101010000100001000000111101100101100001111110111100001001010000111011010111110001000010010110011000111110010100010101110110011010110010100010100100010110000110111010010000000001101111000000000010000101011101111001000011011001011011001000000100001110111101110000010100000000000011100100001101001111111001100010101000101001111010111110001101000000011011010000110000110011000001001000111110010110111100100010010001010011101010010011101011110010111011000100000001111111110010011110001100101110111100011110110011001110000000011001001100011110001011101010011111100001110100001100010011011111100011111101101000001010101000111101100100110101010100111001111001110100100000101001001011000010111100011000110110001101011011110010100011010000001100010001011100100010110100110001010000010010111111001101110100010101111001101101001010011011100010100100110110110110101000000110010111000001100000101000010101001101101001000110010110110101111010111111110011111111011100011000000110100101000000101111111110101001111100101110000100111010101100110110111000001011010100101011110111110110000011100111001111101110010100010111011111001110111001000011101100100001111011001110010001010101101111010000110000011001010100001010000110000100110001011101001100010011111111010011101111111110011100000110011101001110100101000100101001111100111011001110011011110000111111111110110100111010001011111101010110000001100001011100001111011010001111110100100011101011101010101111001001101111010001001110100110010011000010110000010010110000111010001100101100111111011111111010010111011010100011001110110111001010101011011111110101001010110111011000110000010111110111011000111010110010100111110110111110010001111000000001101110010100101000000000101101011101011000100111100001001000101110001110110101101001011010000100111010000110100011111010110011000110100110001000101011000011110010001111101010011000110000011101010010001000010100110110000100101001001001000001111101010001101111010111100001110000001010010001001101010001001000011100001111111010111111100110110101111101000100001111100011111111000001011110100011011100101100000010101001001101111000100000100000111001111001011110110101101011110011010000110001100111101011001101001110110010100111011100101011010011000000010011100011101011110101000000111000011101011100101011000110001010110010111111100010110011111111010110111101010110001011000100001100100001011110101100101011010100111011101111111111001000101100011000111110000001011111010111000110111011100100011011111000100110110000110000000011101001010011100011001011000101010010101110001011110010001011101100011010100010101111100111111100010001100100000110101011001001101000000000100111111000001000001001100101101011110001111001100101101100001010000101111001001111010011011101111111010011010000100001111111100010000110000101100101110111001001100011011011001000010001000100011100101100011101000110111100001010101101000101011001100000101110111010011011110000010101101011110110000010011001110000101001011100100001001001001111011110000011010011100001110111011011111000010011001010000011001001110110111011111100001111110101001000011110001100111011110110111111101111000111000110100110100010111110000001001010011101100111100111101101011101000111001000010000111010100011101011010101110000101010001011001010000101100110100000100010101111110010110110110000111000001111101101110110000110100000101101011000001010001111110110001010111111100001001110000001011000101100111010100111000111000010100000100000101100110011111111101001100010110101101111011111000111100001101101001100110100110100111101100101001011101011111110110001000010110110101000101100000010000011011000111010011000110010110100000110000011110101111110110011010100111101000000101001010001111111100101111101111001111001010100010000111011011101010100010010111000011100011101001011100010100110011111100010100011100111011111110110011101011100010100011001101001010110100100101001110011001100110110100010110110001101001110111000000010001100000101010111100011001100010100111011110000010000111001011110010101011011100001000110100111001001001011100111011110100010110111011001100100111101110010101000011110101001011001001100111110111011111000001001110111011010101100111001001111110011101101101101000101000110001111011111001000010110010101110101110010000110001101101001110011101100000110110000100000011011100000011000101000011100010101000111100110000011111010001001001011101101111011110010011001011101000111100010000101111000011011111001011000001111110111001011011111000101100010101100000101101101101110000111100111100010101010111111110001010110001000010011100111101101110111010010001010101000101000101110010100001000110000111111001011001110001001000001100010111110011110100101101100010101101010001000111101011110111000011111001010100000101110001111100001000011011111110100011110011101011101000000110011101100100110000000110010001101110110110110001000110110000101010111110110000110110101100111111001010110000110110000110101010001000001000100100001011010101010101001000110001001011010001011001101111110011010111100000001110110101010110000101100111011110011101101000111010000000100110111001101000101101001001000110101100111000110001001100101010100101110011010000001110111000001000101001010101111001100111101111001011001100100000010101101001011111010110010010010001100001101011011100111101001110001010000011000011010011101011010010001011010110010111101001011100111110100110111110101100001110110110000001101110101011110111100011001001000110010011100111010010101000110001101110110011100011101110100111101000101111011111001101000100111101100010110000010111100010010010011011101110101110110000000001111111011000001011001110010110101110010011001100010011000000001100001100011010000111001101011101111101000101011011001001111010110001111010111000100010010110000010000011001101110000111001101110111101000000111100011011011110111001110100111111000110111010110000110001111101010110010100101011111101010011010011001001001011001101001011100000001111001011101001000010101111101000001011101001011101000000011001111001100100111000100000000000001001101011001000100011000101010011111010100001110111111011001000000001011100010101100111010110010001101100011111100101001101010001100010001001001101000010101101101011001010100000000100011010100011111011001101111001100001000000011101010101110011101000101010100111110000010001000111100001010010010011010111010000100110101110001011011000011110101110100010110000100010011000100001010001110001000110101111000101001111000010111011001001011111010011000000111001110110101001001101010010110101100010000001101011010011001010110110110011000101110001100011100111101010001100101110010110001011110001110110010010010100110011000011001011111111011111100101111000101011010001000011010010101010110010101111111010111010110100011101101010000110011110001100000100101001011100001011011100001101100110010001011110011110101010011011101101010011001110001111101110110100100111001101011000101111101101001100001011101011011110000001010000100000111110000010100010101001001000101010001000110111111011101000110001001110000011110001111000110001000110001111110101011101010100101101100111111111111001010000101001100110101100000010111100000111011001111100101001111111000110110000010101100001010011010010110111110100001010000011010110011001001010001110000010010000101000000111111100110100000110111100101010011101010111001111110110000000011010110001100000000101111011110011001101110111000010010010100001100011100101000011011000100101110111000011000110001011100110010101100111000011011011001101000011101100001011101110001100101001000111100010101111101101011001000001001010000010001000010110011111010000100010101000001001001010101100011011010110110101110000011010100011010001011000111011011001010010010000101010101110101000111111100111110100011101100000100011001110100010000000001010000011111100001100001000110110010000011101010111011010111100100001000110111000100110111010010101010011000111010111000000010100110010000010101011011011110011001000100101101010000101100011110010001010111000110000100111011111000011100111101111011110000110000001001001100000011001101001111100110001101011001011011110111011011101101011001101011011111000000110000000100010010101111111111101000011100001010101000010111110001110111101100101011110100001011111101101001011110000010111000010100010001001111000111000011110100001010101001000011011011110010011100001111101111110101000111101001110100000010110000001101011111001011111110100001011010111111100011100111010101010011001101110010010000111010110110100001110100101100100011001101110101101011000110101010000010101101110100100101010001110110010111000110011011010100001001101110110000011110010000101001111001000011110011001110001010111100011100110000001111001001000000010110100100001001000011011110100000110100011000101101100100101000010010011100000000011000001101111110101111000110110010111100110101011000110011111111000011110111110111010111001101001010011110110000001100100001110100111001101001101100101001100010000000010101101100001101111110000101010011110000000100100111010101001100100010000011100010110111010011000001101101011100101100111101110110101110011100111011101011111001001010111110101010001011110101011010000101000100111001100100110010000101010000100111101111101011111100110010000011111111110001110110111000000001110001111011011001110010100000111000111000111110010001000111011110001101110000110011001011101101101110111000111000000001001110100100111010010110111011110011111000001101110001011000111110001011111010000111101000111111000111000100001111110110110101100000000010101010011010010011101100001001000111011000100010100110101010011000010000101101000000011110000010011000100100000011011001010001101101010100100000111001010011001011110111010011100001011101001110111010101011011000001110110110101011111011101001001111110001000100111001001110100111000111101000110101100010010100100001110010010110111111110101111010011111000011101101001010001110101000000101101010111111101110111001111001100001101010001000010111001011111010100111011000101101010001010010100001010110011111110000010010111010011111011100000010111011111100100101100000001010100110011110110110001001100010101111010010000110100010101110011001000011010110101100110000111101001000001111000000011000111000000100011100001100101101010100101010011100000011100101110011110000111110101010011110111111111011011001001101111111011011011100100101011010000111101101101101101111010011001101100111011010011011101010101000110010010011001101101101111111001011000100101100010001001100111010111101111010011011000101101111011000111100011101110001101111101101101100111011111001001000010111111110000000010100010010110010111001001101100101100110000101000000010101110011100010001111110111011110010101100100111110100101000011010010000000100111101101000010101000111001100010110111000110001011001100000000100101111011001001000000111100110001001011111011001100101101001011000101101101110001101000010110010000100111011010010001001111111000011100010111101110110010001000011011000001111100010000001111110011001101011101010111010000011001110001101000111100000101100101100010000011000010000111000001010111111011110010001100010111100110111110001100111110100100010111111000000101010111001001011001010110000011100010011101000110000011010101001110100001000010101011101110001001111011101111110101101101111100110110111010100010000000100000010110111110110100011010111011101111000000010111001111111100100101001010011111100100100110100100000100011101110010010010010011100010101010010101100100010100110000000001101010010010101010010010011111101000101100100010110011001010101100001110011100010100101100010011100101101110110110011011010011110010010010101100111101001001110001111111011111110000110010001010001101001010010100010101011100001111110000011010110110011011111001100111010000010100101111000100001110100010011111100101110010001110000001101101010110001001101101011000101010111111100100011100101001001111101110101011001000111100101010100010001000101100010010011011010001110001010011100101100100010011001011111101110110110001110011001010011001110100101111011110110011111011111010101010000110000001100011110101011011010001101110111100010100010110011110101110011101101111000001111100111010011010110001110101001111011010101111000100110001111101111100000001101001000101000001011110110110010110001101011110100000001011000111001110000000110011011001011100110011111000010010011110101001001100000110011111100111110001001111001000110100001100110011101111110001101011111110100100001000010111110100100101000100111100110110011010010010010010110110000000010000010100110000101011111111010000010010000000010010010111110001100010100110001010101000000010111011010110110000100010110010110100010011001001010100100010111010010010000010101110001001011011011111100111111011101010011000011010001000010000110000000110111011111011110100001001010100111101010101100011110000100011101100111011000110010111110100011010011011011111010010000001011001010010000101100000001111110100110110100001001011110011000000101001101110100000000110011001100010110010010100100011011011000010110100010100110010101000111110011001001011011010101000010101011000100011100111001010111100111100000000011101011111010110111000000100100011010011001110110000110001010111000011010110010011101111011110101100010100001011011000001011100100000011101100101011011110011110111111010001001100001111000111001001010001011010000111000111111000101101101011011111101010100101000110101010111101110010010111000001001010111101010111110101111011001011101001101000111010101010110011111011010000111111000100111001110001111000100100001100101110101001010100010010010010001001011111110011110000101011100000111111100011110010011111110010010001111011010110000101011000000001111110001100100001001011100110001010001000110010101001000000100110001100010010011110000011011001000100100111110101111100110000010101110100011001110011101011111101001100111100111000111001000000101110000000010110111011100110110010101100101101010001111000110100010100100111100010011111000101000010011100010111111011111000101001000111001000111010101111100001010011000111111101010101010110001010010000100110100100101110001000110000101010000001101111010101001000100100000001110000000101100110110101101000001110101110111111110110000111100001001101111100100110100010101011001011101011000001101110100001010010110011100111000010110000111000100101111000110100111110110010100000100111010111001111100011001010111011101101101001000011000100011101101101111101100010010000100111110000000100001101000000001110011010010001101111001000001110000001111000011100101000110001010001101100000000001010111100100011101111101100101101011011011101100100111010100011000001000000110010010010011001000111111010111011100000110111101111110110111010010111111010010011011100100001011100000101111111011111011010100111001000110101011000011001101010000001001111100101011010110010010111011110100101001100100101111000011110101011110000011000110101011010110000111110001010101110101101101101001111100011011111110001001100110101001010000010100010000011011101101000110000100101110110010111101100001110010110110001111100111101100001001101101001101100000011110111000010101101111110000000000001011000010011100101000100100011011001101011100000011111010011100000001001100100111111011011111100010101001000010001111011000011001111111001011101110111001010011110100101000110000000101000110000101111010011000111000010001010110101101110001011101101100100011101101000101111001010000111100101100001101011110110101000001100110010010001001110101100110110010010011110010110010011100101111011111100111010001111111011010100010011010011101001111011011111011101110110100001101011000011010010111111111000001110100110110011110010100010000100100110010100101100000110101111001111101010010010010101001101111100001100110111101001110011111001001100010001111100010010100110100111000110111100011111100111100100000101101001101000000101110101010000011111001011110100000100001010010001100111000100001010100100011101110111000000111011110101101000000100001011101111011000000011000010010010001011110110100111111011001010101000001000011110000110011110100110010001101011100100011001010001110010111011010001001011011110101110010111001010010001010010111110111001101110000010011111011111111111000101110010110100001100100110100101010000110111110111100010110111111001010100101111100100111110110000001001110011011100101110101011111101000110011001101000010111000100001101011111100001101011100011100010101101101110011000001000010011011000110010010100110110010001100011101000011101110100010111010000111001000001111010101010010011001011000010101001010010010111010001010010110100011100111110101100011011111100100000110010100010110001011100100111100110011001000111010000101110100010001111111101111011000101001010111010000110011100100101010000100010111101000011101011110000010010010000001010011110111010101001110001011010111101001010110011011110110010000101000101101101001110110111110101110100111100010001010001111100011000000011110111101000111000111100111000010011010101101100111000000100110110011001101111101100111000010001111100111000110011100101111110101110010010011000111001000101111100101000000001111001110111011101010111000101010011010000110100110101000011011010001100100011001000100111000011010001101000010011000010001111001101010011011110010111100111111111101100011010001000111010100101000100000011101001111001110110001001111101000000100011110100101111001011111001011010100110100011000000111110001101010101010001110001101100111010000111110111010000110110110110000010010011010101111001110010100101101010010000101001010011010110110001110110011000110001100011101101001111011100000000010010101000101110000001000010010001100011000010001000110110101111000010110100111110100111101010000110001011000110100101110101010101001101100011100011000110011011111110011100101100001000001100011101010110100100000011100110001110001110110000111011110010010011111000010111001100000001011011000100001110001000001010100111001010011100001100010010001011001001111000011000101110110011000011011110110101111110111001110001101101101110101101110010100000010010101101111100101001010101010011110010101101110011011110101101101010110100011111000011010010010101101101001100011110100001111111011101011001100110000001101100000010100011101000101000001110100100011010100110101001100101101110100011010001110010101110011011101010000010100111010001110101111111110010110100011001101100000100001100111110110001011101011001011001011110001111100110111000100011101000111101000100000101000110101111101111011010000000000011011011010010101100011101111001100011101001001001011110010010100000011101011010000100010000010011100001000010100001001011011001010101101011010110110010001011100110111111110010000001100011011111001110010011010110101110011001101001000011101110001000101111000101110000011101011000101101000100011000000000001010010110110110101101010100111111010110100010111001111010110110000001000100111110110101011011011011001011101100111010010010111101110001101010111111000100101100111011011001111000000101101000010110111010110010011000101001011101110101100011001010101110100111001000011111001101011011010010010011000010011010000111110010000010011110100001000000000010111010000010011010100111000010010000001000110111101110100010010000010010001010110111000111011111100110000101010101011111010010111110000110110001100001111011000100110100000101000001010100010011000110100011011010000011010100110000011110000101100011011000011111111010001000110101010010111100111010101111001011000110000101000101000111011011110101001101100110110001101110001100111100001101000011110011100100011111111110100100100010000010110110011101010110110001001001000111010010000111110110000100011100110011110010110111001110000111001000100101000000010000100001001010011000110101001111111010011111010110100111101011010010100001000011010101010001001110110011011001100011101100011011110110000101100010001100110101111111111000010001001001000010000000101111100001000110001101011100001001011111001100101111001000000100100100101000110010101100010010001110011011010000001111101100100010101100100101011101111100010001110001001100001010010101100001000110011000010110101000000011000101101001110111101010000100100010010010101110010100011101111010011110010111000111001111111110001100011110010100000101101110010011111001101001110011000110010011110010011000001001101101100111110101011100000000000111100010001111011101001011010111011100101100101000111100001111000000110010101101000110100100011110100000101011110111011100010110100101110111111100011001101000000010001110101100000011101000101101011100001100001101100100111000001010010101001011010011011010101110111010001110111010110100110111111111000100100110011110001001010110000001001011001001001101100010011101111001011100110110101010111010001001101011011101101001100100001111110011100111001000010101101000001011111100010111100001000101110000100010000111001110100000000011001011001010100101010110110010110100111001011100010110011010101000011111111101110011001001001110011111100011110111001101011010000110111001000111101010100011101001111100100100100001101010000010110010011011010100100011111011110010100110000010100100000110011110110011011011001010111000010000010111001101010101110001000001111110101100010001011001110000011100100110010010000011010000110110011100010111010001101101101011111111011010110111010000111100010011010010111101010001011010101101010010111010010101111001010010010101111000000110111111111101110110011011100110001000100001100110100010100001101110111011101111101010000010001101000100110111000111100000111001100110110001000100011001111110110101010001111110011011000010111110110001100010000110111010111010010100101101111000010000001000100010100100000011001100011011001100001000101001111111101100100101010111011001000001011111001000101001001010010110010110011101000110101001000000001100011001010000100110010001010100111011111010110101101001110000010001111000111110110001110111001100011011100110011101101011000111111110101000101000000100000001001010001000101101000110110001010100000001110111111110011010101001001011010111110110111001101010000100011101001101001101110000000110110001011110100100100111010000011110001010010100100000100110111100111010000101011110000100111101010111001010100100101000001101110011110001101010000000011011001111011111000010110011000101011011110110100101010010011110100011101001010110110001100011010010010000111111100100001001100011101110110010100010001110000011000100000010000010001100010000011101000010010000011101111101001111111110011001010100110101011001100111010101000110000111010011001100110011110000011110011010001100101001101101110111101101010101001011001100110101011111001000000011011111010100101110001111001011010110011101001100001100010000100010011101110011111001100110000100111110101010110100101010111001100001011111110010100100000001100101001111000111101001100001001000010001010001010110001101000001001111111010110101000011100101010011000000101100111100001000010001011011110011011101101111001011011001101010110100110101010110010000101101111111000001100001111100111111001000011001100010001101001011000000111111011001111111010100000001001000100001111001001101010000011100110110001010001010011011111101001011000111000100100101100011110111011000010000100111100101001110101100011100000111011100101110000001101000000100100001111010011010111011010000011111110100101011100111101110001010101100000100111001000100000010010111000110110001000001001011010110100010010011101111110100111001010110110011001010000110011011011110101100111110011110011010110011110110001110010011110110011110001011111111010101000000101000000101010101100000001101011101100010101010101010111011110111010100011010100001010010011001110010000000001000101010101000000111101001111110100111100000100011011011101000100001010110001010111010110011100110010110011010111101010101011100101111000000001000100000001101010111000111111010000100111111010100001011101101110001010111001001110011000011000001011010001111001011111100001000001110110100000010101111100010101110111001110011000100111010100110010011101000100101010000001000101000000001010011100010011111101111010111011110101111101001110101010110011010001000101111101111100101011111100000111111001001100111011101001010000011110110101001011000011000010100111110001000101101101100100100010110111001100101110011100101110100001011000010110110111101100110100011011111010001111100100111011100010100001100100011110111111000100000110101110011011000000010111100101101001100111110010001101101001011001111001000100001000110010010110011111000101101000001001010101000011101010100100111000010101111010111010100001010111001011011010010111001010111011000111111100000001111100001111100000000010111111010000110010110000000000000001100111001100000110100000111000010010101011010011111111001100000000001111101110001011111000101110111100110100100110001100111000001011000001100001010110101010001010100001110000000000110100011101111111001100111111010000001101101111100011100101111100000111000110010011011000001101001011010101110101111000100011011101000111110111001111011001000111110000011110110000011001101011010101100101100000101010010110001100100000011111001100001111111000010110110010111110011100001100111000011110001011000000001010100011001100011110011110100000111110111101111101001010101100110001000011110111001000001000101110101110000101111011001100010010010100100110001001101010100011010110100011000111000101110001001001110010101000110100111100011011110100101100110110000111010100110111001111101100111101000011010100101111110001110100010001010101111010011010010001000101011101001100111001101010010001010111101100010001111001000000001110110000000100101101110000011100001100000111000001101000100100010001101000001100101101111110111111011110111011110111111110001111100011101010001011111111111111010101101010111101000111101101110010000000100010111111101010111111111011110011011000111101100011001110101000100101011010101101111000101111010111000001000000011000000111011011111111101000110110011111101010101111100011111010010011110110110100011110111101101101010010100101111010001000100000011000011101100110100110001101111001101011100101001101111011110111001011110101010000100000010100010111100000010001011010100111110111101010111011111101110001001010001111010110111010101101110111011000101111111000000110101010110111010111000111101111001110011110001000000010101011001110111001101001111001100011000011011100011100101010110010010000100101011001010000000110100001000110101101101100011011001001011010000001101000101110110100111000100010101001011101100000101001101011110010101110001110100000100011111011011000110011000000011100010100010011001100000110001010101101010000010011000001110010110011011101001111111011001011111100100010011011110110111010111101101111010001100100110011010001111010100010011111001111100111001100111001111111011011110110110000011000111111111111100000010000001110001101110010011010011111100110001111110000001111111100111010100101101110010110101011000001100100000100000010011101100011100001101111001111110101111101100100111111110001101001010111110000000011110110111100010010111001001000110111001110010010000010000100011100011001100111110101110110010101000101011010011101010000110100001010011100111001101000111000000011100111110000110001110111110011000100000101111001110000001100111110011011001000011011100001001100000010011001100101100011111101111101000000001001100001101101110011101011010111011001111110000000101011001101010001011101010110101110100110110110100000001010010011100100000101000011111101000111001101000010010010110100101001000100011111010001100011001000101101100110000001000110010111100001010000111010000011011011000111100110111100100101101010101111110110110000110010101010111101011000000010000011110010101111011010001010100110001011111100101000111110100110010100111001001100001110010011100011010100101010100011011100000110010111101011110101101010101101011111100100111001001011110101101111111111110111110011111011011010011010010100010111110101011011111011111011111110101100000100010011010001000000101111010100111100111110010110010110110111010011101011111000011110010100101111111011010001000001111011111110111001001110110010001101001001101001101011010010011110011100110110110101010101111000011001010000001100000100010110000011101000111000010110101101010001101101111110110101111011101011011001111010101100111100011101011011111010101111010100101001110100110111001010111110010101010100010110111110011110001111111001010111010010011010110000100001100101011111011111100000101010000011000110000001000011000101001001000111111000010010110100111100001110111110001101101010001110010010001000100001001100110111100011010110101001100010010101011111001101010001110111000011101100011110100100101101110101001110100100010000000011111001001011101010000000001110000101111110011110111010000011100100011000000101011000111110100001101111000101010000101101001010111011010010110110100000100000000110100110111101010001110000111000010000000010000111110100101101001000111000010011111111111001111010111100100100010100010000110001111000000100111100111100111111000010111100110010100011001111100011100000101110101111010001010001001001100010110000111101110111010000100011111100100011001111011100111111001101001011001010011010001001010001010000100010010111010110101001001000000000011101110101000011111010111100110001011110110001101101110001000010000011010010011111001000011100110000100101011100000010101110110110000100111100000011100000100001011000101001101000001111010000000000110001001111010111011011111101000001100010010100001011100111010100000111100111110111100000011110101101011111001110101100001001001101111101110010001000101110111011001111011010010000`;
let index = -1;
async function fillState() {
console.log("filling state");
// log = false;
let first = true;
let start = Date.now();
let stateCnt = 40;
send("S".repeat(stateCnt));
let state = "";
for (let i = 0; i < stateCnt; i++) {
let result = await readUntil(EOM);
state += result.indexOf("BOUNC") >= 0 ? "1" : "0";
}
index = (stateString + stateString).indexOf(state);
if (index === -1) {
console.log("big wat");
process.exit(1);
}
index += state.length;
console.log("done filling state ->", index);
// console.log(bounces);
// log = true;
}
async function doFight() {
while (true) {
let result = await readUntil(EOM);
if (result.indexOf("YOU KILL") >= 0) {
// Nice!
return;
} else {
if (index === -1) {
await fillState();
}
if (shouldShield()) {
send("S");
index++;
} else {
send("A");
index += 2;
}
}
}
}
async function exploreGrid() {
// assumuption: we start in the tavern
for (let i = 0; i < 8; i++) {
for (let j = 0; j < 8; j++) {
console.log(i, j);
let result = await readUntil(EOM);
for (let enemy of ENEMIES) {
if (result.indexOf(enemy) >= 0) {
grid[i][j] = enemy;
break;
}
}
if (grid[i][j] === "THE DRUNK DRAGON") {
await send("A");
await readUntil(EOM);
} else if (grid[i][j] !== undefined && grid[i][j] !== "VALIS") {
// Fight! Fight! Fight!
await send("F");
index = -1;
await doFight();
}
await send("E");
}
for (let j = 0; j < 8; j++) {
await readUntil(EOM);
await send("W");
}
await readUntil(EOM);
await send("N");
}
for (let i = 0; i < 8; i++) {
await readUntil(EOM);
await send("S");
}
}
async function run() {
await exploreGrid();
console.log(grid);
while (true) {
await send("T");
await readUntil(EOM);
}
// interactive();
}
async function interactive() {
while (true) {
await send(await wait());
await readUntil(EOM);
}
}
run();
{
"devDependencies": {
"@types/node": "^12.7.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.