We don't stop with the opt!

This commit is contained in:
Emi Simpson 2023-02-12 18:39:46 -05:00
parent f05e1ef3c6
commit e504026cfe
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
1 changed files with 16 additions and 39 deletions

View File

@ -124,41 +124,21 @@ def read_elevations(lines: Iterable[str]) -> Result[Iterator[int], UnparsableEle
]) ])
) )
def gb_to_terrain_type(green_blue: Tuple[int, int]) -> Option[Terrain]: gb_to_terrain_type = {
""" (148, 18): Terrain.OPEN_LAND,
Maps the green and blue components of a color to a terrain type. (192, 0): Terrain.ROUGH_MEADOW,
(255, 255): Terrain.EASY_FOREST,
If no terrain type exists with that color, then `None` is returned. (208, 60): Terrain.MEDIUM_FOREST,
(136, 40): Terrain.WALK_FOREST,
>>> gb_to_terrain_type((192, 0)) (73, 24): Terrain.BRUSH,
Some(<Terrain.ROUGH_MEADOW: 700>) (0, 255): Terrain.WET,
(51, 3): Terrain.ROAD,
>>> gb_to_terrain_type((192, 1)) is None (0, 0): Terrain.FOOTPATH,
True (0, 101): Terrain.OOB
""" }
match green_blue: """
case (148, 18): Maps the green and blue components of a color to a terrain type.
return Some(Terrain.OPEN_LAND) """
case (192, 0):
return Some(Terrain.ROUGH_MEADOW)
case (255, 255):
return Some(Terrain.EASY_FOREST)
case (208, 60):
return Some(Terrain.MEDIUM_FOREST)
case (136, 40):
return Some(Terrain.WALK_FOREST)
case (73, 24):
return Some(Terrain.BRUSH)
case (0, 255):
return Some(Terrain.WET)
case (51, 3):
return Some(Terrain.ROAD)
case (0, 0):
return Some(Terrain.FOOTPATH)
case (0, 101):
return Some(Terrain.OOB)
case _:
return None
class UnrecognizedColor(NamedTuple): class UnrecognizedColor(NamedTuple):
"A color in a provided map was not in the list of recognized colors" "A color in a provided map was not in the list of recognized colors"
@ -186,10 +166,7 @@ def load_gb_pixels_as_map(pixels: Iterable[Tuple[int, int]]) -> Result[Sequence[
coordinates of the pixel which could not be identified. coordinates of the pixel which could not be identified.
""" """
return sequence([ return sequence([
note( try_(lambda _: UnrecognizedColor(pix_no % 395, pix_no // 395), gb_to_terrain_type.get, gb)
lambda: UnrecognizedColor(pix_no % 395, pix_no // 395),
gb_to_terrain_type(gb)
)
for (pix_no, gb) in enumerate(pixels) for (pix_no, gb) in enumerate(pixels)
]) ])