From 642a32b8840a3e78cf4a007bc562f744609149c8 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Wed, 14 Dec 2022 06:51:55 +0100 Subject: [PATCH] Grid.count(); Grid.print() not handles Enums --- tools/grid.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/grid.py b/tools/grid.py index 91def3e..9312d72 100644 --- a/tools/grid.py +++ b/tools/grid.py @@ -143,6 +143,9 @@ class Grid: def getOnCount(self) -> int: return len(self.__grid) + def count(self, value: Any) -> int: + return len([x for x in self.values() if x == value]) + def isSet(self, pos: Coordinate) -> bool: return pos in self.__grid @@ -364,7 +367,11 @@ class Grid: elif true_char: print(true_char if self.get(Coordinate(x, y)) else false_char, end="") else: - print(self.get(Coordinate(x, y)), end="") + value = self.get(Coordinate(x, y)) + if isinstance(value, Enum): + print(value.value, end="") + else: + print(value, end="") print(spacer, end="") print()