I have a grid that looks like this. I place one "b" randomly in the grid and put the number 1 surround the letter "b". This seems to work everywhere except when a 1 is supposed to be placed on the bottom row and the column all the way to the right. For example, it would look something like this
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 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
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 0 0 0 1 0
0 0 0 0 0 0 0 0 1 b
0 0 0 0 0 0 0 0 0 0
Where it should look like
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 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
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 0 0 0 1 1
0 0 0 0 0 0 0 0 1 b
0 0 0 0 0 0 0 0 1 1
Here is the code I am using and I can't figure out why those 1's arent being placed there.
from random import*
mat1 = []
mat2 = []
def makemat(x):
for y in range(x):
list1 = []
list2 = []
for z in range(x):
list1.append(0)
list2.append("-")
mat1.append(list1)
mat2.append(list2)
makemat(10)
def printmat(mat):
for a in range(len(mat)):
for b in range(len(mat)):
print(str(mat[a][b]) + "\t",end="")
print("\t")
def addmines(z):
count = 0
while (count < z):
x = randrange(0,len(mat1))
y = randrange(0,len(mat1))
if mat1[y][x] == "b":
count -= 1
else:
mat1[y][x] = "b"
count += 1
addmines(1)
def addscores():
for x in range(len(mat1)):
for y in range(len(mat1)):
if ((y < len(mat1)-1) and (x < len(mat1)-1)) and ((y >= 0) and (x >= 0))):
if mat1[y+1][x] == "b":
mat1[y][x] = 1
if mat1[y-1][x] == "b":
mat1[y][x] = 1
if mat1[y][x+1] == "b":
mat1[y][x] = 1
if mat1[y][x-1] == "b":
mat1[y][x] = 1
if mat1[y+1][x+1] == "b":
mat1[y][x] = 1
if mat1[y+1][x-1] == "b":
mat1[y][x] = 1
if mat1[y-1][x+1] == "b":
mat1[y][x] = 1
if mat1[y-1][x-1] == "b":
mat1[y][x] = 1
printmat(mat1)
addscores()