Created
October 29, 2020 06:02
-
-
Save khajavi/c3ba09e145389969097f67941abb9c91 to your computer and use it in GitHub Desktop.
This file contains 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
object TicTocToe { | |
sealed trait Action | |
object Action { | |
case object X extends Action | |
case object O extends Action | |
} | |
sealed trait Player | |
object Player { | |
case object X extends Player | |
case object O extends Player | |
} | |
sealed trait State | |
object State { | |
case object NotStarted extends State | |
case object Playing extends State | |
case object Finished extends State | |
} | |
type Board = Array[Array[Action]] | |
case class Game[S <: State](state: S, board: Board) | |
type Cell = (Int, Int) | |
trait PlayGround { | |
/** | |
* Who is the winner? | |
*/ | |
def winner[S <: State.Finished.type](game: Game[S]): Player | |
/** | |
* Who is the next player? | |
*/ | |
def nextPlayer(board: Board): Player | |
//FIXME: who start the game? | |
//FIXME: pick shouldn't work on Finished state | |
def pick[S](game: Game[S]): Cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment