Coding a Complete Chess Game AI With Python (Part 1) | PVP Game Mode

preview_player
Показать описание
In this tutorial I will show how to code a fully functional chess game from scratch, with both player vs player and artificial intelligence game modes, using object-oriented programming, the minimax algorithm, Python and its Pygame module.

LINKS:
- Part 2 (AI Game mode): Soon...

FOLLOW FOR MORE:

⏱ TIMESTAMPS ⏱
00:00 Introduction
4:34 Game Structure (UML)
17:13 Initial Setup
24:42 Rendering Board
31:31 Console Board
39:02 Creating Pieces
1:07:50 Dragger
1:37:07 Checking Valid Moves
3:01:36 Moving Pieces
3:37:36 Game Design Config
4:10:21 Restart Function
4:12:14 Pawn Promotion
4:17:09 Castling
4:33:18 Game Checks
4:58:32 En Passant
5:35:05 Castling Bug
5:36:23 End
Рекомендации по теме
Комментарии
Автор

Bro Part 2 is much needed so we can understand actual AI. Thanks a lot👏

saravanajogan
Автор

How is this so unpopular? One of the most underrated channels😢
Hope you will be doing part 2❤

mmzh
Автор

If the 2nd part comes, I want to translate the IA to Eddie Sharick's project.
Eddie Sharick don't have a Piece class, but his board can recognize his pieces colors (letter 'w' for White and 'b' for Black). Sharick's moving methods is ranged in a move fonctions dictionary, and he have self.pins and self.checks listes to check pins and checks, a class CastleRights of 4 booleans for kingside castle and queenside castle. His class GameState is a complete controller for valid moves

marcmailly
Автор

cant wait to give it a go i've been coding python for 6 months and this project will look good in the portfolio!

brotherjoecarden
Автор

Great video ! There are some bugs though. The king can't make certain moves when he is in check and he can castle when he is in check or by crossing forbidden squares. Also missing is the ability to promote a pawn to a piece other than the queen. Finally, it is necessary to detect the different ways to make a draw (repetition, 50 moves rule, stalemate...). An animation to indicate the end of the game would also be nice. Good luck to solve all these problems and to code the AI. I hope the second part will be released soon and I'm looking forward to it !

pitwolff
Автор

This has been extremely helpful! Thank you for your time and effort!
Cannot wait for part 2!! <3

wiemsaadi
Автор

Still waiting for part 2... this is so sad. Whatever you're doing coding spot, I hope you're well. Loved the video, this was my first real experience with coding a game and you made this first experience so joyful; so thanks a lot.

tripl_t
Автор

great video, looking foward to your next part. One thing i want to talk about your chess code, you forgot at the castling method that when the castling "road" is threatened by some enemy pieces, the king should not able to castling. But doesn't matter, thank you for the awesome video. Last but not least, when you get excited each time your code works made me get passion

namphan
Автор

This is amazing!
You deserve more subs bro. Any news on Part 2?

anonymuz
Автор

This is an such an amazing and in-depth project !! I loved the part where you showed the UML diagrams and the intuition behind each function ! Can't wait for part-2 ! <3

qsjzxdg
Автор

Since I don't see this mentioned, I needed to add "../" to the beginning of the path pointing to the assets folder, in order for python to find the chess piece images. It may have something to do with my interpreter's default "working directory", but anyways, "../" is how you get one more step up a file path tree structure. It has to go up one step from "src" in order to find "assets".

autoCHADsoftware
Автор

There is actually a nicer way of avoiding putting the king in check. This method does not need any copy or simulating all possible moves, it does not need to check for all opponent's possible moves. It works like this.... you must have tracked the kings position every move and save it. Make the move even if it puts the king in check, from there check from the king's position if any piece attacks it by looking at capture moves from the king's position. If it results in a capture, just undo the move. it happens really fast you wont see the invalid move being executed. The idea is that you make a function that assumes the king can move like a queen, bishop, rook, knight or pawn capture.

It is much simpler coz you are only checking from the king's position to move like any other attacking pieces, if they are present from these attacking positions, then that means the last move is invalid so undo the move.

WaveTreader
Автор

Bro your explaination is best pls upload part 2 soon waiting for it eagerly🙌❤

rahulgaikwad
Автор

Hey man! Absolutely amazing video, I learnt so much. Are you going to release part 2 with an Ai version and also fixing all the bugs listed in the comments? Would be amazing if you could!! Thank you

DistinctInstinct
Автор

I'm learning a lot from you Mister! You should add an option for donation for coffee to support you doing this great work.

EugeneMedved
Автор

I just love your tutorials!! They are just amazing

jugujogurt
Автор

Awesome work! Im sure you put a lot of effort in it! I am a passionate chess player and data scientist and I always wanted to code my own Chess game and Chess AI. This is perfect for me!

baronharkonnenaoe
Автор

pls bro give part 2... part 1 very gud and helpful tysm!!!

theanonymousghoul
Автор

Hi. Congratulations on your video. It has helped me a lot. I've just started my doctorate in architecture, studying artificial intelligence applied to it. This was my first real contact with Python, and your video helped me a lot. Can you say when you are going to make the second part available? Thanks.

andrebarcellosferreira
Автор

Wow, keep it up your tutorials. This chess game is the best for beginner in python like me.this is the best tutorials.

Jheter-Pisowifi
join shbcf.ru