All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dererXII.scalashogi_2.13.5.0.2.source-code.Mode.scala Maven / Gradle / Ivy

There is a newer version: 12.1.1
Show newest version
package shogi

sealed abstract class Mode(val id: Int) {

  lazy val name = toString.toLowerCase

  def casual = this == Mode.Casual
  def rated  = this == Mode.Rated

  def fold[A](c: => A, r: => A): A = if (this.casual) c else r
}

object Mode {

  case object Casual extends Mode(0)
  case object Rated  extends Mode(1)

  val all = List[Mode](Casual, Rated)

  val byId: Map[Int, Mode] = all map { v =>
    (v.id, v)
  } toMap

  def apply(id: Int): Option[Mode] = byId get id

  def apply(rated: Boolean): Mode = if (rated) Rated else Casual

  val default: Mode = Casual

  def orDefault(id: Int): Mode = apply(id) | default
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy