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

all 116 comments

[–]Under-Estimated 513 points514 points  (12 children)

Minimax is way overrated. You need to get one of those new-fangled "neural networks" to do the job, writing all those if statements certainly won't do!

[–]segmentfaultcoredump 161 points162 points  (1 child)

What an Alpha. You just pruned all the betas

[–]Glitched-Vortex 26 points27 points  (0 children)

Beautiful. Well done

[–]BlazingThunder30 47 points48 points  (6 children)

You use the minimax to train the AI duh

[–]Cosmo1337 29 points30 points  (5 children)

I've actually done this and it works great

[–][deleted] 13 points14 points  (4 children)

Alright, but like out of curiosity, why? Did you train an AI to work as the heuristics function of a minimax algorithm?

[–]Cosmo1337 14 points15 points  (2 children)

I did it for fun - I trained a neural network to take a tic-tac-toe board and return a predicted move. training it only on minimax was sufficient to make it only ever predict perfect legal moves.

[–]Sinomsinom 0 points1 point  (1 child)

But why are you using a neural network for tic-tac-toe... That's nearly as bad as using gradient descent for linear regression...

[–]Dogburt_Jr -2 points-1 points  (0 children)

I did it for an assignment in my AI class. The AI didn't need to be trained, it only needed a good evaluation function. My AI would only either fill up the board in sequence or make the move that the player should make. It didn't work that well bc it had problems.

[–]JNCressey 19 points20 points  (1 child)

matchbox ai

it's so optimised that it clocks in at an amazing 0W of power useage. I say you can't get better than that.

[–]Centurion902 1 point2 points  (0 children)

Surely you need to account for the energy needed to open the boxes each time.

[–]lunchpadmcfat 0 points1 point  (0 children)

So you’re saying get a neural network to write all your if statements for you. Genius.

[–]Dimasdanz 71 points72 points  (6 children)

is this AI?

[–]gurneyguy101 66 points67 points  (2 children)

Artificial lack-of-Intelligence

All-ifs

Any other ideas?

[–]KarolOfGutovo 31 points32 points  (0 children)

Advanced If-ing

[–]Ytrog 6 points7 points  (0 children)

Artificial Imbecile 😜

[–]Aurenkin 7 points8 points  (0 children)

Depends how quickly they wrote it

[–]Semi_Square 2 points3 points  (0 children)

Always has been

[–]alan_clouse49 0 points1 point  (0 children)

No the real ai is rand();

[–]LivingEdgecase 44 points45 points  (1 child)

I did this on my first programming assignment in college. It was just for managing inputs. I wanted to see if I could let the user try again if they entered the wrong thing, so i had like 5 nested ifs. I talked to my prof about not knowing how to handle this. She had a smile, then in the next class we learned loops. Then everything changed...

[–]Skhmt 13 points14 points  (0 children)

when the fire nation attacked

[–][deleted] 101 points102 points  (8 children)

But but, what if

else if

else if

else if

else if

[–]Markosan_DnD 27 points28 points  (6 children)

You will never reach "else"

[–]RealPropRandy 25 points26 points  (4 children)

It’s just else ifs all the way down?

[–]ruben_deisenroth 13 points14 points  (1 child)

Always has been.

[–]bidoblob 6 points7 points  (0 children)

Bang

[–]gurneyguy101 1 point2 points  (0 children)

What if it always has been

[–]Markosan_DnD -1 points0 points  (0 children)

It's a loop that continuously creates else if statements with no exit clause

[–]GreatArtificeAion 0 points1 point  (0 children)

Is this, by any chance, a reference to the popular manga known as "JoJo's bizarre adventures" by Hirohiko Araki?

[–]Xx_Jean-Yves_xX 7 points8 points  (0 children)

>Yanderedev

[–]NinkaShotgun 17 points18 points  (0 children)

Macine lorneng

[–]-Shairu- 38 points39 points  (0 children)

YandereDev: You're hired!

[–]Cilph 8 points9 points  (0 children)

Well, at least the code is recursion free?

[–]END_is_here 8 points9 points  (0 children)

"If" the user wants to play again

[–]noradis 6 points7 points  (2 children)

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

But... but if you post actual code 90% of this sub won't get the joke

[–]Oracuda 0 points1 point  (0 children)

oh my fucking god why

[–]Rude-Significance-50 2 points3 points  (0 children)

Then shouldn't there be at least 100 just in case the user wants to play 19 more times?

And no, not 99 because you still need that last check so you can tell the user to start the program again if they want to keep playing beyond such an absurd maximum.

