Решение на Игра на живот от Рая Димитрова

Обратно към всички решения

Към профила на Рая Димитрова

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 1 неуспешни тест(а)

Код

def step_board(board):
new_board = create_board()
for row in range(1, BOARD_SIZE + 1):
for column in range(1, BOARD_SIZE + 1):
new_board[row][column] = 0
alive_neighbours = 0
for r in [row - 1, row, row + 1]:
for c in [column - 1, column, column + 1]:
if board[r][c] == 1:
alive_neighbours += 1
if board[row][column] == 1:
alive_neighbours -= 1
if alive_neighbours == 2 or alive_neighbours == 3:
new_board[row][column] = 1
elif board[row][column] == 0:
if alive_neighbours == 3:
new_board[row][column] = 1
for row in range(1, BOARD_SIZE + 1):
for column in range(1, BOARD_SIZE + 1):
board[row][column] = new_board[row][column]

Лог от изпълнението

E
======================================================================
ERROR: test_step_board (__main__.GameOfLifeTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120625-4142-1aqxjrj", line 10, in test_step_board
    self.solution.step_board(board)
  File "/tmp/solution20120625-4142-fpxdad", line 2, in step_board
    new_board = create_board()
NameError: global name 'create_board' is not defined

----------------------------------------------------------------------
Ran 1 test in 0.004s

FAILED (errors=1)

История (1 версия и 0 коментара)

Рая обнови решението на 30.03.2012 22:33 (преди над 12 години)

+def step_board(board):
+ new_board = create_board()
+ for row in range(1, BOARD_SIZE + 1):
+ for column in range(1, BOARD_SIZE + 1):
+ new_board[row][column] = 0
+ alive_neighbours = 0
+ for r in [row - 1, row, row + 1]:
+ for c in [column - 1, column, column + 1]:
+ if board[r][c] == 1:
+ alive_neighbours += 1
+ if board[row][column] == 1:
+ alive_neighbours -= 1
+ if alive_neighbours == 2 or alive_neighbours == 3:
+ new_board[row][column] = 1
+ elif board[row][column] == 0:
+ if alive_neighbours == 3:
+ new_board[row][column] = 1
+ for row in range(1, BOARD_SIZE + 1):
+ for column in range(1, BOARD_SIZE + 1):
+ board[row][column] = new_board[row][column]