It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
Not really. I took an existing thing that can barely be considered a game, and wrote my own version of it.

I trust you know of 2048, a worse but much more popular clone of a game called Threes.

Yeah, I wrote one of those. In Python, using curses for the interface. Or you can import it as a library and build a nicer interface in anything else, which was the original idea, and the curses thing was to be a test, but then I was happy it actually worked and came here.

It's probably one of the worst things you've ever seen. You have been warned.

You don't want to see it, but if you like being offended by crappy code, or for some insane reason wouldn't mind giving me suggestions, here's the repo:
https://gitlab.com/Maighstir/py2048

Since it uses curses, I don't think it runs as-is by default on Windows (it doesn't have curses, can probably install it, or run WSL or a *NIX VM), most other systems should be fine.
Run the file through Python 3. Arrow keys are the game controls, and q quits. Ctrl-c may fuck up your console, just close that one and start another in that case.

Have a good day.
Attachments:
low rated
Well done. Now I'm tempted to write a clone in C. Without curses.
avatar
clarry: Well done. Now I'm tempted to write a clone in C. Without curses.
At first I didn't want to, but all information I found said that Python requires curses in order to listen to keypresses (as opposed to wait for a return key to end the input and store the result in a string), so I researched how to use it.
Post edited July 01, 2019 by Maighstir
low rated
avatar
Maighstir: C doesn't need curses. All information I found said that Python requires curses in order to listen to keypresses (as opposed to wait for a return key to end the input and store the result in a string), so that's what I used.
I'd imagine one can do in Python exactly the same thing one would do in C.

https://docs.python.org/2/library/termios.html
avatar
Maighstir: C doesn't need curses. All information I found said that Python requires curses in order to listen to keypresses (as opposed to wait for a return key to end the input and store the result in a string), so that's what I used.
avatar
clarry: I'd imagine one can do in Python exactly the same thing one would do in C.

https://docs.python.org/2/library/termios.html
See, I told you it was shitty.
low rated
avatar
Maighstir: See, I told you it was shitty.
It's not shitty. I just have a personal vendetta against curses and the silly database of terminal incompatibility that should've been abandoned three decades ago when they dumped hardwired glass terminals and switched to software emulation (mostly based on the ANSI standard with some extensions).
avatar
Maighstir: Since it uses curses, I don't think it runs as-is by default on Windows (it doesn't have curses, can probably install it, or run WSL or a *NIX VM), most other systems should be fine.
Run the file through Python 3. Arrow keys are the game controls, and q quits. Ctrl-c may fuck up your console, just close that one and start another in that case.
Simple way to see if curses is supported by your setup: Start the Python 3 interpreter, and type "import curses". If curses is supported (yes, I know that sounds like bad English), nothing obvious will happen, and you're good to go. (If it isn't supported, you'll get an error to the effect of "module _curses not found".)
avatar
Maighstir: C doesn't need curses. All information I found said that Python requires curses in order to listen to keypresses (as opposed to wait for a return key to end the input and store the result in a string), so that's what I used.
avatar
clarry: I'd imagine one can do in Python exactly the same thing one would do in C.

https://docs.python.org/2/library/termios.html
Why not https://docs.python.org/3/library/termios.html ? (We really should be linking to the Python 3 documentation unless the discussion is specifically about Python 2, which it is not.)

Also, this still doesn't help with getting it to run on Windows. (By the way, in addition to WSL and VMs, there's also the option of cygwin.)
Post edited July 01, 2019 by dtgreene
Right, this is a few months old, anyway, I don't care...

My implementation of 2048 has become a small study of how the same base code can be displayed in different user interfaces. From one suitable for actual teletype terminals to the Curses one I first created, to one built in Tk, to one in PyQt5 and QML. No I didn't get to termios yet, more are likely coming.

Also a slight modification to make it run under Python 2.2 with the Tk interface (because I wanted to see it run on Mac OS 9 - Python 1.5 is an upcoming target because I also want it on System 7 and 68k machines).

Suggestions or ideas for improvement?
Post edited September 27, 2019 by Maighstir
avatar
Maighstir: Right, this is a few months old, anyway, I don't care...

My implementation of 2048 has become a small study of how the same base code can be displayed in different user interfaces. From one suitable for actual teletype terminals to the Curses one I first created, to one built in Tk, to one in PyQt5 and QML. No I didn't get to termios yet, more are likely coming.

