|
@@ -8,19 +8,30 @@ async function main() {
|
|
.split(",")
|
|
.split(",")
|
|
.map((x) => parseInt(x, 10));
|
|
.map((x) => parseInt(x, 10));
|
|
|
|
|
|
|
|
+ // Set the game to autoplay
|
|
|
|
+ input[0] = 2;
|
|
|
|
+
|
|
const arcade = new Computer(input);
|
|
const arcade = new Computer(input);
|
|
arcade.Run();
|
|
arcade.Run();
|
|
|
|
|
|
do {
|
|
do {
|
|
- render(arcade.outputValues);
|
|
|
|
- while (arcade.awaitingInput) {
|
|
|
|
- // arcade.Input(0);
|
|
|
|
- }
|
|
|
|
- await sleep(500);
|
|
|
|
|
|
+ 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);
|
|
} while (arcade.running);
|
|
|
|
+
|
|
|
|
+ render(arcade.outputValues);
|
|
}
|
|
}
|
|
|
|
|
|
function sleep(ms) {
|
|
function sleep(ms) {
|
|
|
|
+ // eslint-disable-next-line no-promise-executor-return
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
}
|
|
}
|
|
|
|
|