I made a 🐍Snake AI 💻
DynamicSquid (5023)

[ currently broken :D ]


I made Snake. You can control it using WASD, or the arrow keys. Eat the red apples, and don't crash into the walls or yourself!


When you press space, it uh... helps you out a little :)


You are viewing a single comment. View All
Coder100 (18872)

Wow! Nice!
Care to explain the algorithm?

DynamicSquid (5023)

@Coder100 Thanks!! It's just a simplified version of the A* algorithm. What it does is it assigns each cell a value:

gcost = dist(cell, snake)
hcost = dist(cell, apple)
fcost = gcost + hcost

Cell with the lowest fcost get's chosen.

I spent an entire day tinkering with which algorithm was best, and how to optimize it, and all that stuff, and I ended up with this. It's not the best, but it's something

Coder100 (18872)

also btw might want to make the snake have a head, sometimes its hard to really define it's shape. (Did you accidentally do more work than you need to?) @DynamicSquid

DynamicSquid (5023)

@Coder100 Well, I would of made the UI way better if I had more time. I actually made this for a school assignment and I only had around 3 hours of work time

ThisUserTaken (245)

@DynamicSquid i don't think I've ever seen a school asignment with 200 upvotes, so congrats!