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
This commit is contained in:
Magnus Wolffelt 2021-09-16 12:29:00 +02:00 committed by GitHub
parent 90ca619839
commit 3e6d63e8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -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:

View File

@ -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