Remove leading number from move message.

This commit is contained in:
Marco 2022-12-21 23:12:19 +01:00
parent f303a572cc
commit b0db6145e8
2 changed files with 9 additions and 4 deletions

View File

@ -21,9 +21,13 @@ func parseMove(received string) (*chessMove, error) {
splitReceived := strings.Split(received, " ")
realMoveString := splitReceived[1]
startSquareString := splitReceived[2]
endSquareString := splitReceived[3]
if len(splitReceived) != 3 {
return nil, errors.New("invalid move command")
}
realMoveString := splitReceived[0]
startSquareString := splitReceived[1]
endSquareString := splitReceived[2]
if strings.Compare(realMoveString, "mv") == 0 {
move.realMove = true

View File

@ -67,12 +67,13 @@ func (game *chessGame) handle() {
return
}
move, err = parseMove(string(receivedMessage))
log.Println("Player 1 moved: ", move)
if err != nil {
log.Println("Game: ", game.id, err)
return
}
log.Println("Player 1 moved: ", move)
gameState = CheckPlayerChange
case CheckPlayerChange: