Promotions should work now.
This commit is contained in:
parent
b052d8e21c
commit
c8407881bf
@ -145,7 +145,7 @@ func Test_CheckMove_validPromotion(t *testing.T) {
|
|||||||
|
|
||||||
board.position[types.Coordinate{Col: 7, Row: 7}] = King{Color: types.Black}
|
board.position[types.Coordinate{Col: 7, Row: 7}] = King{Color: types.Black}
|
||||||
|
|
||||||
shortName := types.QueenShortName
|
shortName := types.QueenShortName.String()
|
||||||
move := types.Move{
|
move := types.Move{
|
||||||
StartSquare: types.Coordinate{Col: 1, Row: 7},
|
StartSquare: types.Coordinate{Col: 1, Row: 7},
|
||||||
EndSquare: types.Coordinate{Col: 1, Row: 8},
|
EndSquare: types.Coordinate{Col: 1, Row: 8},
|
||||||
@ -192,19 +192,19 @@ func Test_CheckMove_HistoryWorks(t *testing.T) {
|
|||||||
{
|
{
|
||||||
StartSquare: types.Coordinate{Col: 1, Row: 2},
|
StartSquare: types.Coordinate{Col: 1, Row: 2},
|
||||||
EndSquare: types.Coordinate{Col: 1, Row: 3},
|
EndSquare: types.Coordinate{Col: 1, Row: 3},
|
||||||
PieceMoved: 'p',
|
PieceMoved: "p",
|
||||||
ColorMoved: "white",
|
ColorMoved: "white",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StartSquare: types.Coordinate{Col: 3, Row: 7},
|
StartSquare: types.Coordinate{Col: 3, Row: 7},
|
||||||
EndSquare: types.Coordinate{Col: 3, Row: 5},
|
EndSquare: types.Coordinate{Col: 3, Row: 5},
|
||||||
PieceMoved: 'p',
|
PieceMoved: "p",
|
||||||
ColorMoved: "black",
|
ColorMoved: "black",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StartSquare: types.Coordinate{Col: 1, Row: 3},
|
StartSquare: types.Coordinate{Col: 1, Row: 3},
|
||||||
EndSquare: types.Coordinate{Col: 1, Row: 4},
|
EndSquare: types.Coordinate{Col: 1, Row: 4},
|
||||||
PieceMoved: 'p',
|
PieceMoved: "p",
|
||||||
ColorMoved: "white",
|
ColorMoved: "white",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ func (p *Pawn) HandlePossiblePromotion(b *Board, move types.Move) bool {
|
|||||||
messageContainsPromotion := move.IsPromotionMove()
|
messageContainsPromotion := move.IsPromotionMove()
|
||||||
|
|
||||||
if messageContainsPromotion {
|
if messageContainsPromotion {
|
||||||
promotionToPiece = *move.PromotionToPiece
|
promotionToPiece = types.PieceShortName(*move.PromotionToPiece)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch move.ColorMoved {
|
switch move.ColorMoved {
|
||||||
|
@ -14,17 +14,17 @@ func GetPieceForShortName(name types.PieceShortName, color types.ChessColor) Pie
|
|||||||
var piece Piece
|
var piece Piece
|
||||||
|
|
||||||
switch name {
|
switch name {
|
||||||
case 'p':
|
case "p":
|
||||||
piece = Pawn{Color: color}
|
piece = Pawn{Color: color}
|
||||||
case 'q':
|
case "q":
|
||||||
piece = Queen{Color: color}
|
piece = Queen{Color: color}
|
||||||
case 'k':
|
case "k":
|
||||||
piece = King{Color: color}
|
piece = King{Color: color}
|
||||||
case 'b':
|
case "b":
|
||||||
piece = Bishop{Color: color}
|
piece = Bishop{Color: color}
|
||||||
case 'r':
|
case "r":
|
||||||
piece = Rook{Color: color}
|
piece = Rook{Color: color}
|
||||||
case 'n':
|
case "n":
|
||||||
piece = Knight{Color: color}
|
piece = Knight{Color: color}
|
||||||
}
|
}
|
||||||
return piece
|
return piece
|
||||||
@ -34,17 +34,17 @@ func GetShortNameForPiece(piece Piece) types.PieceShortName {
|
|||||||
var name types.PieceShortName
|
var name types.PieceShortName
|
||||||
switch piece.(type) {
|
switch piece.(type) {
|
||||||
case Pawn:
|
case Pawn:
|
||||||
name = 'p'
|
name = "p"
|
||||||
case Queen:
|
case Queen:
|
||||||
name = 'q'
|
name = "q"
|
||||||
case King:
|
case King:
|
||||||
name = 'k'
|
name = "k"
|
||||||
case Bishop:
|
case Bishop:
|
||||||
name = 'b'
|
name = "b"
|
||||||
case Rook:
|
case Rook:
|
||||||
name = 'r'
|
name = "r"
|
||||||
case Knight:
|
case Knight:
|
||||||
name = 'n'
|
name = "n"
|
||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package types
|
|||||||
type Move struct {
|
type Move struct {
|
||||||
StartSquare Coordinate `json:"startSquare"`
|
StartSquare Coordinate `json:"startSquare"`
|
||||||
EndSquare Coordinate `json:"endSquare"`
|
EndSquare Coordinate `json:"endSquare"`
|
||||||
PieceMoved PieceShortName
|
PromotionToPiece *string `json:"promotionToPiece,omitempty"`
|
||||||
ColorMoved ChessColor
|
ColorMoved ChessColor
|
||||||
PromotionToPiece *PieceShortName `json:"promotionToPiece,omitempty"`
|
PieceMoved PieceShortName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Move) IsPromotionMove() bool {
|
func (m Move) IsPromotionMove() bool {
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
type PieceShortName rune
|
type PieceShortName string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PawnShortName PieceShortName = 'p'
|
PawnShortName PieceShortName = "p"
|
||||||
RookShortName PieceShortName = 'r'
|
RookShortName PieceShortName = "r"
|
||||||
KnightShortName PieceShortName = 'n'
|
KnightShortName PieceShortName = "n"
|
||||||
BishopShortName PieceShortName = 'b'
|
BishopShortName PieceShortName = "b"
|
||||||
QueenShortName PieceShortName = 'q'
|
QueenShortName PieceShortName = "q"
|
||||||
KingShortName PieceShortName = 'k'
|
KingShortName PieceShortName = "k"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (p PieceShortName) String() string {
|
||||||
|
return string(p)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user