Skip to content

Instantly share code, notes, and snippets.

@khajavi
Created October 29, 2020 06:02
Show Gist options
  • Save khajavi/c3ba09e145389969097f67941abb9c91 to your computer and use it in GitHub Desktop.
Save khajavi/c3ba09e145389969097f67941abb9c91 to your computer and use it in GitHub Desktop.
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