Skip to content
I made a 🐍Snake AI 💻
Profile icon
h
has Hacker Plan
DynamicSquid

[ currently broken :D ]

Hi!

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!

But.....

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

Enjoy!

You are viewing a single comment. View All
Profile icon
Coder100

Wow! Nice!
Care to explain the algorithm?

Profile icon
DynamicSquid

@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

Profile icon
Coder100
Profile icon
Coder100

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

Profile icon
DynamicSquid

@Coder100 lol thanks

Profile icon
DynamicSquid

@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

Profile icon
Coder100
Profile icon
ThisUserTaken

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