1234567891011121314151617181920212223242526272829303132333435363738 |
- const fs = require("node:fs");
- const { render } = require("./common");
- const Computer = require("../IntComp/Computer");
- async function main() {
-
- const input = fs.readFileSync("./13/input.dat", "utf8")
- .split(",")
- .map((x) => parseInt(x, 10));
-
- 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);
-
- await sleep(100);
- } while (arcade.running);
- render(arcade.outputValues);
- }
- function sleep(ms) {
-
- return new Promise((resolve) => setTimeout(resolve, ms));
- }
- main();
|