コード例 #1
0
 def testNeighbourVals(self):
     board = Board(4, 5)
     self.assertEqual(board.get_neighbour_vals(
         3, 4), [False, False, False, False, False, False, False, False])
     board.set_cell(2, 3, True)
     self.assertEqual(board.get_neighbour_vals(
         3, 4), [True, False, False, False, False, False, False, False])
コード例 #2
0
 def testSetCell(self):
     board = Board(3, 4)
     self.assertEqual(board.get_cell(1, 1), False)
     board.set_cell(1, 1, True)
     self.assertEqual(board.get_cell(1, 1), True)
     self.assertEqual(board.get_cell(-1, -1), False)
     self.assertEqual(board.get_cell(3, 4), False)
コード例 #3
0
 def testLine(self):
     board = Board(3, 3)
     board.set_cell(1, 0, True)
     board.set_cell(1, 1, True)
     board.set_cell(1, 2, True)
     self.assertEqual(
         board.get_next_board().board,
         [[False, True, False], [False, True, False], [False, True, False]])
コード例 #4
0
 def testNextStateSquare(self):
     board = Board(2, 2)
     board.set_cell(0, 0, True)
     board.set_cell(1, 0, True)
     board.set_cell(0, 1, True)
     board.set_cell(1, 1, True)
     self.assertEqual(board.get_next_board().board,
                      [[True, True], [True, True]])
コード例 #5
0
ファイル: tests.py プロジェクト: akashsara/game-of-life
def get_next_state(init_state):
    board = Board(3, 3, init_state)
    board.next_state()
    return board.board
コード例 #6
0
 def testRandom(self):
     board = Board(50, 50)
     board.fill()
     assert board.get_number_filled() > 0
コード例 #7
0
 def testFillNum(self):
     board = Board(50, 50)
     board.set_cell(4, 5, True)
     self.assertEquals(board.get_number_filled(), 1)
コード例 #8
0
 def testNextState(self):
     board = Board(2, 2)
     self.assertEqual(board.get_next_board().board,
                      [[False, False], [False, False]])
コード例 #9
0
 def testRows(self):
     board = Board(3, 4)
     self.assertEqual(board.get_rows(), 3)
     self.assertEqual(board.get_cols(), 4)
コード例 #10
0
 def testAllBoardCoords(self):
     board = Board(2, 2)
     self.assertEqual(board.get_board_coords(), [(0, 0), (0, 1), (1, 0),
                                                 (1, 1)])
コード例 #11
0
 def testNextState(self):
     board = Board(4, 5)
     self.assertEqual(board.get_next_state(3, 4), False)
コード例 #12
0
 def testNumNeigh(self):
     board = Board(4, 5)
     self.assertEqual(board.get_num_neigh(3, 4), 0)
     board.set_cell(2, 3, True)
     self.assertEqual(board.get_num_neigh(3, 4), 1)
コード例 #13
0
 def testNeighbours(self):
     board = Board(3, 4)
     self.assertEqual(board.get_neighbours(3, 4), [(2, 3), (2, 4), (2, 5),
                                                   (3, 3), (3, 5), (4, 3),
                                                   (4, 4), (4, 5)])
コード例 #14
0
ファイル: main.py プロジェクト: vanessagl2/game_of_life
import time
from game_of_life import Board
import os

board = Board([
    [0, 1, 0],
    [0, 1, 0],
    [0, 1, 0],
])

for i in range(100):
    print(board)
    board.evolve()
    time.sleep(1)
    os.system('clear')