Share your repls and programming experiences

← Back to all posts
I made a 🐍Snake AI 💻
DynamicSquid (4398)

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!

Commentshotnewtop
firefish (794)

Also are the logos good?

(slice, dusk, and night)

DynamicSquid (4398)

@firefish Slice of pizza. I like the Dusk logo.

firefish (794)

@DynamicSquid slice, thinking like slice of orange (or any citrus fruit for that matter) but okay

firefish (794)

@firefish Why have four eight people upvoted lol, if you upvoted but areb't related to the night project, reveal yourself

firefish (794)

@anonymous360c You have? Oh, why did you undo it then

firefish (794)

@anonymous360c You said

I have now.

But I can't find where it was in reply to... -_-

anonymous360c (16)

Ah yes that. I did and I still have. I think these logos are AWESOME @firefish

firefish (794)

@anonymous360c you know I didn't make the night one, lord SQUOD did

firefish (794)

@DynamicSquid Would this be good for SoN?

SoN literally stands for Slice of Night

DynamicSquid (4398)

@firefish Why is my language eating pizza?

firefish (794)

@DynamicSquid It is the Slice Of Night, A.K.A. SoN

DynamicSquid (4398)

@firefish

"Hi, could I take your order now?"

"Sure, what are your specials today?"

"We're offering a slice of Night"

"Yeah I'll take that"

firefish (794)

@DynamicSquid

"Eat in or takeaway?"

"Eat in please."

"Sorry, it's lockdown, we can only offer takeaways"

DynamicSquid (4398)

@firefish

"Then why did you ask me if I wanted eat in"

firefish (794)

@DynamicSquid
"Because our restaurant aims to have as many one star reviews as possible."

"Why?"

"Confidential Policy."

"Buy why?"

"Policy."

"I'll hire a policy designer for you."

"We already have. He was the chef's pet rat."

"I'm out of here."

DynamicSquid (4398)

@firefish wait how is this is most upvoted comment lol

firefish (794)

@DynamicSquid I asked the same question lol

firefish (794)

@AlianaYee dat le one i didn't make

DynamicSquid (4398)

@firefish Ah! There's a guy spamming repl.it with 10 posts per second!!

[deleted]

@firefish - Slice the 8, because its 12 now(including me lol)

[deleted]

@DynamicSquid - 10 posts per second!!! He must be one of those dynamic tentacly creatures...only they have ten-tacles that can post ten comments every second...

[deleted]

@firefish

"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..."

lol @RayhanaDev

firefish (794)

@Lethdev2019 lol then how are you sending messages, I just got home

firefish (794)

@KelpHead

Slice the 8, because its 12 now(including me lol)

nice grammar lol

Lethdev2019 (200)

they can't block it even if they tried. @firefish

DynamicSquid (4398)

@firefish I send messages all the time at school. I also get my phone taien away from me all the time at school

firefish (794)

@DynamicSquid Have you seen this @poopyarmy nut? He's spamming the repltalk rules and gave me 68 flipping pings

LTI2 (113)

@firefish
"But Why?"
"We work for the FBI"
"But Why?"
"Welp, time to lock you in the brainwashing chamber."

firefish (794)

@LTI2
manager walks in with a rat on his shoulder
"Eh, what's this?"
"This is our manager. He takes care of the chef's rat."
customer punches rat
"You WHAT?"
customer runs away

GeneralBaker (44)

"Wait where did the chef's rat go?"
"I don't know, but something is moving in your Slice of Night pizza box."
@firefish

firefish (794)

@GeneralBaker
"Mine? I only just came in. I think the pizza box belongs to the nut who just ran out of here."

GeneralBaker (44)

"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
"Good flavor."
Chef runs in
"WHERE IS MY RAT?!"
@firefish

firefish (794)

@GeneralBaker
"Uh... maybe there?" pointing towards the mystery meat

"YOU'RE FIRED! AND SO ARE YOU! FOR FEEDING THIS MAN MY RAT!"

