コード例 #1
0
ファイル: game.py プロジェクト: AlexTheMagnus/CodeKata-ASL
    def apply_rule_one(self, cell: Cell) -> bool:
        surrounded_alive_cells = []
        cell_positions = cell.return_position()
        x = cell_positions[0]
        y = cell_positions[1]
        allowed_positions = [[x - 1, y], [x + 1, y], [x, y - 1], [x, y + 1],
                             [x + 1, y + 1], [x - 1, y - 1], [x - 1, y + 1],
                             [x + 1, y - 1]]
        for row in range(0, self.grid.size):
            [
                surrounded_alive_cells.append(cell)
                for cell in self.grid.grid[row]
                if cell.live and cell.position in allowed_positions
            ]

        if len(surrounded_alive_cells) > 3:
            cell.live = False
            return False

        return True
コード例 #2
0
 def test_assign_correct_coordinates(self):
     state = Life(False)
     posX = Position(12)
     posY = Position(2)
     cell = Cell(live=state,position_x= posX, position_y = posY)
     self.assertEqual([12,2], cell.return_position())
コード例 #3
0
 def test_assign_wrong_coordinates(self):
     state = Life(False)
     posX = Position(-12)
     posY = Position(2)
     cell = Cell(live=state,position_x= posX, position_y = posY)
     self.assertEqual(False, cell.return_position())