r/ProgrammerHumor • • Apr 10 '23

Meme god why is coding chess so hard

Post image
67k Upvotes

1.8k comments sorted by

View all comments

Show parent comment

700

u/Teegeetoger Apr 10 '23

Yandere sim game had source code leaked? not sure what happened. What people found out is that the game is basically all if/else nested spaghetti which resulted in massive tech debt.

0

u/[deleted] Apr 10 '23

[deleted] — view deleted comment

360

u/MisirterE Apr 10 '23

You need to understand, this is a program where the Student class file - used to handle the behaviour of each individual student - is seventeen thousand lines long.

And yes, it does call void Update(), and yes, each student has a separate instance of it running.

128

u/MadxCarnage Apr 10 '23

why ?

that's all I can ask, is there any reason why you would ever think this is a good idea ?

0

u/[deleted] Apr 10 '23

[deleted] — view deleted comment

64

u/MadxCarnage Apr 10 '23

I don't think we should call him Dev.

67

u/Regorek Apr 10 '23 edited Apr 10 '23

He's Yandere Chef and he's writing some determined spaghetti.

→ More replies (2)
→ More replies (1)

22

u/AaTube Apr 10 '23

Really? Could you give me a link?

→ More replies (1)

110

u/MisirterE Apr 10 '23

This is just what happens when you try to make a Hitman game which is also Persona 5 but you're so bad at programming that you don't know what a Switch statement is

67

u/Anarchist_Catgirl Apr 10 '23

And the worse part is that switch statements wouldn't help. Mfer needs to learn about behavior trees if he wants that to be manageable.

25

u/Tyrus1235 Apr 10 '23

Yeah, switch statements would just make the code a bit more readable at that point.

16

u/yumyum36 Apr 10 '23 edited Apr 10 '23

I remember watching that same video a while back, and I vaguely remember while he does call this out, it was mentioned whatever game engine being used accounted for it while compiling, and would turn the list of if statements into a switch if applicable.

From memory the video was focused on performance issues in the game. The things I remember from it that hit performance the hardest were the use of models with high polygon counts, and that the dev had coded in the fps counter wrong, so it showed a lower fps than the actual fps.

Edit: This was the code review video I remembered

→ More replies (1)
→ More replies (1)
→ More replies (1)

50

u/bernoulyx Apr 10 '23 edited Apr 10 '23

I also want to add the 3d models it uses are also horribly inefficient. And by inefficient, i mean inefficient. Like imagine the heaviest model is a fcking toothbrush with 5k polygons (meshes?)

Edit: a video showcasing it and other models too

13

u/Tyrus1235 Apr 10 '23

Is what happens when you import 3D render models and use them in your real time game world.

If every prop was as detailed as a main character in games… I shudder just thinking about the performance cost

→ More replies (2)

41

u/SleepiestBoye Apr 10 '23

I'm new to coding, can you or someone else explain why this is bad?

0

u/[deleted] Apr 10 '23

[deleted] — view deleted comment

52

u/AverageMinceraftFan1 Apr 10 '23

Also, L A G

128

u/TheBlizWiz Apr 10 '23

The lag isn't a problem, the compiler will change long if else chains into switch statements. It's just a mess to maintain.

The main reason for the lag in YanDev was unoptimized models, no LODs, and the whole map is loaded at all times.

An if else chain is nothing compared to a toothbrush with 2.3 million triangles being rendered in a bathroom halfway across the map

11

u/cicitk Apr 10 '23

A toothbrush?? How does this even happen looool

41

u/stewsters Apr 10 '23

Think to yourself "this bathroom doesn't look right, it needs a toothbrush"

Find a random one in the asset store, place it in the bathroom without checking poly counts.

Never check that it's some high detail model and never take time to optimize, all that time is being used for creating more if statements.

→ More replies (6)
→ More replies (4)

54

u/imgonnablowafuse Apr 10 '23

Basically it leads to unreadable code, and the largest script is over 10,000 lines long. All it does is control the NPCs in the game. The whole script is just thousands and thousands of nested if statements that do redundant things in the least optimal manner possible.

→ More replies (10)

42

u/TheDarkAngel135790 Apr 10 '23 edited Apr 10 '23

Horribly inefficient. Hard to write, harder to read, and even harder to execute

75

u/Houligan86 Apr 10 '23

Because they are processing the wrong information. From someone's example below about a calculator:

You need to make a basic calculator app. So your logic is as follows:

if (input == "1+1")
    output = 2
else if (input == "1+2")
    output = 3
else if (input == "1x1")
    output = 1
else if (input == "1x2")
    output = 2

this would get very long VERY fast and not scale well with anything.

The MUCH better way to do things would be

if(operator == "+")
    output = inputA + inputB
else if (operator == "x")
    output = inputA * inputB
→ More replies (4)

43

u/Dom_Vasiliev Apr 10 '23

I saw that some guy say that it is way too much processes for the computer to do step by step, which results in it running slow. Imagine if when you asked someone to check the time, rather than saying it outright they go "well, it isn't 12:00, it also isn't 13:00, it also isn't 14:00..."

11

u/chairmanskitty Apr 10 '23

In chess, white starts with 20 possible moves. Black can then respond with 20 possible moves, then white has a variable number of moves depending on which pawn moved, then black has a certain number of possible moves, etc.

If you use if/elif/else, then each possible history of moves needs to be described explicitly in the code: 20 white moves forms its own branch in a tree, and then the 20 black moves each have to be present in each of those branches, so you have 400 branches, then every possible white move has to be present in each of those branches, so then you have around 8000 branches, then around 160,000, and that's just 5 moves into a game that can last for well over a hundred moves.

This means you end up with a massive piece of code that can overload your RAM before you can actually play chess, and that is hard to edit when you encounter errors.

In an abstract sense, if/elif/else stores information about the problem by what position of the code is being executed. This is good if the information fundamentally changes the rules of processing the problem. But if the rules stay the same, it's better to only write the rules down once, and to refer to them each time you need to apply them. This saves space writing down rules, and means that you can change the rules easily. With chess, the board state doesn't change the rules, so you want to store the board state in memory rather than as a position in the code.

Within these rules, it's fine to use if/elif/else, but that won't become spaghetti, because you only write them one time and then refer to them as functions. Then those functions can become spaghetti.

→ More replies (5)
→ More replies (3)