<story><title>1D Pac-Man</title><url>https://abagames.github.io/crisp-game-lib-11-games/?pakupaku</url></story><parent_chain><item><author>mrb</author><text>Here, I found it fun to write a small bot to play automatically. Just paste this JS code in the dev console. It reached 9000 points on my first attempt to let it run. Feel free to tweak the code to make pac-man survive longer :-)&lt;p&gt;&lt;pre&gt;&lt;code&gt;    function bot() {
        &amp;#x2F;* direction of the enemy: to our right (1) or to our left (-1) *&amp;#x2F;
        dir = (enemy.x &amp;gt; player.x) ? 1 : -1;
        &amp;#x2F;* if pac-man... *&amp;#x2F;
        if (
            &amp;#x2F;* ...has no powerup or powerup expires in less than 10 &amp;quot;ticks&amp;quot; *&amp;#x2F; powerTicks &amp;lt; 10 &amp;amp;&amp;amp;
            &amp;#x2F;* ...is headed toward enemy *&amp;#x2F; player.vx == dir &amp;amp;&amp;amp;
            &amp;#x2F;* ...is too close to enemy *&amp;#x2F; abs(player.x - enemy.x) &amp;lt; 25 &amp;amp;&amp;amp;
            &amp;#x2F;* and if enemy&amp;#x27;s state is not &amp;quot;eyes flying back&amp;quot; *&amp;#x2F; enemy.eyeVx == 0
        ) {
            &amp;#x2F;&amp;#x2F; &amp;quot;ArrowUp&amp;quot; or any arrow key reverses the direction of pac-man
            document.dispatchEvent(new KeyboardEvent(&amp;#x27;keydown&amp;#x27;, {code: &amp;#x27;ArrowUp&amp;#x27;}));
            document.dispatchEvent(new KeyboardEvent(&amp;#x27;keyup&amp;#x27;, {code: &amp;#x27;ArrowUp&amp;#x27;}));
        }
    }
    setInterval(bot, 100);
&lt;/code&gt;&lt;/pre&gt;
The strategy is ultra simple. Every 100 ms it evaluates the situation and chooses to move away from the enemy (ghost) if it&amp;#x27;s too close to it, and has no powerup (or if the powerup is expiring very soon).&lt;p&gt;The corner cases where pac-man dies is the game difficulty progressively increases (the ghost becomes faster) until you eat it, so sometimes some pellets are left in the middle and pac-man doesn&amp;#x27;t have enough time to eat them until the ghost reaches it. The ghost will progressively get faster and faster and death is guaranteed. You could improve the code by tempting the ghost to get close to one edge, then cross over to the other edge and quickly eat the middle pellets.&lt;p&gt;Also, as soon as new pellets are added, one should prioritize eating the middle pellets.&lt;p&gt;Also, one could add code to detect the powerup pellets, and chose to NOT move away from the ghost if it calculates it can eat the powerup pellet before the ghost reaches pac-man.</text></item></parent_chain><comment><author>AnotherGoodName</author><text>I simply changed the distance to be dynamic based on closeness to the edge and it&amp;#x27;s getting into the many 100&amp;#x27;s of thousands. This simple change also seemed to fix the edge case of the respawn hitting the player is solved since the player never gets into that magic position (the enemy has to be in a very specific position for the eyes to reach the end just as the player does).&lt;p&gt;&lt;pre&gt;&lt;code&gt;    function bot() {
        &amp;#x2F;* direction of the enemy: to our right (1) or to our left (-1) *&amp;#x2F;
        dir = (enemy.x &amp;gt; player.x) ? 1 : -1;
        nearWall = enemy.x &amp;lt; 10 || enemy.x &amp;gt; 90
        &amp;#x2F;* if pac-man... *&amp;#x2F;
        if (
            (
            &amp;#x2F;* ...has no powerup or powerup expires in less than 10 &amp;quot;ticks&amp;quot; *&amp;#x2F; 
            powerTicks &amp;lt; 10 &amp;amp;&amp;amp;
            &amp;#x2F;* ...is headed toward enemy *&amp;#x2F; player.vx == dir &amp;amp;&amp;amp;
            &amp;#x2F;* ...is too close to enemy *&amp;#x2F; abs(player.x - enemy.x) 
            &amp;#x2F;* ...the distance before running away can be lower if we&amp;#x27;re near an edge *&amp;#x2F;
                &amp;lt; (dir == 1 ? player.x &amp;#x2F; 7 : ((100 - player.x) &amp;#x2F; 7))+7 &amp;amp;&amp;amp;
            &amp;#x2F;* and if enemy&amp;#x27;s state is not &amp;quot;eyes flying back&amp;quot; *&amp;#x2F; 
            enemy.eyeVx == 0)
        ) {
            &amp;#x2F;&amp;#x2F; &amp;quot;ArrowUp&amp;quot; or any arrow key reverses the direction of pac-man
            document.dispatchEvent(new KeyboardEvent(&amp;#x27;keydown&amp;#x27;, {code: &amp;#x27;ArrowUp&amp;#x27;}));
            document.dispatchEvent(new KeyboardEvent(&amp;#x27;keyup&amp;#x27;, {code: &amp;#x27;ArrowUp&amp;#x27;}));
        }
    }
    setInterval(bot, 10);&lt;/code&gt;&lt;/pre&gt;</text></comment>
<story><title>1D Pac-Man</title><url>https://abagames.github.io/crisp-game-lib-11-games/?pakupaku</url></story><parent_chain><item><author>mrb</author><text>Here, I found it fun to write a small bot to play automatically. Just paste this JS code in the dev console. It reached 9000 points on my first attempt to let it run. Feel free to tweak the code to make pac-man survive longer :-)&lt;p&gt;&lt;pre&gt;&lt;code&gt;    function bot() {
        &amp;#x2F;* direction of the enemy: to our right (1) or to our left (-1) *&amp;#x2F;
        dir = (enemy.x &amp;gt; player.x) ? 1 : -1;
        &amp;#x2F;* if pac-man... *&amp;#x2F;
        if (
            &amp;#x2F;* ...has no powerup or powerup expires in less than 10 &amp;quot;ticks&amp;quot; *&amp;#x2F; powerTicks &amp;lt; 10 &amp;amp;&amp;amp;
            &amp;#x2F;* ...is headed toward enemy *&amp;#x2F; player.vx == dir &amp;amp;&amp;amp;
            &amp;#x2F;* ...is too close to enemy *&amp;#x2F; abs(player.x - enemy.x) &amp;lt; 25 &amp;amp;&amp;amp;
            &amp;#x2F;* and if enemy&amp;#x27;s state is not &amp;quot;eyes flying back&amp;quot; *&amp;#x2F; enemy.eyeVx == 0
        ) {
            &amp;#x2F;&amp;#x2F; &amp;quot;ArrowUp&amp;quot; or any arrow key reverses the direction of pac-man
            document.dispatchEvent(new KeyboardEvent(&amp;#x27;keydown&amp;#x27;, {code: &amp;#x27;ArrowUp&amp;#x27;}));
            document.dispatchEvent(new KeyboardEvent(&amp;#x27;keyup&amp;#x27;, {code: &amp;#x27;ArrowUp&amp;#x27;}));
        }
    }
    setInterval(bot, 100);
&lt;/code&gt;&lt;/pre&gt;
The strategy is ultra simple. Every 100 ms it evaluates the situation and chooses to move away from the enemy (ghost) if it&amp;#x27;s too close to it, and has no powerup (or if the powerup is expiring very soon).&lt;p&gt;The corner cases where pac-man dies is the game difficulty progressively increases (the ghost becomes faster) until you eat it, so sometimes some pellets are left in the middle and pac-man doesn&amp;#x27;t have enough time to eat them until the ghost reaches it. The ghost will progressively get faster and faster and death is guaranteed. You could improve the code by tempting the ghost to get close to one edge, then cross over to the other edge and quickly eat the middle pellets.&lt;p&gt;Also, as soon as new pellets are added, one should prioritize eating the middle pellets.&lt;p&gt;Also, one could add code to detect the powerup pellets, and chose to NOT move away from the ghost if it calculates it can eat the powerup pellet before the ghost reaches pac-man.</text></item></parent_chain><comment><author>trevithick</author><text>This is really cool. My bot score stayed low because there was a single dot remaining near the middle which Pac-Man couldn&amp;#x27;t reach. They went back and forth for a long time until the ghost became fast enough to get him. Still fun to watch.</text></comment>