Skip to content

Commit

Permalink
Uses "Black"/"White" instead of 'b'/'w' for turn. Fixes defaultGame.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Gappa committed Dec 28, 2019
1 parent e0699ed commit bd847de
Show file tree
Hide file tree
Showing 12 changed files with 416 additions and 473 deletions.
4 changes: 2 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func (a API) DefaultGame() OutputGame {
return mapGameToOutputGame(defaultGame)
}

func (a API) ParseGame(g InputGame) (OutputGame, error) {
parsedGame, err := a.parseGame(g)
func (a API) ParseGame(game InputGame) (OutputGame, error) {
parsedGame, err := a.parseGame(game)
if err != nil {
return OutputGame{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion api/api_entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Board struct {
HalfMoveClock int `json:"halfMoveClock"`
FullMoveNumber int `json:"fullMoveNumber"`
EnPassantTargetSquare string `json:"enPassantTargetSquare"` // in Algebraic notation, or empty string
Turn byte `json:"turn"` // 'b' or 'w'
Turn string `json:"turn"` // "Black" or "White"
}

type OutputGame struct {
Expand Down
6 changes: 3 additions & 3 deletions api/bishop_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestBishopActions(t *testing.T) {
"♙♙♙♙♙♙♙♙",
"♖♘♗♕♔♗♘♖",
},
turn: 'b',
turn: "Black",
},
color: colorBlack,
xy: xy{3, 3},
Expand All @@ -47,7 +47,7 @@ func TestBishopActions(t *testing.T) {
"♙♙ ♙♙",
"♖♘ ♕♔♗♘♖",
},
turn: 'w',
turn: "White",
},
color: colorWhite,
xy: xy{3, 4},
Expand All @@ -66,7 +66,7 @@ func TestBishopActions(t *testing.T) {
"♙♙♙ ♙♙♙♙",
"♖♘ ♕♔♗♘♖",
},
turn: 'w',
turn: "White",
},
color: colorWhite,
xy: xy{3, 4},
Expand Down
12 changes: 6 additions & 6 deletions api/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type board struct {
halfMoveClock int
fullMoveNumber int
enPassantTargetSquare string // in Algebraic notation, or empty string
turn byte // 'b' or 'w'
turn string // "Black" or "White"
}

var (
errBoardInvalidEnPassantTargetSquare = fmt.Errorf("enPassantTargetSquare must be either empty string or valid algebraic notation square e.g. d6")
errBoardTurnMustBeBlackOrWhite = fmt.Errorf("turn must be either 'b' or 'w'")
errBoardTurnMustBeBlackOrWhite = fmt.Errorf("turn must be either Black or White")
errBoardDuplicateKing = fmt.Errorf("board has two kings of the same color")
errBoardKingMissing = fmt.Errorf("board is missing one of the kings")
errBoardDimensionsWrong = fmt.Errorf("board dimensions are wrong; should be 8x8")
Expand Down Expand Up @@ -53,10 +53,10 @@ func newGameFromBoard(b board) (game, error) {
}

// Move number
if b.turn != 'b' && b.turn != 'w' {
if b.turn != "Black" && b.turn != "White" {
return game{}, errBoardTurnMustBeBlackOrWhite
}
if b.turn == 'b' {
if b.turn == "Black" {
g.moveNumber++
}

Expand Down Expand Up @@ -208,10 +208,10 @@ func (g game) toBoard() board {
halfMoveClock: g.halfMoveClock,
fullMoveNumber: g.fullMoveNumber,
enPassantTargetSquare: "",
turn: 'b',
turn: "Black",
}
if g.turn() == colorWhite {
result.turn = 'w'
result.turn = "White"
}
if g.isLastMoveEnPassant {
result.enPassantTargetSquare = fmt.Sprintf("%v%v", "abcdefgh"[g.enPassantTargetSquare.x], 8-g.enPassantTargetSquare.y)
Expand Down
Loading

0 comments on commit bd847de

Please sign in to comment.