"Wait... this is rat?" pukes

GeneralBaker (44)

"No really, the rat is OK! I didn't cook it!"
customer pukes again
@firefish

firefish (794)

@GeneralBaker
customer can't hear because he is still vomiting his dinner from yesterday out

GeneralBaker (44)

"Make sure you at least give us a 1 star review on the way out." - chef
"ARE YOU KIDDING?! I AM GIVING YOU A FREAKING 5 STAR REVIEW FOR THIS! NOW NO ONE WILL EVER COME HERE AGAIN!!!"
"Please no! You will ruin me!"
@firefish

firefish (794)

@GeneralBaker
food hygiene inspector enters
"So, what's this?"

"My customer ate my pet rat."

"Good grief! Close your restaurant. How on earth did you manage to get business?!?!"

GeneralBaker (44)

"It's ok. This customer already destroyed my 1 star review record." @firefish

AJDevelopment (83)

@GeneralBaker walks in "Where's the Slices of Night?"
Manager: "Leave, this place is closed"
Me: "Aw, now I don't get a slice of night. Well, I guess I'm going to Subway."
plays 4"33'

firefish (794)

@SwaroopBappanad I knew this was going to pop up.

DynamicSquid (4398)

@firefish guys stop cloggin up my notifications

firefish (794)

@DynamicSquid Just pretend it was the poopypants guy off spamming again

firefish (794)

@DynamicSquid help @realTronsi dared me to code in a script font

realTronsi (782)

@firefish why are you exposing me everywhere :(

firefish (794)

@DynamicSquid HOW MANY CYCLES DID I GET FROM THIS COMMENT AGAIN? 69 that's right i think

DynamicSquid (4398)

@firefish lol. oh I'm working on the interpreter for v4 now and I've encountered a bump. not yet sure if the bump is small, or if the bump is an entire fricking mountain. i'll let you know soon

firefish (794)

@DynamicSquid oki, I'll carry on rEmAkInG NiGhT In rUsT grilling apricots on the barbecue

firefish (794)

@DynamicSquid NIGHT'S DYNAMICALLY TYPED NOW HELP ME PLOZ GOSH NO OW HELP THE VM DIED OF DEAD @fuzzyastrocat

firefish (794)

@DynamicSquid I saw it, use cargo please, the include! macro is ew

firefish (794)

@DynamicSquid Due to this change, Night will have to be unaffiliated from SoN

DynamicSquid (4398)

@firefish I tried using cargo but it's too complicated. Also I don't have time cause it's for a school project and it's due tomorrow and I have so many buggies to fix

firefish (794)

@DynamicSquid

cargo new mirror

you're done

DynamicSquid (4398)

@firefish what does that command do?

firefish (794)

@DynamicSquid creates a new directory called mirror
creates a directory called src inside it
you put your files there
instead of include! you import modules
done

DynamicSquid (4398)

@firefish okay so I've been deeply thinking about it and I think it works

firefish (794)

@fuzzyastrocat SoN is no longer the Slice Of Night, it just SliceVM now

fuzzyastrocat (1297)

@firefish Well, that's fine... plenty of langs have a purpose-built vm, like Python

firefish (794)

@DynamicSquid oki! just SoN is now SliceVM, and night is nolonger c-style, so yeah a lot to think about

firefish (794)

@fuzzyastrocat just removing a lot of night references is reeeeeeeeeee

fuzzyastrocat (1297)

@DynamicSquid Dang I wish my school projects could be that cool...

DynamicSquid (4398)

@fuzzyastrocat Oh, about lang dev, if I want my lang to be good, it has to be different. Right now, it's very similar to Python. Aside from catching some errors at compile time, what are some interesting things that I could add to Night?

firefish (794)

@DynamicSquid Dang I wish my school projects could be that cool...

@fuzzyastrocat Yeah, and not to draw out pictures of castles... (our history teacher was generous last year, not so much now)

DynamicSquid (4398)

@fuzzyastrocat No my teacher isn't asking us to build a language lol. My teacher gave out a final assignment and said show me your skills

firefish (794)

@DynamicSquid Expressions: anonymus functions.
e.g.

set f = (a,b,c> a+b+c);

is equivalent to

def f(a, b, c) {
    return a + b + c;
}
DynamicSquid (4398)

@firefish Social (or History) is the most boring class ngl

fuzzyastrocat (1297)

@firefish Lol, history class ≠ art class

@DynamicSquid That's my point... I've never been asked "Show me your skills in relation to this class's subject matter". It's always "here's the project, do this."

firefish (794)

@fuzzyastrocat thou hast been pungethed to the new repl

DynamicSquid (4398)

@firefish lambdas? I'm definitly going to add those in, but Python already has those

DynamicSquid (4398)

@fuzzyastrocat What language do you do at school? Make a interpreter/compiler for that language and do the assignment in your interpreter/compiler :)

fuzzyastrocat (1297)

@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 my_var.some_function, the some_function I'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 (1297)

@DynamicSquid I don't do a language at school. Not even offered.

DynamicSquid (4398)

@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
fuzzyastrocat (1297)

@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 str() and 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 int and str functions, but the function itself is used as the type it casts to.)
  • Great!

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!"
DynamicSquid (4398)

@fuzzyastrocat Wait, you don't have computer science at your school :(

Oh that does seem interesting. I probably will add types as functions

fuzzyastrocat (1297)

@DynamicSquid Can you come on the fuzpy repl for a sec (not to discuss fuzpy, but just to discuss this)

firefish (794)

@fuzzyastrocat so fuzpy WAS a collaboration... hehe

fuzzyastrocat (1297)

@firefish No, I had invited Squid to show them how a bytecode interpreter works.

fuzzyastrocat (1297)

@firefish You can ask squod if you don't believe me

DynamicSquid (4398)

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?

firefish (794)

So got any ideas?

@DynamicSquid Not at 3am I sure don't

firefish (794)

@DynamicSquid You sent me that message at 3am my time, it's 6pm now not a problem

firefish (794)

@DynamicSquid and go back to primary school

firefish (794)

@DynamicSquid I'm seven hours ahead of you

DynamicSquid (4398)

@firefish Trust me, I'm an expert when doing mhdjgb

LTI2 (113)

@AJDevelopment
Manager: BTW, we didn't lock you in the brainwashing chamber yet. Snek!
Me: Vomits

firefish (794)

@LTI2
customer still vomiting, has been for about a minute
ambulance comes
customer get's taken to hospital

LTI2 (113)

@firefish
Customer vomits for another hour
Manager: Be sure to give a one-star review!

firefish (794)

@LTI2 Headlines:

Customer gets food poisoning at worst-rated restaurant

DynamicSquid (4398)

@firefish but somehow the among us repl took 1st place for highest upvoted posts within the last 3 years

fuzzyastrocat (1297)

@DynamicSquid Wow, I've enjoyed this thoughtful discussion!

firefish (794)

@fuzzyastrocat snek? Boom, new esolang idea.

DynamicSquid (4398)

@firefish ooh, so that's how esolangs are made lol

fuzzyastrocat (1297)

@DynamicSquid @firefish Lol, I have zero idea what you mean by snek being an esolang idea but ok. I always make esolangs based around an idea rather than just a thing, but maybe I'm not understanding correctly.

firefish (794)

@fuzzyastrocat Remember the salmonApple? You literally said (to the best of my memory)

fuzzyastrocat: s.a could mean string called a, salmon and apples, or sick to an appointment
firefish: what language uses salmon and apples as a main construct
fuzzyastrocat: boom, new language idea.

firefish (794)

@fuzzyastrocat i'm starting to get confused with the SoN VM again

firefish (794)

@fuzzyastrocat anyway, I think I have an idea for a Christmas-themed EsoLang

fuzzyastrocat (1297)

