Skip to content

Commit

Permalink
feat: use currentMaiaModel instead of player rating ofr maia white wi…
Browse files Browse the repository at this point in the history
…n rate

fix: bug where maia value head wasn't updated when new maia version is used for user games
  • Loading branch information
kevinjosethomas committed Nov 23, 2024
1 parent 1a43923 commit d7ca815
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
29 changes: 6 additions & 23 deletions src/hooks/useAnalysisController/useAnalysisController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,12 @@ import { AnalyzedGame, Color, MoveMap, StockfishEvaluation } from 'src/types'

function parseMaiaWinRate(
turnPlayed: string,
whiteRating: number,
blackRating: number,
currentMaiaModel: string,
maiaValues?: { [key: string]: number },
) {
if (maiaValues === undefined) return -1

if (Object.keys(maiaValues).length === 1) {
const maiaWr = Object.values(maiaValues)[0]

return maiaWr !== -1 && turnPlayed === 'white' ? 1 - maiaWr : maiaWr
}

let rating =
Math.floor(
((turnPlayed === 'black' ? whiteRating : blackRating) || 1100) / 100,
) * 100
rating = Math.min(1900, Math.max(1100, rating))

let maiaWr = maiaValues ? maiaValues[`maia_kdd_${rating}`] : -1
let maiaWr = maiaValues ? maiaValues[currentMaiaModel] : -1
if (maiaWr !== -1 && turnPlayed === 'white') {
maiaWr = 1 - maiaWr
}
Expand Down Expand Up @@ -225,8 +212,7 @@ export const useAnalysisController = (
const turnPlayed = controller.currentIndex % 2 === 0 ? 'black' : 'white'
const maiaWr = parseMaiaWinRate(
turnPlayed,
game.whitePlayer.rating || 1100,
game.blackPlayer.rating || 1100,
currentMaiaModel,
maiaValues,
)
const moveEval = {
Expand All @@ -241,8 +227,7 @@ export const useAnalysisController = (
const turnPlayed = controller.currentIndex % 2 === 0 ? 'black' : 'white'
const maiaWr = parseMaiaWinRate(
turnPlayed,
game.whitePlayer.rating || 1100,
game.blackPlayer.rating || 1100,
currentMaiaModel,
maiaValues,
)
const moveEval = {
Expand Down Expand Up @@ -273,8 +258,7 @@ export const useAnalysisController = (
const turnPlayed = controller.currentIndex % 2 === 0 ? 'black' : 'white'
const maiaWr = parseMaiaWinRate(
turnPlayed,
game.whitePlayer.rating || 1100,
game.blackPlayer.rating || 1100,
currentMaiaModel,
maiaValues,
)
const moveEval = {
Expand All @@ -293,8 +277,7 @@ export const useAnalysisController = (
const turnPlayed = controller.currentIndex % 2 === 0 ? 'black' : 'white'
const maiaWr = parseMaiaWinRate(
turnPlayed,
game.whitePlayer.rating || 1100,
game.blackPlayer.rating || 1100,
currentMaiaModel,
maiaValues,
)

Expand Down
10 changes: 10 additions & 0 deletions src/pages/analysis/[...id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,16 @@ const Analysis: React.FC<Props> = ({
const newAnalyzedGame = { ...analyzedGame }
newAnalyzedGame.maiaEvaluations[model] = evals

for (let i = 0; i < analyzedGame.moves.length; i++) {
const maiaValues = newAnalyzedGame.moves[i].maia_values
if (maiaValues) {
const newMaiaValues = game.moves[i].maia_values as {
[key: string]: number
}
maiaValues[model] = newMaiaValues[model]
}
}

setAnalyzedGame(newAnalyzedGame)
setCurrentMaiaModel(model)
}
Expand Down

0 comments on commit d7ca815

Please sign in to comment.