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