tmscli 0.1.0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tmscli/__init__.py +0 -0
- tmscli/main.py +143 -0
- tmscli-0.1.0.dist-info/METADATA +4 -0
- tmscli-0.1.0.dist-info/RECORD +6 -0
- tmscli-0.1.0.dist-info/WHEEL +5 -0
- tmscli-0.1.0.dist-info/entry_points.txt +3 -0
tmscli/__init__.py
ADDED
|
File without changes
|
tmscli/main.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import random
|
|
2
|
+
class minesweeper():
|
|
3
|
+
def __init__(self,size,num):
|
|
4
|
+
self.size=size
|
|
5
|
+
self.num=num
|
|
6
|
+
['uncovered?','flagged?','display']
|
|
7
|
+
def print_board(self,board):
|
|
8
|
+
|
|
9
|
+
top=' 1 2 3 4 5 6 7 8 9 10'
|
|
10
|
+
print(top)
|
|
11
|
+
for i in range(self.size):
|
|
12
|
+
buffer=str(i+1)+' '
|
|
13
|
+
for j in board[i]:
|
|
14
|
+
if j[0]==True:
|
|
15
|
+
buffer+=str(j[2])+' '
|
|
16
|
+
elif j[1]==True:
|
|
17
|
+
buffer+='F'+' '
|
|
18
|
+
else:
|
|
19
|
+
buffer+=' '+' '
|
|
20
|
+
print(buffer[:-1])
|
|
21
|
+
def get_mines(self):
|
|
22
|
+
mines=[]
|
|
23
|
+
while len(mines)<self.num:
|
|
24
|
+
temp=(random.randint(1,self.size),random.randint(1,self.size))
|
|
25
|
+
if temp not in mines:
|
|
26
|
+
mines.append(temp)
|
|
27
|
+
return mines
|
|
28
|
+
def sub1(self, coord):
|
|
29
|
+
a,b=coord
|
|
30
|
+
return (a-1,b-1)
|
|
31
|
+
def create_starting_board(self,mines):
|
|
32
|
+
board=[]
|
|
33
|
+
o=[False,False,0,False]
|
|
34
|
+
for i in range(self.size):
|
|
35
|
+
board.append(list([]))
|
|
36
|
+
for j in range(self.size):
|
|
37
|
+
board[i].append(list(o))
|
|
38
|
+
for i in mines:
|
|
39
|
+
mine=self.sub1(i)
|
|
40
|
+
x,y=mine
|
|
41
|
+
board[x][y][2]='M'
|
|
42
|
+
for i in range(self.size):
|
|
43
|
+
for j in range(self.size):
|
|
44
|
+
c=0
|
|
45
|
+
if board[i][j][2]=='M':
|
|
46
|
+
continue
|
|
47
|
+
for k in range(-1,2):
|
|
48
|
+
for l in range(-1,2):
|
|
49
|
+
try:
|
|
50
|
+
if board[i+k][j+l][2]=='M':
|
|
51
|
+
c+=1
|
|
52
|
+
except:
|
|
53
|
+
pass
|
|
54
|
+
board[i][j][2]=c
|
|
55
|
+
return board
|
|
56
|
+
def print_ending(self,board):
|
|
57
|
+
for i in board:
|
|
58
|
+
buffer=''
|
|
59
|
+
for j in i:
|
|
60
|
+
buffer+=str(j[2])+' '
|
|
61
|
+
print(buffer)
|
|
62
|
+
exit()
|
|
63
|
+
def check_success(self,board):
|
|
64
|
+
for i in board:
|
|
65
|
+
for j in i:
|
|
66
|
+
if j[2]!='M':
|
|
67
|
+
if not j[0]:
|
|
68
|
+
return False
|
|
69
|
+
return True
|
|
70
|
+
def check_death(self,board):
|
|
71
|
+
for i in board:
|
|
72
|
+
for j in i:
|
|
73
|
+
if j[2]=='M':
|
|
74
|
+
if j[0]:
|
|
75
|
+
return True
|
|
76
|
+
return False
|
|
77
|
+
def check(self,board):
|
|
78
|
+
if self.check_death(board):
|
|
79
|
+
print('GAME OVER')
|
|
80
|
+
self.print_ending(board)
|
|
81
|
+
elif self.check_success(board):
|
|
82
|
+
print('YOU WIN')
|
|
83
|
+
self.print_ending(board)
|
|
84
|
+
def richochet(self,board,coord):
|
|
85
|
+
x,y=coord
|
|
86
|
+
board[x][y][3]=True
|
|
87
|
+
for i in range(-1,2):
|
|
88
|
+
for j in range(-1,2):
|
|
89
|
+
try:
|
|
90
|
+
if not board[x+i][y+j][3]:
|
|
91
|
+
board[x+i][y+j][0]=True
|
|
92
|
+
board[x+i][y+j][3]=True
|
|
93
|
+
if board[x+i][y+j][2]==0:
|
|
94
|
+
self.richochet(board,(x+i,y+j))
|
|
95
|
+
except:
|
|
96
|
+
continue
|
|
97
|
+
|
|
98
|
+
return board
|
|
99
|
+
|
|
100
|
+
terminal_minesweeper=minesweeper(10,10)
|
|
101
|
+
# terminal_minesweeper.print_board(board)
|
|
102
|
+
def main_loop(board):
|
|
103
|
+
while True:
|
|
104
|
+
terminal_minesweeper.print_board(board)
|
|
105
|
+
cmd=input()
|
|
106
|
+
cmds=cmd.split()
|
|
107
|
+
if cmds[0]=='uc':
|
|
108
|
+
if (not board[int(cmds[1])-1][int(cmds[2])-1][0]) and (not board[int(cmds[1])-1][int(cmds[2])-1][1]):
|
|
109
|
+
board[int(cmds[1])-1][int(cmds[2])-1][0]=True
|
|
110
|
+
if board[int(cmds[1])-1][int(cmds[2])-1][2]==0:
|
|
111
|
+
board=terminal_minesweeper.richochet(board,(int(cmds[1])-1,int(cmds[2])-1))
|
|
112
|
+
else:
|
|
113
|
+
print('already uncovered')
|
|
114
|
+
elif cmds[0]=='fl':
|
|
115
|
+
if not board[int(cmds[1])-1][int(cmds[2])-1][1]:
|
|
116
|
+
board[int(cmds[1])-1][int(cmds[2])-1][1]=True
|
|
117
|
+
else:
|
|
118
|
+
print('already flagged')
|
|
119
|
+
elif cmds[0]=='uf':
|
|
120
|
+
if board[int(cmds[1])-1][int(cmds[2])-1][2]:
|
|
121
|
+
board[int(cmds[1])-1][int(cmds[2])-1][0]=False
|
|
122
|
+
else:
|
|
123
|
+
print('already not flagged')
|
|
124
|
+
terminal_minesweeper.check(board)
|
|
125
|
+
def run():
|
|
126
|
+
mines=terminal_minesweeper.get_mines()
|
|
127
|
+
board=terminal_minesweeper.create_starting_board(mines)
|
|
128
|
+
main_loop(board)
|
|
129
|
+
|
|
130
|
+
def print_rules():
|
|
131
|
+
print('''
|
|
132
|
+
Minesweeper is a game where you uncover squares in a minefield, and discover where the mines are
|
|
133
|
+
this version has a 10 x 10 board with 10 mines in it
|
|
134
|
+
commands:
|
|
135
|
+
uc x y = uncovers square (x,y)
|
|
136
|
+
fl x y = flags square (x,y)
|
|
137
|
+
uf x y = unflags square (x,y)
|
|
138
|
+
|
|
139
|
+
Aim:
|
|
140
|
+
uncover every square without a mine on it
|
|
141
|
+
|
|
142
|
+
If you step on a mine you lose, the number on the square is how many mines are around it (3 x 3 radius)
|
|
143
|
+
''')
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
tmscli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
tmscli/main.py,sha256=8u6byuG_E7NlsMXHyFTXEIHoY6Sqjw1t3f_7FIS_qmc,4848
|
|
3
|
+
tmscli-0.1.0.dist-info/METADATA,sha256=vZVEcwKUr6hEUcl5OJRth4SUZew7p_KsqpRJ6tumGAI,121
|
|
4
|
+
tmscli-0.1.0.dist-info/WHEEL,sha256=DnXx7cBEyVTTMvhePCuz2Now68IkDfyaQ4wNff8GnEk,105
|
|
5
|
+
tmscli-0.1.0.dist-info/entry_points.txt,sha256=xQKzfdpyJZVhr-qlnf3OPTnmd0G7t4a6GGXBoBfSHeI,72
|
|
6
|
+
tmscli-0.1.0.dist-info/RECORD,,
|