Comments to not forget how to check checkmate
This commit is contained in:
parent
060ac8ad9e
commit
c205c4dc86
@ -46,10 +46,31 @@ func (b Board) GetPieceAt(coord types.Coordinate) (types.Piece, bool) {
|
|||||||
return piece, found
|
return piece, found
|
||||||
}
|
}
|
||||||
func (b *Board) CheckMove(move types.Move) (bool, string) {
|
func (b *Board) CheckMove(move types.Move) (bool, string) {
|
||||||
_, found := b.GetPieceAt(move.StartSquare)
|
pieceAtStartSquare, found := b.GetPieceAt(move.StartSquare)
|
||||||
if !found {
|
if !found {
|
||||||
return false, "no piece at start square"
|
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, ""
|
return true, ""
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user