-
Notifications
You must be signed in to change notification settings - Fork 0
/
minesweeper.py
110 lines (93 loc) · 4.19 KB
/
minesweeper.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import numpy as np
bomb = 5
board = [[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0]]
board = np.array(board)
display_board = [['x','x','x','x','x'],
['x','x','x','x','x'],
['x','x','x','x','x'],
['x','x','x','x','x'],
['x','x','x','x','x']]
display_board = np.array(display_board)
def bomb_check(x,y,board_max):
bomb_around = 0
if board[y,x] == 1:
print("game over!")
print(board)
print("bombs place")
exit()
elif x == 0 and y == 0:
bomb_around = bomb_around + 1 if board[y+1,x] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y,x+1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y+1,x+1] == 1 else bomb_around
elif x == board_max and y == board_max:
bomb_around = bomb_around + 1 if board[y-1,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y-1,x] == 1 else bomb_around
elif x == 0:
if y != board_max:
bomb_around = bomb_around + 1 if board[y+1,x] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y+1,x+1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y-1,x] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y-1,x+1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y,x+1] == 1 else bomb_around
elif y == 0:
if x != board_max:
bomb_around = bomb_around + 1 if board[y,x+1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y+1,x+1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y+1,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y+1,x] == 1 else bomb_around
elif x == board_max:
bomb_around = bomb_around + 1 if board[y-1,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y+1,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y-1,x] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y+1,x] == 1 else bomb_around
elif y == board_max:
bomb_around = bomb_around + 1 if board[y-1,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y-1,x] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y-1,x+1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y,x+1] == 1 else bomb_around
else:
bomb_around = bomb_around + 1 if board[y-1,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y+1,x-1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y-1,x] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y+1,x] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y-1,x+1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y,x+1] == 1 else bomb_around
bomb_around = bomb_around + 1 if board[y+1,x+1] == 1 else bomb_around
display_board[y,x] = bomb_around
board_max = len(board) - 1
panel = len(board)**2
print(display_board)
a = input("xyの順でスペースで分割して入力").split()
x = int(a[0])
y = int(a[1])
panel -= 1
for i in range(bomb):
while(1):
tmpX = np.random.randint(0,len(board))
tmpY = np.random.randint(0,len(board))
if board[tmpY,tmpX] != 1 and tmpX != x and tmpY != y:
board[tmpY,tmpX] = 1
break
bomb_check(x,y,board_max)
while(1):
print(display_board)
a = input("xyの順でスペースで分割して入力").split()
x = int(a[0])
y = int(a[1])
#print(board.shape)
print(panel)
if display_board[y,x] == 'x':
bomb_check(x,y,board_max)
panel -= 1
if panel == bomb:
print("game clear!")
exit()