Fix handicap bug

This commit is contained in:
Claude Brisson
2024-01-25 08:22:48 +01:00
parent a8a1fd4103
commit f2e9cd5acc
2 changed files with 8 additions and 8 deletions

View File

@@ -89,7 +89,7 @@ sealed class Tournament <P: Pairable>(
val white = solver.pairables.find { p-> p.id == game.white }!! val white = solver.pairables.find { p-> p.id == game.white }!!
val black = solver.pairables.find { p-> p.id == game.black }!! val black = solver.pairables.find { p-> p.id == game.black }!!
game.drawnUpDown = solver.dudd(black, white) game.drawnUpDown = solver.dudd(black, white)
game.handicap = solver.hd(black, white) game.handicap = solver.hd(white = white, black = black)
} }
fun usedTables(round: Int): BitSet = fun usedTables(round: Int): BitSet =

View File

@@ -186,8 +186,8 @@ sealed class BaseSolver(
// This cost is never applied if potential Handicap != 0 // This cost is never applied if potential Handicap != 0
// It is fully applied if wbBalance(sP1) and wbBalance(sP2) are strictly of different signs // It is fully applied if wbBalance(sP1) and wbBalance(sP2) are strictly of different signs
// It is half applied if one of wbBalance is 0 and the other is >=2 // It is half applied if one of wbBalance is 0 and the other is >=2
val hd1 = pairing.handicap.handicap(p1, p2) val hd1 = pairing.handicap.handicap(white = p1, black = p2)
val hd2 = pairing.handicap.handicap(p2, p1) val hd2 = pairing.handicap.handicap(white = p2, black = p1)
val potentialHd: Int = max(hd1, hd2) val potentialHd: Int = max(hd1, hd2)
val score = if (potentialHd == 0) { val score = if (potentialHd == 0) {
val wb1: Int = p1.colorBalance val wb1: Int = p1.colorBalance
@@ -505,7 +505,7 @@ sealed class BaseSolver(
open fun HandicapParams.color(p1: Pairable, p2: Pairable): Double { open fun HandicapParams.color(p1: Pairable, p2: Pairable): Double {
var score = 0.0 var score = 0.0
val hd = pairing.handicap.handicap(p1,p2) val hd = pairing.handicap.handicap(white = p1, black = p2)
if(hd==0){ if(hd==0){
if (p1.colorBalance > p2.colorBalance) { if (p1.colorBalance > p2.colorBalance) {
score = - 1.0 score = - 1.0
@@ -537,13 +537,13 @@ sealed class BaseSolver(
} }
//return white.group - black.group //return white.group - black.group
} }
fun hd(black: Pairable, white: Pairable): Int { fun hd(white: Pairable, black: Pairable): Int {
return pairing.handicap.handicap(white, black) return pairing.handicap.handicap(white = white, black = black)
} }
open fun games(black: Pairable, white: Pairable): List<Game> { open fun games(white: Pairable, black: Pairable): List<Game> {
// CB TODO team of individuals pairing // CB TODO team of individuals pairing
val table = if (black.id == 0 || white.id == 0) 0 else usedTables.nextClearBit(1) val table = if (black.id == 0 || white.id == 0) 0 else usedTables.nextClearBit(1)
usedTables.set(table) usedTables.set(table)
return listOf(Game(id = Store.nextGameId, table = table, black = black.id, white = white.id, handicap = hd(white, black), drawnUpDown = dudd(black, white))) return listOf(Game(id = Store.nextGameId, table = table, black = black.id, white = white.id, handicap = hd(white = white, black = black), drawnUpDown = dudd(black, white)))
} }
} }