• PeriodicallyPedantic@lemmy.ca
    link
    fedilink
    arrow-up
    87
    arrow-down
    1
    ·
    11 months ago

    No lie, after taking about 2 weeks of my first programming course in university, I did almost exactly this, trying to make a poker game.

    I hadn’t learned about objects, or functions, or even loops. Just one big method that had an if for every hand permutation.

    I hadn’t ever been exposed to programming before, and I loved it, but I knew nothing about it. Those were the only tools I had in my toolbox, and you know what they say about how when you only have a hammer everything looks like a nail.

    I’m a professional dev now, so I really hope I grew out of it lol

    • homura1650@lemm.ee
      link
      fedilink
      arrow-up
      12
      ·
      11 months ago

      Back when I was learning, I made a flashcard program. It had a class that was essentially a constant array, so you could call get(int i), and it would return an object describing both sides of the card.

      How did I implement such a class you ask? First, I made a spreadsheet with 2 collumns to hold the data, with a third collumn of incrementing integers. Then, in the 4th column, I used string concatanation to right a java if statement that compared a variable against the index collumn; and if they match, return an object constructed from the 2 data columns.

      Click and drag the 1 cell I wrote in the 4th collumn to replicate it in all the rows, then copy and paste the 4th collumn into notepad++.

      I’d like to say I’ve moved past this; but my most successful projects have mostly been code generation ones; so really I’ve just moved past Excell.

      • luciferofastora@lemmy.zip
        link
        fedilink
        arrow-up
        1
        ·
        8 months ago

        I mean, moving past Excel is still an excellent development.

        Signed, a guy that keeps dealing with people who need my code to spit out weird spreadsheets.

    • Droechai@lemm.ee
      link
      fedilink
      arrow-up
      10
      arrow-down
      1
      ·
      11 months ago

      Time to get some qbasic coding in, your if and goto experience will do wonders

    • AwkwardLookMonkeyPuppet@lemmy.world
      link
      fedilink
      arrow-up
      6
      ·
      11 months ago

      I’m a professional dev now, so I really hope I grew out of it lol

      I was reading your comment and wondering if I’ve outgrown it. I’ve been a programmer for 20 years…

    • nelly_man@lemmy.world
      link
      fedilink
      English
      arrow-up
      4
      ·
      11 months ago

      Same thing with me and chess in high school. I learned TrueBASIC, and I didn’t learn about arrays or subroutines. But, I did manage to make a chess application that two people could play a game of chess on. It highlighted legal moves when you clicked on a piece and ensured that only legal moves were made. It also showed the captured pieces to the side of the board. I think I had it set up so that you could only promote to a previously captured piece, but all the other rules were implemented properly (or at least, I assumed they were).

      The implementation involved a bunch of variables for each individual chess piece and a bunch of if statements inside a loop. I remember describing arrays and explaining that I wished they existed, but never actually found out they did until I was finished. I don’t know how many lines of code it was, but when I copied it into Word, and it spanned about 350 pages in total.

      Part of me is proud of the accomplishment. Another part is horrified.

    • LarmyOfLone@lemm.ee
      link
      fedilink
      arrow-up
      4
      ·
      edit-2
      11 months ago

      I still remember when “the light went on” as realized how variables worked. I was on my way to school and couldn’t focus on mundane things and started hating school.

      Now I live in a van down by the river. But I’m still coding!

    • lionkoy5555@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      11 months ago

      That’s why its good to have a mentor or someone just to give feedback if we can find one for ourselves

      • PeriodicallyPedantic@lemmy.ca
        link
        fedilink
        arrow-up
        2
        ·
        11 months ago

        To be fair, or only took a few more classes before they introduced things like arrays and loops, and I realized how stupid my plan was lol

    • Researchgrant@lemmy.world
      link
      fedilink
      arrow-up
      91
      ·
      11 months ago

      It’s definitely satire. 2 million lines of code is an absurd under-exageration. This post had me looking up the number of possible chess games, because if you coded chess like above you would have to have an if statement for every outcome, and it’s 10^120 different possible games.

      https://en.wikipedia.org/wiki/Shannon_number

      • Taalen@lemmy.world
        link
        fedilink
        arrow-up
        45
        ·
        11 months ago

        The way I understood it, it’s two million lines and nowhere near finished.

        Anyway, satire.

      • PeriodicallyPedantic@lemmy.ca
        link
        fedilink
        arrow-up
        6
        ·
        edit-2
        11 months ago

        That’s the number of possible games, the number of possible board states is much lower, 10^40.

        Although you’re still clearly correct in the end anyways because it’s still an absurd number of board states and it’s not even formatted to be one state per line.

      • flames5123@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        11 months ago

        You only have to code a fraction of those as the computer should take the same move for several of the user inputs.

      • safesyrup@feddit.ch
        link
        fedilink
        arrow-up
        4
        arrow-down
        1
        ·
        11 months ago

        I read that there are less atoms in the universe than possible chess games, which is quite insane

        • chetradley@lemmy.world
          link
          fedilink
          arrow-up
          16
          ·
          11 months ago

          By an extremely significant margin. Here’s another fun one: getting a unique shuffle in a deck of cards is 1/52!. So if you wanted to count all of the different possible arrangements of cards, counting one per second, you can:

          Start walking around the equator at a leisurely pace of one step per billion years.

          Once you’ve made it around the earth, remove a single drop of water from the Pacific Ocean and walk around the earth again.

          Once the Pacific Ocean is empty, re-fill it and lay a sheet of paper on the ground. Keep stacking a new sheet every time you’ve re-emptied the ocean drop by drop every time you circle the earth at one step every billion years.

          When the stack of paper reaches the sun, you’re about a third of the way there!

          • hakase@lemm.ee
            link
            fedilink
            English
            arrow-up
            9
            ·
            edit-2
            11 months ago

            The way I like to put it is that every single time you randomly shuffle a deck of cards, you are guaranteed to get an order that has never been seen before, by anyone in history. That will be the case for every person who ever shuffles a deck of cards for the rest of time.

            • Ookami38@sh.itjust.works
              link
              fedilink
              arrow-up
              5
              ·
              11 months ago

              To be fair there was that one time a perfect shuffle led to a perfect bridge deal, each player getting a full suit. Sometimes even a fair shuffle goes weird lol.

      • Xyre@lemmus.org
        link
        fedilink
        English
        arrow-up
        10
        ·
        11 months ago

        For a second there I thought the 100% science-based dragons game had been made.

      • Da_Boom@iusearchlinux.fyi
        link
        fedilink
        English
        arrow-up
        7
        ·
        11 months ago

        Holy shit… That’s nuts. I do see the occasional boolean in there. But it might as well be ifs ints and strings like you said.

        Man went full static C programming in C# and coded the whole thing in what looks like one class. Instances?, loops excepting XNA gameloop? What’s that? Whos that? Where’s that?

        Honestly I’m not even mad, that’s dedication. Dedication and a refusal to learn more than just the basics. Kinda want to buy the game now just to see how far a fucktonne of if statements can get. By the looks of it, I’d say straight into the dragons maw.

      • SkyezOpen@lemmy.world
        link
        fedilink
        arrow-up
        5
        ·
        11 months ago

        Yandev as well. Guy put the ai for every single character in a single function separated with if/then statements. It was also called every game tick.

      • CeeBee@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        edit-2
        11 months ago

        My eyes! The global variable list is huge!

        Edit: nm, I looked again and they’re in a class. Still insane either way.

    • nicolairathjen@lemmy.world
      link
      fedilink
      arrow-up
      18
      ·
      11 months ago

      The post is satire, but I remember being ~8-9 and trying to create a “game” in Microsoft Word with hyperlinks between documents and nothing else. I had hundreds of documents (each representing a game state) before I got tired of that project.

      • aksdb@lemmy.world
        link
        fedilink
        arrow-up
        7
        ·
        11 months ago

        That’s pretty clever for that age and shows, that your brain already had the right wiring for (software) engineering. You set out to solve a problem by leveraging the tools you had and bending their functions to your needs. There’s a lot of abstract thinking involved.

      • grue@lemmy.world
        link
        fedilink
        English
        arrow-up
        11
        ·
        11 months ago

        The person who downvoted you must not have thought it through.

        For comparison to that 10120 possible game states, the number of atoms in the universe is only 1082 and the amount of time until the “Dark Era” of the universe (after all the stars have died and even all the black holes have decayed via Hawking radiation) is only 10114 to 10117 seconds. In other words, it really is literally impossible either to build a computer big enough to store all the board states or to write them all down even if you did.

        • morrowind@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          11 months ago

          is only 10114 to 10117 seconds

          I mean a good program could do a 100 million states/s . So if you could make a computer that lasts until the end of the universe it could go through all of them I guess?

          With supercomputers, probably way more, that’s just the figure for like a laptop. Plus you could filter out all the states that are symmetric and stuff and lower it by one order of magnitude.

          • grue@lemmy.world
            link
            fedilink
            English
            arrow-up
            3
            ·
            11 months ago

            I guess, maybe?

            I’m not prepared to speculate on the performance of a computer literally larger than the universe.

            • morrowind@lemmy.ml
              link
              fedilink
              arrow-up
              1
              ·
              11 months ago

              that’s the most fun type of speculation. No fun speculating over computers that could emulate realistic things like all states of a rubiks cube, cause that’s probably already been done.

              • grue@lemmy.world
                link
                fedilink
                English
                arrow-up
                1
                ·
                edit-2
                11 months ago

                …hey, wait a second, you pulled a fast one on me with that “100 million states/s” silliness!

                I just remembered what the time boundary I was talking about was actually trying to measure: it had nothing to do with the speed of computation; it was the speed of typing in the program code. That’s why 1 state per second was a reasonable estimate (if not overly optimistic). If you tried to type in all those ifs and prints manually, that’s what would take you longer than the heat death of the universe.

                Besides, even executing the program can’t do 100 million states per second because it only does one state transition and then waits for user input.

                • morrowind@lemmy.ml
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  11 months ago

                  Oh I was assuming you’d write another program to create this program, like the “4 billion if’s” blog post if you’ve read it.

    • Droggelbecher@lemmy.world
      link
      fedilink
      arrow-up
      10
      ·
      edit-2
      11 months ago

      There’s a mathematician that figured that there’s 10^120 possible chess games, as a lower bound. https://en.m.wikipedia.org/wiki/Shannon_number#:~:text=Shannon showed a calculation for,a Computer for Playing Chess". That’s a 1 followed by 120 zeros for just the number of possible games. With this method they’d have to manually go through every move for every one of those games. If we say a game lasts 30 turns on average and they’d take 1 second to code each turn (realistically it’d be longer) it’d take 6.9*10^109 (69 followed by 108 zeros) times as long as the age of the universe.

  • adONis@lemmy.world
    link
    fedilink
    arrow-up
    43
    ·
    11 months ago

    Lol… stupid junior-devs… in such case you should go with switch-statements instead… much cleaner.

    • Gumus@lemmy.world
      link
      fedilink
      arrow-up
      12
      arrow-down
      1
      ·
      11 months ago

      Switch-statement (called match) was added to Python 3.10 in late 2021. This is a reasonable, albeit older style of enumerated branching.

      • vithigar@lemmy.ca
        link
        fedilink
        arrow-up
        8
        arrow-down
        4
        ·
        11 months ago

        Switch statements and differently named but similarly purposed statements have been around since the 60s. Get outta here with this “switch is a newer style because python only just got them” nonsense.

  • doctorcrimson@lemmy.world
    link
    fedilink
    arrow-up
    23
    ·
    11 months ago

    Don’t stop now, there are only 7,728,772,977,965,919,677,164,873,487,685,453,137,329,736,519 more legal positions to code.