-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcellExplore.py
More file actions
49 lines (35 loc) · 1.88 KB
/
cellExplore.py
File metadata and controls
49 lines (35 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from globalVal import *
from utils import checkInsideLength
from kivy.app import App
def exploreFromStart(cellX, cellY): # this function handles the exploration of cells that have an adj count > 0
exploreNext = [[cellX, cellY]]
while len(exploreNext) != 0:
nextGen = []
for (index, cell) in enumerate(exploreNext):
exploreAdjCell(cell, nextGen)
exploreNext = nextGen
def exploreAdjCell(cellPos, nextGen):
if exploreWithOffset(cellPos, 1, 0): nextGen.append([cellPos[0] + 1, cellPos[1]])
if exploreWithOffset(cellPos, -1, 0): nextGen.append([cellPos[0] - 1, cellPos[1]])
if exploreWithOffset(cellPos, 0, 1): nextGen.append([cellPos[0], cellPos[1] + 1])
if exploreWithOffset(cellPos, 0, -1): nextGen.append([cellPos[0], cellPos[1] - 1])
if exploreWithOffset(cellPos, 0, 0): nextGen.append([cellPos[0], cellPos[1]])
# diagonals
if exploreWithOffset(cellPos, 1, 1): nextGen.append([cellPos[0] + 1, cellPos[1] + 1])
if exploreWithOffset(cellPos, 1, -1): nextGen.append([cellPos[0] + 1, cellPos[1] - 1])
if exploreWithOffset(cellPos, -1, 1): nextGen.append([cellPos[0] - 1, cellPos[1] + 1])
if exploreWithOffset(cellPos, -1, -1): nextGen.append([cellPos[0] - 1, cellPos[1] - 1])
def exploreWithOffset(cellPos, offX, offY):
if not checkInsideLength(cellPos[0] + offX, cellPos[1] + offY, CELLCOUNT):
return False
cell = cells[cellPos[0] + offX][cellPos[1] + offY]
if cell.cellHiddenState == 1 or cell.cellState == 1:
# this is a bomb, or it is discovered, or it is surrounded by bombs
return False
cell.cellState = 1 # explored
cell.background_color = CELL_DISCOVER_COLOR
if cell.adjBombCount != 0:
cell.callCell()
if not App.get_running_app().isInsideDialog:
cell.checkDialog() # the possibility is calculated inside the button
return cell.adjBombCount == 0