mchess-server/chess/piece_interface.go

51 lines
948 B
Go
Raw Normal View History

package chess
import (
2023-06-25 14:11:29 +00:00
"mchess_server/types"
)
type Piece interface {
2023-06-27 20:32:24 +00:00
GetAllNonBlockedMoves(board Board, fromSquare types.Coordinate) []types.Coordinate
GetAllAttackedSquares(board Board, fromSquare types.Coordinate) []types.Coordinate
GetColor() types.ChessColor
2023-06-25 14:11:29 +00:00
}
2023-06-25 22:51:20 +00:00
func GetPieceForShortName(name types.PieceShortName, color types.ChessColor) Piece {
2023-06-25 14:11:29 +00:00
var piece Piece
switch name {
case 'p':
2023-06-25 22:51:20 +00:00
piece = Pawn{Color: color}
2023-06-25 14:11:29 +00:00
case 'q':
2023-06-25 22:51:20 +00:00
piece = Queen{Color: color}
2023-06-25 14:11:29 +00:00
case 'k':
2023-06-25 22:51:20 +00:00
piece = King{Color: color}
2023-06-25 14:11:29 +00:00
case 'b':
2023-06-25 22:51:20 +00:00
piece = Bishop{Color: color}
2023-06-25 14:11:29 +00:00
case 'r':
2023-06-25 22:51:20 +00:00
piece = Rook{Color: color}
2023-06-25 14:11:29 +00:00
case 'n':
2023-06-25 22:51:20 +00:00
piece = Knight{Color: color}
2023-06-25 14:11:29 +00:00
}
return piece
}
2023-06-25 22:51:20 +00:00
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
}