λ Tony's Blog λ
Scala exercise with types and abstraction
Posted on January 9, 2011Write an API for playing tic-tac-toe. There should be no side-effects (or variables), at all, for real. The move
function will take a game state, a Position
and it will return a data type that you write yourself.
The following functions (at least) must be supported:
move
(as mentioned)whoseTurn
(returns which player’s turn it is)whoWon
(returns who won or if a draw)playerAt
(returns which player, if any, is at a given position)
Importantly, the following must be true:
It is a compile-time error to call
move
orwhoseTurn
on a game that has been completedIt is a compile-time error to call
whoWon
on a game that has not been completedThe
playerAt
function must be supported on both complete and in-play games
Good luck and may the types be with you.