mchess-server/chess/rook.go
Marco af993876fd Introduce check if the game has ended (checkmate/stalemate)
Introduce checkmate check and send out 'gameEnded' message
2024-01-17 23:06:48 +01:00

41 lines
960 B
Go

package chess
import (
"mchess_server/types"
)
type Rook struct {
Color types.ChessColor
}
func (r Rook) GetAllAttackedSquares(board Board, fromSquare types.Coordinate) []types.Coordinate {
return r.GetAllNonBlockedSquares(board, fromSquare)
}
func (r Rook) GetColor() types.ChessColor {
return r.Color
}
func (r Rook) GetAllNonBlockedSquares(board Board, fromSquare types.Coordinate) []types.Coordinate {
return board.GetNonBlockedRowAndColumn(fromSquare)
}
func (r Rook) AfterMoveAction(board *Board, fromSquare types.Coordinate) {
switch r.Color {
case types.Black:
if fromSquare.Col == types.RangeLastValid {
board.state.BlackHRookMoved = true
}
if fromSquare.Col == types.RangeFirstValid {
board.state.BlackARookMoved = true
}
case types.White:
if fromSquare.Col == types.RangeLastValid {
board.state.WhiteHRookMoved = true
}
if fromSquare.Col == types.RangeFirstValid {
board.state.WhiteARookMoved = true
}
}
}