Programming a Chess Game in C# | Part 8 - Detect Check & Legal Moves

Опубликовано: 07 Август 2026
на канале: OttoBotCode
7,883
143

Learn how to program a Chess game in C#!

Welcome to part 8 of my C# Chess tutorial.
Have you noticed that our game sometimes generates moves that are illegal? That's because it's never allowed to make any move that leaves your king in check.

In this part, we write code that can detect if a player is in check or not
and use it to filter out all illegal moves. Next time, we'll also use the check detection code to handle checkmate and stalemate as well!

Assets:
https://ottobotcode.com/chess/ChessAs...

Source code is available here:
  / 78701  

Chapters:
0:00 - Illegal Moves?
0:19 - Examples
1:55 - Plan
2:28 - CanCaptureOpponentKing
4:09 - Override For Pawn
5:27 - Override For King
6:45 - Detect Check
10:06 - Copy The Board
11:57 - Legal Move Algorithm
14:01 - Removing Illegal Moves
15:00 - Success!