-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemineur.py
68 lines (53 loc) · 2.12 KB
/
demineur.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# fonction génératrice de grille à partir d'une taille de côté M - ou 2 tailles (M,N)
# cases K : cases pleines, ou noires, ou True, ou X ; répartie aléatoirement
# cases vides, ou blanches, ou False,
# Générer cette grille en ligne de commande en python.
import random
def main():
revealGrid(3, 5, "#", "⬜️", "💣")
print()
def createEmptyGrid(widthSide, lengthSide, hiddenSquare):
gridList = []
newList = []
for length in range(lengthSide):
for width in range(widthSide):
newList.append(hiddenSquare)
print(newList, end="")
gridList.append(newList)
newList = []
print()
return gridList
def countBombs(grid, square):
counterOfBombs = 0
for sublist in grid:
for item in sublist:
if item == square:
counterOfBombs += 1
else:
counterOfBombs = counterOfBombs
print("nombre de bombes: ", counterOfBombs)
def revealGrid(widthSide, lengthSide, hiddenSquare, emptySquare, fullSquare):
gridList = createEmptyGrid(widthSide, lengthSide, hiddenSquare)
randomList = [emptySquare, fullSquare, emptySquare]
repetition = int(widthSide) * int(lengthSide)
newList = []
# print("grid list de départ: ", gridList)
for i in range(repetition):
squareClicked = input("Enter the location of a square: ")
squareLocationOrd, squareLocationAbs = squareClicked.split(':')
ord = int(squareLocationOrd)
abs = int(squareLocationAbs)
for length in range(0, lengthSide):
for width in range(0, widthSide):
newList.append(hiddenSquare)
if width + 1 == abs and length + 1 == ord:
newList.insert(abs, random.choice(randomList))
newList.pop(width)
gridList[ord - 1].insert(abs - 1, newList[abs - 1])
gridList[ord - 1].pop(width + 1)
print(newList, end="")
newList = []
print()
print("gridList: ", gridList)
countBombs(gridList, fullSquare)
main()