forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoveTime.scala
25 lines (17 loc) · 686 Bytes
/
MoveTime.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package lila
package game
object MoveTime {
def encode(mts: List[Int]): String = mts map { mt ⇒
encodeHash get mt getOrElse lastChar
} mkString
def encode(mt: Int): Char = encodeHash get mt getOrElse lastChar
def decode(str: String): List[Int] = str.toList map { mt ⇒
decodeHash get mt getOrElse lastInt
}
private val chars: List[Char] =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toList
private val decodeHash: Map[Char, Int] = chars.zipWithIndex.toMap
private val encodeHash: Map[Int, Char] = decodeHash.map(x ⇒ x._2 -> x._1).toMap
private val lastChar: Char = chars.last
private val lastInt: Int = chars.size - 1
}