@@ -118,13 +118,26 @@ export async function getScrabbleDex(): Promise<ScrabbleDexEntry[] | null> {
118118 const winCtx = game . winCtx as ScrabbleWinCtx | undefined ;
119119 const winners = winCtx ?. type === 'win' ? winCtx . winnerIds : [ ] ;
120120 const logs = game . log . map < ScrabbleLog > ( log => JSON . parse ( log ) ) ;
121- if ( winCtx ?. type === 'dq' ) {
121+ if ( winCtx ?. type === 'dq' || winCtx ?. type === 'regular' ) {
122122 const leftUsers = logs . filter ( log => log . action === 'dq' || log . action === 'forfeit' ) . map ( log => log . turn ) ;
123- winners . push (
124- ...Object . values ( game . players )
125- . map ( player => player . turn )
126- . filter ( player => ! leftUsers . includes ( player ) )
127- ) ;
123+ if ( winCtx . type === 'dq' )
124+ winners . push (
125+ ...Object . values ( game . players )
126+ . map ( player => player . turn )
127+ . filter ( player => ! leftUsers . includes ( player ) )
128+ ) ;
129+ else if ( winCtx . type === 'regular' && logs . filter ( log => log . action === 'play' ) . length > 20 ) {
130+ const points : Record < string , number > = { } ;
131+ logs . forEach ( log => {
132+ if ( log . action === 'play' ) {
133+ points [ log . turn ] ??= 0 ;
134+ points [ log . turn ] += log . ctx . points . total ;
135+ }
136+ } ) ;
137+ const players = Object . entries ( points ) . filter ( ( [ player ] ) => ! leftUsers . includes ( player ) ) ;
138+ const maxPoints = Math . max ( ...players . map ( ( [ _player , score ] ) => score ) ) ;
139+ winners . push ( ...players . filter ( ( [ _player , score ] ) => score === maxPoints ) . map ( ( [ player ] ) => player ) ) ;
140+ }
128141 }
129142 return logs
130143 . filterMap < ScrabbleDexEntry [ ] > ( log => {
0 commit comments