diff --git a/chess/game.go b/chess/game.go index 70d07c7..ea2c283 100644 --- a/chess/game.go +++ b/chess/game.go @@ -161,20 +161,20 @@ func (game Game) notifyPlayersAboutGameStart() error { } game.GetPlayer1().writeMessage(colorDeterminedPlayer1) - game.GetPlayer1().SendBoardState(game.board.PGN(), types.White) + game.GetPlayer1().SendBoardState(types.Move{}, game.board.PGN(), types.White) game.GetPlayer2().writeMessage(colorDeterminedPlayer2) - game.GetPlayer2().SendBoardState(game.board.PGN(), types.Black) + game.GetPlayer2().SendBoardState(types.Move{}, game.board.PGN(), types.White) return nil } func (game Game) broadcastMove(move types.Move) error { - err := game.GetPlayer1().SendMoveAndPosition(move, game.board.PGN()) + err := game.GetPlayer1().SendBoardState(move, game.board.PGN(), game.currentTurnPlayer.color) if err != nil { return err } - err = game.GetPlayer2().SendMoveAndPosition(move, game.board.PGN()) + err = game.GetPlayer2().SendBoardState(move, game.board.PGN(), game.currentTurnPlayer.color) if err != nil { return err } diff --git a/chess/player.go b/chess/player.go index 13d5348..28d2b57 100644 --- a/chess/player.go +++ b/chess/player.go @@ -45,7 +45,7 @@ func (p *Player) SetWebsocketConnectionAndSendBoardState( turnColor types.ChessColor, ) { p.SetWebsocketConnection(ctx, ws) - p.SendBoardState(boardPosition, turnColor) + p.SendBoardState(types.Move{}, boardPosition, turnColor) } func (p *Player) SetDisconnectCallback(cb func(*Player)) { @@ -62,13 +62,14 @@ func (p *Player) IsInGame() bool { return p.hasWebsocketConnection() } -func (p *Player) SendBoardState(boardPosition string, turnColor types.ChessColor) error { +func (p *Player) SendBoardState(move types.Move, boardPosition string, turnColor types.ChessColor) error { var pColor = p.color if p.color == "" { // we default to white if we do not know the color yet pColor = types.White } messageToSend, err := json.Marshal(api.WebsocketMessage{ + Move: &move, Type: api.BoardStateMessage, TurnColor: &turnColor, PlayerColor: &pColor,