fix fishnet opening book randomization
parent
9a24b9b2cc
commit
cdffb0efe0
|
@ -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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue