From c205c4dc866cbcf27153899c8d7c031720d10052 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 14 Jun 2023 00:59:16 +0200 Subject: [PATCH] Comments to not forget how to check checkmate --- chess/board.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/chess/board.go b/chess/board.go index 86a7ce8..3e65695 100644 --- a/chess/board.go +++ b/chess/board.go @@ -46,10 +46,31 @@ func (b Board) GetPieceAt(coord types.Coordinate) (types.Piece, bool) { return piece, found } func (b *Board) CheckMove(move types.Move) (bool, string) { - _, found := b.GetPieceAt(move.StartSquare) + pieceAtStartSquare, found := b.GetPieceAt(move.StartSquare) if !found { return false, "no piece at start square" } + pieceAtEndSquare, found := b.GetPieceAt(move.EndSquare) + if found { + if pieceAtEndSquare.Color == pieceAtStartSquare.Color { + return false, "same-coloured piece at end square" + } + } + + //Check if king of moving color is in check -> move not allowed + //Do that by checking if the king is in a square attacked by the other color. + + //Check for checkmate + //Is every square that the king can move to attacked? And can no other + //piece block? -> checkmate + + //Maybe for checking checkmate, we have to check the 'path' in which the + //checkmate is given + + // |K| | | | |Q| + // in this scenaria the path are all the squares between queen and king. + // If a piece can be moved into the path, it is no checkmate + return true, "" }