mchess-server/chess/rook.go

41 lines
1.0 KiB
Go
Raw Normal View History

package chess
2023-06-27 20:32:24 +00:00
import (
"mchess_server/types"
)
type Rook struct {
Color types.ChessColor
}
2023-06-27 20:32:24 +00:00
func (r Rook) GetAllAttackedSquares(board Board, fromSquare types.Coordinate) []types.Coordinate {
return r.GetAllNonBlockedMoves(board, fromSquare)
}
func (r Rook) GetColor() types.ChessColor {
return r.Color
}
2023-06-27 20:32:24 +00:00
func (r Rook) GetAllNonBlockedMoves(board Board, fromSquare types.Coordinate) []types.Coordinate {
return board.GetNonBlockedRowAndColumn(fromSquare)
}
2023-07-05 19:15:01 +00:00
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
}
}
}