Compare commits

..

No commits in common. "e972dcfd8329e845dedc4e2c8f965c2e5cc536d3" and "2929495348b0a4e1a1f777aca6a31543717a38da" have entirely different histories.

13 changed files with 4 additions and 95 deletions

3
.idea/.gitignore vendored
View File

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/PythEnv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>

View File

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (Machine_learning_2023)" project-jdk-type="Python SDK" />
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Machine_learning_2023.iml" filepath="$PROJECT_DIR$/.idea/Machine_learning_2023.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -30,13 +30,5 @@ class VacuumMoveCommand(Command):
if self.world.is_obstacle_at(end_x, end_y): if self.world.is_obstacle_at(end_x, end_y):
return return
if self.world.is_garbage_at(end_x, end_y):
if self.vacuum.get_container_filling() < 100:
self.vacuum.increase_container_filling()
self.world.dust[end_x][end_y].pop()
if self.world.is_docking_station_at(end_x, end_y):
self.vacuum.dump_trash()
self.vacuum.x = end_x self.vacuum.x = end_x
self.vacuum.y = end_y self.vacuum.y = end_y

View File

@ -1,10 +0,0 @@
from domain.entities.entity import Entity
from domain.world import World
class Doc_Station(Entity):
def __init__(self, x: int, y: int):
super().__init__(x, y, "DOC_STATION")
self.power = True
# TODO Docing Station: add more properties

View File

@ -9,13 +9,4 @@ class Vacuum(Entity):
self.cleaning_detergent = 100 self.cleaning_detergent = 100
self.container_filling = 0 self.container_filling = 0
def increase_container_filling(self) -> None:
self.container_filling += 25
def dump_trash(self) -> None:
self.container_filling = 0
def get_container_filling(self):
return self.container_filling
# TODO VACUUM: add more properties # TODO VACUUM: add more properties

View File

@ -2,7 +2,7 @@ from domain.entities.entity import Entity
class World: class World:
def __init__(self, width: int, height: int) -> object: def __init__(self, width: int, height: int):
self.width = width self.width = width
self.height = height self.height = height
self.dust = [[[] for j in range(height)] for i in range(width)] self.dust = [[[] for j in range(height)] for i in range(width)]
@ -10,15 +10,12 @@ class World:
self.vacuum = None self.vacuum = None
self.cat = None self.cat = None
self.doc_station = None
def add_entity(self, entity: Entity): def add_entity(self, entity: Entity):
if entity.type == "PEEL": if entity.type == "PEEL":
self.dust[entity.x][entity.y].append(entity) self.dust[entity.x][entity.y].append(entity)
elif entity.type == "VACUUM": elif entity.type == "VACUUM":
self.vacuum = entity self.vacuum = entity
elif entity.type == "DOC_STATION":
self.doc_station = entity
elif entity.type == "CAT": elif entity.type == "CAT":
self.cat = entity self.cat = entity
self.obstacles[entity.x][entity.y].append(entity) self.obstacles[entity.x][entity.y].append(entity)
@ -27,9 +24,3 @@ class World:
def is_obstacle_at(self, x: int, y: int) -> bool: def is_obstacle_at(self, x: int, y: int) -> bool:
return bool(self.obstacles[x][y]) return bool(self.obstacles[x][y])
def is_garbage_at(self, x: int, y: int) -> bool:
return bool(self.dust[x][y])
def is_docking_station_at(self, x: int, y: int) -> bool:
return bool(self.doc_station.x == x and self.doc_station.y == y)

View File

@ -7,7 +7,6 @@ from domain.commands.vacuum_move_command import VacuumMoveCommand
from domain.entities.cat import Cat from domain.entities.cat import Cat
from domain.entities.entity import Entity from domain.entities.entity import Entity
from domain.entities.vacuum import Vacuum from domain.entities.vacuum import Vacuum
from domain.entities.docking_station import Doc_Station
from domain.world import World from domain.world import World
from view.renderer import Renderer from view.renderer import Renderer
@ -63,6 +62,7 @@ class Main:
def update(self): def update(self):
self.commands.append(RandomCatMoveCommand(self.world, self.world.cat)) self.commands.append(RandomCatMoveCommand(self.world, self.world.cat))
for command in self.commands: for command in self.commands:
command.run() command.run()
self.commands.clear() self.commands.clear()
@ -75,7 +75,6 @@ def generate_world(tiles_x: int, tiles_y: int) -> World:
temp_y = randint(0, tiles_y - 1) temp_y = randint(0, tiles_y - 1)
world.add_entity(Entity(temp_x, temp_y, "PEEL")) world.add_entity(Entity(temp_x, temp_y, "PEEL"))
world.vacuum = Vacuum(1, 1) world.vacuum = Vacuum(1, 1)
world.doc_station = Doc_Station(9, 8)
world.cat = Cat(7, 8) world.cat = Cat(7, 8)
world.add_entity(world.cat) world.add_entity(world.cat)
world.add_entity(Entity(2, 8, "PLANT1")) world.add_entity(Entity(2, 8, "PLANT1"))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

View File

@ -31,13 +31,10 @@ class Renderer:
pygame.display.set_caption("AI Vacuum Cleaner") pygame.display.set_caption("AI Vacuum Cleaner")
self.screen = pygame.display.set_mode((self.width, self.height)) self.screen = pygame.display.set_mode((self.width, self.height))
self.font = pygame.font.SysFont('Arial', 26, bold=True)
self.sprites = { self.sprites = {
"VACUUM": pygame.transform.scale(pygame.image.load("media/sprites/vacuum.png"), "VACUUM": pygame.transform.scale(pygame.image.load("media/sprites/vacuum.png"),
(self.tile_width, self.tile_height)), (self.tile_width, self.tile_height)),
"DOC_STATION": pygame.transform.scale(pygame.image.load("media/sprites/docking_station.png"),
(self.tile_width, self.tile_height)),
"WALL": pygame.transform.scale(pygame.image.load("media/sprites/wall.png"), "WALL": pygame.transform.scale(pygame.image.load("media/sprites/wall.png"),
(self.tile_width, self.tile_height)), (self.tile_width, self.tile_height)),
"TILE": pygame.transform.scale(pygame.image.load("media/sprites/tile_cropped.jpeg"), "TILE": pygame.transform.scale(pygame.image.load("media/sprites/tile_cropped.jpeg"),
@ -79,7 +76,6 @@ class Renderer:
for entity in world.obstacles[x][y]: for entity in world.obstacles[x][y]:
self.draw_entity(entity) self.draw_entity(entity)
self.draw_entity(world.vacuum) self.draw_entity(world.vacuum)
self.draw_entity(world.doc_station)
self.draw_entity(world.cat) self.draw_entity(world.cat)
pygame.display.update() pygame.display.update()
@ -96,19 +92,10 @@ class Renderer:
def draw_entity(self, entity: Entity): def draw_entity(self, entity: Entity):
sprite = self.sprites.get(entity.type, None) sprite = self.sprites.get(entity.type, None)
draw_pos = (entity.x * self.tile_width, entity.y * self.tile_height) draw_pos = (entity.x * self.tile_width, entity.y * self.tile_height)
if "PEEL" in entity.type:
draw_pos = ((entity.x - 0.1) * self.tile_width, (entity.y - 0.25) * self.tile_height)
if "PLANT" in entity.type: if "PLANT" in entity.type:
draw_pos = ((entity.x - 0.1) * self.tile_width, (entity.y - 0.25) * self.tile_height) draw_pos = ((entity.x - 0.1) * self.tile_width, (entity.y - 0.25) * self.tile_height)
if "CAT" in entity.type and isinstance(entity, Cat): if "CAT" in entity.type and isinstance(entity, Cat):
sprite = self.cat_direction_sprite[entity.direction] sprite = self.cat_direction_sprite[entity.direction]
if "VACUUM" in entity.type:
# Add text displaying container filling level
text_surface = self.font.render(f"Filling: {entity.container_filling}%", True, Color("black"))
text_pos = (draw_pos[0] + self.tile_width / 2 - text_surface.get_width() / 2, draw_pos[1] + self.tile_height)
self.screen.blit(text_surface, text_pos)
if "DOC_STATION" in entity.type:
draw_pos = ((entity.x - 0.1) * self.tile_width, (entity.y - 0.25) * self.tile_height)
self.screen.blit(sprite, draw_pos) self.screen.blit(sprite, draw_pos)
def draw_sprite(self, x: int, y: int, sprite_name: str): def draw_sprite(self, x: int, y: int, sprite_name: str):