Skip to content

Instantly share code, notes, and snippets.

@Tremeschin
Last active June 5, 2025 01:24
Show Gist options
  • Save Tremeschin/4839a3258dea6e03f900ea382ce4b828 to your computer and use it in GitHub Desktop.
Save Tremeschin/4839a3258dea6e03f900ea382ce4b828 to your computer and use it in GitHub Desktop.
Snake game in 12 lines of Python, 348 characters
from random import randint as r
X,Y,M,W=[5],[5],(4,2),10
while 1:
G=[["."]*W for _ in range(W)]
G[M[1]][M[0]]='*'
for x,y in zip(X,Y):G[y][x]='#'
for R in G:print(''.join(R))
while not(i:=input()):pass
x,y=(i=="d")-(i=="a"),(i=="s")-(i=="w")
X.insert(0,X[0]+x);Y.insert(0,Y[0]+y)
if(X[0],Y[0])==M:M=(r(0,W-1),r(0,W-1))
else:X.pop(),Y.pop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment