-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path疫情.py
110 lines (92 loc) · 2.84 KB
/
疫情.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 random
def createlist(c):
a=[]
b=[]
for i in range(c):
b=[]
for j in range(c):
b.append(0)
a.append(b)
return a
def printlist(a):
for i in range(len(a)):
print(a[i])
print()
def createpeople(list,people):
for i in range(len(list)):
for j in range(people):
list[i][j]=1
list[0][0]=2
list[0][1]=0
return list
def listrandom(list):
for i in range(len(list)):
for i in range(len(list[i])):
random.shuffle(list[i])
random.shuffle(list)
return list
def goto(list,x,y,a):
if list[y][x]!=0:
if a==1:
if y-1>=0 and list[y-1][x]==0:
list[y-1][x]=list[y][x]
list[y][x]=0
if a==2:
if y+1<len(list) and list[y+1][x]==0:
list[y+1][x]=list[y][x]
list[y][x]=0
if a==3:
if x-1>=0 and list[y][x-1]==0:
list[y][x-1]=list[y][x]
list[y][x]=0
if a==4:
if x+1<len(list[y]) and list[y][x+1]==0:
list[y][x+1]=list[y][x]
list[y][x]=0
return list
def refresh(list):
for i in range(len(list)):
for j in range(len(list[i])):
if list[i][j]!=0 and list[i][j]<=2:
list=goto(list,j,i,random.randint(1,4))
if list[i][j]>2:
list[i][j]=list[i][j]-1
list=goto(list,j,i,random.randint(1,4))
return list
def disease(list,a,x,y,q):
if list[y][x]==1:
if y+1<len(list) and list[y+1][x]>=2:
b=random.randint(1,100)
if b<=a:
list[y][x]=q
if y-1>-1 and list[y-1][x]>=2:
b=random.randint(1,100)
if b<=a:
list[y][x]=q
if y+1<len(list) and x+1<len(list[0]) and list[y+1][x+1]>=2:
b=random.randint(1,100)
if b<=a:
list[y][x]=q
if y+1<len(list) and x-1>-1 and list[y+1][x-1]>=2:
b=random.randint(1,100)
if b<=a:
list[y][x]=q
if y>-1 and x+1<len(list[0]) and list[y-1][x+1]>=2:
b=random.randint(1,100)
if b<=a:
list[y][x]=q
if y-1>-1 and x-1>-1 and list[y-1][x-1]>=2:
b=random.randint(1,100)
if b<=a:
list[y][x]=q
return list
def refresh2(list,s,q,z):
for i in range(len(list)):
for j in range(len(list[i])):
b=random.randint(1,100)
if list[i][j]==1:
list=disease(list,s,i,j,q)
if list[i][j]==2:
if b<=z:
list[i][j]=0
return list