From 34a1709a36849a31468b170ceca1318ab01ba818 Mon Sep 17 00:00:00 2001 From: Ksan Date: Sat, 20 Dec 2025 19:52:49 +0100 Subject: [PATCH] inital commit --- .gitignore | 10 ++++++++++ map | 7 +++++++ src/minesolver.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 .gitignore create mode 100644 map create mode 100644 src/minesolver.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f46ee83 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +plan + +# Virtual environment +.venv/ + +# Python cache files +__pycache__/ +*.pyc +*.pyo + diff --git a/map b/map new file mode 100644 index 0000000..3dc76a1 --- /dev/null +++ b/map @@ -0,0 +1,7 @@ +0 1 x 1 1 +0 2 2 3 x +0 1 x 3 1 +0 1 1 1 0 +0 0 0 0 0 +0 1 1 2 0 +0 1 x 2 x diff --git a/src/minesolver.py b/src/minesolver.py new file mode 100644 index 0000000..3a02cfc --- /dev/null +++ b/src/minesolver.py @@ -0,0 +1,49 @@ +from enum import IntEnum + +class Tile(IntEnum): + UNKNOWN = -1 + FLAG = -2 + EMPTY = 0 + ONE = 1 + TWO = 2 + THREE = 3 + FOUR = 4 + FIVE = 5 + SIX = 6 + SEVEN = 7 + EIGHT = 8 + +def makegrid(n,m, value=Tile.UNKNOWN): + return [[value for _ in range(m)] for _ in range(n)] + +def print_grid(grid): + for row in grid: + print(" ".join(f"[{cell}]" for cell in row)) + +def loadMap(location: str): + rows = 0 + cols = 0 + + with open("map", "r") as f: + for i in f: + rows+=1 + print(i) + if rows == 1: + for j in i.split(): + print(j) + cols +=1 + + return [rows, cols, map] + + +loadedmap = loadMap("map") +map = loadedmap[2] +print("====") +print(loadedmap[0]) +print(loadedmap[1]) +grid = makegrid(loadedmap[0], loadedmap[1]) +print_grid(grid) + +print(map) + +