Game of Life #1
The "Game of Life" is a cellular automaton devised by John Horton Conway in 1970.
Basically it is a zero-player game, which takes an initial state and simply evolves by itself. No further input is required. It starts with an infinite two-dimensional
orthogonal grid of square cells, each of which is in one of two possible states, alive or dead. Every cell interacts with its 8 neighbours. At each step in time, its state
depends on the number of its alive neighbours.
The Game of Life rules:
Any live cell with fewer than 2 live neighbours dies, as if caused by underpopulation.
Any live cell with 2 or 3 live neighbours lives on to the next generation.
Any live cell with more than 3 live neighbours dies, as if by overpopulation.
Any dead cell with exactly 3 live neighbours becomes a live cell, as if by reproduction.
Implement a function which takes a NumPy array p of shape 3x3. Each element is in the format of int, 1 indicates a live cell, and 0 means a dead cell. Please output if
the central cell is a live cell or not at the next iteration.
For example, if the input is the following array:
array([[ 1, 0, 0],
[ 1, 0, 0],
[ 0, 1, 0]], dtype='int')
Your output should be True since there are exactly 3 live neighbours, as if by reproduction.
Your solution:
import numpy as np
def central_cell_is_alive(p):
decision = True
### START YOUR CODE HERE ###
#### END YOUR CODE HERE ####
return decision