@firefish That was a joke, I didn't actually intend for you to make a language based on that. :D

fuzzyastrocat (1297)

@DynamicSquid Lol I love how this comment has gotten 5 upvotes

DynamicSquid (4398)

@fuzzyastrocat lol yeah. and @firefish's comment about Night got 11 for some reason lol

fuzzyastrocat (1297)

@DynamicSquid People just upvote random things lol

firefish (794)

@DynamicSquid lol the most upvoted post of mine got 11 upvotes

firefish (794)

@DynamicSquid lol it's true, 90% of my cycles come from comments

[deleted]

@firefish - SoN equals Son of Neptune a.k.a me :P

firefish (794)

@fuzzyastrocat thanks for stopping by but I was in the middle of something

firefish (794)

@DynamicSquid I think most people upvoted that comment for the chef's rat sketch

fuzzyastrocat (1297)

@firefish Are you by any chance a Monty Python fan?

firefish (794)

@fuzzyastrocat not exactly, but does sound like the sort of thing Monty Python would make...

fuzzyastrocat (1297)

@firefish Yeah. (I asked because when you said "the chef's rat sketch" I thought of something funny, but it would only make sense in the context of Monty Python)

firefish (794)

@fuzzyastrocat yay lord fuzzy has 1000 cycles!

firefish (794)

@fuzzyastrocat i'll unupvote ten things of yours to make you down to 999 actually no having having second thoughts on that
also sneklang is turning out good

RayhanADev (1002)

Amazing, now sneks that look like Mr. Schwarzenegger are going to take over the world. Joy! 🐍

RayhanADev (1002)

@DynamicSquid lol. I love how you used Java instead of JS xD.

DynamicSquid (4398)

@RayhanADev Well, I actually prefer JS but I made this for a school project and Processing was most convenient

[deleted]

@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...

Whippingdot (65)

Are you guys classmates or someting? @RayhanADev @DynamicSquid @firefish

firefish (794)

@Whippingdot What the hell? Squod lives in Canada, Rayhan (I think in the US) and I live in the UK, lol wut, I don't even use repl.it for school

firefish (794)

@RayhanADev My point is we live in different countries, we can't possibly even be classmates

RayhanADev (1002)

@firefish hmmm
it’s Zoom meet time xD

RayhanADev (1002)

@firefish oh btw how is it in the UK?

firefish (794)

@RayhanADev No worries, I'll find one from every country, legend has it the @pope is here

firefish (794)

@RayhanADev Lockdown in two days, currently the news is actually absorbed by the US election, live coverage starting from 11pm our time (~6pm ET i think), and oh boy, I don't want to get too political here

RayhanADev (1002)

@firefish lmao US politics go brrrrrr
also RIP lockdown, but honestly Texas is gonna go into a big lockdown as well, I’m willing to bet cash on that xD. We’re big in everything, apparently that means corona as well ƪ(˘⌣˘)ʃ.

Whippingdot (65)

I live in India, but am from Seattle. Stayed there and was born there for 8 years. And did you know 22% of Americans believe the election will go on without cheating. 🤣🤣 @RayhanADev

DynamicSquid (4398)

@Whippingdot Watching the election, doing my Math homework, and surfing repl.it at the same time is what I'm doing right now lol

Whippingdot (65)

I am in the middle of school right now. 😃🤣🤣. Gotta go. Science. @DynamicSquid

firefish (794)

@Whippingdot Ah yes, I was born in Seattle for 8 years.

RayhanADev (1002)

@firefish so you were born for 8 years, dang that must be tuff xDxDxD jk.

Whippingdot (65)

Hey, you wrote the exact thing I was going to write. 😢😢🤣 @RayhanADev

realTronsi (782)

164 upvotes... u hacked the repl talk algorithm

AndrewWingfield (1)

I like it! I've always wanted to make/see a snake bot. The only problem is, (the first time I tried it) your bot died. Otherwise, a great game!

Jakman (458)

Your power is increasing. I feel it.

