Learn how to program a Chess game in C#!
Welcome to part 13 of my C# Chess tutorial.
In this video we add Castling moves the the game, both king side and queen side!
We start by writing a "Castle" class which represents both types of castling moves.
The execute method moves both the player's king, and one of their rooks, at once.
Next, we add some logic in the King class which generates castling moves if two conditions are met:
a) Neither the king nor rook may have moved
b) There are no pieces between the king and the rook
Finally, we override the IsLegal method for castling moves.
This method must check that:
a) The king is not in check before the move
b) The king will not move through or into check
Assets:
https://ottobotcode.com/chess/ChessAs...
Source code is available here:
/ 78701
Chapters:
0:00 - Plan & Castling Moves
1:00 - Castling Rules
2:10 - Castle Class
6:24 - Execute Castling Move
7:22 - Generate Castling Move
9:53 - King Side Legality
11:57 - Queen Side Legality
14:20 - Obey Check Rules
17:26 - Celebration Time?
18:06 - Test Rules
19:30 - Next Part