fix: deterministic behaviour for radar by storing the random fractions when generating rd.json (#372)

* Store the random blip positions when generating rd.json

Fixes: https://github.com/AOEpeople/aoe_technology_radar/issues/148

Simple solution to creating stable blips is to store the randomly generated angle and radius in rg.json.

Attempted a few hash functions but found it hard to spread blips 'nicely'
(they tended to clump into groups or sections of the radar).

* distribute points within .1 and .9 of the arc

---------

Co-authored-by: Bastian Ike <bastian.ike@bare.id>
This commit is contained in:
Eddie Whiteside
2023-06-01 11:01:42 +01:00
committed by GitHub
parent 71e397459f
commit 3b272dacb3
4 changed files with 14 additions and 6 deletions

View File

@@ -26,13 +26,15 @@ function generateCoordinates(
ringPadding = 0.7;
// radian between 0 and 90 degrees
const randomDegree = (Math.random() * 90 * pi) / 180;
const randomDegree = ((0.1 + (blip.angleFraction || Math.random()) * .8) * 90 * pi) / 180;
// random distance from the centre of the radar, but within given ring. Also, with some "padding" so the points don't touch ring borders.
const radius = randomBetween(
const radius = pointBetween(
previousRingRadius + ringPadding,
ringRadius - ringPadding
ringRadius - ringPadding,
blip.radiusFraction || Math.random()
);
/*
/*
Multiples of PI/2. To apply the calculated position to the specific quadrant.
Order here is counter-clockwise, so we need to "invert" quadrant positions (i.e. swap 2 with 4)
*/
@@ -44,8 +46,8 @@ function generateCoordinates(
};
}
function randomBetween(min: number, max: number): number {
return Math.random() * (max - min) + min;
function pointBetween(min: number, max: number, amount: number): number {
return amount * (max - min) + min;
}
function distanceBetween(point1: Point, point2: Point): number {

View File

@@ -25,6 +25,8 @@ export type Item = ItemAttributes & {
info: string;
flag: FlagType;
revisions: Revision[];
angleFraction?: number;
radiusFraction?: number;
};
export type Blip = Item & {