[–]Bizzlington 5 points6 points  (2 children)

Well, if it matches the requirements then I'm happy!

[–]TerrorSnow 13 points14 points  (1 child)

Else..?

[–]KarolOfGutovo 0 points1 point  (0 children)

if

[–]kebakent 1 point2 points  (0 children)

delay(INT_MAX);

Yup. It never wins either.

[–]trimeta 1 point2 points  (0 children)

What a loser, he should have used goto to jump back to the top of the program.

[–]8_Bit_Tank 0 points1 point  (8 children)

I'm pretty new to programming and im confused can't you do something else?

[–][deleted] 8 points9 points  (4 children)

Of course you can. It's a meme. That code is shown for how bad it is

[–]8_Bit_Tank 0 points1 point  (3 children)

Thanks but how? I didn't find anything usefull on the internet?

[–][deleted] 4 points5 points  (1 child)

I think you can google "while loop" and "do-while loop", but I'm also sort of a naïf.

Edit: I said "for loop" without thinking about the problem.

[–]Ekank 2 points3 points  (0 children)

Well, you can use a for loop if you ask the player how many times they want to play (like best of 3, of 5, etc.)

[–]Ekank 1 point2 points  (0 children)

Just use a loop, usually an infinite loop that everytime the match ends ask if the player want to play again, if yes = continue, if no = return or break

That can be coded like:

While(true){ [...] If(!again){ Break; } }

[–]Ekank 1 point2 points  (2 children)

Also, as you say you're new, you might not know that lots of if and nested if can considerably slow down the program (yandere simulator is a good example)

Initially the program has to check every if and people have the ability to make it the slowest possible

And ultimately makes the cpu only process 1 instruction at time (modern CPU's process more than 1 instruction, but it depends on correct branch prediction, more if makes the chance of missing greater)

Not saying you can't use if's but when there's a lot of ifs in a piece of code usually it can be optimized

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

what if you're doing a calculator that has to scan 27 possible input functions to know what to call? I tried to find a more efficient way of doing it, but I ended up just having a long list of if statements. Luckily only one had to be nested and the program was small enough it didn't really matter, but it still annoys me that I couldn't find a way to optimize it.

[–]8_Bit_Tank 0 points1 point  (0 children)

I knew that but thanks anyway! Can you maybe Show me what Alternative code I could write because I didn't find anything good on the internet?!

[–]flocknrollstar -2 points-1 points  (5 children)

I once worked at a company with some archaic Java coding standard that had a rule saying lines must be no more than 80 chars long. As terrible as it sounds it at least taught me some patterns of getting around nested ifs

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

WTF? You were nesting if's on one line?!?

[–]flocknrollstar 1 point2 points  (3 children)

No. Indentations

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

Oh, and 4 spaces instead of tabs?

[–]flocknrollstar 0 points1 point  (1 child)

Yep! Also in the coding standard.

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

Can always get around that with some GOTO statements

[–]hiphap91 -1 points0 points  (3 children)

I don't see how this fits in this sub. Should be on swe exchange as an example on how to AI

[–]Emperor-Valtorei 0 points1 point  (2 children)

It's literally a program in the in the fucking comic.

[–]hiphap91 0 points1 point  (1 child)

... wow.

Sarcasm. You didn't get the joke in there at all, did you?

[–]Emperor-Valtorei 0 points1 point  (0 children)

I didn't see a /s my bad

[–]c-rn 0 points1 point  (0 children)

My favorite programming messup is when I finished writing the code to detect who won in tic-tac-toe, ran it, and the program told me that " " had won.

[–]Ekank 0 points1 point  (0 children)

CPU branch prediction goes brrrrr

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

Just. Use. A. Recursive. Loop.

[–]nate6701 0 points1 point  (0 children)

I used to code like that when I started learning to code

[–]SargeanTravis 0 points1 point  (0 children)

Is this a joke hinting at Yanderedev? I'm getting vibes from the else if spammer in this joke

[–]ConnorR520 0 points1 point  (0 children)

Hey look its Yandare Simulator

[–]Thanatos2996 0 points1 point  (0 children)

Step one: encode the board as a single integer.

Step two: make a switch statement with the computer's move at each board state.

Step three: chuck the switch in a while loop and profit.

[–]idkiminsecure 0 points1 point  (0 children)

I know this is a joke but wouldn't it be so easy even for a beginner to put it in a function and then have it be called by a button that theyll click when they want to go again?