No video

Coding an Unbeatable Tic Tac Toe AI Using Python and the Minimax Algorithm

In this tutorial I will show how to code an unbeatable AI to play against in Tic Tac Toe using object oriented programming, the minimax algorithm (game theory), Python and its Pygame module.
LINKS:
😺 GitHub Repo: github.com/AlejoG10/python-ti...
- Classic Tic tac toe Tutorial: • Tic Tac Toe Using Pyth...
- Windows Setup: • How to Install Python ...
- Mac Setup: • How to Install Python ...
FOLLOW FOR MORE:
💥 GITHUB: github.com/AlejoG10
💥 INSTAGRAM: / coding_sp0t
⏱ TIMESTAMPS ⏱
00:00 Introduction
03:49 Screen & Background
17:43 Console Board
31:06 Drawing Figures
43:46 Board Functions
59:38 Minimax Explanation
1:13:21 Random AI
1:22:49 Minimax Function
1:40:17 Keyboard Events
1:49:40 Fix Bug
1:54:10 Show Wins
2:04:07 End

Пікірлер: 76

  • @JohnlukeSabile99963
    @JohnlukeSabile99963 Жыл бұрын

    One of the BEST project tutorials EVER. Thank you. This was awesome.

  • @anushriiii08
    @anushriiii082 жыл бұрын

    Thank you so much for this tutorial ! Very useful tbh ! Got to learn a lot. Please keep making these!

  • @jscioo
    @jscioo Жыл бұрын

    Your voice is the only voice that didn't make me go insane after hours of listening. Subscribed!

  • @codingspot

    @codingspot

    Жыл бұрын

    Happy to hear that my friend!

  • @sergiogarzonmarino9878
    @sergiogarzonmarino9878 Жыл бұрын

    Wow brother, this is the most clear tutorial that I could find. Thank you so much! Keeing up!

  • @anonymuz9575
    @anonymuz9575 Жыл бұрын

    You're so good at explaining things man! Mark my words: this man will blow up one day

  • @pedroliedu4257
    @pedroliedu4257 Жыл бұрын

    Thank you very much! Great tutorial video, helped me a lot! Many thanks again!

  • @romanizzo3412
    @romanizzo34122 жыл бұрын

    Best tutorial out there. Thanks

  • @jugujogurt4300
    @jugujogurt43002 жыл бұрын

    Thanks you very much for making this!! I have been waiting long for a good tic tac toe ai tutorial and this is perfekt!!

  • @codingspot

    @codingspot

    2 жыл бұрын

    Hope you like it!

  • @masternobody1896

    @masternobody1896

    2 жыл бұрын

    @@codingspot thanks

  • @GrowWithArup23

    @GrowWithArup23

    3 ай бұрын

    @@codingspot How to make "ai vs ai" mode? kindly help!!

  • @builtbydhruv
    @builtbydhruv3 ай бұрын

    Well thanks brother , this is amazing .

  • @lalaissosoft
    @lalaissosoft2 жыл бұрын

    seriously best tutorial ever. Thank u for your amazing work

  • @ATGG
    @ATGG2 жыл бұрын

    Welcome back man! Hope you good!

  • @codingspot

    @codingspot

    2 жыл бұрын

    Hey bro!! Doing great thanks!

  • @adityakangune770
    @adityakangune7702 жыл бұрын

    Thank you!

  • @solalabouaf5838
    @solalabouaf58382 жыл бұрын

    thanks a lot for this video

  • @chrismai48
    @chrismai482 ай бұрын

    I understand everything except the AI minmax method coding and unfortunately that was the reason that i watch your video. Never the less i think you 've done a pretty good job...

  • @daniel173880
    @daniel1738802 жыл бұрын

    This is so good!!! Thank you!!

  • @codingspot

    @codingspot

    2 жыл бұрын

    Happy to hear that my bro!

  • @mohithrajds8852

    @mohithrajds8852

    9 ай бұрын

    brother where i can get code@@codingspot

  • @bluidguy4007
    @bluidguy4007 Жыл бұрын

    I'm at: Time: @1:38:30 I copied the code as you did it and I am getting the same result as you EXCEPT on the print out, for some reason it is showing 0 when the eval should be -1 because it knows it's going to win, any idea what I did wrong?

  • @rebhuroy3713
    @rebhuroy3713 Жыл бұрын

    Hey thanks for preparing this video... I have coded it in Java but found in some corner cases it doesn't work.. can you help me to identify the issue

  • @sheafsmash142
    @sheafsmash142 Жыл бұрын

    Does anyone know the Color Theme that he uses? I liked the colors of the variables in the code @Coding Spot

  • @majdalotaibi5510
    @majdalotaibi5510 Жыл бұрын

    I have a question , I used ur code to my AI course and I need to make sure of something, how can I communicate with you please help me

  • @akhiltamgaonkar23
    @akhiltamgaonkar23 Жыл бұрын

    Hello ..I am getting an error offset is not defined.. Would you please tell me how do I fix it

  • @MrWhiteGorilla98
    @MrWhiteGorilla98 Жыл бұрын

    I follow the tutorial i get a good result but it can be beatable somehow if I start playing in some pos the ai doesn't mark the smart position I think its kinda see the fast move not the best move hope u understand me thanks

  • @laasd1613
    @laasd1613 Жыл бұрын

    What's the alternative way to write the code at 49:22?

  • @nishthasharma3161
    @nishthasharma31614 ай бұрын

    Hlo can u please tell me how to solve some error. Width is not defined

  • @user-jz2si1ew7s
    @user-jz2si1ew7s Жыл бұрын

    can u make the same project with android syudio?

  • @GrowWithArup23
    @GrowWithArup233 ай бұрын

    How to make "ai vs ai" mode? kindly help!!

  • @abderrahmanegorram
    @abderrahmanegorram Жыл бұрын

    i have an error in the move variable

  • @ChocoAnime465
    @ChocoAnime465 Жыл бұрын

    For some reason when the AI starts and my first move is in the centre, I will always win. Why's that?

  • @ThePackLeaderWolfe
    @ThePackLeaderWolfe2 жыл бұрын

    Hey would it be possible to implement this Ai into the tic tac toe game made with your previous tutorial?

  • @codingspot

    @codingspot

    2 жыл бұрын

    Sure, I did it this way because I think is much easier, but you can do it without classes and objects too

  • @ThePackLeaderWolfe

    @ThePackLeaderWolfe

    2 жыл бұрын

    @@codingspot Would it be possible for you to write out small sample code without objects and classes so i can get an idea of how i'd implement it into the old noughts and crosses python tutorial

  • @umutokcurmr
    @umutokcurmr Жыл бұрын

    where can i get the codes

  • @0Weath
    @0Weath Жыл бұрын

    can u add a score board with it

  • @nguyenthaihoc5192
    @nguyenthaihoc5192 Жыл бұрын

    can 4x4?

  • @WebDevXpert
    @WebDevXpert3 ай бұрын

    Tic Tac Toe Game in JavaScript | JS Project Day 1 | JavaScript Full Course : kzread.info/dash/bejne/foVtm8qHgZDSqrA.html

  • @RahulSingh-cl3wm
    @RahulSingh-cl3wm9 ай бұрын

    Can I ask basic question, why non maximising is ai player ? Can maximising be ai player?

  • @ajsingh3100
    @ajsingh31002 жыл бұрын

    are this video and that tic tac toe video which have 5 parts same? which video should i watch first? and can i use sublime text ?

  • @codingspot

    @codingspot

    2 жыл бұрын

    Hey! They are not the same, the one with 5 parts is the clasic player vs player tic tac toe game (easier). In this one you will add a computer to play against (harder).

  • @codingspot

    @codingspot

    2 жыл бұрын

    And sure you can use SublimeText or any other text editor, just make sure to have pygame installed.

  • @ajsingh3100

    @ajsingh3100

    2 жыл бұрын

    @@codingspot thank you so much

  • @namphan9317
    @namphan93172 жыл бұрын

    I tried to code based on your idea and found that if I let the AI goes first, specifically at grid (1, 1), there might be a chance that the AI doesn't win immediately. I wonder if you could try that on yourself and see if this is only my problem or because of how the mechanism of minimax work :D anyways, thanks for your help, I was able to finish my school's lab.

  • @brand_blitz

    @brand_blitz

    7 ай бұрын

    same issue

  • @xxtbge0457
    @xxtbge04572 жыл бұрын

    May i please ask that can i learn this if im like between intermediate and beginner ?

  • @codingspot

    @codingspot

    2 жыл бұрын

    Sure you can, I tried to make it beginner friendly. But you can also start with the normal tic tac toe tutorial which is easier.

  • @xxtbge0457

    @xxtbge0457

    2 жыл бұрын

    @@codingspot oh ok thanks:>>

  • @rajnigupta8581
    @rajnigupta85812 жыл бұрын

    Hey, can you help me out ? A bit urgent, I'm trying to implement a similar (4*4 tic tac toe) but getting an error here!

  • @codingspot

    @codingspot

    2 жыл бұрын

    Can you paste the error to see it

  • @rajnigupta8581

    @rajnigupta8581

    2 жыл бұрын

    @@codingspot It goes into infinite loop and throws an error on board not responding...Would you mind telling me a mode where I can share pic?

  • @codingspot

    @codingspot

    2 жыл бұрын

    You can send me it through Instagram

  • @sanghoaxuan2028

    @sanghoaxuan2028

    10 ай бұрын

    Have you fixed this error yet ?

  • @DancewithChhavi20
    @DancewithChhavi202 жыл бұрын

    half part was same in you older pvp series parts

  • @ajsingh3100
    @ajsingh31002 жыл бұрын

    please i need your help!!

  • @mohithrajds8852
    @mohithrajds88529 ай бұрын

    hello any one can send code of tic tac game

  • @armyegymox5530
    @armyegymox55302 жыл бұрын

    hi why no massage for who when

  • @renielmanalo7282
    @renielmanalo72822 жыл бұрын

    it doesn't work and it says error because of "numpy" what should I do?

  • @codingspot

    @codingspot

    2 жыл бұрын

    Make sure you have numpy installed

  • @renielmanalo7282

    @renielmanalo7282

    2 жыл бұрын

    @@codingspot nice! but one last question, how do you change the O and X to S and O? because we have a project and we need to change it to a SOS game but works like a TICTACTOE game. hope you can help

  • @codingspot

    @codingspot

    2 жыл бұрын

    You will need to change the method that draws the figures. Instead of drawing an 'X', you should draw an 'S' (try drawing it like the number 5 with 5 lines), the 'O' will be the same in your case.

  • @oumaimadguigou9882
    @oumaimadguigou98822 жыл бұрын

    I don't know why in the 26 minute the compilation shows up but once i click on the screen it disappears

  • @codingspot

    @codingspot

    2 жыл бұрын

    Is there any error showing up?

  • @oumaimadguigou9882

    @oumaimadguigou9882

    2 жыл бұрын

    It's oky I juste make an error Thank you so much for your efforts

  • @merarebbadro9328
    @merarebbadro9328 Жыл бұрын

    Please add the translation

  • @sachinjain6913
    @sachinjain6913 Жыл бұрын

    Shouldn't O be maximizing? Because it moves first????, Is it because we return -1 for the first player, Alright, Got it , great tutorial!

  • @TheMaskedDev
    @TheMaskedDev10 ай бұрын

    well i beat it

  • @OmarParyad-oi6um
    @OmarParyad-oi6um2 ай бұрын

    Please Active Subtitle I'm From Iran

  • @weirdfactsfromluka
    @weirdfactsfromluka2 жыл бұрын

    can you copy the code in here?have a great day!!!

  • @codingspot

    @codingspot

    2 жыл бұрын

    Code is too long to paste it here, but you can find it on my github (link on description)

  • @mohithrajds8852

    @mohithrajds8852

    9 ай бұрын

    brother it is not opening @@codingspot

  • @pantanlp7187
    @pantanlp7187 Жыл бұрын

    there is a problem with when the ai is starting... i mean the best possible move is to place it in the center cause its not necessarily a draw then cause the human player can still mess up but i mean the same counts for what its doing right now of course but the chances of winning are much better when starting in the center at least in a human sense.

  • @FR4NKTUB3
    @FR4NKTUB32 ай бұрын

    It's not AI tho