josteink 7 years ago

Have we really come so far? This has to be full circle, right?

First we had a wave of “see what can be done in a browser!” kind of demos.

Which at the time was massively impressing, because nobody thought you could seriously use the browser for other things than documents and very slow and clicky applications.

These days impressive browser-based experiences are the norm and native software is often accused of being visually “boring” and inanimate.

And here we’re back at the beginning: a tech demo for a native app, in the terminal, trying to reproduce what was once a tech demo of what you could do in a browser, as if that’s somehow novel.

Just 30 (or more?) years after nethack.

I’m honestly not sure how to feel about that ;)

  • chx 7 years ago

    > trying to reproduce what was once a tech demo of what you could do in a browser

    2048 was never that, it was a shitty knockoff of Threes and remains so.

    • TeMPOraL 7 years ago

      Maybe it's a knockoff, but I'd call it improved. I never liked number 3, and for me the additions in Threes look completely arbitrary. Whereas 2048 features nice, round (base 2) numbers.

      And I'm only half-joking. I've been working with base 2 for two thirds of my life now, so powers of two are really more pleasant emotionally to me than multiples of 3.

      • krylon 7 years ago

        I get that, I still feel a little weird my work computer has 12GB of RAM.

      • Tarragon 7 years ago

        The problem with 2048 is that it’s not a very good game. You can solve it algorithmicly.

        Repeat swipe left then down down. If the board gets stuck swipe right then down and repeat.

        • solveit 7 years ago

          I believe that that strategy is decent but not optimal.

          • TeMPOraL 7 years ago

            It's not really even decent, but I agree that it helped me improve my win rate quote a bit, mostly through avoiding movements up unless necessary, and by trying to stick and keep the largest number in one of the lower corners.

        • ben-schaaf 7 years ago

          Most (if not all) games can be played algorithmically, some can be solved (ie. have a known best move for every state). As far as I'm aware 2048 is far from being solved, however expectimax implementations fare quite well.

          From playing the game with your algorithm, you won't have a high win rate.

        • cyphar 7 years ago

          Chess can also be solved algorithmically (the first algorithms for solving games were specifically for the solving of chess games). I don't think a game being solvable by an algorithm detracts from its quality as a game (though 2048 might be a bad game for other reasons).

          I actually am struggling to think of a game that cannot be played by an algorithm (aside from obvious games like tennis). Even Jeopardy could be played by a computer.

        • TeMPOraL 7 years ago

          > The problem with 2048 is that it’s not a very good game. You can solve it algorithmicly.

          Every game is susceptible to algorithms by definition, by itself, it doesn't make a game more or less good, or more or less fun.

          For me, 2048 hits a perfect spot where I can play it during meetings/conference calls/regular phone calls, to give that 20% of my mind that gets bored something to do, while not impacting my ability to focus on the discussion itself.

      • Cogito 7 years ago

        Threes! is inherently more complicated, dare I say topographically so.

        The two games are obviously very similar, and you can list their rules pretty easily, and how those rules differ. I'm going to attempt to write them out below for my benefit more than anything else, but my point is mostly about rule number (4):

        In Threes! tiles combine if they are 3 or greater and the same, or if they add to 3; in 2048 they combine only if they are the same.

        This means that the 'base level' tiles, 1 and 2, cannot combine with copies of themselves. Coupled with (7) this means that there is a lot of planning to make sure that new tiles can be combined with the correct type of tile.

        This mechanic is not possible using powers of 2, unless you had two 'types' of 2-tile that cannot combine with themselves. For example, a black 2 and a white 2, that combine to make a grey 4. That would be interesting, but less clean than using 1+2=3, I think.

        The other differences in the rules are important but have less to do with multiples of 3 (where the multipliers are powers of 2) vs powers of 2.

        While both games have randomness inherent in them, Threes! allows forward planning a lot more. You can keep track of which tiles are left in the deck, and as tiles only move one grid square at a time they are somewhat more manoeuvrable. Tiles only combine if you squeeze them together, while in 2048 they feel a lot more 'magnetic', jumping together as soon as they can. This gives you more control over when tiles combine, which is really important for positioning moves. It also means that Threes! has more tiles on it and feels more crowded as the game goes on, because many moves will not combine any tiles at all, while in 2048 almost any move will combine some tiles.

        ==== Rules ====

        Start with a grid that has tiles on it, each tile taking one space and containing a number. A turn consists of pushing all tiles in one direction, either up, down, left, or right.

        Tiles will either stay where they are or slide in the direction pushed, and may combine with tiles next to them (in the direction of pushing). When tiles combine they create a new tile with number equal to the sum of the two that combine, and this new tile replaces the other two.

        We will say a tile is next to another tile only if they are adjacent in the direction of the push.

        In Threes!

        1. the grid is 4x4

        2. a tile stays where it is if it is next to a wall, or next to a tile that is staying where it is and that it cannot combine with

        3. a tile that moves will only ever move one tile

        4. two tiles can combine if their sum is 3, or they are 3 or greater and the same

        5. two tiles that can combine will combine if they are next to each other and both cannot move

        6. after each move a new tile will appear next to the opposite wall, on a line where at least one tile moved

        7. new tiles are drawn from a shuffled 'deck' of twelve tiles - four 1s, four 2s, and four 3s. Occasionally a large 'wild' tile will be picked instead of the next tile from the deck

        8. to start, the grid has 9 new tiles placed randomly on it

        In 2048

        1. the grid is 4x4

        2. a tile stays where it is if it is next to a wall, or next to a tile that is staying where it is and that it cannot combine with

        3. a tile will move as far as possible in the direction it is pushed

        4. two tiles can combine if they are the same

        5. two tiles that can combine will always combine if there are no other tiles between them

        6. after each move a new tile will appear in a random empty square

        7. new tiles will be either a 2 (90%) or 4 (10%)

        8. to start, the grid has 1 new tile placed randomly on it

  • chickenfries 7 years ago

    The game that 2048 is based on is a native mobile app...

    • chickenfries 7 years ago

      Also, neither game was successful because it was an impressive graphically... it was just a fun game. This whole discussion is irrelevant but happens all the time on HN. Why?

  • keyle 7 years ago

    Wasn't 2048 based on a game call Three on iOS? It was a blatant copy over to Android. Or maybe I got my wires crossed.

    • Lazare 7 years ago

      Indirectly, yes. The developer of the version of 2048 everyone has heard of (Gabriele Cirulli) had apparently never heard of or seen Threes, but the games he was copying/inspired were in turn inspired by/copied from Threes, if you dig back far enough.

      Note that Threes has different, more complex rules. Some prefer it, but apparently, more people don't. :)

  • theandrewbailey 7 years ago

    This is much better than Electron apps for simple things that eat 1 GB of RAM (more or less as a rule) and are horrendously laggy.

