mchess-server/types/common.go
2023-06-14 19:46:46 +02:00

44 lines
761 B
Go

package types
type Coordinate struct {
Col int `json:"col"`
Row int `json:"row"`
}
type Move struct {
StartSquare Coordinate `json:"startSquare"`
EndSquare Coordinate `json:"endSquare"`
}
type PieceClass string
const (
Pawn PieceClass = "pawn"
Rook PieceClass = "rook"
Knight PieceClass = "knight"
Bishop PieceClass = "bishop"
Queen PieceClass = "queen"
King PieceClass = "king"
)
type ChessColor string
const (
White ChessColor = "white"
Black ChessColor = "black"
)
func (c ChessColor) Opposite() ChessColor {
if c == White {
return Black
} else {
return White
}
}
type Piece struct {
Class PieceClass
Color ChessColor
HasMoved bool //we need this for pawns (first move is special) and rooks+king (for castling)
}