I made a 🐍Snake AI 💻
[ 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 :)
"Wait! Please make sure you give us a one-star review! Also, don't go out, its not safe"
"Why do you care?"
"We also have a policy that we should protect annoyed customers"
"Lemme guess, your 'policy designer', the rat, created this policy?"
"No sir, this was created by our Customer Care team of specialists"
"What? Humans made such a dumb policy?"
"I never said they were humans...a parakeet, a chimpanzee, a kangaroo, and a snek make a fine team, don't they?"
"I do not even want to imagine what a snek is..."
"But you obviously came for our famous Slice of Night, so we had it prepared in advance. We also make assumptions about our customers, so we prepared this 'mystery meat' just for you."
"You happen to be correct, I love mystery meat."
Customer takes a bite
Chef runs in
"WHERE IS MY RAT?!"
@DynamicSquid You could add:
- Some kind of interesting memory management paradigm. Perhaps ownership-style?
- A type system like Haskell's, where you can pass types to functions as if they were normal values. Basically, making types "first-class citizens".
- Multiple dispatch. This one is neat, I'd highly suggest it. Basically, in most OO langs you have single dispatch — when I call
some_functionI'm calling depends on the type of
my_var. Well, what if the function depended on the types of all arguments? So, instead of doing:
def my_function(x, y, z): if type(x) is int and type(y) is str and type(z) is int: # stuff 1 elif type(x) is str and type(y) is int and type(z) is str: # stuff 2 # etc etc
You do something like:
def my_function (x: int, y: str, z: int): # stuff 1 def my_function (x: str, y: int, z: str): # stuff 1 # etc etc
And obviously, you don't have to give a type — doing
def x(y): would apply to
y of any type.
More info on multiple dispatch can be found here.
@fuzzyastrocat What so what do you do in Computer Science class then?
- Oh no. I've already have enough nightmares about memory ownership in Rust lol
- That seems interesting, but I feel like it might seem off in a dynamically typed lang
- Ooh... that seems really interesting... definitely going to look more into that
@DynamicSquid There is no computer science class.
- Eh, I don't mean strictly rustian. You could probably make it your own, I'm just saying it'd be neat to have a unique memory management scheme.
- Well, I'm not sure. I mean, the functions
int()exist in Python, so why can't the types themselves exist as entities? (Or, maybe each type is a function, and when called that function casts the argument to its type. So basically like Python's
strfunctions, but the function itself is used as the type it casts to.)
A lang with both the second and third ideas could be cool:
int # => the "int" type, which is actually a function int("32") # => calling the int function, which casts "32" to an int class MyType: # a demo type pass int(MyType()) # oh no, there is no dispatch for type `MyType` in the int function! def int(x: MyType): # adding a dispatch option print("Hooray!") int(MyType()) # => "Hooray!"
Hey, @firefish, care to help me on something?
So I checked the GitHub Linguist guide, and in order for them to add syntax highlighting to a user made language, it must be in at least 200 repositories.
For example, this person tried to add their own language, but fell short of the 200 person requirement.
Right now, a total of
NullPointerException repositories on GitHub are written in Night.
Which means we're actually really close. If my math is correct then we only need
200 - 0 = 20 repositories and then we can add a language on GitHub!
Now I'm not saying that I want to get 200 people using Night right now. It'll probably take decades, or perhaps never, I'm perfectly fine with that, but I'd be interesting to try...
So got any ideas?
Amazing, now sneks that look like Mr. Schwarzenegger are going to take over the world. Joy! 🐍
@RayhanADev - Nope, snakes won't conquer as long as they keep bumping into their fat tails and dying lol...that happened to me...my snake got to 22 and died because it bumped into its tail...RIP...
@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
One question. When you make an error in a Java Processing repl, it just says "Script Error" but doesn't say where it is. With a project as big as your's, how are you still alive?
I like the over-all outcome! But I thought the SPACE would reduce the SIZE of the snake. Lol. It actually PLAYS it for you. :) I don't like it that much. Reducing the size by 1 square would be nice. Thank you! :)
It's a little buggy (you can move back and kill yourself instantly; thus, restarting the game). The frames could probably be increased a little, and maybe the refresh rate of drawing on the canvas as well. The AI is also a little buggy when trying to get to the apples, but it's actually pretty good!