Skip to content

Commit

Permalink
fix(map,unreleased): fix potential nondeterministic behavior in front…
Browse files Browse the repository at this point in the history
…ier bubble logic
  • Loading branch information
MichaelMakesGames committed Aug 24, 2024
1 parent b720cc2 commit 8b22dea
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/renderer/src/lib/map/data/processSystemOwnership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,16 @@ export default function processSystemOwnership(
// first try most connected (by hyperlane) neighbor
const reassignedSectorId = Object.keys(neighborSectorToNumConnections)
.map((key) => parseInt(key))
.sort(
(a, b) =>
(neighborSectorToNumConnections[b] ?? 0) - (neighborSectorToNumConnections[a] ?? 0),
)[0];
.sort((a, b) => {
let comparison =
(neighborSectorToNumConnections[b] ?? 0) - (neighborSectorToNumConnections[a] ?? 0);
if (comparison === 0) {
// if 0, sort by id, to safeguard against non-deterministic behavior
// (the order of the keys in json from rust is not guaranteed to be consistent)
comparison = a - b;
}
return comparison;
})[0];

// assign system to target if found
if (reassignedSectorId != null) {
Expand Down

0 comments on commit 8b22dea

Please sign in to comment.