def start_new_game(): global running_game running_game = Game()
import random from lib.helper import quit_game, remove_empty_cells, accumulate_neighbours from lib.models import Cell, Game running_game = Game() def start_new_game(): global running_game running_game = Game() def add_random_number(): """ Add a random number to an empty place in the game """ empty_cells = [] for row in running_game.game_matrix: for cell in row: if cell.empty: empty_cells.append(cell) count = len(empty_cells) if count == 0: quit_game("No more valid places!") random_cell = empty_cells[random.randint(0, count - 1)] choices = [2, 2, 4] random_cell.value = choices[random.randint(0, len(choices)-1)] def move_cells(row):