How to Program a Connect 4 AI (implementing the minimax algorithm)

preview_player
Показать описание
Learn data skills with hands-on exercises & tutorials at Datacamp!

In this video we take the connect 4 game that we built in the How to Program Connect 4 in Python series and add an expert level AI to it. We start out with a very simple implementation of just dropping a piece randomly and then progress to choosing a column based on score and then finally implementing the minimax algorithm with alpha beta pruning.

To build the game we started out with, watch these four videos:

Follow me on social media too please :)

Thanks for watching! Hope you all learning something

SUBSCRIBE to not miss out on any future videos

---------------------

Join the Python Army to get access to perks!

*I use affiliate links on the products that I recommend. I may earn a purchase commission or a referral bonus from the usage of these links.
Рекомендации по теме
Комментарии
Автор

Hey Keith, thank you so much for this series

I had an assignment about this in university and I followed your entire series and programmed along, this helped so much. Lately university has been stressing me out lately, but this series helped me enjoy programming again, thank you

abdulrahmanalsaleh
Автор

This was pretty damn hard but when i got the hang of it, it really worked.Thank you Keith you are a great teacher i thank you a lot.I have now got an A* in computing for A-levels thx a lot.

schhatani
Автор

Great video! Thanks a lot for this. You are making a subject that at first seemed hard and daunting much easier to understand and I will now try to implement my own minimax algorithm!

YoutubAcccount
Автор

Excellent series explaining nuances of Connect 4 and implementation of MinMax. God Bless You.

asheeshmathur
Автор

Amazing, I’ve been looking for this for a long time !

NicolasSchmidMusic
Автор

Loved the way, interactivity and such programmer stuffs- producing silly sounds in between. I hope we could get a professor like you... Anyways thanks a lot, it was really helpful.

ashwanivarshney
Автор

Thank you so much for this series, you make coding n algorithms more understandable n funn!!

kaverirv
Автор

4:48 small quirk
you can have
for ...:
...
else:
...

what it does is it will execute the else only if you didn't break out of the loop
(also works with while)

jgtbpl
Автор

I want to say that I made My project for University AI Lecture upon your Video, Thanks a lot

AMG
Автор

Thanks a lot for the series, help me a lot for assignment

junlun
Автор

Thanks mate. Spent hours trying to understand the blog by Pascal Pons and still got lost. But this has totally made it easy to understand (and the code helps as well).
Just on making the start turn random (at 11:07), it might be easier for the player to choose red or yellow as red always starts...

Ruskin
Автор

50:42 the part when minimax algorithm gets iplemented

Kirsehirliable
Автор

in sublime press alt+shift+2 for a 2 column layout to minimize alt tabbing
or alt+shift+8 for a 2 row layout
menu > view > layout

TheNewton
Автор

Thank you so much for all of your videos, it is helping me a lot through uni!!

bananaeater
Автор

Thank you so much for this video! Helped a lot with my assignment :)

ayusharora
Автор

Thank you SOOO much!! You are unbelievably amazing!! <3

leakoussaifi
Автор

Questions if you're still active on this vid:
1. I see this uses heuristic eval at a depth of 6 or so - does that mean it has imperfect play? Or is the game simple enough that the heuristic converges on perfect play even with very limited depth?
2. Does the alpha-beta pruning cut off enough of the tree that you can unlimit depth and go all the way to the leaf nodes?
3. How can such a low depth give successful moves if it takes at least 4 turns = 8 ply to build any winning chain?

I have written a solver in Rust and I want perfect play - I have sped it up via pruning, memoization, and heuristic sorting of child nodes. I have no heuristic return statement because I want perfect play, but it seems that without a heuristic return to cut off the depth that the tree is too big for live time results even with my optimizations.

AMPolymath
Автор

Great tutorial, thanks!

I'm completely lost against the AI, cannot beat it on depth 4. :-D

BodinhoDE
Автор

The time delay for the random AI: Ian Bell - before he cowrote the game Elite (famous in 1980s UK home computer game history) - wrote an Othello game with its own AI, which again worked so fast that he too had to put a fake delay for a game on the old BBC Micro :)

SuperBartles
Автор

OK, i found it! Thanks for making this. BTW, vids1-4 were lots of fun - and educational.

serenityrahn