# placeBoardNumbers.py (Terminal [Python])

Mar 27th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # Original: https://pastebin.com/ku2GB80q
3.
4. def placeNumbersNormal(usedBoard, Mine, Space):
5.   for i in range(usedBoard.Size[1]):
6.     for j in range(usedBoard.Size[0]):
7.       if isinstance(usedBoard.Contents[i][j], Mine):
8.         # catch sides
9.         # Up
10.         try:
11.           if isinstance(usedBoard.Contents[i-1][j], Space) and i-1 != -1:
12.             usedBoard.Contents[i-1][j].MinesAround += 1
13.         except IndexError:
14.           pass
15.         # Down
16.         try:
17.           if isinstance(usedBoard.Contents[i+1][j], Space) and i+1 != usedBoard.Size[1]+1:
18.             usedBoard.Contents[i+1][j].MinesAround += 1
19.         except IndexError:
20.           pass
21.         # Left
22.         try:
23.           if isinstance(usedBoard.Contents[i][j-1], Space) and j-1 != -1:
24.             usedBoard.Contents[i][j-1].MinesAround += 1
25.         except IndexError:
26.           pass
27.         # Right
28.         try:
29.           if isinstance(usedBoard.Contents[i][j+1], Space) and j+1 != usedBoard.Size[0]+1:
30.             usedBoard.Contents[i][j+1].MinesAround += 1
31.         except IndexError:
32.           pass
33.
34.         # Catch Corners
35.         # Up-Left
36.         try:
37.           if isinstance(usedBoard.Contents[i-1][j-1], Space) and i-1 != -1 and j-1 != -1:
38.             usedBoard.Contents[i-1][j-1].MinesAround += 1
39.         except IndexError:
40.           pass
41.         # Down-Right
42.         try:
43.           if isinstance(usedBoard.Contents[i+1][j+1], Space) and i+1 != usedBoard.Size[1]+1 and j+1 != usedBoard.Size[0]+1:
44.             usedBoard.Contents[i+1][j+1].MinesAround += 1
45.         except IndexError:
46.           pass
47.         # Down-Left
48.         try:
49.           if isinstance(usedBoard.Contents[i+1][j-1], Space) and j-1 != -1 and i+1 != usedBoard.Size[1]+1:
50.             usedBoard.Contents[i+1][j-1].MinesAround += 1
51.         except IndexError:
52.           pass
53.         # Up-Right
54.         try:
55.           if isinstance(usedBoard.Contents[i-1][j+1], Space) and i-1 != -1 and j+1 != usedBoard.Size[0]+1:
56.             usedBoard.Contents[i-1][j+1].MinesAround += 1
57.         except IndexError:
58.           pass
59.   return
60. def placeNumbersKnight(usedBoard, Mine, Space):
61.   for i in range(usedBoard.Size[1]):
62.     for j in range(usedBoard.Size[0]):
63.       if isinstance(usedBoard.Contents[i][j], Mine):
64.         # catch sides
65.         # Up
66.         try:
67.           if isinstance(usedBoard.Contents[i-1][j], Space) and i-1 != -1:
68.             usedBoard.Contents[i-1][j].MinesAround += 1
69.         except IndexError:
70.           pass
71.         # Down
72.         try:
73.           if isinstance(usedBoard.Contents[i+1][j], Space) and i+1 != usedBoard.Size[1]+1:
74.             usedBoard.Contents[i+1][j].MinesAround += 1
75.         except IndexError:
76.           pass
77.         # Left
78.         try:
79.           if isinstance(usedBoard.Contents[i][j-1], Space) and j-1 != -1:
80.             usedBoard.Contents[i][j-1].MinesAround += 1
81.         except IndexError:
82.           pass
83.         # Right
84.         try:
85.           if isinstance(usedBoard.Contents[i][j+1], Space) and j+1 != usedBoard.Size[0]+1:
86.             usedBoard.Contents[i][j+1].MinesAround += 1
87.         except IndexError:
88.           pass
89.
90.         # Catch Corners
91.         # Up-Left
92.         try:
93.           if isinstance(usedBoard.Contents[i-1][j-1], Space) and i-1 != -1 and j-1 != -1:
94.             usedBoard.Contents[i-1][j-1].MinesAround += 1
95.         except IndexError:
96.           pass
97.         # Down-Right
98.         try:
99.           if isinstance(usedBoard.Contents[i+1][j+1], Space) and i+1 != usedBoard.Size[1]+1 and j+1 != usedBoard.Size[0]+1:
100.             usedBoard.Contents[i+1][j+1].MinesAround += 1
101.         except IndexError:
102.           pass
103.         # Down-Left
104.         try:
105.           if isinstance(usedBoard.Contents[i+1][j-1], Space) and j-1 != -1 and i+1 != usedBoard.Size[1]+1:
106.             usedBoard.Contents[i+1][j-1].MinesAround += 1
107.         except IndexError:
108.           pass
109.         # Up-Right
110.         try:
111.           if isinstance(usedBoard.Contents[i-1][j+1], Space) and i-1 != -1 and j+1 != usedBoard.Size[0]+1:
112.             usedBoard.Contents[i-1][j+1].MinesAround += 1
113.         except IndexError:
114.           pass
115.   return