Skip to content

Commit b0cb04d

Browse files
fix: was merging leaderboard archive incorrectly
1 parent 881d375 commit b0cb04d

3 files changed

Lines changed: 180 additions & 41 deletions

File tree

packages/client/src/GameUI.tsx

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -341,38 +341,31 @@ export function GameUI({
341341
className="disableScrollBar fadeBottom"
342342
>
343343
{(() => {
344-
const allPlayers = new Map<string, { currentScore: number; archiveScore: number }>();
344+
const playerScores = new Map<string, bigint[]>();
345345

346-
// Add players from current high scores.
346+
// Start by populating with current scores.
347347
Array.from(liveState.gameState.highScores).forEach(([entityId, highScores]) => {
348-
const username =
349-
liveState.gameState.usernames.get(entityId) ??
350-
("UNKNOWN " + entityId.toString().slice(0, 4)).toUpperCase();
351-
352-
const currentScore = Math.floor(sum(highScores).fromWad());
353-
354-
allPlayers.set(username, {
355-
currentScore,
356-
archiveScore: leaderboardArchive[username as keyof typeof leaderboardArchive] || 0,
357-
});
348+
const username = liveState.gameState.usernames.get(entityId);
349+
if (!username) throw new Error("Username not found for entityId: " + entityId);
350+
playerScores.set(username, highScores as bigint[]);
358351
});
359352

360-
// Add players from archive who aren't already in current scores.
361-
Object.entries(leaderboardArchive).forEach(([username, archiveScore]) => {
362-
if (!allPlayers.has(username)) {
363-
allPlayers.set(username, {
364-
currentScore: 0,
365-
archiveScore,
366-
});
367-
}
353+
// Incorporate archived scores.
354+
leaderboardArchive.forEach(({ username, highScores }) => {
355+
const current = playerScores.get(username) || [];
356+
const archived = highScores.map((score) => BigInt(score));
357+
playerScores.set(username, [...current, ...archived]);
368358
});
369359

370360
// Convert to array, calculate total scores, filter and sort.
371-
return Array.from(allPlayers.entries())
372-
.map(([username, data]) => ({
373-
username,
374-
totalScore: data.currentScore + data.archiveScore,
375-
}))
361+
return Array.from(playerScores.entries())
362+
.map(([username, allScores]) => {
363+
const playerTopKScores = allScores
364+
.sort((a, b) => Number(b - a))
365+
.slice(0, gameConfig.highScoreTopK);
366+
367+
return { username, totalScore: Math.floor(sum(playerTopKScores).fromWad()) };
368+
})
376369
.filter((player) => player.totalScore > 0)
377370
.sort((a, b) => b.totalScore - a.totalScore)
378371
.map(({ username, totalScore }) => (
Lines changed: 161 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,161 @@
1-
{
2-
"hibillh": 239631,
3-
"nubit_org": 67567,
4-
"transmissions11": 31253,
5-
"azacharyf": 27254,
6-
"exwhyyy": 25542,
7-
"plotchy": 17114,
8-
"aalimsahin": 10514,
9-
"0xhank": 8909,
10-
"rjected": 7828,
11-
"0xnimara": 6636,
12-
"tome11i": 1112,
13-
"ncah": 226,
14-
"0xoptimus": 101
15-
}
1+
[
2+
{
3+
"username": "transmissions11",
4+
"highScores": [
5+
"1474323623539854735964",
6+
"1790583633525363154956",
7+
"1838756877534204222620",
8+
"2339361733026030422058",
9+
"3182314184301991148480",
10+
"1934206671270218215098",
11+
"2261187687509761885636",
12+
"5717889737642058148944",
13+
"6675958749239671218827",
14+
"4039405712451464315525"
15+
]
16+
},
17+
{
18+
"username": "tome11i",
19+
"highScores": ["512000000000000000000", "512000000000000000000", "88390439494926001496"]
20+
},
21+
{
22+
"username": "0xhank",
23+
"highScores": [
24+
"60016904942573711724",
25+
"200046324038811164511",
26+
"98173591330469942963",
27+
"347176699657089379257",
28+
"206812761915263740069",
29+
"185718114041461068494",
30+
"228544651580368852317",
31+
"3183998987948954765991",
32+
"627475750359808051987",
33+
"3771101106107257043918"
34+
]
35+
},
36+
{
37+
"username": "0xnimara",
38+
"highScores": [
39+
"41521503854729486775",
40+
"147192339956816129954",
41+
"1394623716779797557689",
42+
"2892865027786743823892",
43+
"1067195166047427240836",
44+
"1093256678798898482579"
45+
]
46+
},
47+
{
48+
"username": "azacharyf",
49+
"highScores": [
50+
"2105494687711481098685",
51+
"2246386352357798574907",
52+
"2295074179140997197699",
53+
"2257002481636218782006",
54+
"2952962984695782335398",
55+
"3893605519339914393678",
56+
"2479336526667712093202",
57+
"2671108662784668847189",
58+
"2515758980412581652214",
59+
"3837315579310808307097"
60+
]
61+
},
62+
63+
{
64+
"username": "ncah",
65+
"highScores": ["226751275747999485328"]
66+
},
67+
{
68+
"username": "0xoptimus",
69+
"highScores": ["101842780323044220542"]
70+
},
71+
{
72+
"username": "rjected",
73+
"highScores": [
74+
"494092226785658235282",
75+
"547924992835203217243",
76+
"508585288222973957851",
77+
"640540337058458587002",
78+
"670936891577425900920",
79+
"579810130182832507235",
80+
"807477442410767587575",
81+
"1202401639582050100463",
82+
"1472282531085974458380",
83+
"904531803076050415042"
84+
]
85+
},
86+
{
87+
"username": "hibillh",
88+
"highScores": [
89+
"16434124512936730434886",
90+
"19527582047289877935715",
91+
"20474681813440450164916",
92+
"20799760193623978806266",
93+
"25855275799711920452984",
94+
"26161255605423629498549",
95+
"22606710447967273301266",
96+
"22301387872466145157538",
97+
"27693868555813433768235",
98+
"37777213452627853225780"
99+
]
100+
},
101+
{
102+
"username": "nubit_org",
103+
"highScores": [
104+
"5085495076670436181900",
105+
"5273504315960755761956",
106+
"5205219060949721974824",
107+
"6121499868564962703447",
108+
"6834765468730517948299",
109+
"8604769024587500676676",
110+
"6483510655312907737769",
111+
"8424979708694720239904",
112+
"6921790690760363885262",
113+
"8612298932061778274993"
114+
]
115+
},
116+
{
117+
"username": "plotchy",
118+
"highScores": [
119+
"1063774364635810840832",
120+
"1271294008817918844612",
121+
"1118829202892893210138",
122+
"1348747247626941529843",
123+
"1334700936318341326252",
124+
"1595670790306196343540",
125+
"2494810889879353346552",
126+
"1683150544348849749079",
127+
"3567392884139599523791",
128+
"1635957089440137974427"
129+
]
130+
},
131+
{
132+
"username": "exwhyyy",
133+
"highScores": [
134+
"1834259514856611955813",
135+
"2188191144245427367617",
136+
"1961628329436950669520",
137+
"2826705491950290841612",
138+
"2464754723115432954953",
139+
"2341856186893553154028",
140+
"2156431171519793366888",
141+
"2853790400916528266129",
142+
"3326436592848686330692",
143+
"3588839500311721662448"
144+
]
145+
},
146+
{
147+
"username": "aalimsahin",
148+
"highScores": [
149+
"515360784853065043808",
150+
"571246874253611860798",
151+
"554073134332106626884",
152+
"907748928993371995774",
153+
"1082936188189831392101",
154+
"824023967241678156236",
155+
"1614963718416558024378",
156+
"1528817890747145874658",
157+
"1822351282923715223540",
158+
"1092510394026337115606"
159+
]
160+
}
161+
]

packages/client/src/utils/bigintMinHeap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// instead of using the specialized heap functions defined below.
33
export type BigintMinHeap = readonly bigint[];
44

5-
export function sum(mh: BigintMinHeap): bigint {
5+
export function sum(mh: readonly bigint[]): bigint {
66
return mh.reduce((acc, val) => acc + val, 0n);
77
}
88

0 commit comments

Comments
 (0)