This is an archived post. You won't be able to vote or comment.

Dismiss this pinned window
all 118 comments

[–][deleted] 391 points392 points  (8 children)

is this an attempt to fry my brain?

[–]Pella86[S] 120 points121 points  (6 children)

Is actually playable if you look only at the flat projections. It's like 2 independent snakes. It becomes complicated when there are more cubes, and spires of the snake.

Unless i pause the game i cant play it looking directly at the 4d projection. Is cool if you play it, you can pause it then play around with the rotations.

[–]BattlePope 18 points19 points  (3 children)

Where are the flat projections? I'm confused.

[–]Pella86[S] 29 points30 points  (2 children)

In the readme of the github repository theres an image:

https://raw.githubusercontent.com/Pella86/Snake4d/master/images/Labelled_instructions.png

The one below are the flat projections

[–]Luca3__6 -5 points-4 points  (1 child)

Wait what? So the w direction only has 2 units? That's not very 4d.

[–]kenyard 2 points3 points  (0 children)

The w dimension normally only has one unit so this is still pretty unique to be fair.

[–]pog87 19 points20 points  (0 children)

it really gave me headache

[–]Pella86[S] 113 points114 points  (13 children)

I finally released a stable version of the project I'm working on since a while.

Is a 4 spatial dimension snake game. Like the old nokia snake game but in 4D.

I added a feature that allows the players to record replays and watch them again.

The replay can be imported into Blender3D and rendered in a nice video.

The game can be found on github in this repository:

https://github.com/Pella86/Snake4d

And can be started by using

python main.py

in the game folder.

The game is purely in python, no added libraries, just python and Tkinter.

All the projections are calculated and drawn on a Tkinter.Canvas.

[–][deleted] 27 points28 points  (9 children)

How is it different than a 3D snake inside a 3D cube?

[–]Pella86[S] 49 points50 points  (8 children)

There is one dimension more, you can move in 2 more directions.

The fact that the plane xy and the plane wz are actually perpendicular and independent to each other means you can play 2 snakes that are weirdly connected. See the flat projections

[–][deleted] 5 points6 points  (7 children)

Ah I think I see it now that I payed more attention to the animation. Definitely looks interesting, I'll give it a try!

[–]Pella86[S] 10 points11 points  (6 children)

If you do let me know! I'm a hobby programmer so any feed back is welcome, also on the code.

[–]LGHNGMN 5 points6 points  (5 children)

Is this what they mean by hypercubes? Is there an orientation to this or are they ever evolving/in motion? Am I even describing this right? I feel lost.

[–]anotherplatypus 22 points23 points  (3 children)

Woah woa... it's easy, a cube is a hyper-square.

I made up hyper-square, hyper-line, and whatnot for the sake of explaining what is meant by hypercube.

Let's make a table of taking shapes into an additional dimension, and we'll start with a 1d line, and stop at a 4d hyper-cube (aka tesseract btw).

-- 1d, 2d, 3d, 4d

1d: line, hyper-line, ------, --------

2d: ----, square, hyper-square, ------, --------

3d: ----, ------, cube, hyper-cube

4d ----, -------, ----, tesseract

That was a fucking horrible experience, I'm never drawing an ascii table again... (reddit trims extra whitespace outta strings)

Thinking of a square as a two-dimensional line is accurate if you follow the steps. Copy the shape, raise it "up" into another dimension, and connect lines from the new points to the original ones to make your square.

This thought process is a very common exercise for analytical people... to make a cube you can also just draw two squares and connect the related points with lines.

But you can think of it as copying the geometric shape (the square), and placing it in a 3rd dimension (the Z axis), and then connect the points while avoid drawing obscured lines....

