这里是我的python代码:from numpy import *
from copy import *
def Grid(s, p):
return random.binomial(1, p, (s,s))
def InitialSpill(G, i, j):
G[i, j] = 2
def Fillable(G, i, j):
if i > 0 and G[i - 1, j] == 2:
return True
if j > 0 and G[i, j - 1] == 2:
return True
if i < len(G) - 1 and G[i + 1, j] == 2:
return True
if j < len(G) - 1 and G[i, j + 1] == 2:
return True
return False
def Fill(G):
F = copy(G)
for i in range(len(G)):
for j in range(len(G)):
if F[i, j] == 2:
G[i, j] = 3 # 3 denote a "dry" cell
elif F[i, j] == 1 and Fillable(F, i, j):
G[i, j] = 2 # 2 denote a "filled" cell
def EndReached(G): # Check if all filled cells are dry and if no c