Skip to content

Commit 9dbdd8e

Browse files
committed
add heatmap from pre-analyzed moves
1 parent 8dfdf00 commit 9dbdd8e

File tree

3 files changed

+69
-36
lines changed

3 files changed

+69
-36
lines changed

src/components/Goban.js

+54-35
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export default class Goban extends Component {
220220
paintMap = [],
221221
analysis,
222222
analysisType,
223+
showAnalysis,
223224
highlightVertices = [],
224225
dimmedStones = [],
225226

@@ -409,41 +410,59 @@ export default class Goban extends Component {
409410

410411
let heatMap = []
411412

412-
if (drawHeatMap && analysis != null) {
413-
let maxVisitsWin = Math.max(
414-
...analysis.variations.map(x => x.visits * x.winrate)
415-
)
416-
heatMap = board.signMap.map(row => row.map(_ => null))
417-
418-
for (let {
419-
vertex: [x, y],
420-
visits,
421-
winrate,
422-
scoreLead
423-
} of analysis.variations) {
424-
let strength = Math.round((visits * winrate * 8) / maxVisitsWin) + 1
425-
426-
winrate =
427-
strength <= 3 ? Math.floor(winrate) : Math.floor(winrate * 10) / 10
428-
scoreLead = scoreLead == null ? null : Math.round(scoreLead * 10) / 10
429-
if (scoreLead === 0) scoreLead = 0 // Avoid -0
430-
431-
heatMap[y][x] = {
432-
strength,
433-
text:
434-
visits < 10
435-
? ''
436-
: [
437-
analysisType === 'winrate'
438-
? i18n.formatNumber(winrate) +
439-
(Math.floor(winrate) === winrate ? '%' : '')
440-
: analysisType === 'scoreLead' && scoreLead != null
441-
? (scoreLead >= 0 ? '+' : '') + i18n.formatNumber(scoreLead)
442-
: '–',
443-
visits < 1000
444-
? i18n.formatNumber(visits)
445-
: i18n.formatNumber(Math.round(visits / 100) / 10) + 'k'
446-
].join('\n')
413+
if (drawHeatMap && showAnalysis) {
414+
let variations
415+
416+
if (analysis != null) {
417+
variations = analysis.variations
418+
} else {
419+
variations = []
420+
for (const v in board.childrenInfo) {
421+
const [x, y] = v.split(',').map(x => +x)
422+
const {visits, winrate, scoreLead} = board.childrenInfo[v]
423+
if (isFinite(visits) && isFinite(winrate)) {
424+
variations.push({vertex: [x, y], visits, winrate, scoreLead})
425+
}
426+
}
427+
}
428+
429+
if (variations.length) {
430+
let maxVisitsWin = Math.max(
431+
...variations.map(x => x.visits * x.winrate)
432+
)
433+
heatMap = board.signMap.map(row => row.map(_ => null))
434+
435+
for (let {
436+
vertex: [x, y],
437+
visits,
438+
winrate,
439+
scoreLead
440+
} of variations) {
441+
let strength = Math.round((visits * winrate * 8) / maxVisitsWin) + 1
442+
443+
winrate =
444+
strength <= 3 ? Math.floor(winrate) : Math.floor(winrate * 10) / 10
445+
scoreLead = scoreLead == null ? null : Math.round(scoreLead * 10) / 10
446+
if (scoreLead === 0) scoreLead = 0 // Avoid -0
447+
448+
heatMap[y][x] = {
449+
strength,
450+
text:
451+
visits < 10
452+
? ''
453+
: [
454+
analysisType === 'winrate'
455+
? i18n.formatNumber(winrate) +
456+
(Math.floor(winrate) === winrate ? '%' : '')
457+
: analysisType === 'scoreLead' && scoreLead != null
458+
? (scoreLead >= 0 ? '+' : '') +
459+
i18n.formatNumber(scoreLead)
460+
: '–',
461+
visits < 1000
462+
? i18n.formatNumber(visits)
463+
: i18n.formatNumber(Math.round(visits / 100) / 10) + 'k'
464+
].join('\n')
465+
}
447466
}
448467
}
449468
}

src/components/MainView.js

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export default class MainView extends Component {
144144
analysisTreePosition === treePosition
145145
? analysis
146146
: null,
147+
showAnalysis,
147148
paintMap,
148149
dimmedStones: ['scoring', 'estimator'].includes(mode)
149150
? deadStones

src/modules/gametree.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,20 @@ export function getBoard(tree, id) {
358358
type = 'good'
359359
}
360360

361-
list[v] = {sign, type}
361+
let visits = null
362+
let winrate = null
363+
let scoreLead = null
364+
if (isFinite(node.data.VISITS)) {
365+
visits = +node.data.VISITS
366+
}
367+
if (isFinite(node.data.WINRATE)) {
368+
winrate = (0.5 + sign * (node.data.WINRATE - 0.5)) * 100
369+
}
370+
if (isFinite(node.data.SCORELEAD)) {
371+
scoreLead = node.data.SCORELEAD * sign
372+
}
373+
374+
list[v] = {sign, type, visits, winrate, scoreLead}
362375
}
363376

364377
for (let child of node.children) {

0 commit comments

Comments
 (0)