[deleted]

my highest is 37

poopingrn (2)

this is a very good code! if you could you can try to make them fruits instead of just red squares. over all tho very good!

SwaroopBappanad (48)

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?

DynamicSquid (4398)

@SwaroopBappanad Great question! I use the Processing IDE, then just transfer the code here

SwaroopBappanad (48)

@DynamicSquid What a madlad. Where exactly do you said IDE?

DynamicSquid (4398)

@SwaroopBappanad Do you mean what IDE I use? I use the official Processing IDE

SwaroopBappanad (48)

@DynamicSquid oops I meant "Where exactly do you find said IDE" but I forgot I was illiterate

SwaroopBappanad (48)

@DynamicSquid Do I download the 32-bit or 64-bit version? (I'm on Windows)

CodingMaster55 (1)

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! :)

CodingMaster55 (1)

@DynamicSquid That was just my suggestion. It's totally up to you! :)

Glare (237)

This is so cool. I'm trying to learn algorithms/AI as well. Nice job!

tankerguy1917 (84)

man this is so cool. I pressed space and then i was like, "bruh, this is so cool". Honestly this is really cool

abdullahrajput9 (247)

IDK why @DynamicSquid but EVERY time you upload a post, it reaches number 1 on trending. This shows your great work :) :) :)

RayvelArjoon (96)

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!

DynamicSquid (4398)

@RayvelArjoon oh thanks!! And yeah... they're a bunch if things i could improve, but i made this for a school proj and didnt have much time

RayvelArjoon (96)

@DynamicSquid It's good for a rushed project :)

Yuktha1456 (2)

This is fire and fun! Thank you for making this, it passes time! I showed my coding teacher this and he was amazed!

DynamicSquid (4398)

@Yuktha1456 thanks! glad you enjoyed :)

lanjan (1)

lmao i didnt realize what space did until i rage quitted because i thought the computer was messing me with me then realized it was getting the apples by itself

Code1Tech (88)

Wow, you actually made a snake AI!
It works, and it does perfectly!
I'm interested in how it works. Mind explaining?

DynamicSquid (4398)

@Code1Tech Thanks!! So basically it's a simplified version of the A* path finding algorithm. It doesn't work that well, and usually dies at around 30ish points, but at least it's something.

What it does is it assigns each cell a value:

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

The cell with the lowest fcost get's chosen.

This video offers a great explanation

Code1Tech (88)

Thanks, @DynamicSquid. I understand how it works!

Bookie0 (4607)

niceeee!

add a point systems and a leaderboard tho lo!

DynamicSquid (4398)

@Bookie0 Thanks!! Also yeah, might give it one more quick look and I'll ping you soon

Bookie0 (4607)

cool, I'll wait for ur ping! ;) @DynamicSquid

Bookie0 (4607)

aight, you mind if i share it tomorrow morning? @DynamicSquid I'll add the images in the post ;)

Bookie0 (4607)

cool thx, will do tomorrow and ping you when it's posted. Cya! @DynamicSquid

DynamicSquid (4398)

@Bookie0 👍 (I have school tmr so I might not respond for a while)

Bookie0 (4607)

@DynamicSquid 👌 (np, respond when you can/want! ;)

JacksonPhilips (66)

@DynamicSquid man school must be really long

[deleted]

Plz

[deleted]

Can u make a snack io?

[deleted]

It’s a game we’re a big fat pixel human has to get to a burger but to do that u need to help him go through obstacles and he has a little r.c robot that u can use to face some of the challenges. There would be 12 challenges in a order of easy to hard. U can add combos to fight some of the evil aliens that protect the burger on each obstacle. Can u make that kinda [email protected]

Flyingcrabs (5)

go to 11+ @pepelaugh scroll to bottom

pepelaugh (496)

@Flyingcrabs Just follow whatever your teacher is teaching you, grats man :D

Flyingcrabs (5)

well now its tooooooooooooooooo slow @pepelaugh