Skip to content

Commit

Permalink
Start lila-fishnet v2
Browse files Browse the repository at this point in the history
- Remove all the code except models
- Clean sbt settings
- Add new dependencies
  • Loading branch information
lenguyenthanh committed Nov 15, 2023
1 parent 6cb86aa commit 32cdf61
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 477 deletions.
53 changes: 48 additions & 5 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
version = "2.6.3"
align.preset = more
version = 3.7.15
runner.dialect = scala3
maxColumn = 110
spaces.inImportCurlyBraces = true
rewrite.rules = [SortImports, RedundantParens, SortModifiers]
rewrite.redundantBraces.stringInterpolation = true

newlines.source = keep

trailingCommas = "multiple"

rewrite {
rules = [Imports]
imports.sort = ascii
}

rewrite.scala3 {
convertToNewSyntax = yes
removeOptionalBraces = yes
}

align {
allowOverflow = true
preset = more
openParenCallSite = false
stripMargin = true
}

continuationIndent {
callSite = 2
defnSite = 4
}

docstrings {
style = Asterisk
oneline = keep
wrap = no
}

spaces {
beforeContextBoundColon = Never
inImportCurlyBraces = true
}

fileOverride {
"glob:**/build.sbt" {
runner.dialect = scala213
}
"glob:**/project/**" {
runner.dialect = scala213
}
}
46 changes: 0 additions & 46 deletions app/AppLoader.scala

This file was deleted.

87 changes: 0 additions & 87 deletions app/JsonApi.scala

This file was deleted.

70 changes: 5 additions & 65 deletions app/Lila.scala
Original file line number Diff line number Diff line change
@@ -1,82 +1,22 @@
package lila.fishnet

import chess.format.{ FEN, Uci }
import io.lettuce.core._
import io.lettuce.core.pubsub._
import chess.format.{ Fen, Uci }
import org.joda.time.DateTime
import play.api.Configuration
import play.api.Logger

final class Lila(
moveDb: MoveDb,
config: Configuration
) {
object Lila:

private val logger = Logger(getClass)
private val redis = RedisClient create config.get[String]("redis.uri")

def pubsub(chanIn: String, chanOut: String): Lila.Move => Unit = {

val connIn = redis.connectPubSub()
val connOut = redis.connectPubSub()

def send(move: Lila.Move): Unit = connIn.async.publish(chanIn, move.write)

connOut.addListener(new RedisPubSubAdapter[String, String] {
override def message(chan: String, msg: String): Unit =
Lila.readMoveReq(msg) match {
case None => logger warn s"LilaOut invalid move $msg"
case Some(req) => moveDb add req
}
})

connOut.async.subscribe(chanOut) thenRun { () => connIn.async.publish(chanIn, "start") }

send
}
}

object Lila {

case class Move(game: Work.Game, uci: Uci) {
case class Move(game: Work.Game, uci: Uci):
def sign = game.moves.takeRight(20).replace(" ", "")
def write = s"${game.id} $sign ${uci.uci}"
}

def readMoveReq(msg: String): Option[Work.Move] =
msg.split(";", 6) match {
case Array(gameId, levelS, clockS, variantS, initialFenS, moves) =>
for {
level <- levelS.toIntOption
variant = chess.variant.Variant.orDefault(variantS)
initialFen = if (initialFenS.isEmpty) None else Some(FEN(initialFenS))
clock = readClock(clockS)
} yield Work.Move(
_id = Work.makeId,
game = Work.Game(
id = gameId,
initialFen = initialFen,
variant = variant,
moves = moves
),
level = level,
clock = clock,
tries = 0,
lastTryByKey = None,
acquired = None,
createdAt = DateTime.now
)
case _ => None
}
def readMoveReq(msg: String): Option[Work.Move] = ???

def readClock(s: String) =
s split ' ' match {
s split ' ' match
case Array(ws, bs, incs) =>
for {
wtime <- ws.toIntOption
btime <- bs.toIntOption
inc <- incs.toIntOption
} yield Work.Clock(wtime, btime, inc)
case _ => None
}
}
Loading

0 comments on commit 32cdf61

Please sign in to comment.