From cab4b6815ed0a585771d9f10abc393f6a83ba904 Mon Sep 17 00:00:00 2001 From: David GAILLETON Date: Sun, 15 Mar 2026 15:40:58 +0100 Subject: [PATCH] commit before uv rework --- Makefile | 19 ++++++++++++++ requirement.txt | 4 +++ src/lib/class/Cell.py | 59 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 requirement.txt create mode 100644 src/lib/class/Cell.py diff --git a/Makefile b/Makefile index e69de29..b88045a 100644 --- a/Makefile +++ b/Makefile @@ -0,0 +1,19 @@ +install: + pip install -r requirement.txt + +run: + python3 a_maze_ing.py config.txt + +debug: + pdb python3 a_maze_ing.py config.txt + +clean: + rm -rf __pycache__ .mypy_cache + +lint: + flake8 . + mypy . --warn-return-any --warn-unused-ignores --ignore-missing-imports --disallow-untyped-defs --check-untyped-defs + +lint-strict: + flake8 . + mypy . --strict diff --git a/requirement.txt b/requirement.txt new file mode 100644 index 0000000..c024d7d --- /dev/null +++ b/requirement.txt @@ -0,0 +1,4 @@ +pydantic +numpy +flake8 +mypy diff --git a/src/lib/class/Cell.py b/src/lib/class/Cell.py new file mode 100644 index 0000000..67d3ee6 --- /dev/null +++ b/src/lib/class/Cell.py @@ -0,0 +1,59 @@ +from pydantic import BaseModel, Field + + +class Cell(BaseModel): + value: int = Field(ge=0, le=15) + + def __str__(self) -> str: + return hex(self.value) + + def set_north(self, is_wall: bool) -> None: + if (is_wall and self.value | 14 == 15) or ( + not is_wall and self.value | 14 != 15 + ): + self.value = self.value ^ (1) + + def get_north(self) -> bool: + return self.value & 1 == 1 + + def set_est(self, is_wall: bool) -> None: + if (is_wall and self.value | 13 == 15) or ( + not is_wall and self.value | 13 != 15 + ): + self.value = self.value ^ (2) + + def get_est(self) -> bool: + return self.value & 2 == 2 + + def set_south(self, is_wall: bool) -> None: + if (is_wall and self.value | 11 == 15) or ( + not is_wall and self.value | 11 != 15 + ): + self.value = self.value ^ (4) + + def get_south(self) -> bool: + return self.value & 4 == 4 + + def set_west(self, is_wall: bool) -> None: + if (is_wall and self.value | 8 == 15) or ( + not is_wall and self.value | 8 != 15 + ): + self.value = self.value ^ (8) + + def get_west(self) -> bool: + return self.value & 8 == 8 + + +def main() -> None: + c = Cell(value=1) + print(c.get_north()) + c.set_north(True) + print(c.get_north()) + c.set_north(True) + print(c.get_north()) + c.set_north(False) + print(c.get_north()) + + +if __name__ == "__main__": + main()