Marco
ff2ec599fe
In order to simplify special moves like en passant or castling for the client, we want to deliver the board state after every move (and not only start square and end square). With PGN we can encode a chess position into a string. This commit implies changes to logic of the pieces' shortnames. This will break the client/server connection (at least for promotions).
41 lines
956 B
Go
41 lines
956 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.GetAllNonBlockedMoves(board, fromSquare)
|
|
}
|
|
|
|
func (r Rook) GetColor() types.ChessColor {
|
|
return r.Color
|
|
}
|
|
|
|
func (r Rook) GetAllNonBlockedMoves(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
|
|
}
|
|
}
|
|
}
|