Quellcode durchsuchen

Add day 13 pt 2 solution

ApisNecros vor 2 Monaten
Ursprung
Commit
2078d2de47
1 geänderte Dateien mit 16 neuen und 5 gelöschten Zeilen
  1. 16 5
      13/13_2.js

+ 16 - 5
13/13_2.js

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