initial commit, nothing much here
This commit is contained in:
28
grid/sphere/grid.py
Normal file
28
grid/sphere/grid.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from random import choice, randint
|
||||
|
||||
from grid.sphere.cell import Cell
|
||||
|
||||
class Grid():
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.start = None
|
||||
|
||||
def set_start(self, cell: Cell):
|
||||
self.start = cell
|
||||
|
||||
@classmethod
|
||||
def generate_grid(cls, sphere_number: int=10) -> 'Grid':
|
||||
# pick an impl type instead
|
||||
starting_point = Cell()
|
||||
cls.generate_neighbors(starting_point, sphere_number)
|
||||
grid = cls()
|
||||
grid.set_start(starting_point)
|
||||
return grid
|
||||
|
||||
@classmethod
|
||||
def generate_neighbors(cls, current_cell: Cell, remaining_cells: int) -> Cell:
|
||||
number_of_neighbor = randint(Cell.MIN_NEIGHBORS, Cell.MAX_NEIGHBORS)
|
||||
for _ in number_of_neighbor:
|
||||
current_cell.add_neightbor(Cell())
|
||||
remaining_cells = max(0, remaining_cells-number_of_neighbor)
|
||||
return choice(current_cell.neighbors)
|
||||
Reference in New Issue
Block a user