j'ai le même problème sur une matrice mais je sais pas comment le resoudre: je vous met mon code pour comprendre le problème:
J'ai une matrice avec des bombes à l'interieur et pour chaque case, il faut que je cherche les bombes autour si quelqu'un peut m'aider...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 def mineautour(size): global mat for i in range(5): for j in range(5): k=0; if (mat[i][j]=='B'): break else: if (mat[i-1][j]=='B'): k=k+1; if (mat[i-1][j+1]=='B'): k=k+1; if (mat[i][j+1]=='B'): k=k+1; if (mat[i+1][j+1]=='B'): k=k+1; if (mat[i+1][j]=='B'): k=k+1; if (mat[i+1][j-1]=='B'): k=k+1; if (mat[i][j-1]=='B'): k=k+1; if (mat[i-1][j-1]=='B'): k=k+1; if (mat[i-1][j]=='B'): k=k+1; mat[i][j]=k;
Partager