fix fishnet opening book randomization

dark-default
Thibault Duplessis 2021-11-05 11:51:52 +01:00
parent 9a24b9b2cc
commit cdffb0efe0
1 changed files with 9 additions and 12 deletions

View File

@ -54,18 +54,15 @@ object FishnetOpeningBook {
trait Depth trait Depth
case class Response(moves: List[Move]) { case class Response(moves: List[Move]) {
def randomPonderedMove: Option[Move] = moves.size match { def randomPonderedMove: Option[Move] = {
case 0 => none val sum = moves.map(_.nb).sum
case size => val rng = ThreadLocalRandom nextInt sum
val sum = moves.map(_.nb).sum / size moves
val rng = ThreadLocalRandom nextInt sum .foldLeft((none[Move], 0)) { case ((found, it), next) =>
moves val nextIt = it + next.nb
.foldLeft((none[Move], 0)) { case ((found, it), next) => (found orElse (nextIt > rng).option(next), nextIt)
val nextIt = it + next.nb }
(found orElse (nextIt > rng).option(next), nextIt) ._1
}
._1
.orElse(moves.headOption)
} }
} }