Minimax Algorithm for Tic Tac Toe (Coding Challenge 154)

Minimax Algorithm for Tic Tac Toe (Coding Challenge 154)

The Coding Train

4 года назад

798,518 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Aaron. Prog. Z
Aaron. Prog. Z - 21.10.2023 21:05

Thanks for making this video! You make programming very fun!

Ответить
DEUTY
DEUTY - 05.10.2023 13:21

Im seeing this after my friend challenging me to a split competetion
Only thing im good is coding thats why

Ответить
User Name
User Name - 01.09.2023 05:30

@TheCodingTrain and everyone question - I go to p5.js, look at the code and the bestMove() function seems to be invoked but it's not defined anywhere! I can't find it - any tips?

Ответить
AI OPEN KNOWLEDGE
AI OPEN KNOWLEDGE - 17.08.2023 02:45

The book AI technology- explore infinite knowledge by L.T. Tzur.

Ответить
Sannin
Sannin - 14.08.2023 16:34

Sir , what if I use a 4×4 ,tic tac toe ,
And I want to do minimax in it
Is it okay, or it's gonna take 1 day for computer to make move in starting, bcoz it's 10 power 12 ?

Ответить
Antonio Roberio Barreto de Oliveira Filho
Antonio Roberio Barreto de Oliveira Filho - 09.08.2023 15:46

te amo

Ответить
julian santos
julian santos - 16.06.2023 12:31

Tnx for this nice and informative video

Ответить
Bluehawk2008
Bluehawk2008 - 28.05.2023 05:53

When I wrote a tic-tac-toe game in high school, I had a loop check every row, column and diagonal for a scenario where the AI could win by selecting an empty spot: an O-O-blank scenario. If it found one, it filled it and won the game. Next it would look for scenarios where the player would win, X-X-blank, and block them by choosing the empty spot. If it couldn't find either scenario anywhere on the board, it would just choose one at random. With only 9 spaces and half of the turns belonging to the player, the AI quickly becomes reactive and competitive instead of random.

It wasn't perfect, and my implementation was awful with giant nested if-then-else trees, but the finished product worked and was as fun as you could expect from tic-tac-toe.

Ответить
Abhishek Kuber
Abhishek Kuber - 26.05.2023 08:36

great explanation! I have understood most of the code, but can someone please explain me 'depth' and calling the minimax function recursively using 'depth+1' , and how does it help/ work. TIA

Ответить
Andrew Werner
Andrew Werner - 23.05.2023 09:55

I'm relatively confident it's nit going in the corner because it's thr best move (most ways to trap the player) because you're expected to play perfectly, so all sauares will end in a tie from its point of view. So it just always goes in the first space. If you indexed the swuares another way, it would take another cell first. You could add a random chance among all equivalent choices to show this.

I know you said you didn't want to add in any game theory assuming the player won't play perfectly, but i think a stat of most player options that end in traps is a good one to start with. Then, if your move is center, its best choice is the far corner opposite where it started, making an XOX sandwich on the diagonal. (Actually, I was interested to see how your algorithm would respond to that when you chose to go first. If it takes one of the remaining 2 corners on its move, you can again trap it. I think it should avoid that in favor of a tie option, but it's a good test of the algorithm.

Ответить
Sara Yan
Sara Yan - 08.05.2023 12:42

U ARE AMAAAAAAAAZIIIIIIIIIIIIING ILY

Ответить
SimpleCarGuy
SimpleCarGuy - 13.04.2023 18:17

This guy is so pleasant to watch, I wish I had this energy and positivity! Also, thanks for leaving the mistakes in, doesn’t make me feel so dumb.

Ответить
Alexander Viana
Alexander Viana - 07.04.2023 11:43

See this Remake -> Tic Tac Toe Decrepit.

Ответить
Олександр Яківець
Олександр Яківець - 03.03.2023 18:18

you speak very fast. can not understand anything

Ответить
Trifortay
Trifortay - 24.02.2023 19:30

I'm also unbeatable. I memorized all the patterns years ago and still haven't forgot them. I play sometimes against a computer, (even the impossible ones) to make sure I'm still not rusty.

Ответить
Mousie
Mousie - 21.12.2022 14:29

It's crazy how this is my current homework assignment and here I'm sitting watching a step by step tutorial how to solve it. Like it's too good to be true. THANKS for this!

Ответить
carlitoz
carlitoz - 21.12.2022 04:24

why if you start at center ? btw thanks for your videos, they're both fun and really well done

Ответить
Akshat Dhiman
Akshat Dhiman - 19.12.2022 09:40

I made a recursive algorithm but now it is taking only middle spot why ?

Ответить
Piotr Jagła
Piotr Jagła - 02.12.2022 14:25

thank you so much

Ответить
Batuğ Koçak
Batuğ Koçak - 01.12.2022 12:42

Guys, is it possible to make this Algorithm work for Nxn not just 3x3?

Ответить