reduce TV clock heuristic coefficient

pull/83/head
Thibault Duplessis 2013-09-11 13:42:43 +02:00
parent f07011bce5
commit 5bb2693338
3 changed files with 22 additions and 24 deletions

View File

@ -95,7 +95,7 @@ object Featured {
def sort(games: List[Game]): List[Game] = games sortBy { -score(_) }
private def score(game: Game): Int = math.round {
private[game] def score(game: Game): Int = math.round {
(heuristics map {
case (fn, coefficient) heuristicBox(fn(game)) * coefficient
}).sum * 1000
@ -110,19 +110,19 @@ object Featured {
private val heuristics: List[(Heuristic, Float)] = List(
eloHeuristic(Color.White) -> 1f,
eloHeuristic(Color.Black) -> 1f,
speedHeuristic -> 1f,
speedHeuristic -> 0.5f,
progressHeuristic -> 1f)
private def eloHeuristic(color: Color): Heuristic = game
private[game] def eloHeuristic(color: Color): Heuristic = game
eloBox(game.player(color).elo | 1100)
private def speedHeuristic: Heuristic = game
private[game] def speedHeuristic: Heuristic = game
1 - timeBox(game.estimateTotalTime)
private def progressHeuristic: Heuristic = game
private[game] def progressHeuristic: Heuristic = game
1 - turnBox(game.turns)
// boxes and reduce to 0..1 range
private def box(in: Range.Inclusive)(v: Float): Float =
// boxes and reduces to 0..1 range
private[game] def box(in: Range.Inclusive)(v: Float): Float =
(math.max(in.start, math.min(v, in.end)) - in.start) / (in.end - in.start).toFloat
}

View File

@ -1,7 +1,6 @@
package lila.app
package lila
package game
import lila.game._
import lila.user._
class FeaturedTest extends LilaSpec {
@ -39,18 +38,19 @@ class FeaturedTest extends LilaSpec {
game = chess.Game(chess.Variant.default),
whitePlayer = Player.white.copy(elo = 1600.some),
blackPlayer = Player.black,
ai = None,
creatorColor = chess.Color.White,
mode = chess.Mode.default,
variant = chess.Variant.default,
source = Source.Lobby,
pgnImport = None)
pgnImport = None).copy(id = "game1")
val game2 = game1.copy(
id = "game2",
clock = chess.Clock(180,0).some,
turns = 11)
val game3 = game1.copy(
id = "game3",
clock = chess.Clock(60,0).some,
turns = 21)
@ -61,7 +61,7 @@ class FeaturedTest extends LilaSpec {
eloHeuristic(chess.Color.White)(game1) must_== 0.6f
}
"game1 black" in {
eloHeuristic(chess.Color.Black)(game1) must_== 0f
eloHeuristic(chess.Color.Black)(game1) must_== 0.1f
}
}
"speed" in {
@ -69,7 +69,7 @@ class FeaturedTest extends LilaSpec {
speedHeuristic(game1) must_== 0
}
"game2" in {
speedHeuristic(game2) must_== 0.5f
speedHeuristic(game2) must_== 0.6f
}
"game3" in {
speedHeuristic(game3) must_== 1f
@ -80,29 +80,29 @@ class FeaturedTest extends LilaSpec {
progressHeuristic(game1) must_== 1f
}
"game2" in {
progressHeuristic(game2) must_== 0.5f
progressHeuristic(game2) must beCloseTo(0.5f, 0.1f)
}
"game3" in {
progressHeuristic(game3) must_== 0f
progressHeuristic(game3) must beCloseTo(0.1f, 0.1f)
}
}
"score" in {
"game1" in {
score(game1) must_== 0.6f + 0f + 1f * 0.5f
score(game1) must_== 1700
}
"game2" in {
score(game2) must_== 0.6f + 0.5f + 0.5f * 0.5f
score(game2) must_== 1583
}
"game3" in {
score(game3) must_== 0.6f + 1f + 0f * 0.5f
score(game3) must_== 1367
}
}
"best" in {
"3 games" in {
best(games) must_== game3.some
sort(games).headOption must_== game1.some
}
"3 games reversed" in {
best(games.reverse) must_== game3.some
sort(games.reverse).headOption must_== game1.some
}
}
}

View File

@ -1,9 +1,7 @@
package lila.app
package lila
import org.specs2.mutable._
import ornicar.scalalib.test.ValidationMatchers
trait LilaSpec
extends Specification
with ValidationMatchers {
trait LilaSpec extends Specification with ValidationMatchers {
}