News for hackers. Stuff that matters.
Re:1D Pac-Man by AnotherGoodName on Tuesday January 02, 2024 @09:15PM (#38849868)
I simply changed the distance to be dynamic based on closeness to the edge and it's getting into the many 100'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).

    function bot() {
        /* direction of the enemy: to our right (1) or to our left (-1) */
        dir = (enemy.x > player.x) ? 1 : -1;
        nearWall = enemy.x < 10 || enemy.x > 90
        /* if pac-man... */
        if (
            (
            /* ...has no powerup or powerup expires in less than 10 "ticks" */ 
            powerTicks < 10 &&
            /* ...is headed toward enemy */ player.vx == dir &&
            /* ...is too close to enemy */ abs(player.x - enemy.x) 
            /* ...the distance before running away can be lower if we're near an edge */
                < (dir == 1 ? player.x / 7 : ((100 - player.x) / 7))+7 &&
            /* and if enemy's state is not "eyes flying back" */ 
            enemy.eyeVx == 0)
        ) {
            // "ArrowUp" or any arrow key reverses the direction of pac-man
            document.dispatchEvent(new KeyboardEvent('keydown', {code: 'ArrowUp'}));
            document.dispatchEvent(new KeyboardEvent('keyup', {code: 'ArrowUp'}));
        }
    }
    setInterval(bot, 10);
Re:1D Pac-Man by TuLithu on Tuesday January 02, 2024 @10:37PM (#38850411)
I don't think you thought this was fun.
Re:1D Pac-Man by eru on Tuesday January 02, 2024 @11:19PM (#38850685)
What's that supposed to mean? Playing the game for a few minutes is fun, then writing a bot gives you another bout of fun.
Re:1D Pac-Man by gantron on Wednesday January 03, 2024 @01:10AM (#38851268)
Seems fun to me.
Re:1D Pac-Man by mrb on Wednesday January 03, 2024 @04:08AM (#38852108)
Of course ! Nice.
Re:1D Pac-Man by xomopinok on Saturday January 06, 2024 @11:51AM (#38892939)
A shorter way to change the direction of the player is to use player.vx *= -1;