2023-06-20 21:53:54 +00:00
|
|
|
package chess
|
|
|
|
|
2023-06-27 20:32:24 +00:00
|
|
|
import (
|
|
|
|
"mchess_server/types"
|
|
|
|
)
|
2023-06-20 21:53:54 +00:00
|
|
|
|
|
|
|
type Rook struct {
|
2023-06-26 21:58:40 +00:00
|
|
|
Color types.ChessColor
|
2023-06-20 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 20:32:24 +00:00
|
|
|
func (r Rook) GetAllAttackedSquares(board Board, fromSquare types.Coordinate) []types.Coordinate {
|
2024-01-17 16:38:06 +00:00
|
|
|
return r.GetAllNonBlockedSquares(board, fromSquare)
|
2023-06-27 20:32:24 +00:00
|
|
|
}
|
|
|
|
|
2023-06-20 21:53:54 +00:00
|
|
|
func (r Rook) GetColor() types.ChessColor {
|
|
|
|
return r.Color
|
|
|
|
}
|
|
|
|
|
2024-01-17 16:38:06 +00:00
|
|
|
func (r Rook) GetAllNonBlockedSquares(board Board, fromSquare types.Coordinate) []types.Coordinate {
|
2023-06-27 20:32:24 +00:00
|
|
|
return board.GetNonBlockedRowAndColumn(fromSquare)
|
2023-06-20 21:53:54 +00:00
|
|
|
}
|
2023-07-05 19:15:01 +00:00
|
|
|
|
|
|
|
func (r Rook) AfterMoveAction(board *Board, fromSquare types.Coordinate) {
|
|
|
|
switch r.Color {
|
|
|
|
case types.Black:
|
2023-08-12 09:24:40 +00:00
|
|
|
if fromSquare.Col == types.RangeLastValid {
|
|
|
|
board.state.BlackHRookMoved = true
|
|
|
|
}
|
|
|
|
if fromSquare.Col == types.RangeFirstValid {
|
|
|
|
board.state.BlackARookMoved = true
|
|
|
|
}
|
2023-07-05 19:15:01 +00:00
|
|
|
case types.White:
|
2023-08-12 09:24:40 +00:00
|
|
|
if fromSquare.Col == types.RangeLastValid {
|
|
|
|
board.state.WhiteHRookMoved = true
|
|
|
|
}
|
|
|
|
if fromSquare.Col == types.RangeFirstValid {
|
|
|
|
board.state.WhiteARookMoved = true
|
|
|
|
}
|
2023-07-05 19:15:01 +00:00
|
|
|
}
|
|
|
|
}
|