From 6c983e07955f48fe41d2cd6ec4874a59dc41a15c Mon Sep 17 00:00:00 2001 From: luxick Date: Wed, 20 Nov 2019 19:43:43 +0100 Subject: [PATCH] Check if the game has already ended before making a move. --- src/libmttt.nim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libmttt.nim b/src/libmttt.nim index aba04c2..f72b6b3 100644 --- a/src/libmttt.nim +++ b/src/libmttt.nim @@ -136,11 +136,13 @@ proc checkBoard*(board: Board[Board[Mark]]): Mark = # Process Player Moves ################################################### -proc makeMove*(state: GameState, cell: Coordinate): GameState = +proc makeMove*(state: GameState, cell: Coordinate): GameState = + if state.result != Mark.Free: + raise newException(IllegalMoveError, "The game has already ended") if cell.x > 2 or cell.y > 2: raise newException(IndexError, "Move target not in bounds of the board") if state.currentBoard.isNone: - raise newException(ValueError, "No board value passed") + raise newException(IllegalMoveError, "No board value passed") let board = state.currentBoard.get() var currBoard = state.board[board.x][board.y] @@ -167,7 +169,9 @@ proc makeMove*(state: GameState, cell: Coordinate): GameState = return state -proc makeMove*(state: GameState, cell: Coordinate, boardChoice: Coordinate): GameState = +proc makeMove*(state: GameState, cell: Coordinate, boardChoice: Coordinate): GameState = + if state.result != Mark.Free: + raise newException(IllegalMoveError, "The game has already ended") if checkBoard(state.board[boardChoice.x][boardChoice.y]) != Mark.Free: raise newException(IllegalMoveError, "Player must choose an open board to play in") if state.currentBoard.isSome: