inital commit
This commit is contained in:
commit
34a1709a36
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
plan
|
||||||
|
|
||||||
|
# Virtual environment
|
||||||
|
.venv/
|
||||||
|
|
||||||
|
# Python cache files
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
|
||||||
7
map
Normal file
7
map
Normal file
@ -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
|
||||||
49
src/minesolver.py
Normal file
49
src/minesolver.py
Normal file
@ -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)
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user