1234567891011121314151617181920212223242526272829303132333435363738 |
- const fs = require("node:fs");
- const { render } = require("./common");
- const Computer = require("../IntComp/Computer");
- async function main() {
- // Load and parse the input
- const input = fs.readFileSync("./13/input.dat", "utf8")
- .split(",")
- .map((x) => parseInt(x, 10));
- // Set the game to autoplay
- input[0] = 2;
- const arcade = new Computer(input);
- arcade.Run();
- do {
- const [ballX, paddleX] = render(arcade.outputValues, false, true);
- let movement = 0;
- if (ballX > paddleX) { movement = 1; }
- else if (ballX < paddleX) { movement = -1; }
- arcade.Input(movement);
- // eslint-disable-next-line no-await-in-loop
- await sleep(100);
- } while (arcade.running);
- render(arcade.outputValues);
- }
- function sleep(ms) {
- // eslint-disable-next-line no-promise-executor-return
- return new Promise((resolve) => setTimeout(resolve, ms));
- }
- main();
|