mchess-server/chess/piece_interface.go

52 lines
1008 B
Go

package chess
import (
"mchess_server/types"
)
type Piece interface {
GetAllNonBlockedMoves(board Board, fromSquare types.Coordinate) []types.Coordinate
GetAllAttackedSquares(board Board, fromSquare types.Coordinate) []types.Coordinate
GetColor() types.ChessColor
AfterMoveAction(board *Board, fromSquare types.Coordinate)
}
func GetPieceForShortName(name types.PieceShortName, color types.ChessColor) Piece {
var piece Piece
switch name {
case "p":
piece = Pawn{Color: color}
case "q":
piece = Queen{Color: color}
case "k":
piece = King{Color: color}
case "b":
piece = Bishop{Color: color}
case "r":
piece = Rook{Color: color}
case "n":
piece = Knight{Color: color}
}
return piece
}
func GetShortNameForPiece(piece Piece) types.PieceShortName {
var name types.PieceShortName
switch piece.(type) {
case Pawn:
name = "p"
case Queen:
name = "q"
case King:
name = "k"
case Bishop:
name = "b"
case Rook:
name = "r"
case Knight:
name = "n"
}
return name
}