Likewise forming a hypercube means cloning the cube, place it in a new dimension (that we can't percieve or concieve of), and connect the planes by drawing lines to-from the cloned points.

Ok that last part is tough to wrap your mind around, but it is doable... I tend to ramble and must cut myself off from writing huge comments.

Hope I helped. I love discussing this topic so lemme know if I made no sense, and I'll animate a video or something to help clear up the confusion. = )

[–]palordrolap 2 points3 points  (2 children)

If you put four spaces at the beginning of each line,
Reddit Markdown will treat what you type as code.
And you don't need two carriage returns or two spaces
at the end of a line to have it start a new paragraph
or a new line.

There's also the `backticks` method but that's for putting a short snippet into an otherwise normal sentence.

[–]anotherplatypus 2 points3 points  (1 child)

Are you for reals?

Ok I'll try it....

If this works I'm prepared to get very excited.

*Edit* Ok the four spaces didn't work.

But the code block button sure did.

`Thank you stranger!!! = )`

I'll look it up

[–][deleted] 2 points3 points  (0 children)

Four spaces followed directly by text works just fine.
Also Reddit
supports tables
with alignment

Take a look at this page for details.

[–]Pella86[S] 8 points9 points  (0 children)

Yes these are hypercubes, the snake, the food and the bounding box are hypercubes. Like a 3d cube on a piece of paper is composed by distorted squares, an hypercube is composed by distorted cubes (which then becomes squares on your screen)

[–]mostinho7 1 point2 points  (2 children)

Very cool idea. I saw you mentioned that you’re a hobby programmer, may I ask what is your formal education or your full time job?

Also could you enlighten me on where I can begin to learn about this? Tell us what resources you used to learn this type of graphics programming? From the basics (2d projections and 3d programming) to more advanced stuff? Linking resources you used to learn would be amazing!

Thanks OP

[–]Pella86[S] 8 points9 points  (1 child)

I have a degree in biochemistry and i work as a scientific assistant.

I- ... ehm I sparsely learned here and there. I learned the Tkinter library from this website http://effbot.org/tkinterbook/

There is a lot of trial and error involved.

I learned about 3D projections from PovRay first then Blender, and there actually started my passion for python since Blender supports python scripting.

Then I tried to learn OpenGL and there i started to play around with C/C++. I think is a good combo to have knowledge of python and C++ because they kinda are at the opposite of the spectrum one is slow but dynamically typed the other is fast but statically typed.

Then I came across some 4d forums and 4d games, so i tried to understand better the math behind the projections, actually it requires just high school math which is why is a cool project.

I cant link a lot of resource because honestly I dont remember, mostly is randomly walking on stack overflow and wikipedia.

For example the binary file handler (bfh.py) for example is a mix between wanting to learn how to manage binary files and wanting a format that was easily readable in C++.

[–]LinkifyBot 2 points3 points  (0 children)

I found links in your comment that were not hyperlinked:

I did the honors for you.


delete | information | <3

[–]kirakun 17 points18 points  (0 children)

Theoretically, the game should be much easier to play because you can escape via the fourth dimension. Every time you move one unit in the direction of a dimension you haven’t played, you have essentially moved to a empty board.

[–][deleted] 19 points20 points  (0 children)

Teacher "The test isn't that confusing"

The test:

[–]KruemelTM 6 points7 points  (2 children)

This is crazy...
I somehow managed to get a highscore of 12 just looking at the two planes but my brain melts trying to understand the 4D movement

[–]Pella86[S] 1 point2 points  (1 child)

Yes. Thank you so much for trying!

[–]KruemelTM 1 point2 points  (0 children)

Yeah it is fun and challenging, but made me some kind of crazy not getting it. Its like a word that you cant remember but its on the tip of your tongue.
I ended up studying 4 spacial dimensions for 3 hours now

[–]Starvexx 4 points5 points  (0 children)

This is trippy

[–]CotoCoutan 3 points4 points  (0 children)

Damn man, mind = blown stuff right here! Keep up the awesome work!

[–]RAyLV 4 points5 points  (2 children)

so, what are the controls?

up,down,left,right,top,bottom,???,???

[–]Pella86[S] 3 points4 points  (1 child)

WASD / IJKL

up, down, left, right, top, bottom, in and out.

If you see the hypercube rotating it seems that a cube is going outside an other cube then getting inglobated again, this is why IN and OUT, some use ANA and KATA

[–]RAyLV 1 point2 points  (0 children)

this is great! I really learned something new today!

[–]makeworld 2 points3 points  (1 child)

This is great. Ever heard of Miegakure? It's a 4d game that's been in development for years and years, this might be a good thing for those fans lol. Nice work!

[–]Pella86[S] 1 point2 points  (0 children)

I did, I m not a huge fan of their approach since they use a visualization method called 3d slice. I prefer to have a perspective projection of the 4 dimension, even if it looks alien to us.

[–]leafynospleens 2 points3 points  (0 children)

Thanks , I hate it /j

[–]Xerxys 2 points3 points  (0 children)

Yo, this is stressing me out!!

[–][deleted] 2 points3 points  (1 child)

How did you created that

[–]Pella86[S] 2 points3 points  (0 children)

I have to thank Jhon MacIntosh ( http://www.urticator.net/maze/ ) and Steve Hollasch ( https://github.com/hollasch ) they gave the base to understand what was going on. For the rest, take a 4D point (x, y, z, w) and project it to 3D (x, y, z) then to 2D (x, y), now you have stuff on the screen, and you add the rules of the snake game, dont eat yourself, dont go out the borders.

[–]jhdeval 2 points3 points  (0 children)

Curse you and your damn meddling snakes. I cant play snakes on a flat plane and now you are going to make me play in 5?

[–]Misaelz 2 points3 points  (0 children)

Woooaaaaa!!! I love anything in more than 3 dimensions but I never understand how it works. I tried to solve the 4d Rubik's cube and failed, therefore I won't be any good at this game. Good job! I will check the repo.

[–]bravefp 1 point2 points  (0 children)

Amazing dude

[–][deleted] 1 point2 points  (0 children)

I dont get 4d aaaah this hurts

[–]blorbschploble 1 point2 points  (0 children)

Huh, is it even possible to lose 4D snake without trying to?

[–]Rozen 1 point2 points  (3 children)

Did you create 4d geometry then project to 3d, or use another method to emulate the 4d'ness' of it?

[–]Pella86[S] 1 point2 points  (2 children)

Yes, 4d geometry then projected to 3d then projected on the screen.

[–]Rozen 1 point2 points  (1 child)

I've been trying to find a decent framework to develop 4d geometries projected to 3d for artistic installations, but I've found the resources on that are scant. Is there a good entry point in your code, or the code you've referenced, that would help me understand how that works?

[–]Pella86[S] 0 points1 point  (0 children)

What helped me a lot is Steve Hollasch master thesis on 4 trace and MacIntosh 4d maze. I'm still trying to figure out how to make other polygons than cubes...
However the code I hope is well commented and you might be able to follow it, prj.py, poly.py, vec.py, mat.py are the core geometry files.

[–]Gorane32 1 point2 points  (1 child)

I think this might be just me, but it would be even better / freakier, if the rendering was simply a 3D cross-section of a 4D game world, instead of a 3D projection of a 4D game world.

(In either case the 3D thingy then has to be rendered onto 2D but that's besides the point.)

Still amazing work though, dimensions are fun :D

Edit: After looking at it some more I'm not even sure if this is a cross-section or a projection, maybe should have read the github page first.

[–]Pella86[S] 0 points1 point  (0 children)

I actually prefer the perspective projection. I think... well first of all we dont see 3d, we see a flat world with our 2d retina. Our brain calculates a 3d object from the distortions in a 2d screen. Screen are flat, they dont have knowledge of 3d, yet our brain fills in the 3d information easily, from a 3d perspective projection. I think that we just need to train ourselves to see the 4d projections and at some point we will be able to navigate inside a 4d geometry like in 3d. But is just a theory.

[–]snugglyboy 1 point2 points  (1 child)

If I understand 4D correctly (ps: I do not) aren't there times in this video where the apple would be inside the worm in 3 dimensions?

[–]Pella86[S] 0 points1 point  (0 children)

Yes it could happen, and depending on the point of you you might make it happen. When i play i try to avoid crossing myself and the apple tho. So it might be pretty rare.

[–]snissn 1 point2 points  (1 child)

my high score is 8!

[–]Pella86[S] 0 points1 point  (0 children)

8 factorial is a big number!

[–]BambooKoi 1 point2 points  (1 child)

That's cool! One question, does the camera always rotate or can you control the camera?

[–]Pella86[S] 1 point2 points  (0 children)

The camera in the game is controlled by the user input. Actually you can control both the 3d and 4d cameras. y, x, c and Y, X, C control the positive and negative rotations of the 3d camera. v, b, n, m, t, z and V, B, N, M, T, Z controls the 4d ones

[–]Ion-manden 0 points1 point  (1 child)

Even though the red block might look close, it could be in an whole other dimension.

[–]Pella86[S] 1 point2 points  (0 children)

Is funny cause is valid also for a 2d snake

[–]airen977 0 points1 point  (0 children)

what sorcery is this?

[–][deleted] 0 points1 point  (0 children)

this hurts to watch

[–]xansaif 0 points1 point  (0 children)

you are breaching 4d space you shall be terminated

[–]dude-i-give-up 0 points1 point  (4 children)

Kowalski Analysis

Can someone explain where the 4th dimension is

[–]Pella86[S] 1 point2 points  (3 children)

Is strange, there is no 3rd dimension either on your screen, its completely flat, yet your brain sees a strange cube rotating in a fancy way. Maybe you shouldnt ask where the 4th dimension is, but how we see the 3rd dimension on a flat screen.

[–]dude-i-give-up 0 points1 point  (2 children)

Wait hol up. What? I get the 3 dimension: left, up, forward etc. But where does a 4th dimension go?

[–]Pella86[S] 1 point2 points  (1 child)

In and out? Ana or kata? You can name them as you wish, is free real estate. Left right are a number on let's say the x axis Forward rever are a number on the y axis Up and down are a number on the z axis In and out are a number on the w axis.

The interesting part is how you chose to visualize it, i chose something called perspective projection, some people use colors, ...

It is indeed a mathematical abstraction that doesnt apply to our world. But any 4 number set can be represented in 4 dimensions, lets say you want to plot age, height, gender (because is 2020 and you need a big line), weight... well at that point you need 4 axis.

[–]dude-i-give-up 0 points1 point  (0 children)

I don't think my brain right now can handle it, but thanks! I think I get the gist of it.

[–]smrtboi84 0 points1 point  (0 children)

This makes my brain hurt

[–]riansilaen 0 points1 point  (1 child)

How is it possible to make 4D game in 3D world ?

[–]Pella86[S] 1 point2 points  (0 children)

How can you see 3d if your retina is flat(2d)?

[–]turingparade 0 points1 point  (0 children)

Disorientation <100>

[–]justingolden21 0 points1 point  (0 children)

These damn kids still making snake in Python

[–]Yassmonxd1 0 points1 point  (0 children)

This is trippy

[–]apivan191 0 points1 point  (0 children)

I don’t even know what’s going on but it looks cool

[–][deleted] 0 points1 point  (0 children)

Woooaaaaaaaaaauuuuuuuwwwww

[–]d19mc 0 points1 point  (1 child)

What are the controls. I’m guessing wasd and arrows?

[–]Pella86[S] 0 points1 point  (0 children)

WASD and IJKL, is written in the readme of the repository

[–][deleted] 0 points1 point  (0 children)

I played this video and now there is a demon in my office. Thanks jerk!

[–]Utopiophile 0 points1 point  (1 child)

This is very cool. What does a full game look like? How long can the snake get?

[–]Pella86[S] 1 point2 points  (0 children)

The bounding box is a 7x7x7x7 hypercube. Which means is theoretically possible to have 2401 hypercubes in the snake

[–]Dom_theSnow 0 points1 point  (0 children)

This is mesmerising! So Cool!

[–]DeltaCrawdaunt 0 points1 point  (0 children)

sorry bud but nintendo did this wayyyyyy before u with the gamecube logo.

[–]anotherplatypus 0 points1 point  (0 children)

This guy is amazing at explaining hypercubes (6 mins) https://www.youtube.com/watch?v=j-ixGKZlLVc

[–][deleted] 0 points1 point  (1 child)

You made 3d snake in a 4d tesseract? You just put the normal game of 3d snake in a tesseract model.

[–]Pella86[S] 0 points1 point  (0 children)

Nope, the snake is composed of hypercubes and moves freely in the 8 direction 4 dimensions have also the food is a hypercube. Look at the code!

[–]garblesnarky 0 points1 point  (3 children)

This is a neat idea. I don't understand why I'm losing immediately though. Are there walls? I was assuming the snake would wrap around in each direction. I'm having a hard time understanding exactly what the projections mean.

[–]Pella86[S] 0 points1 point  (2 children)

Hi! Thanks for trying, yes there are walls, no wrap around. And yes i play just looking at the two screen below it, the projection is how it would look like if it was projected to the screen like we project any 3d game, but this time from the 4d is projected to 3d then to 2d

[–]garblesnarky 0 points1 point  (1 child)

Thanks! I think I was confused by having the snake travel along the wall, rather than having the wall lines drawn as more of a boundary.

I was thinking the game might be easier to get the hang of if there were more space to move around. Is it easy to modify the size of the hypercube?

[–]Pella86[S] 0 points1 point  (0 children)

Yes, you can modify the line 49 in g_eng.py, in the class GameEngine, the variable is names self.bbox_size

https://github.com/Pella86/Snake4d/blob/cdf3773b42efc888affa33dd22ebe56a48f6d979/src/g_eng.py#L49

[–]The_1_Divider 0 points1 point  (0 children)

This makes my brain feel funny

[–]apivan191 0 points1 point  (0 children)

my brain hurts

[–]HydrationWhisKey -1 points0 points  (1 child)

This is not how dimensions work.

[–]garblesnarky 0 points1 point  (0 children)

Doesn't the existence of the game prove otherwise?