erayare 7 years ago

Type

    telnet telehack.com

    2048

in a terminal

  • garaetjjte 7 years ago

    For other telnet games, there is milek7.pl with tetris, breakout and multiplayer pong.

    • ccozan 7 years ago

      oh, I miss the backgammon games over telnet.

      Does anyone knows of any servers still online?

      • patrickdavey 7 years ago

        There's always fibs :)

        telnet fibs.com 4321

    • Fnoord 7 years ago

      Tetrinet for CLI [1]. Not sure if it still works.

      Also, Tron over SSH [2]

      [1] http://tetrinet.or.cz/

      [2] $ ssh sshtron.zachlatta.com

abecedarius 7 years ago

Another, in Python: https://github.com/darius/sturm/blob/master/2048.py This one animates the sliding of the pieces.

The terminal input-handling might not work in your OS -- I gave up trying to find a nice cross-platform approach to that.

  • hk__2 7 years ago

    > The terminal input-handling might not work in your OS -- I gave up trying to find a nice cross-platform approach to that.

    I wrote a terminal version of 2048 back in 2014 [1] and the input-handling works on all platforms I know of. You may want to look at the code: https://github.com/bfontaine/term2048/blob/master/term2048/k...

    [1]: https://github.com/bfontaine/term2048

    • abecedarius 7 years ago

      Thanks. I'm not sure yet if that will help with the trouble I was having (I wanted the library to support extra features not needed for 2048), but it's great to see small code to learn from.

jgtrosh 7 years ago

I did a similar thing with 1010 a while ago: https://github.com/trosh/1010

These projects are probably useless but very fun to make and contribute to if you feel like practising. Some stranger actually contributed to my rushed 1010 clone, it was the best feeling ever.

ninjakeyboard 7 years ago

Very cool!

I noticed Wikipedia references another app for terminal in C: https://github.com/Tiehuis/2048-cli

Might be interesting to compare.

  • krylon 7 years ago

    There is version written in sed, too.

    • themattrix 7 years ago
      • krylon 7 years ago

        You rock!

        EDIT: Not only because of the technical achievement, but because this little has allowed me to waste some time playing a fun game, while looking very busy to passers-by to whom anything being done in a terminal looks like black magic from The Matrix. ;-) That game can be seriously addictive.

billconan 7 years ago

nice! how did you record the commandline as a gif?

  • ioddly 7 years ago

    Not sure how OP did it, but I use peek. Pretty handy for readmes, even for showing clients stuff without having to deploy.

  • gbaygon 7 years ago

    I will throw another option, very lightweight: licecap, works on win and osx, from the original dev of winamp!

    https://www.cockos.com/licecap/

    • mikewhy 7 years ago

      Had no idea and I've been pushing licecap for years.

sossles 7 years ago

Ok, now I'm tempted to rewrite Twenty to work in the terminal. It's already c++!

djsumdog 7 years ago

Huh. Seems to misalign the right side of the grid in my terminal. Still pretty cool though.

foota 7 years ago

At first I thought this was going to be one of those template preprocessor games.