Also a slight modification to make it run under Python 2.2 with the Tk interface (because I wanted to see it run on Mac OS 9 - Python 1.5 is an upcoming target because I also want it on System 7 and 68k machines).

Suggestions or ideas for improvement?
Another thing to try:
* Port the core to another language, such as C. (This can be a great way to learn a new programming language, and knowing C can be beneficial even if you're actually writing code on a higher level language.) Once you have this port, you can now target an even bigger variety of systems, including some embedded targets (anything with a C compiler and suitable I/O capabilities) that might not have a Python implementation for them. (Fun fact: Did you know that the most popular Python implementation, the one you are probably using, is written in C?).
* Taking that C core, create a Python wrapper that's compatible with your core in Python; this should get you learning about how to get different languages to interact. (You can use ctypes, cffi, or even create an extension module.)
avatar
Maighstir: Right, this is a few months old, anyway, I don't care...

My implementation of 2048 has become a small study of how the same base code can be displayed in different user interfaces. From one suitable for actual teletype terminals to the Curses one I first created, to one built in Tk, to one in PyQt5 and QML. No I didn't get to termios yet, more are likely coming.

Also a slight modification to make it run under Python 2.2 with the Tk interface (because I wanted to see it run on Mac OS 9 - Python 1.5 is an upcoming target because I also want it on System 7 and 68k machines).

Suggestions or ideas for improvement?
avatar
dtgreene: Another thing to try:
* Port the core to another language, such as C. (This can be a great way to learn a new programming language, and knowing C can be beneficial even if you're actually writing code on a higher level language.) Once you have this port, you can now target an even bigger variety of systems, including some embedded targets (anything with a C compiler and suitable I/O capabilities) that might not have a Python implementation for them. (Fun fact: Did you know that the most popular Python implementation, the one you are probably using, is written in C?).
* Taking that C core, create a Python wrapper that's compatible with your core in Python; this should get you learning about how to get different languages to interact. (You can use ctypes, cffi, or even create an extension module.)
Good idea. I did a bit of C(++?, can't remember now, doesn't matter) in high school through programming class, and tried learning Java in junior high, never got very far in either and didn't like the latter, and that was all quite a while ago now.

With that my Amiga 500 and DOS-based 386 should be possible targets.
Post edited September 27, 2019 by Maighstir
low rated
avatar
Maighstir: Suggestions or ideas for improvement?
Add DRM-free multiplayer. With achievements, rankings, etc. And no logins. ;-)

Some day I'll do this just to shut up every idiot who thinks DRM is mandatory for multiplayer.. these forums are full of such people. :)
Post edited September 27, 2019 by clarry
avatar
Maighstir: Suggestions or ideas for improvement?
avatar
clarry: Add DRM-free multiplayer. With achievements, rankings, etc. And no logins. ;-)

Some day I'll do this just to shut up every idiot who thinks DRM is mandatory for multiplayer.. these forums are full of such people. :)
Multiplayer and achievements might be a bit too much for a game like 2048, the former could be suitable for minesweeper (I did start to work on a multiplayer minesweeper long ago, and then didn't continue). Ranking could probably work, but network work is a bit beyond me at the moment (at least anything more advanced than pulling data off a web server, meaning I haven't done any actual networking stuff myself at all).
Post edited September 28, 2019 by Maighstir
low rated
avatar
Maighstir: network work is a bit beyond me at the moment (at least anything more advanced than pulling data off a web server, meaning I haven't done any actual networking stuff myself at all).
Sounds like a perfect opportunity to get some practice on a not-too-serious project that you can scrap if it doesn't pan out ;3
avatar
Maighstir: network work is a bit beyond me at the moment (at least anything more advanced than pulling data off a web server, meaning I haven't done any actual networking stuff myself at all).
avatar
clarry: Sounds like a perfect opportunity to get some practice on a not-too-serious project that you can scrap if it doesn't pan out ;3
I wonder how a serverless networked ranking list would be done? Blockchain seems like it would work (unmutable history and whatnot), but also like a just slightly too heavy tool for such a job.
low rated
avatar
Maighstir: I wonder how a serverless networked ranking list would be done?
What do you mean by serverless?

There has to be a server, since data won't materialize out of thin air to those who want to see it. Unless you mean something like P2P, which is viable only if you have a sufficiently large network of persistent clients.
Post edited September 29, 2019 by clarry