Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ornicar/lila
Browse files Browse the repository at this point in the history
* 'master' of github.com:ornicar/lila:
  wiki: Fix length limit check
  Don't abort unlimited AI games after 6 hours
  AI play book: only decent moves
  • Loading branch information
ornicar committed Nov 24, 2021
2 parents d22d1fd + cc79e29 commit f32c366
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
19 changes: 11 additions & 8 deletions modules/fishnet/src/main/FishnetOpeningBook.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package lila.fishnet

import chess.format.Forsyth
import chess.format.Uci
import chess.Speed
import chess.{ Color, Speed }
import com.softwaremill.tagging._
import play.api.libs.json._
import play.api.libs.ws.JsonBodyReadables._
Expand Down Expand Up @@ -45,7 +45,7 @@ final private class FishnetOpeningBook(
for {
data <- res.body[JsValue].validate[Response](responseReader).asOpt
_ = if (data.moves.isEmpty) outOfBook.put(game.id)
move <- data.randomPonderedMove
move <- data randomPonderedMove game.turnColor
} yield move.uci
}
.monTry { res =>
Expand All @@ -66,11 +66,13 @@ object FishnetOpeningBook {
trait Depth

case class Response(moves: List[Move]) {
def randomPonderedMove: Option[Move] = {
val sum = moves.map(_.nb).sum
val novelty = 1
val rng = ThreadLocalRandom.nextInt(sum + novelty)
moves

def randomPonderedMove(turn: Color): Option[Move] = {
val decentMoves = moves.filter(_.lossRatioFor(turn) < 0.66)
val sum = decentMoves.map(_.nb).sum
val novelty = 1
val rng = ThreadLocalRandom.nextInt(sum + novelty)
decentMoves
.foldLeft((none[Move], 0)) { case ((found, it), next) =>
val nextIt = it + next.nb
(found orElse (nextIt > rng).option(next), nextIt)
Expand All @@ -80,7 +82,8 @@ object FishnetOpeningBook {
}

case class Move(uci: Uci, white: Int, draws: Int, black: Int) {
def nb = white + draws + black
def nb = white + draws + black
def lossRatioFor(color: Color): Float = (nb > 0) ?? color.fold(black, white).toFloat / nb
}

implicit val moveReader = Json.reads[Move]
Expand Down
2 changes: 1 addition & 1 deletion modules/game/src/main/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ case class Game(
def abandoned =
(status <= Status.Started) && {
movedAt isBefore {
if (hasAi && !hasCorrespondenceClock) Game.aiAbandonedDate
if (hasAi && hasClock) Game.aiAbandonedDate
else Game.abandonedDate
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/analyse/src/wiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function wikiTheory(): WikiTheory {
async (nodes: Tree.Node[]) => {
const pathParts = nodes.slice(1).map(n => `${plyPrefix(n)}${n.san}`);
const path = pathParts.join('/').replace(/[+!#?]/g, '') ?? '';
if (pathParts.length > 30 || !path || path.length > 255) show('');
if (pathParts.length > 30 || !path || path.length > 255 - 21) show('');
else if (cache.has(path)) show(cache.get(path)!);
else if (
Array.from({ length: pathParts.length }, (_, i) => -i - 1)
Expand Down

0 comments on commit f32c366

Please sign in to comment.