@@ -89,6 +89,7 @@ import type { DrawBrushes, DrawShape } from 'chessground/draw'
8989import { MAIA_MODELS } from 'src/constants/common'
9090import { applyEngineAnalysisData } from 'src/lib/analysis'
9191import { formatMaiaName } from 'src/lib/maiaNames'
92+ import { playerLabel } from 'src/lib/pgn'
9293import { cpToWinrate , parseLichessPgn } from 'src/lib'
9394import {
9495 applyImportedVariations ,
@@ -559,22 +560,31 @@ interface Props {
559560
560561// Stored games' names are already formatted with the game's date (see
561562// fetchAnalyzedMaiaGame); any other Maia name is taken to be current.
562- const formatAnalysisPlayerName = ( name : string ) =>
563- / ^ m a i a _ k d d _ \d + $ / i. test ( name ) ? formatMaiaName ( name ) : name
563+ // A player without a name is shown as playerLabel says.
564+ const formatAnalysisPlayerName = (
565+ name : string ,
566+ color : 'white' | 'black' ,
567+ gameType ?: string ,
568+ ) => {
569+ const label = playerLabel ( name , color , gameType )
570+ return / ^ m a i a _ k d d _ \d + $ / i. test ( label ) ? formatMaiaName ( label ) : label
571+ }
564572
565573// Apart from the page so that it renders only when the game changes: each
566574// render of <Head> makes Next.js update the document's head, and the page
567575// re-renders on every engine update.
568576const AnalysisHead = React . memo ( function AnalysisHead ( {
569577 whitePlayer,
570578 blackPlayer,
579+ gameType,
571580} : {
572581 whitePlayer ?: string
573582 blackPlayer ?: string
583+ gameType ?: string
574584} ) {
575585 const players =
576586 whitePlayer !== undefined && blackPlayer !== undefined
577- ? `${ formatAnalysisPlayerName ( whitePlayer ) } vs ${ formatAnalysisPlayerName ( blackPlayer ) } `
587+ ? `${ formatAnalysisPlayerName ( whitePlayer , 'white' , gameType ) } vs ${ formatAnalysisPlayerName ( blackPlayer , 'black' , gameType ) } `
578588 : null
579589 return (
580590 < Head >
@@ -1647,7 +1657,11 @@ const Analysis: React.FC<Props> = ({
16471657 />
16481658 < div className = "flex min-w-0 items-center gap-1" >
16491659 < p className = "truncate text-sm" title = { player . name } >
1650- { formatAnalysisPlayerName ( player . name ) }
1660+ { formatAnalysisPlayerName (
1661+ player . name ,
1662+ index === 0 ? 'white' : 'black' ,
1663+ analyzedGame . type ,
1664+ ) }
16511665 </ p >
16521666 < span className = "shrink-0 text-xs" >
16531667 { player . rating ? < > ({ player . rating } )</ > : null }
@@ -1682,7 +1696,11 @@ const Analysis: React.FC<Props> = ({
16821696 < div className = "h-2 w-2 rounded-full bg-white" />
16831697 </ span >
16841698 < span className = "truncate font-medium" >
1685- { formatAnalysisPlayerName ( analyzedGame . whitePlayer . name ) }
1699+ { formatAnalysisPlayerName (
1700+ analyzedGame . whitePlayer . name ,
1701+ 'white' ,
1702+ analyzedGame . type ,
1703+ ) }
16861704 </ span >
16871705 { analyzedGame . whitePlayer . rating && (
16881706 < span className = "shrink-0 text-primary/60" >
@@ -1710,7 +1728,11 @@ const Analysis: React.FC<Props> = ({
17101728 < div className = "h-2 w-2 rounded-full border-[0.5px] bg-black" />
17111729 </ span >
17121730 < span className = "truncate font-medium" >
1713- { formatAnalysisPlayerName ( analyzedGame . blackPlayer . name ) }
1731+ { formatAnalysisPlayerName (
1732+ analyzedGame . blackPlayer . name ,
1733+ 'black' ,
1734+ analyzedGame . type ,
1735+ ) }
17141736 </ span >
17151737 { analyzedGame . blackPlayer . rating && (
17161738 < span className = "shrink-0 text-primary/60" >
@@ -2571,6 +2593,7 @@ const Analysis: React.FC<Props> = ({
25712593 < AnalysisHead
25722594 whitePlayer = { analyzedGame ?. whitePlayer . name }
25732595 blackPlayer = { analyzedGame ?. blackPlayer . name }
2596+ gameType = { analyzedGame ?. type }
25742597 />
25752598 < MaiaDownloadPrompt engine = { controller . maia } />
25762599 < TreeControllerContext . Provider value = { controller } >
0 commit comments