Giter Site home page Giter Site logo

snakebot's Introduction

snakebot

a mastodon bot that plays snake, using polls

check it out at https://botsin.space/@snake_game

  • snakebot-core contains the code for the snake game
  • snakebot-masto is the actual mastodon bot
  • snakebot-web is a web ui for testing the bot, without needing to run a mastodon instance. i made it because i didn't want to run a mastodon instance. i probably put too much effort into it but who cares

running

  • npm i --workspaces to install dependencies
  • npm run start-bot to build and run the mastodon bot
  • npm run start-web to build start the web ui

snakebot-masto requires some environment variables to be either defined, or provided in a .env file in its folder

help how does it actually work your code is incomprehensible

  1. searches for the last post by the bot user that begins with the game's, as well as the bot's replies to it
    • the header matches the pattern /^➡ (.+) - GAME (\d+) (END )?⬅️/
  2. decodes the game's state from the invisible text in the post's text
    • the text is made out of the characters U+2061, U+2062, U+2063, U+2064
    • check hiddenEncode.ts for how exactly it works
  3. checks the result of the poll to decide where to move next
    • if the poll is tied, the topmost option is picked
    • the snake's current direction is always at the top, so if no one votes, the snake keeps moving forward
  4. update's the game's state and posts the next image and poll
    • they have to be in separate posts because mastodon doesn't allow having both an image and a poll in one ..

snakebot's People

Contributors

wires5210 avatar

Stargazers

MangoCubes avatar Michael White avatar  avatar Talon Kettuso avatar Ry avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.