38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
|
import random
|
||
|
import time
|
||
|
|
||
|
def calc_check_area(row: int, column: int, rows: int, columns: int) -> list:
|
||
|
min_row = row-1
|
||
|
if min_row < 0:
|
||
|
min_row = 0
|
||
|
|
||
|
max_row = row+2
|
||
|
if max_row >= rows:
|
||
|
max_row = rows
|
||
|
|
||
|
min_column = column-1
|
||
|
if min_column < 0:
|
||
|
min_column = 0
|
||
|
|
||
|
max_column = column+2
|
||
|
if max_column >= columns:
|
||
|
max_column = columns
|
||
|
|
||
|
check_rows = list(range(min_row, max_row))
|
||
|
check_columns = list(range(min_column, max_column))
|
||
|
check_list = []
|
||
|
|
||
|
for check_row in check_rows:
|
||
|
for check_column in check_columns:
|
||
|
if not (check_row == row and check_column == column):
|
||
|
check_list.append((check_row, check_column))
|
||
|
|
||
|
return check_list
|
||
|
|
||
|
def randomise(columns: int, rows: int, probability: int, color_status: list, green: tuple):
|
||
|
random.seed(int(time.time()))
|
||
|
for column in range(columns):
|
||
|
for row in range(rows):
|
||
|
r = random.randint(0,10001)
|
||
|
if r <= int(probability*100):
|
||
|
color_status[row][column] = green
|