Skip to content

Commit a6599bf

Browse files
committed
Add a safety check on the which spaces are chosen
1 parent e73e67e commit a6599bf

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

ticTacToe.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ class TicTacToeBoard() {
461461
}
462462

463463
def setSpaceOwner(space : Int, newOwner : String) {
464+
if (space < 1 || space > 9) {
465+
throw new InvalidParameter(s"A player tried to move to space ${space}, which is not a valid space on the Tic-tac-toe board.")
466+
}
464467
if (previousMarkMove == newOwner) {
465468
throw new TwoMovesInARow(s"${newOwner} tried to make a move on the board, but it was the last player to make a move. Can't make two moves in a row.")
466469
}

0 commit comments

Comments
 (0)