Skip to content

Commit

Permalink
refactor: refacotor to make stuff work
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasfremming committed Nov 5, 2024
1 parent 9ce6330 commit 198c620
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 36 deletions.
11 changes: 3 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ def create_population(population_size, creature: Creature):
return population

def main():

genetic_algorithm = GeneticAlgorithm()

# Initialize Pygame and Pymunk

pygame.init()
screen_width, screen_height = SCREEN_WIDTH, SCREEN_HEIGHT
screen = pygame.display.set_mode((screen_width, screen_height))
Expand All @@ -96,8 +91,8 @@ def main():
environment.ground_type = GroundType.BASIC_GROUND

population_size = 10
creatures = create_creatures(population_size, space)
creature_instance = creatures[0]
creatures: list[Creature] = create_creatures(population_size, space)
creature_instance: Creature = creatures[0]
population = create_population(population_size, creature_instance)
neat_networks: list[NEATNetwork] = []
for genome in population:
Expand All @@ -122,7 +117,7 @@ def main():
screen.fill((135, 206, 235))
environment.update()
environment.render()
creature.render(screen)
creature_instance.render(screen)

# TODO: vision should be part of a creature, and not environment
inputs = np.array([environment.vision.get_near_periphery().x,
Expand Down
4 changes: 3 additions & 1 deletion src/agent_parts/creature.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@


class Creature:

limbs: list[Limb]
motors: list[MotorJoint]

def __init__(self, space):
"""Initialize a creature with an empty list of limbs and motors."""
self.space = space
Expand Down
29 changes: 2 additions & 27 deletions src/game_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,5 @@


class GameLoop:

def scene_graph(
self,
scene_node: RenderObject,
transformations: list
) -> None:

"""
A method that traverses the scene graph and applies '
transformations to the nodes.
Parameters:
----------
scene_node : RenderObject
The root node of the scene graph.
transformations : list
A list of transformations to apply to the nodes.
"""
for transformation in transformations:
transformation.apply(scene_node)

scene_node.render()

for child in scene_node.children:
self.scene_graph(child, transformations)




5 changes: 5 additions & 0 deletions src/ground.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ def get_first_shifted_point(self) -> tuple[int, int]:
scroll_offset = self.start_x-self.poly.body.position[0]
return (points[0][0] - scroll_offset, points[0][1])

def init_pymunk_polygon(self, space) -> None:
body = pymunk.Body(0, 0, 1)
poly = pymunk.Poly(body, self.points, radius=0.0)
space.add(body, poly)

class BasicGround(RenderObject, Ground, BasicSegment):
def __init__(self, screen: pg.display, space: pymunk.space, segment_width: int) -> None:
self.screen = screen
Expand Down

0 comments on commit 198c620

Please sign in to comment.