-
-
Save monkey-codes/dcc98e5c40110221642403753682b165 to your computer and use it in GitHub Desktop.
Making a move on the tic tac toe game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| fun make(move: Move): Either<GameError, Game> = either { | |
| val (coord, symbol) = move | |
| ensure(symbol == nextPlayer) { raise(NotPlayersTurn(symbol)) } | |
| ensure(cell(move.coordinates) == BLANK) { raise(InvalidMove(move)) } | |
| state | |
| .mapIndexed { ri, row -> | |
| if (ri == coord.row) { | |
| row.mapIndexed { ci, cell -> if (ci == coord.col) symbol else cell } | |
| } else row | |
| } | |
| .toGame() | |
| } | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment