From 3e6d63e8f705a28bb25ee3cb4d1a223ef3a29d7c Mon Sep 17 00:00:00 2001 From: Magnus Wolffelt Date: Thu, 16 Sep 2021 12:29:00 +0200 Subject: [PATCH] Fix random heading function, randomize wind better (#1619) * Fix random heading function, randomize wind better * Use 359 as max default for random heading, for uniform distribution --- game/utils.py | 2 +- game/weather.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/game/utils.py b/game/utils.py index fbb28d0e..9e3826a6 100644 --- a/game/utils.py +++ b/game/utils.py @@ -224,7 +224,7 @@ class Heading: return cls(Heading.reduce_angle(deg)) @classmethod - def random(cls, min_angle: int = 0, max_angle: int = 0) -> Heading: + def random(cls, min_angle: int = 0, max_angle: int = 359) -> Heading: return Heading.from_degrees(random.randint(min_angle, max_angle)) def __add__(self, other: Heading) -> Heading: diff --git a/game/weather.py b/game/weather.py index 0d20b370..47287184 100644 --- a/game/weather.py +++ b/game/weather.py @@ -152,6 +152,8 @@ class Weather: @staticmethod def random_wind(minimum: int, maximum: int) -> WindConditions: wind_direction = Heading.random() + wind_direction_2000m = wind_direction + Heading.random(-90, 90) + wind_direction_8000m = wind_direction + Heading.random(-90, 90) at_0m_factor = 1 at_2000m_factor = 2 at_8000m_factor = 3 @@ -160,8 +162,8 @@ class Weather: return WindConditions( # Always some wind to make the smoke move a bit. at_0m=Wind(wind_direction.degrees, max(1, base_wind * at_0m_factor)), - at_2000m=Wind(wind_direction.degrees, base_wind * at_2000m_factor), - at_8000m=Wind(wind_direction.degrees, base_wind * at_8000m_factor), + at_2000m=Wind(wind_direction_2000m.degrees, base_wind * at_2000m_factor), + at_8000m=Wind(wind_direction_8000m.degrees, base_wind * at_8000m_factor), ) @staticmethod @@ -220,7 +222,7 @@ class ClearSkies(Weather): return None def generate_wind(self) -> WindConditions: - return self.random_wind(0, 0) + return self.random_wind(1, 4) class Cloudy(Weather): @@ -240,7 +242,7 @@ class Cloudy(Weather): return None def generate_wind(self) -> WindConditions: - return self.random_wind(0, 4) + return self.random_wind(1, 4) class Raining(Weather): @@ -260,7 +262,7 @@ class Raining(Weather): return None def generate_wind(self) -> WindConditions: - return self.random_wind(0, 6) + return self.random_wind(1, 6) class Thunderstorm(Weather): @@ -281,7 +283,7 @@ class Thunderstorm(Weather): ) def generate_wind(self) -> WindConditions: - return self.random_wind(0, 8) + return self.random_wind(1, 8) @dataclass