diff --git a/read_in.py b/read_in.py index 7a91d82..b14298f 100644 --- a/read_in.py +++ b/read_in.py @@ -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]: - """ - Maps the green and blue components of a color to a terrain type. - - If no terrain type exists with that color, then `None` is returned. - - >>> gb_to_terrain_type((192, 0)) - Some() - - >>> gb_to_terrain_type((192, 1)) is None - True - """ - match green_blue: - case (148, 18): - 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 +gb_to_terrain_type = { + (148, 18): Terrain.OPEN_LAND, + (192, 0): Terrain.ROUGH_MEADOW, + (255, 255): Terrain.EASY_FOREST, + (208, 60): Terrain.MEDIUM_FOREST, + (136, 40): Terrain.WALK_FOREST, + (73, 24): Terrain.BRUSH, + (0, 255): Terrain.WET, + (51, 3): Terrain.ROAD, + (0, 0): Terrain.FOOTPATH, + (0, 101): Terrain.OOB +} +""" +Maps the green and blue components of a color to a terrain type. +""" class UnrecognizedColor(NamedTuple): "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. """ return sequence([ - note( - lambda: UnrecognizedColor(pix_no % 395, pix_no // 395), - gb_to_terrain_type(gb) - ) + try_(lambda _: UnrecognizedColor(pix_no % 395, pix_no // 395), gb_to_terrain_type.get, gb) for (pix_no, gb) in enumerate(pixels) ])