deepcrayonfish^2
Benedikt Werner 2021-12-04 03:47:10 +01:00
parent 004dbceab8
commit 0fd1d268ed
No known key found for this signature in database
GPG Key ID: 1DBFF0F8E9E121EB
1 changed files with 6 additions and 6 deletions

View File

@ -45,7 +45,7 @@ final private class FishnetOpeningBook(
for { for {
data <- res.body[JsValue].validate[Response](responseReader).asOpt data <- res.body[JsValue].validate[Response](responseReader).asOpt
_ = if (data.moves.isEmpty) outOfBook.put(game.id) _ = if (data.moves.isEmpty) outOfBook.put(game.id)
move <- data randomPonderedMove(game.turnColor, level) move <- data randomPonderedMove (game.turnColor, level)
} yield move.uci } yield move.uci
} }
.monTry { res => .monTry { res =>
@ -68,9 +68,9 @@ object FishnetOpeningBook {
case class Response(moves: List[Move]) { case class Response(moves: List[Move]) {
def randomPonderedMove(turn: Color, level: Int): Option[Move] = { def randomPonderedMove(turn: Color, level: Int): Option[Move] = {
val sum = moves.map(_.score(turn, level)).sum val sum = moves.map(_.score(turn, level)).sum
val novelty = 5L * 14 // score of 5 winning games val novelty = 5L * 14 // score of 5 winning games
val rng = ThreadLocalRandom.nextLong(sum + novelty) val rng = ThreadLocalRandom.nextLong(sum + novelty)
moves moves
.foldLeft((none[Move], 0L)) { case ((found, it), next) => .foldLeft((none[Move], 0L)) { case ((found, it), next) =>
val nextIt = it + next.score(turn, level) val nextIt = it + next.score(turn, level)
@ -84,8 +84,8 @@ object FishnetOpeningBook {
def score(turn: Color, level: Int): Long = def score(turn: Color, level: Int): Long =
// interpolate: real frequency at lvl 1, expectation value at lvl 8 // interpolate: real frequency at lvl 1, expectation value at lvl 8
14L * turn.fold(white, black) + 14L * turn.fold(white, black) +
(15L - level) * draws + (15L - level) * draws +
(16L - 2 * level) * turn.fold(black, white) (16L - 2 * level) * turn.fold(black, white)
} }
implicit val moveReader = Json.reads[Move] implicit val moveReader = Json.reads[Move]