Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Original: https://pastebin.com/ku2GB80q
- # In action: https://repl.it/@Null_Cat/Bad-Minesweeper
- def placeNumbersNormal(usedBoard, Mine, Space):
- for i in range(usedBoard.Size[1]):
- for j in range(usedBoard.Size[0]):
- if isinstance(usedBoard.Contents[i][j], Mine):
- # catch sides
- # Up
- try:
- if isinstance(usedBoard.Contents[i-1][j], Space) and i-1 != -1:
- usedBoard.Contents[i-1][j].MinesAround += 1
- except IndexError:
- pass
- # Down
- try:
- if isinstance(usedBoard.Contents[i+1][j], Space) and i+1 != usedBoard.Size[1]+1:
- usedBoard.Contents[i+1][j].MinesAround += 1
- except IndexError:
- pass
- # Left
- try:
- if isinstance(usedBoard.Contents[i][j-1], Space) and j-1 != -1:
- usedBoard.Contents[i][j-1].MinesAround += 1
- except IndexError:
- pass
- # Right
- try:
- if isinstance(usedBoard.Contents[i][j+1], Space) and j+1 != usedBoard.Size[0]+1:
- usedBoard.Contents[i][j+1].MinesAround += 1
- except IndexError:
- pass
- # Catch Corners
- # Up-Left
- try:
- if isinstance(usedBoard.Contents[i-1][j-1], Space) and i-1 != -1 and j-1 != -1:
- usedBoard.Contents[i-1][j-1].MinesAround += 1
- except IndexError:
- pass
- # Down-Right
- try:
- if isinstance(usedBoard.Contents[i+1][j+1], Space) and i+1 != usedBoard.Size[1]+1 and j+1 != usedBoard.Size[0]+1:
- usedBoard.Contents[i+1][j+1].MinesAround += 1
- except IndexError:
- pass
- # Down-Left
- try:
- if isinstance(usedBoard.Contents[i+1][j-1], Space) and j-1 != -1 and i+1 != usedBoard.Size[1]+1:
- usedBoard.Contents[i+1][j-1].MinesAround += 1
- except IndexError:
- pass
- # Up-Right
- try:
- if isinstance(usedBoard.Contents[i-1][j+1], Space) and i-1 != -1 and j+1 != usedBoard.Size[0]+1:
- usedBoard.Contents[i-1][j+1].MinesAround += 1
- except IndexError:
- pass
- return
- def placeNumbersKnight(usedBoard, Mine, Space):
- for i in range(usedBoard.Size[1]):
- for j in range(usedBoard.Size[0]):
- if isinstance(usedBoard.Contents[i][j], Mine):
- # catch sides
- # Up
- try:
- if isinstance(usedBoard.Contents[i-1][j], Space) and i-1 != -1:
- usedBoard.Contents[i-1][j].MinesAround += 1
- except IndexError:
- pass
- # Down
- try:
- if isinstance(usedBoard.Contents[i+1][j], Space) and i+1 != usedBoard.Size[1]+1:
- usedBoard.Contents[i+1][j].MinesAround += 1
- except IndexError:
- pass
- # Left
- try:
- if isinstance(usedBoard.Contents[i][j-1], Space) and j-1 != -1:
- usedBoard.Contents[i][j-1].MinesAround += 1
- except IndexError:
- pass
- # Right
- try:
- if isinstance(usedBoard.Contents[i][j+1], Space) and j+1 != usedBoard.Size[0]+1:
- usedBoard.Contents[i][j+1].MinesAround += 1
- except IndexError:
- pass
- # Catch Corners
- # Up-Left
- try:
- if isinstance(usedBoard.Contents[i-1][j-1], Space) and i-1 != -1 and j-1 != -1:
- usedBoard.Contents[i-1][j-1].MinesAround += 1
- except IndexError:
- pass
- # Down-Right
- try:
- if isinstance(usedBoard.Contents[i+1][j+1], Space) and i+1 != usedBoard.Size[1]+1 and j+1 != usedBoard.Size[0]+1:
- usedBoard.Contents[i+1][j+1].MinesAround += 1
- except IndexError:
- pass
- # Down-Left
- try:
- if isinstance(usedBoard.Contents[i+1][j-1], Space) and j-1 != -1 and i+1 != usedBoard.Size[1]+1:
- usedBoard.Contents[i+1][j-1].MinesAround += 1
- except IndexError:
- pass
- # Up-Right
- try:
- if isinstance(usedBoard.Contents[i-1][j+1], Space) and i-1 != -1 and j+1 != usedBoard.Size[0]+1:
- usedBoard.Contents[i-1][j+1].MinesAround += 1
- except IndexError:
- pass
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement