changes
This commit is contained in:
parent
ddb69cc1ec
commit
ef7aa77470
12
.gitignore
vendored
12
.gitignore
vendored
@ -1,7 +1,7 @@
|
|||||||
/venv
|
/venv
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/.vscode
|
/.vscode
|
||||||
__pycache__
|
__pycache__
|
||||||
|
|
||||||
#PyCharm
|
#PyCharm
|
||||||
.idea/
|
.idea/
|
6
.idea/.gitignore
vendored
6
.idea/.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
# Default ignored files
|
# Default ignored files
|
||||||
/shelf/
|
/shelf/
|
||||||
/workspace.xml
|
/workspace.xml
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module type="PYTHON_MODULE" version="4">
|
<module type="PYTHON_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<excludeFolder url="file://$MODULE_DIR$/PythEnv" />
|
<excludeFolder url="file://$MODULE_DIR$/PythEnv" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PyDocumentationSettings">
|
<component name="PyDocumentationSettings">
|
||||||
<option name="format" value="PLAIN" />
|
<option name="format" value="PLAIN" />
|
||||||
<option name="myDocStringFormat" value="Plain" />
|
<option name="myDocStringFormat" value="Plain" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -1,6 +1,6 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
<component name="InspectionProjectProfileManager">
|
||||||
<settings>
|
<settings>
|
||||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
<version value="1.0" />
|
<version value="1.0" />
|
||||||
</settings>
|
</settings>
|
||||||
</component>
|
</component>
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (Machine_learning_2023)" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (Machine_learning_2023)" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/Machine_learning_2023.iml" filepath="$PROJECT_DIR$/.idea/Machine_learning_2023.iml" />
|
<module fileurl="file://$PROJECT_DIR$/.idea/Machine_learning_2023.iml" filepath="$PROJECT_DIR$/.idea/Machine_learning_2023.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
3
.vs/ProjectSettings.json
Normal file
3
.vs/ProjectSettings.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"CurrentProjectSetting": null
|
||||||
|
}
|
BIN
.vs/slnx.sqlite
Normal file
BIN
.vs/slnx.sqlite
Normal file
Binary file not shown.
@ -1,80 +1,80 @@
|
|||||||
from domain.commands.vacuum_move_command import VacuumMoveCommand
|
from domain.commands.vacuum_move_command import VacuumMoveCommand
|
||||||
from domain.world import World
|
from domain.world import World
|
||||||
|
|
||||||
|
|
||||||
class State:
|
class State:
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.x, self.y))
|
return hash((self.x, self.y))
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return self.x == other.x and self.y == other.y
|
return self.x == other.x and self.y == other.y
|
||||||
|
|
||||||
|
|
||||||
class GoAnyDirectionBFS:
|
class GoAnyDirectionBFS:
|
||||||
def __init__(self, world: World, start_state: State, goal_state: State):
|
def __init__(self, world: World, start_state: State, goal_state: State):
|
||||||
self.start_state = start_state
|
self.start_state = start_state
|
||||||
self.goal_state = goal_state
|
self.goal_state = goal_state
|
||||||
self.visited = set()
|
self.visited = set()
|
||||||
self.parent = {}
|
self.parent = {}
|
||||||
self.actions = []
|
self.actions = []
|
||||||
self.path = []
|
self.path = []
|
||||||
self.world = world
|
self.world = world
|
||||||
self.queue = []
|
self.queue = []
|
||||||
|
|
||||||
def search(self):
|
def search(self):
|
||||||
self.queue.append(self.start_state)
|
self.queue.append(self.start_state)
|
||||||
self.visited.add(self.start_state)
|
self.visited.add(self.start_state)
|
||||||
while self.queue:
|
while self.queue:
|
||||||
state = self.queue.pop(0)
|
state = self.queue.pop(0)
|
||||||
if state == self.goal_state:
|
if state == self.goal_state:
|
||||||
self.actions = self.get_actions()
|
self.actions = self.get_actions()
|
||||||
self.path = self.get_path()
|
self.path = self.get_path()
|
||||||
return True
|
return True
|
||||||
for successor in self.successors(state):
|
for successor in self.successors(state):
|
||||||
if successor not in self.visited:
|
if successor not in self.visited:
|
||||||
self.visited.add(successor)
|
self.visited.add(successor)
|
||||||
self.parent[successor] = state
|
self.parent[successor] = state
|
||||||
self.queue.append(successor)
|
self.queue.append(successor)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def successors(self, state):
|
def successors(self, state):
|
||||||
new_successors = [
|
new_successors = [
|
||||||
State(state.x + dx, state.y + dy)
|
State(state.x + dx, state.y + dy)
|
||||||
for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]
|
for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]
|
||||||
if self.world.accepted_move(state.x + dx, state.y + dy)
|
if self.world.accepted_move(state.x + dx, state.y + dy)
|
||||||
]
|
]
|
||||||
|
|
||||||
return new_successors
|
return new_successors
|
||||||
|
|
||||||
def get_actions(self):
|
def get_actions(self):
|
||||||
actions = []
|
actions = []
|
||||||
state = self.goal_state
|
state = self.goal_state
|
||||||
while state != self.start_state:
|
while state != self.start_state:
|
||||||
parent_state = self.parent[state]
|
parent_state = self.parent[state]
|
||||||
dx = state.x - parent_state.x
|
dx = state.x - parent_state.x
|
||||||
dy = state.y - parent_state.y
|
dy = state.y - parent_state.y
|
||||||
if dx == 1:
|
if dx == 1:
|
||||||
actions.append("RIGHT")
|
actions.append("RIGHT")
|
||||||
elif dx == -1:
|
elif dx == -1:
|
||||||
actions.append("LEFT")
|
actions.append("LEFT")
|
||||||
elif dy == 1:
|
elif dy == 1:
|
||||||
actions.append("DOWN")
|
actions.append("DOWN")
|
||||||
elif dy == -1:
|
elif dy == -1:
|
||||||
actions.append("UP")
|
actions.append("UP")
|
||||||
state = parent_state
|
state = parent_state
|
||||||
actions.reverse()
|
actions.reverse()
|
||||||
return actions
|
return actions
|
||||||
|
|
||||||
def get_path(self):
|
def get_path(self):
|
||||||
path = []
|
path = []
|
||||||
state = self.goal_state
|
state = self.goal_state
|
||||||
while state != self.start_state:
|
while state != self.start_state:
|
||||||
path.append((state.x, state.y))
|
path.append((state.x, state.y))
|
||||||
state = self.parent[state]
|
state = self.parent[state]
|
||||||
path.append((self.start_state.x, self.start_state.y))
|
path.append((self.start_state.x, self.start_state.y))
|
||||||
path.reverse()
|
path.reverse()
|
||||||
return path
|
return path
|
||||||
|
@ -1,113 +1,113 @@
|
|||||||
import heapq
|
import heapq
|
||||||
from domain.world import World
|
from domain.world import World
|
||||||
|
|
||||||
|
|
||||||
class State:
|
class State:
|
||||||
def __init__(self, x, y, direction=(1, 0), entity=None):
|
def __init__(self, x, y, direction=(1, 0), entity=None):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
|
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.x, self.y))
|
return hash((self.x, self.y))
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return (
|
return (
|
||||||
self.x == other.x
|
self.x == other.x
|
||||||
and self.y == other.y
|
and self.y == other.y
|
||||||
and self.direction == other.direction
|
and self.direction == other.direction
|
||||||
)
|
)
|
||||||
|
|
||||||
def heuristic(self, goal_state):
|
def heuristic(self, goal_state):
|
||||||
return abs(self.x - goal_state.x) + abs(self.y - goal_state.y)
|
return abs(self.x - goal_state.x) + abs(self.y - goal_state.y)
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, state: State, g_score: int, goal_state: State):
|
def __init__(self, state: State, g_score: int, goal_state: State):
|
||||||
self.state = state
|
self.state = state
|
||||||
self.g_score = g_score
|
self.g_score = g_score
|
||||||
self.f_score = g_score + state.heuristic(goal_state)
|
self.f_score = g_score + state.heuristic(goal_state)
|
||||||
self.parent = None
|
self.parent = None
|
||||||
self.action = None
|
self.action = None
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return self.f_score < other.f_score
|
return self.f_score < other.f_score
|
||||||
|
|
||||||
|
|
||||||
def action_sequence(node: Node):
|
def action_sequence(node: Node):
|
||||||
actions = []
|
actions = []
|
||||||
while node.parent:
|
while node.parent:
|
||||||
actions.append(node.action)
|
actions.append(node.action)
|
||||||
node = node.parent
|
node = node.parent
|
||||||
actions.reverse()
|
actions.reverse()
|
||||||
return actions
|
return actions
|
||||||
|
|
||||||
|
|
||||||
class RotateAndGoAStar:
|
class RotateAndGoAStar:
|
||||||
def __init__(self, world: World, start_state: State, goal_state: State):
|
def __init__(self, world: World, start_state: State, goal_state: State):
|
||||||
self.world = world
|
self.world = world
|
||||||
self.start_state = start_state
|
self.start_state = start_state
|
||||||
self.goal_state = goal_state
|
self.goal_state = goal_state
|
||||||
self.fringe = []
|
self.fringe = []
|
||||||
self.enqueued_states = set()
|
self.enqueued_states = set()
|
||||||
self.explored = set()
|
self.explored = set()
|
||||||
self.actions = []
|
self.actions = []
|
||||||
|
|
||||||
def get_g_score(self, state):
|
def get_g_score(self, state):
|
||||||
return self.world.get_cost(state.x, state.y)
|
return self.world.get_cost(state.x, state.y)
|
||||||
|
|
||||||
def search(self):
|
def search(self):
|
||||||
heapq.heappush(
|
heapq.heappush(
|
||||||
self.fringe, Node(self.start_state, 0, self.goal_state)
|
self.fringe, Node(self.start_state, 0, self.goal_state)
|
||||||
)
|
)
|
||||||
|
|
||||||
while self.fringe:
|
while self.fringe:
|
||||||
elem = heapq.heappop(self.fringe)
|
elem = heapq.heappop(self.fringe)
|
||||||
if self.is_goal(elem.state):
|
if self.is_goal(elem.state):
|
||||||
self.actions = action_sequence(elem)
|
self.actions = action_sequence(elem)
|
||||||
return True
|
return True
|
||||||
self.explored.add(elem.state)
|
self.explored.add(elem.state)
|
||||||
|
|
||||||
for action, state in self.successors(elem.state):
|
for action, state in self.successors(elem.state):
|
||||||
if state in self.explored:
|
if state in self.explored:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
new_g_score = new_g_score = elem.g_score + self.world.get_cost(state.x, state.y)
|
new_g_score = new_g_score = elem.g_score + self.world.get_cost(state.x, state.y)
|
||||||
if state not in self.enqueued_states:
|
if state not in self.enqueued_states:
|
||||||
next_node = Node(state, new_g_score, self.goal_state)
|
next_node = Node(state, new_g_score, self.goal_state)
|
||||||
next_node.action = action
|
next_node.action = action
|
||||||
next_node.parent = elem
|
next_node.parent = elem
|
||||||
heapq.heappush(self.fringe, next_node)
|
heapq.heappush(self.fringe, next_node)
|
||||||
self.enqueued_states.add(state)
|
self.enqueued_states.add(state)
|
||||||
elif new_g_score < self.get_g_score(state):
|
elif new_g_score < self.get_g_score(state):
|
||||||
for node in self.fringe:
|
for node in self.fringe:
|
||||||
if node.state == state:
|
if node.state == state:
|
||||||
node.g_score = new_g_score
|
node.g_score = new_g_score
|
||||||
node.f_score = (
|
node.f_score = (
|
||||||
new_g_score + node.state.heuristic(self.goal_state)
|
new_g_score + node.state.heuristic(self.goal_state)
|
||||||
)
|
)
|
||||||
node.parent = elem
|
node.parent = elem
|
||||||
node.action = action
|
node.action = action
|
||||||
heapq.heapify(self.fringe)
|
heapq.heapify(self.fringe)
|
||||||
break
|
break
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def successors(self, state: State):
|
def successors(self, state: State):
|
||||||
new_successors = [
|
new_successors = [
|
||||||
("RR", State(state.x, state.y, (-state.direction[1], state.direction[0]))),
|
("RR", State(state.x, state.y, (-state.direction[1], state.direction[0]))),
|
||||||
("RL", State(state.x, state.y, (state.direction[1], -state.direction[0]))),
|
("RL", State(state.x, state.y, (state.direction[1], -state.direction[0]))),
|
||||||
]
|
]
|
||||||
next_x = state.x + state.direction[0]
|
next_x = state.x + state.direction[0]
|
||||||
next_y = state.y + state.direction[1]
|
next_y = state.y + state.direction[1]
|
||||||
if self.world.accepted_move(next_x, next_y):
|
if self.world.accepted_move(next_x, next_y):
|
||||||
new_successors.append(
|
new_successors.append(
|
||||||
("GO", State(next_x, next_y, state.direction))
|
("GO", State(next_x, next_y, state.direction))
|
||||||
)
|
)
|
||||||
return new_successors
|
return new_successors
|
||||||
|
|
||||||
def is_goal(self, state: State) -> bool:
|
def is_goal(self, state: State) -> bool:
|
||||||
return (
|
return (
|
||||||
state.x == self.goal_state.x
|
state.x == self.goal_state.x
|
||||||
and state.y == self.goal_state.y )
|
and state.y == self.goal_state.y )
|
@ -1,83 +1,83 @@
|
|||||||
import queue
|
import queue
|
||||||
|
|
||||||
from domain.world import World
|
from domain.world import World
|
||||||
|
|
||||||
|
|
||||||
class State:
|
class State:
|
||||||
def __init__(self, x, y, direction=(1, 0)):
|
def __init__(self, x, y, direction=(1, 0)):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.x, self.y))
|
return hash((self.x, self.y))
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return (self.x == other.x and self.y == other.y
|
return (self.x == other.x and self.y == other.y
|
||||||
and self.direction == other.direction)
|
and self.direction == other.direction)
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, state: State):
|
def __init__(self, state: State):
|
||||||
self.state = state
|
self.state = state
|
||||||
self.parent = None
|
self.parent = None
|
||||||
self.action = None
|
self.action = None
|
||||||
|
|
||||||
|
|
||||||
def action_sequence(node: Node):
|
def action_sequence(node: Node):
|
||||||
actions = []
|
actions = []
|
||||||
while node.parent:
|
while node.parent:
|
||||||
actions.append(node.action)
|
actions.append(node.action)
|
||||||
node = node.parent
|
node = node.parent
|
||||||
actions.reverse()
|
actions.reverse()
|
||||||
return actions
|
return actions
|
||||||
|
|
||||||
|
|
||||||
class RotateAndGoBFS:
|
class RotateAndGoBFS:
|
||||||
def __init__(self, world: World, start_state: State, goal_state: State):
|
def __init__(self, world: World, start_state: State, goal_state: State):
|
||||||
self.world = world
|
self.world = world
|
||||||
self.start_state = start_state
|
self.start_state = start_state
|
||||||
self.goal_state = goal_state
|
self.goal_state = goal_state
|
||||||
self.fringe = queue.Queue()
|
self.fringe = queue.Queue()
|
||||||
self.enqueued_states = set()
|
self.enqueued_states = set()
|
||||||
self.explored = set()
|
self.explored = set()
|
||||||
self.actions = []
|
self.actions = []
|
||||||
|
|
||||||
def search(self):
|
def search(self):
|
||||||
self.fringe.put(Node(self.start_state))
|
self.fringe.put(Node(self.start_state))
|
||||||
|
|
||||||
while self.fringe:
|
while self.fringe:
|
||||||
elem = self.fringe.get()
|
elem = self.fringe.get()
|
||||||
if self.is_goal(elem.state):
|
if self.is_goal(elem.state):
|
||||||
self.actions = action_sequence(elem)
|
self.actions = action_sequence(elem)
|
||||||
return True
|
return True
|
||||||
self.explored.add(elem.state)
|
self.explored.add(elem.state)
|
||||||
|
|
||||||
for (action, state) in self.successors(elem.state):
|
for (action, state) in self.successors(elem.state):
|
||||||
if state in self.explored or state in self.enqueued_states:
|
if state in self.explored or state in self.enqueued_states:
|
||||||
continue
|
continue
|
||||||
next_node = Node(state)
|
next_node = Node(state)
|
||||||
next_node.action = action
|
next_node.action = action
|
||||||
next_node.parent = elem
|
next_node.parent = elem
|
||||||
self.fringe.put(next_node)
|
self.fringe.put(next_node)
|
||||||
self.enqueued_states.add(state)
|
self.enqueued_states.add(state)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def successors(self, state: State):
|
def successors(self, state: State):
|
||||||
new_successors = [
|
new_successors = [
|
||||||
# rotate right
|
# rotate right
|
||||||
("RR", State(state.x, state.y, (-state.direction[1], state.direction[0]))),
|
("RR", State(state.x, state.y, (-state.direction[1], state.direction[0]))),
|
||||||
# rotate left
|
# rotate left
|
||||||
("RL", State(state.x, state.y, (state.direction[1], -state.direction[0]))),
|
("RL", State(state.x, state.y, (state.direction[1], -state.direction[0]))),
|
||||||
]
|
]
|
||||||
if self.world.accepted_move(state.x + state.direction[0], state.y + state.direction[1]):
|
if self.world.accepted_move(state.x + state.direction[0], state.y + state.direction[1]):
|
||||||
new_successors.append(
|
new_successors.append(
|
||||||
("GO", State(state.x + state.direction[0], state.y + state.direction[1], state.direction)))
|
("GO", State(state.x + state.direction[0], state.y + state.direction[1], state.direction)))
|
||||||
return new_successors
|
return new_successors
|
||||||
|
|
||||||
def is_goal(self, state: State) -> bool:
|
def is_goal(self, state: State) -> bool:
|
||||||
return (
|
return (
|
||||||
state.x == self.goal_state.x
|
state.x == self.goal_state.x
|
||||||
and state.y == self.goal_state.y
|
and state.y == self.goal_state.y
|
||||||
)
|
)
|
||||||
|
@ -1,60 +1,60 @@
|
|||||||
******
|
******
|
||||||
|
|
||||||
Dokumentacja projektu "Automatyczny robot sprzątający"
|
Dokumentacja projektu "Automatyczny robot sprzątający"
|
||||||
|
|
||||||
Wprowadzenie:
|
Wprowadzenie:
|
||||||
Projekt "Automatyczny robot sprzątający" jest projektem bazującym się na symulacji pracy robota sprzątającego w pomieszczeniu za pomocą sztucznej inteligencji. Robot ma za zadanie wyznaczać miejsca do sprzątania oraz uniknąć przeszkód oraz reagować na zdarzenia losowe. Projekt jest napisany w języku Python.
|
Projekt "Automatyczny robot sprzątający" jest projektem bazującym się na symulacji pracy robota sprzątającego w pomieszczeniu za pomocą sztucznej inteligencji. Robot ma za zadanie wyznaczać miejsca do sprzątania oraz uniknąć przeszkód oraz reagować na zdarzenia losowe. Projekt jest napisany w języku Python.
|
||||||
|
|
||||||
Instrukcja obsługi:
|
Instrukcja obsługi:
|
||||||
|
|
||||||
Uruchomienie projektu:
|
Uruchomienie projektu:
|
||||||
Aby uruchomić projekt należy uruchomić plik "main.py" za pomocą interpretera Python. Projektu wyświetli się w konsoli.Po uruchomieniu projektu na ekranie wyświetli się plansza o wymiarach NxN (default: 10x10). Robot "Cleaner" (oznaczony jako "R" na planszy) startuje z pozycji (0,0). użytkownik ma za zadanie wprowadzić pozycje do sprzątania, które są oznaczone na planszy jako litery "D". Możliwe pozycje to liczby od 0 do N-1.
|
Aby uruchomić projekt należy uruchomić plik "main.py" za pomocą interpretera Python. Projektu wyświetli się w konsoli.Po uruchomieniu projektu na ekranie wyświetli się plansza o wymiarach NxN (default: 10x10). Robot "Cleaner" (oznaczony jako "R" na planszy) startuje z pozycji (0,0). użytkownik ma za zadanie wprowadzić pozycje do sprzątania, które są oznaczone na planszy jako litery "D". Możliwe pozycje to liczby od 0 do N-1.
|
||||||
|
|
||||||
Użytkownik wprowadza pozycje za pomocą terminala. Wprowadzenie koordynat odbywa się w następujący sposób:
|
Użytkownik wprowadza pozycje za pomocą terminala. Wprowadzenie koordynat odbywa się w następujący sposób:
|
||||||
Najpierw wprowadzamy numer wiersza, a następnie numer kolumny, oddzielając je spacją.
|
Najpierw wprowadzamy numer wiersza, a następnie numer kolumny, oddzielając je spacją.
|
||||||
Przykładowo, jeśli chcemy wskazać pozycję (4,5) wpisujemy: "4 5".
|
Przykładowo, jeśli chcemy wskazać pozycję (4,5) wpisujemy: "4 5".
|
||||||
Po wskazaniu pozycji do sprzątania, użytkownik musi uniknąć przeszkód, które są oznaczone na planszy jako znak "X". Robot nie może przejść przez przeszkody. Jeśli użytkownik wskazuje pozycję przeszkody, projektu zwróci błąd i będzie wymagała podania nowych współrzędnych.
|
Po wskazaniu pozycji do sprzątania, użytkownik musi uniknąć przeszkód, które są oznaczone na planszy jako znak "X". Robot nie może przejść przez przeszkody. Jeśli użytkownik wskazuje pozycję przeszkody, projektu zwróci błąd i będzie wymagała podania nowych współrzędnych.
|
||||||
|
|
||||||
Przebieg projektu:
|
Przebieg projektu:
|
||||||
Robot, zgodnie z zbudowaną mapą, musi obliczyć najkrótszą ścieżkę do sprzątania wszystkich pozycji oraz uniknąć przeszkód. Podczas sprzątania mogą wystąpić przypadkowe zdarzenia, na które robot będzie reagował. W tym celu, z pomocą sieci neuronowych, robot analizuje zdjęcie zdarzenia, aby wybrać najlepsze rozwiązania.
|
Robot, zgodnie z zbudowaną mapą, musi obliczyć najkrótszą ścieżkę do sprzątania wszystkich pozycji oraz uniknąć przeszkód. Podczas sprzątania mogą wystąpić przypadkowe zdarzenia, na które robot będzie reagował. W tym celu, z pomocą sieci neuronowych, robot analizuje zdjęcie zdarzenia, aby wybrać najlepsze rozwiązania.
|
||||||
|
|
||||||
Zakończenie projektu:
|
Zakończenie projektu:
|
||||||
Program kończy swoje działanie w momencie, gdy robot posprząta wszystkie przez użytkownika wybrane pola do sprzątania. Na zakończenie programu zostanie wyświetlona liczba wykonanych ruchów przez robota oraz podjęte decyzje w przypadku zaistnienia zdarzeń.
|
Program kończy swoje działanie w momencie, gdy robot posprząta wszystkie przez użytkownika wybrane pola do sprzątania. Na zakończenie programu zostanie wyświetlona liczba wykonanych ruchów przez robota oraz podjęte decyzje w przypadku zaistnienia zdarzeń.
|
||||||
|
|
||||||
Możliwe modyfikacje:
|
Możliwe modyfikacje:
|
||||||
Projekt zostanie napisany z myślą o możliwości łatwej modyfikacji. Można zmienić wymiary planszy, dodać lub usunąć przeszkody oraz ilość przypadkowych zdarzeń i pozycji do sprzątania. Wszystkie te zmiany można wprowadzić w pliku "config.py".
|
Projekt zostanie napisany z myślą o możliwości łatwej modyfikacji. Można zmienić wymiary planszy, dodać lub usunąć przeszkody oraz ilość przypadkowych zdarzeń i pozycji do sprzątania. Wszystkie te zmiany można wprowadzić w pliku "config.py".
|
||||||
|
|
||||||
Podsumowanie:
|
Podsumowanie:
|
||||||
Projekt "Automatyczny robot sprzątający" to prosty, ale edukacyjny projekt programistyczny. Użytkownik ma za zadanie wskazanie pozycji, które robot powinien posprzątać, a także koordynat przeszkody. Natomiast zadaniem robota, który został zbudowany przy użyciu sztucznej inteligencji, jest unikanie przeszkód, podejmowanie decyzji w przypadku wystąpienia przypadkowych zdarzeń oraz sprzątanie wyznaczonych punktów. Projekt został napisany w języku Python z wykorzystaniem sztucznej inteligencji. Analiza zdjęć jest oparta na sieciach neuronowych.
|
Projekt "Automatyczny robot sprzątający" to prosty, ale edukacyjny projekt programistyczny. Użytkownik ma za zadanie wskazanie pozycji, które robot powinien posprzątać, a także koordynat przeszkody. Natomiast zadaniem robota, który został zbudowany przy użyciu sztucznej inteligencji, jest unikanie przeszkód, podejmowanie decyzji w przypadku wystąpienia przypadkowych zdarzeń oraz sprzątanie wyznaczonych punktów. Projekt został napisany w języku Python z wykorzystaniem sztucznej inteligencji. Analiza zdjęć jest oparta na sieciach neuronowych.
|
||||||
|
|
||||||
******
|
******
|
||||||
|
|
||||||
Documentation of the "Automatic Cleaning Robot" project
|
Documentation of the "Automatic Cleaning Robot" project
|
||||||
|
|
||||||
Introduction:
|
Introduction:
|
||||||
The "Automatic Cleaning Robot" project is based on simulating the work of a cleaning robot in a room using artificial intelligence. The robot is tasked with determining the areas to be cleaned, avoiding obstacles, and reacting to random events. The project is written in Python.
|
The "Automatic Cleaning Robot" project is based on simulating the work of a cleaning robot in a room using artificial intelligence. The robot is tasked with determining the areas to be cleaned, avoiding obstacles, and reacting to random events. The project is written in Python.
|
||||||
|
|
||||||
User Guide:
|
User Guide:
|
||||||
Starting the project:
|
Starting the project:
|
||||||
To start the project, you need to run the "main.py" file using a Python interpreter. The project will be displayed on the console. Once the project is launched, a 10x10 board will be displayed on the screen. The "Cleaner" robot (marked as "R" on the board) starts from the position (0,0). The user needs to enter the positions to be cleaned, which are marked as the letter "D" on the board. The possible positions are numbers from 0 to 9.
|
To start the project, you need to run the "main.py" file using a Python interpreter. The project will be displayed on the console. Once the project is launched, a 10x10 board will be displayed on the screen. The "Cleaner" robot (marked as "R" on the board) starts from the position (0,0). The user needs to enter the positions to be cleaned, which are marked as the letter "D" on the board. The possible positions are numbers from 0 to 9.
|
||||||
|
|
||||||
The user enters the positions through the terminal. The entry of coordinates is done as follows:
|
The user enters the positions through the terminal. The entry of coordinates is done as follows:
|
||||||
First, we enter the row number, and then the column number, separating them with a space.
|
First, we enter the row number, and then the column number, separating them with a space.
|
||||||
For example, if we want to indicate the position (4,5), we enter "4 5".
|
For example, if we want to indicate the position (4,5), we enter "4 5".
|
||||||
After indicating the positions to be cleaned, the user must avoid obstacles, which are marked on the board as the "X" symbol. The robot cannot pass through obstacles. If the user points to an obstacle position, the project will return an error and require new coordinates.
|
After indicating the positions to be cleaned, the user must avoid obstacles, which are marked on the board as the "X" symbol. The robot cannot pass through obstacles. If the user points to an obstacle position, the project will return an error and require new coordinates.
|
||||||
|
|
||||||
Project process:
|
Project process:
|
||||||
Based on the built map, the robot must calculate the shortest path to clean all positions and avoid obstacles. Random events may occur during cleaning, to which the robot will react. To do this, with the help of neural networks, the robot analyzes the image of the event to choose the best solutions.
|
Based on the built map, the robot must calculate the shortest path to clean all positions and avoid obstacles. Random events may occur during cleaning, to which the robot will react. To do this, with the help of neural networks, the robot analyzes the image of the event to choose the best solutions.
|
||||||
|
|
||||||
Project conclusion:
|
Project conclusion:
|
||||||
The program is ending when the robot cleans all the fields selected by the user. At the end of the program, the number of robot moves performed and the decisions made in case of events will be displayed.
|
The program is ending when the robot cleans all the fields selected by the user. At the end of the program, the number of robot moves performed and the decisions made in case of events will be displayed.
|
||||||
|
|
||||||
Possible modifications:
|
Possible modifications:
|
||||||
The "Automatic cleaning robot" project has been designed with the possibility of easy modifications in mind. Users can change the dimensions of the board, add or remove obstacles, and adjust the number of random events and cleaning positions. All these changes can be made in the "config.py" file.
|
The "Automatic cleaning robot" project has been designed with the possibility of easy modifications in mind. Users can change the dimensions of the board, add or remove obstacles, and adjust the number of random events and cleaning positions. All these changes can be made in the "config.py" file.
|
||||||
|
|
||||||
Summary:
|
Summary:
|
||||||
The "Automatic cleaning robot" project is a simple yet educational programming project. Users are tasked with specifying the positions that the robot should clean, as well as the coordinates of obstacles. The robot, built using artificial intelligence, is responsible for avoiding obstacles, making decisions in case of random events, and cleaning the designated points. The project was written in Python with the use of artificial intelligence. The analysis of images is based on neural networks.
|
The "Automatic cleaning robot" project is a simple yet educational programming project. Users are tasked with specifying the positions that the robot should clean, as well as the coordinates of obstacles. The robot, built using artificial intelligence, is responsible for avoiding obstacles, making decisions in case of random events, and cleaning the designated points. The project was written in Python with the use of artificial intelligence. The analysis of images is based on neural networks.
|
||||||
|
|
||||||
******
|
******
|
||||||
******
|
******
|
||||||
|
|
||||||
|
116
README.md
116
README.md
@ -1,58 +1,58 @@
|
|||||||
******
|
******
|
||||||
|
|
||||||
Dokumentacja projektu "Automatyczny robot sprzątający"
|
Dokumentacja projektu "Automatyczny robot sprzątający"
|
||||||
|
|
||||||
Wprowadzenie:
|
Wprowadzenie:
|
||||||
Projekt "Automatyczny robot sprzątający" jest projektem bazującym się na symulacji pracy robota sprzątającego w pomieszczeniu za pomocą sztucznej intelegencji. Robot ma za zadanie wyznaczać miejsca do sprzątania oraz uniknąć przeszkód oraz reagować na zdarzenia randomowe. Projekt jest napisany w języku Python.
|
Projekt "Automatyczny robot sprzątający" jest projektem bazującym się na symulacji pracy robota sprzątającego w pomieszczeniu za pomocą sztucznej intelegencji. Robot ma za zadanie wyznaczać miejsca do sprzątania oraz uniknąć przeszkód oraz reagować na zdarzenia randomowe. Projekt jest napisany w języku Python.
|
||||||
|
|
||||||
Instrukcja obsługi:
|
Instrukcja obsługi:
|
||||||
|
|
||||||
Uruchomienie projektu:
|
Uruchomienie projektu:
|
||||||
Aby uruchomić projekt należy uruchomić plik "main.py" za pomocą interpretera Python. Projektu wyświetli się w konsoli.Po uruchomieniu projektu na ekranie wyświetli się plansza o wymiarach 10x10. Robot "Cleaner" (oznaczony jako "R" na planszy) startuje z pozycji (0,0). użytkownik ma za zadanie wprowadzić pozycje do sprzątania, które są oznaczone na planszy jako litery "D". Możliwe pozycje to liczby od 0 do 9.
|
Aby uruchomić projekt należy uruchomić plik "main.py" za pomocą interpretera Python. Projektu wyświetli się w konsoli.Po uruchomieniu projektu na ekranie wyświetli się plansza o wymiarach 10x10. Robot "Cleaner" (oznaczony jako "R" na planszy) startuje z pozycji (0,0). użytkownik ma za zadanie wprowadzić pozycje do sprzątania, które są oznaczone na planszy jako litery "D". Możliwe pozycje to liczby od 0 do 9.
|
||||||
|
|
||||||
Użytkownik wprowadza pozycje za pomocą terminala. Wprowadzenie koordynat odbywa się w następujący sposób:
|
Użytkownik wprowadza pozycje za pomocą terminala. Wprowadzenie koordynat odbywa się w następujący sposób:
|
||||||
Najpierw wprowadzamy numer wiersza, a następnie numer kolumny, oddzielając je spacją.
|
Najpierw wprowadzamy numer wiersza, a następnie numer kolumny, oddzielając je spacją.
|
||||||
Przykładowo, jeśli chcemy wskazać pozycję (4,5) wpisujemy: "4 5".
|
Przykładowo, jeśli chcemy wskazać pozycję (4,5) wpisujemy: "4 5".
|
||||||
Po wskazaniu pozycji do sprzątania, użytkownik musi uniknąć przeszkód, które są oznaczone na planszy jako znak "X". Robot nie może przejść przez przeszkody. Jeśli użytkownik wskazuje pozycję przeszkody, projektu zwróci błąd i będzie wymagała podania nowych koordynatów.
|
Po wskazaniu pozycji do sprzątania, użytkownik musi uniknąć przeszkód, które są oznaczone na planszy jako znak "X". Robot nie może przejść przez przeszkody. Jeśli użytkownik wskazuje pozycję przeszkody, projektu zwróci błąd i będzie wymagała podania nowych koordynatów.
|
||||||
|
|
||||||
Przebieg projektu:
|
Przebieg projektu:
|
||||||
Robot, zgodnie z zbudowaną mapą, musi obliczyć najkrótszą ścieżkę do sprzątania wszystkich pozycji oraz uniknąć przeszkód. Podczas sprzątania mogą wystąpić przypadkowe zdarzenia, na które robot będzie reagował. W tym celu, z pomocą sieci neuronowych, robot analizuje zdjęcie zdarzenia, aby wybrać najlepsze rozwiązania.
|
Robot, zgodnie z zbudowaną mapą, musi obliczyć najkrótszą ścieżkę do sprzątania wszystkich pozycji oraz uniknąć przeszkód. Podczas sprzątania mogą wystąpić przypadkowe zdarzenia, na które robot będzie reagował. W tym celu, z pomocą sieci neuronowych, robot analizuje zdjęcie zdarzenia, aby wybrać najlepsze rozwiązania.
|
||||||
|
|
||||||
Zakończenie projektu:
|
Zakończenie projektu:
|
||||||
Program kończy swoje działanie w momencie, gdy robot posprząta wszystkie przez użytkownika wybrane pola do sprzątania. Na zakończenie programu zostanie wyświetlona liczba wykonanych ruchów przez robota oraz podjęte decyzje w przypadku zaistnienia zdarzeń.
|
Program kończy swoje działanie w momencie, gdy robot posprząta wszystkie przez użytkownika wybrane pola do sprzątania. Na zakończenie programu zostanie wyświetlona liczba wykonanych ruchów przez robota oraz podjęte decyzje w przypadku zaistnienia zdarzeń.
|
||||||
|
|
||||||
Możliwe modyfikacje:
|
Możliwe modyfikacje:
|
||||||
Projekt zostanie napisany z myślą o możliwości łatwej modyfikacji. Można zmienić wymiary planszy, dodać lub usunąć przeszkody oraz ilość przypadkowych zdarzeń i pozycji do sprzątania. Wszystkie te zmiany można wprowadzić w pliku "config.py".
|
Projekt zostanie napisany z myślą o możliwości łatwej modyfikacji. Można zmienić wymiary planszy, dodać lub usunąć przeszkody oraz ilość przypadkowych zdarzeń i pozycji do sprzątania. Wszystkie te zmiany można wprowadzić w pliku "config.py".
|
||||||
|
|
||||||
Podsumowanie:
|
Podsumowanie:
|
||||||
Projekt "Automatyczny robot sprzątający" to prosty, ale edukacyjny projekt programistyczny. Użytkownik ma za zadanie wskazanie pozycji, które robot powinien posprzątać, a także koordynat przeszkody. Natomiast zadaniem robota, który został zbudowany przy użyciu sztucznej inteligencji, jest unikanie przeszkód, podejmowanie decyzji w przypadku wystąpienia przypadkowych zdarzeń oraz sprzątanie wyznaczonych punktów. Projekt został napisany w języku Python z wykorzystaniem sztucznej inteligencji.Analiza zdięć jest oparta na sieciach neuronowych.
|
Projekt "Automatyczny robot sprzątający" to prosty, ale edukacyjny projekt programistyczny. Użytkownik ma za zadanie wskazanie pozycji, które robot powinien posprzątać, a także koordynat przeszkody. Natomiast zadaniem robota, który został zbudowany przy użyciu sztucznej inteligencji, jest unikanie przeszkód, podejmowanie decyzji w przypadku wystąpienia przypadkowych zdarzeń oraz sprzątanie wyznaczonych punktów. Projekt został napisany w języku Python z wykorzystaniem sztucznej inteligencji.Analiza zdięć jest oparta na sieciach neuronowych.
|
||||||
|
|
||||||
******
|
******
|
||||||
|
|
||||||
Documentation of the "Automatic Cleaning Robot" project
|
Documentation of the "Automatic Cleaning Robot" project
|
||||||
|
|
||||||
Introduction:
|
Introduction:
|
||||||
The "Automatic Cleaning Robot" project is based on simulating the work of a cleaning robot in a room using artificial intelligence. The robot is tasked with determining the areas to be cleaned, avoiding obstacles, and reacting to random events. The project is written in Python.
|
The "Automatic Cleaning Robot" project is based on simulating the work of a cleaning robot in a room using artificial intelligence. The robot is tasked with determining the areas to be cleaned, avoiding obstacles, and reacting to random events. The project is written in Python.
|
||||||
|
|
||||||
User Guide:
|
User Guide:
|
||||||
Starting the project:
|
Starting the project:
|
||||||
To start the project, you need to run the "main.py" file using a Python interpreter. The project will be displayed on the console. Once the project is launched, a 10x10 board will be displayed on the screen. The "Cleaner" robot (marked as "R" on the board) starts from the position (0,0). The user needs to enter the positions to be cleaned, which are marked as the letter "D" on the board. The possible positions are numbers from 0 to 9.
|
To start the project, you need to run the "main.py" file using a Python interpreter. The project will be displayed on the console. Once the project is launched, a 10x10 board will be displayed on the screen. The "Cleaner" robot (marked as "R" on the board) starts from the position (0,0). The user needs to enter the positions to be cleaned, which are marked as the letter "D" on the board. The possible positions are numbers from 0 to 9.
|
||||||
|
|
||||||
The user enters the positions through the terminal. The entry of coordinates is done as follows:
|
The user enters the positions through the terminal. The entry of coordinates is done as follows:
|
||||||
First, we enter the row number, and then the column number, separating them with a space.
|
First, we enter the row number, and then the column number, separating them with a space.
|
||||||
For example, if we want to indicate the position (4,5), we enter "4 5".
|
For example, if we want to indicate the position (4,5), we enter "4 5".
|
||||||
After indicating the positions to be cleaned, the user must avoid obstacles, which are marked on the board as the "X" symbol. The robot cannot pass through obstacles. If the user points to an obstacle position, the project will return an error and require new coordinates.
|
After indicating the positions to be cleaned, the user must avoid obstacles, which are marked on the board as the "X" symbol. The robot cannot pass through obstacles. If the user points to an obstacle position, the project will return an error and require new coordinates.
|
||||||
|
|
||||||
Project process:
|
Project process:
|
||||||
Based on the built map, the robot must calculate the shortest path to clean all positions and avoid obstacles. Random events may occur during cleaning, to which the robot will react. To do this, with the help of neural networks, the robot analyzes the image of the event to choose the best solutions.
|
Based on the built map, the robot must calculate the shortest path to clean all positions and avoid obstacles. Random events may occur during cleaning, to which the robot will react. To do this, with the help of neural networks, the robot analyzes the image of the event to choose the best solutions.
|
||||||
|
|
||||||
Project conclusion:
|
Project conclusion:
|
||||||
The program is ending when the robot cleans all the fields selected by the user. At the end of the program, the number of robot moves performed and the decisions made in case of events will be displayed.
|
The program is ending when the robot cleans all the fields selected by the user. At the end of the program, the number of robot moves performed and the decisions made in case of events will be displayed.
|
||||||
|
|
||||||
Possible modifications:
|
Possible modifications:
|
||||||
The "Automatic cleaning robot" project has been designed with the possibility of easy modifications in mind. Users can change the dimensions of the board, add or remove obstacles, and adjust the number of random events and cleaning positions. All these changes can be made in the "config.py" file.
|
The "Automatic cleaning robot" project has been designed with the possibility of easy modifications in mind. Users can change the dimensions of the board, add or remove obstacles, and adjust the number of random events and cleaning positions. All these changes can be made in the "config.py" file.
|
||||||
|
|
||||||
Summary:
|
Summary:
|
||||||
The "Automatic cleaning robot" project is a simple yet educational programming project. Users are tasked with specifying the positions that the robot should clean, as well as the coordinates of obstacles. The robot, built using artificial intelligence, is responsible for avoiding obstacles, making decisions in case of random events, and cleaning the designated points. The project was written in Python with the use of artificial intelligence. The analysis of images is based on neural networks.
|
The "Automatic cleaning robot" project is a simple yet educational programming project. Users are tasked with specifying the positions that the robot should clean, as well as the coordinates of obstacles. The robot, built using artificial intelligence, is responsible for avoiding obstacles, making decisions in case of random events, and cleaning the designated points. The project was written in Python with the use of artificial intelligence. The analysis of images is based on neural networks.
|
||||||
|
|
||||||
******
|
******
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[APP]
|
[APP]
|
||||||
cat = False
|
cat = False
|
||||||
movement = robot
|
movement = robot
|
||||||
#accept: human, robot
|
#accept: human, robot
|
@ -1,22 +1,200 @@
|
|||||||
1-2-3-4-5;1-green 2-yellow 3-orange 4-black 5-while 6-blue;in dB 0-100;0-24;0/1;in cm;in C;0/1
|
1-2-3-4-5;1-green 2-yellow 3-orange 4-black 5-while 6-blue;in dB 0-100;0-24;0/1;in cm;in C;0/1
|
||||||
Size;Color;Sound;Time;Smell;Height;Temperature;ToRemove
|
Size;Color;Sound;Sharp;Smell;Length;Temperature;Weight;ToRemove;
|
||||||
1;2;0;16;1;10;25;1
|
1;1;0;0;0;2;22;0;1;
|
||||||
2;1;0;12;0;50;24;0
|
1;2;0;0;0;2;22;0;1;
|
||||||
2;3;30;13;1;38;38;0
|
1;3;0;0;0;2;22;0;1;
|
||||||
1;4;0;7;1;5;27;1
|
1;4;0;0;0;2;22;0;1;
|
||||||
1;2;0;16;1;10;25;1
|
1;5;0;0;0;2;22;0;1;
|
||||||
2;1;0;12;0;50;24;0
|
1;6;0;0;0;2;22;0;1;
|
||||||
2;3;30;13;1;38;38;0
|
1;7;0;0;0;2;22;0;1;
|
||||||
1;4;0;7;1;5;27;1
|
1;8;0;0;0;2;22;0;1;
|
||||||
1;2;0;16;1;10;25;1
|
1;9;0;0;0;2;22;0;1;
|
||||||
2;1;0;12;0;50;24;0
|
1;2;0;0;1;3;25;0;1;
|
||||||
2;3;30;13;1;38;38;0
|
1;2;0;0;1;4;25;0;1;
|
||||||
1;4;0;7;1;5;27;1
|
1;2;0;0;1;5;25;0;1;
|
||||||
1;2;0;16;1;10;25;1
|
2;2;0;0;1;3;25;0;1;
|
||||||
2;1;0;12;0;50;24;0
|
2;2;0;0;1;4;25;0;1;
|
||||||
2;3;30;13;1;38;38;0
|
2;2;0;0;1;5;25;0;1;
|
||||||
1;4;0;7;1;5;27;1
|
2;2;0;0;1;6;25;0;1;
|
||||||
1;2;0;16;1;10;25;1
|
3;2;0;0;1;3;25;0;1;
|
||||||
2;1;0;12;0;50;24;0
|
1;7;0;0;1;3;25;2;1;
|
||||||
2;3;30;13;1;38;38;0
|
1;6;0;0;1;4;25;2;1;
|
||||||
1;4;0;7;1;5;27;1
|
1;6;0;0;1;5;25;2;1;
|
||||||
|
1;6;0;0;1;2;25;2;1;
|
||||||
|
2;6;0;0;1;2;25;3;1;
|
||||||
|
2;6;0;0;1;3;25;3;1;
|
||||||
|
2;6;0;0;1;4;25;3;1;
|
||||||
|
2;6;0;0;1;5;25;3;1;
|
||||||
|
3;6;0;0;1;2;25;4;1;
|
||||||
|
2;1;0;0;0;20;24;1;0;
|
||||||
|
2;2;0;0;0;20;24;1;0;
|
||||||
|
2;3;0;0;0;20;24;1;0;
|
||||||
|
2;4;0;0;0;20;24;1;0;
|
||||||
|
2;5;0;0;0;20;24;1;0;
|
||||||
|
2;6;0;0;0;20;24;1;0;
|
||||||
|
2;7;0;0;0;20;24;1;0;
|
||||||
|
2;8;0;0;0;20;24;1;0;
|
||||||
|
2;9;0;0;0;20;24;1;0;
|
||||||
|
1;1;0;1;0;1;20;0;0;
|
||||||
|
1;2;0;1;0;1;20;0;0;
|
||||||
|
1;3;0;1;0;1;20;0;0;
|
||||||
|
1;4;0;1;0;1;20;0;0;
|
||||||
|
1;5;0;1;0;1;20;0;0;
|
||||||
|
1;6;0;1;0;1;20;0;0;
|
||||||
|
1;7;0;1;0;1;20;0;0;
|
||||||
|
1;8;0;1;0;1;20;0;0;
|
||||||
|
2;4;0;0;0;14;22;1;0;
|
||||||
|
1;2;0;0;1;6;24;1;1;
|
||||||
|
2;2;0;0;1;6;24;1;1;
|
||||||
|
1;2;0;0;1;5;24;1;1;
|
||||||
|
3;1;4;0;0;18;24;2;0;
|
||||||
|
3;2;4;0;0;18;24;2;0;
|
||||||
|
3;3;4;0;0;18;24;2;0;
|
||||||
|
3;4;4;0;0;18;24;2;0;
|
||||||
|
3;5;4;0;0;18;24;2;0;
|
||||||
|
3;6;4;0;0;18;24;2;0;
|
||||||
|
3;7;4;0;0;18;24;2;0;
|
||||||
|
3;8;4;0;0;18;24;2;0;
|
||||||
|
3;9;4;0;0;18;24;2;0;
|
||||||
|
4;3;20;0;1;32;37;5;0;
|
||||||
|
4;4;20;0;1;32;37;5;0;
|
||||||
|
4;5;20;0;1;32;37;5;0;
|
||||||
|
4;6;20;0;1;32;37;5;0;
|
||||||
|
5;3;25;0;1;40;37;6;0;
|
||||||
|
5;4;25;0;1;40;37;6;0;
|
||||||
|
5;5;25;0;1;40;37;6;0;
|
||||||
|
5;6;25;0;1;40;37;6;0;
|
||||||
|
1;5;0;0;0;20;22;2;0;
|
||||||
|
1;5;0;0;0;30;22;2;0;
|
||||||
|
1;5;0;0;0;40;22;2;0;
|
||||||
|
1;5;0;0;0;50;22;2;0;
|
||||||
|
1;4;0;0;0;20;22;2;0;
|
||||||
|
1;4;0;0;0;30;22;2;0;
|
||||||
|
1;4;0;0;0;40;22;2;0;
|
||||||
|
1;4;0;0;0;50;22;2;0;
|
||||||
|
2;5;0;0;0;20;22;2;0;
|
||||||
|
2;5;0;0;0;30;22;2;0;
|
||||||
|
2;5;0;0;0;40;22;2;0;
|
||||||
|
2;4;0;0;0;20;22;2;0;
|
||||||
|
2;4;0;0;0;30;22;2;0;
|
||||||
|
2;4;0;0;0;40;22;2;0;
|
||||||
|
1;5;0;0;1;2;24;0;1;
|
||||||
|
1;3;0;0;0;13;23;0;1;
|
||||||
|
1;4;0;0;0;13;23;0;1;
|
||||||
|
1;5;0;0;0;13;23;0;1;
|
||||||
|
1;6;0;0;0;13;23;0;1;
|
||||||
|
1;3;0;0;0;14;23;0;1;
|
||||||
|
1;4;0;0;0;14;23;0;1;
|
||||||
|
1;5;0;0;0;14;23;0;1;
|
||||||
|
1;6;0;0;0;14;23;0;1;
|
||||||
|
1;3;0;0;0;15;23;0;1;
|
||||||
|
1;4;0;0;0;15;23;0;1;
|
||||||
|
1;5;0;0;0;15;23;0;1;
|
||||||
|
1;6;0;0;0;15;23;0;1;
|
||||||
|
1;1;0;1;0;3;22;1;1;
|
||||||
|
1;2;0;1;0;3;22;1;1;
|
||||||
|
1;3;0;1;0;3;22;1;1;
|
||||||
|
1;4;0;1;0;3;22;1;1;
|
||||||
|
1;5;0;1;0;3;22;1;1;
|
||||||
|
1;6;0;1;0;3;22;1;1;
|
||||||
|
1;7;0;1;0;3;22;1;1;
|
||||||
|
1;8;0;1;0;3;22;1;1;
|
||||||
|
1;9;0;1;0;3;22;1;1;
|
||||||
|
2;1;0;1;0;7;22;1;0;
|
||||||
|
2;2;0;1;0;7;22;1;0;
|
||||||
|
2;3;0;1;0;7;22;1;0;
|
||||||
|
2;4;0;1;0;7;22;1;0;
|
||||||
|
2;5;0;1;0;7;22;1;0;
|
||||||
|
2;6;0;1;0;7;22;1;0;
|
||||||
|
2;7;0;1;0;7;22;1;0;
|
||||||
|
2;8;0;1;0;7;22;1;0;
|
||||||
|
2;9;0;1;0;7;22;1;0;
|
||||||
|
3;3;10;0;1;24;36;3;0;
|
||||||
|
3;4;10;0;1;24;36;3;0;
|
||||||
|
3;5;10;0;1;24;36;3;0;
|
||||||
|
3;6;10;0;1;24;36;3;0;
|
||||||
|
1;1;0;0;0;2;20;1;0;
|
||||||
|
1;2;0;0;0;2;20;1;0;
|
||||||
|
1;3;0;0;0;2;20;1;0;
|
||||||
|
1;4;0;0;0;2;20;1;0;
|
||||||
|
1;5;0;0;0;2;20;1;0;
|
||||||
|
1;6;0;0;0;2;20;1;0;
|
||||||
|
1;7;0;0;0;2;20;1;0;
|
||||||
|
1;8;0;0;0;2;20;1;0;
|
||||||
|
1;9;0;0;0;2;20;1;0;
|
||||||
|
2;1;0;0;1;2;24;0;1;
|
||||||
|
2;2;0;0;1;2;24;0;1;
|
||||||
|
2;3;0;0;1;2;24;0;1;
|
||||||
|
2;7;0;0;1;2;24;0;1;
|
||||||
|
2;8;0;0;1;2;24;0;1;
|
||||||
|
2;9;0;0;1;2;24;0;1;
|
||||||
|
1;5;0;0;0;2;22;0;1;
|
||||||
|
1;5;0;0;0;3;22;0;1;
|
||||||
|
1;5;0;0;0;4;22;0;1;
|
||||||
|
1;6;0;0;0;2;22;0;1;
|
||||||
|
1;6;0;0;0;3;22;0;1;
|
||||||
|
1;6;0;0;0;4;22;0;1;
|
||||||
|
2;5;0;0;0;2;22;0;1;
|
||||||
|
2;5;0;0;0;3;22;0;1;
|
||||||
|
2;5;0;0;0;4;22;0;1;
|
||||||
|
2;6;0;0;0;2;22;0;1;
|
||||||
|
2;6;0;0;0;3;22;0;1;
|
||||||
|
2;6;0;0;0;4;22;0;1;
|
||||||
|
2;1;0;0;0;2;20;0;0;
|
||||||
|
2;2;0;0;0;2;20;0;0;
|
||||||
|
2;3;0;0;0;2;20;0;0;
|
||||||
|
2;4;0;0;0;2;20;0;0;
|
||||||
|
2;5;0;0;0;2;20;0;0;
|
||||||
|
2;6;0;0;0;2;20;0;0;
|
||||||
|
2;7;0;0;0;2;20;0;0;
|
||||||
|
2;8;0;0;0;2;20;0;0;
|
||||||
|
2;9;0;0;0;2;20;0;0;
|
||||||
|
2;1;0;0;1;3;22;0;1;
|
||||||
|
2;2;0;0;1;3;22;0;1;
|
||||||
|
2;3;0;0;1;3;22;0;1;
|
||||||
|
2;4;0;0;1;3;22;0;1;
|
||||||
|
2;5;0;0;1;3;22;0;1;
|
||||||
|
2;6;0;0;1;3;22;0;1;
|
||||||
|
2;7;0;0;1;3;22;0;1;
|
||||||
|
2;8;0;0;1;3;22;0;1;
|
||||||
|
2;9;0;0;1;3;22;0;1;
|
||||||
|
3;1;0;0;0;16;23;3;0;
|
||||||
|
3;2;0;0;0;16;23;3;0;
|
||||||
|
3;3;0;0;0;16;23;3;0;
|
||||||
|
3;4;0;0;0;16;23;3;0;
|
||||||
|
3;5;0;0;0;16;23;3;0;
|
||||||
|
3;6;0;0;0;16;23;3;0;
|
||||||
|
3;7;0;0;0;16;23;3;0;
|
||||||
|
3;8;0;0;0;16;23;3;0;
|
||||||
|
3;9;0;0;0;16;23;3;0;
|
||||||
|
1;5;0;0;0;2;23;0;1;
|
||||||
|
1;5;0;0;0;3;23;0;1;
|
||||||
|
1;5;0;0;0;4;23;0;1;
|
||||||
|
1;5;0;0;0;5;23;0;1;
|
||||||
|
1;5;0;0;0;6;23;0;1;
|
||||||
|
2;5;0;0;0;3;23;0;1;
|
||||||
|
2;5;0;0;0;4;23;0;1;
|
||||||
|
2;5;0;0;0;5;23;0;1;
|
||||||
|
2;5;0;0;0;6;23;0;1;
|
||||||
|
2;5;0;0;0;2;23;0;1;
|
||||||
|
2;5;0;0;1;4;26;1;1;
|
||||||
|
3;5;0;0;1;4;26;2;1;
|
||||||
|
1;7;0;1;0;1;22;0;1;
|
||||||
|
1;7;0;1;0;1;22;0;1;
|
||||||
|
4;1;0;0;1;30;21;4;0;
|
||||||
|
4;1;0;0;1;25;21;4;0;
|
||||||
|
1;6;0;0;1;1;22;0;1;
|
||||||
|
1;6;0;0;1;1;22;1;1;
|
||||||
|
4;3;30;0;1;50;36;4;0;
|
||||||
|
5;3;30;0;1;50;36;4;0;
|
||||||
|
1;1;0;0;0;9;22;0;0;
|
||||||
|
1;8;0;0;0;9;22;0;0;
|
||||||
|
3;1;0;0;0;25;22;2;0;
|
||||||
|
3;2;0;0;0;25;22;2;0;
|
||||||
|
3;3;0;0;0;25;22;2;0;
|
||||||
|
3;4;0;0;0;25;22;2;0;
|
||||||
|
3;5;0;0;0;25;22;2;0;
|
||||||
|
3;6;0;0;0;25;22;2;0;
|
||||||
|
3;7;0;0;0;25;22;2;0;
|
||||||
|
3;8;0;0;0;25;22;2;0;
|
||||||
|
3;9;0;0;0;25;22;2;0;
|
|
Binary file not shown.
@ -1,9 +1,9 @@
|
|||||||
import joblib
|
import joblib
|
||||||
|
|
||||||
def evaluate(data):
|
def evaluate(data):
|
||||||
# Load the model
|
# Load the model
|
||||||
clf = joblib.load('decisionTree/decision_tree_model.pkl')
|
clf = joblib.load('decisionTree/decision_tree_model.pkl')
|
||||||
|
|
||||||
# Make a prediction
|
# Make a prediction
|
||||||
prediction = clf.predict(data)
|
prediction = clf.predict(data)
|
||||||
return prediction
|
return prediction
|
@ -1,21 +1,21 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
from sklearn.tree import DecisionTreeClassifier
|
from sklearn.tree import DecisionTreeClassifier
|
||||||
from sklearn.model_selection import train_test_split
|
from sklearn.model_selection import train_test_split
|
||||||
from sklearn import metrics
|
from sklearn import metrics
|
||||||
import joblib
|
import joblib
|
||||||
|
|
||||||
pima = pd.read_csv("data.csv", header=1, delimiter=';')
|
pima = pd.read_csv("data.csv", header=1, delimiter=';')
|
||||||
|
|
||||||
feature_cols = ['Size', 'Color', 'Sound', 'Time','Smell', 'Height','Temperature']
|
feature_cols = ['Size', 'Color', 'Sound', 'Sharp','Smell', 'Length','Temperature', 'Weight']
|
||||||
X = pima[feature_cols]
|
X = pima[feature_cols]
|
||||||
y = pima.ToRemove
|
y = pima.ToRemove
|
||||||
|
|
||||||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)
|
||||||
clf = DecisionTreeClassifier()
|
clf = DecisionTreeClassifier()
|
||||||
clf = clf.fit(X_train,y_train)
|
clf = clf.fit(X_train,y_train)
|
||||||
|
|
||||||
joblib.dump(clf, 'decision_tree_model.pkl')
|
joblib.dump(clf, 'decision_tree_model.pkl')
|
||||||
|
|
||||||
y_pred = clf.predict(X_test)
|
y_pred = clf.predict(X_test)
|
||||||
|
|
||||||
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
|
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
|
@ -1,3 +1,3 @@
|
|||||||
class Command:
|
class Command:
|
||||||
def run(self):
|
def run(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -1,70 +1,70 @@
|
|||||||
from random import randint
|
from random import randint
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
from domain.commands.command import Command
|
from domain.commands.command import Command
|
||||||
from domain.entities.cat import Cat
|
from domain.entities.cat import Cat
|
||||||
from domain.world import World
|
from domain.world import World
|
||||||
|
|
||||||
|
|
||||||
class RandomCatMoveCommand(Command):
|
class RandomCatMoveCommand(Command):
|
||||||
def __init__(self, world: World, cat: Cat) -> None:
|
def __init__(self, world: World, cat: Cat) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.world = world
|
self.world = world
|
||||||
self.cat = cat
|
self.cat = cat
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
move_vector = (0, 0)
|
move_vector = (0, 0)
|
||||||
now = pygame.time.get_ticks()
|
now = pygame.time.get_ticks()
|
||||||
# region cat random movement
|
# region cat random movement
|
||||||
cat = self.world.cat
|
cat = self.world.cat
|
||||||
if now - cat.last_tick >= cat.cooldown:
|
if now - cat.last_tick >= cat.cooldown:
|
||||||
if not cat.busy:
|
if not cat.busy:
|
||||||
while True:
|
while True:
|
||||||
cat.direction = randint(0, 3)
|
cat.direction = randint(0, 3)
|
||||||
if not (
|
if not (
|
||||||
(cat.direction == 0 and cat.y == 0)
|
(cat.direction == 0 and cat.y == 0)
|
||||||
or (cat.direction == 1 and cat.x == self.world.width - 1)
|
or (cat.direction == 1 and cat.x == self.world.width - 1)
|
||||||
or (cat.direction == 2 and cat.y == self.world.height - 1)
|
or (cat.direction == 2 and cat.y == self.world.height - 1)
|
||||||
or (cat.direction == 3 and cat.x == 0)
|
or (cat.direction == 3 and cat.x == 0)
|
||||||
):
|
):
|
||||||
break
|
break
|
||||||
|
|
||||||
if cat.direction == 0: # up
|
if cat.direction == 0: # up
|
||||||
if cat.busy:
|
if cat.busy:
|
||||||
move_vector = (0, -1)
|
move_vector = (0, -1)
|
||||||
cat.busy = not cat.busy
|
cat.busy = not cat.busy
|
||||||
if cat.direction == 1: # right
|
if cat.direction == 1: # right
|
||||||
if cat.busy:
|
if cat.busy:
|
||||||
move_vector = (1, 0)
|
move_vector = (1, 0)
|
||||||
cat.busy = not cat.busy
|
cat.busy = not cat.busy
|
||||||
if cat.direction == 2: # down
|
if cat.direction == 2: # down
|
||||||
if cat.busy:
|
if cat.busy:
|
||||||
move_vector = (0, 1)
|
move_vector = (0, 1)
|
||||||
cat.busy = not cat.busy
|
cat.busy = not cat.busy
|
||||||
if cat.direction == 3: # left
|
if cat.direction == 3: # left
|
||||||
if cat.busy:
|
if cat.busy:
|
||||||
move_vector = (-1, 0)
|
move_vector = (-1, 0)
|
||||||
cat.busy = not cat.busy
|
cat.busy = not cat.busy
|
||||||
cat.last_tick = pygame.time.get_ticks()
|
cat.last_tick = pygame.time.get_ticks()
|
||||||
|
|
||||||
if move_vector == (0, 0):
|
if move_vector == (0, 0):
|
||||||
return
|
return
|
||||||
|
|
||||||
end_x = cat.x + move_vector[0]
|
end_x = cat.x + move_vector[0]
|
||||||
end_y = cat.y + move_vector[1]
|
end_y = cat.y + move_vector[1]
|
||||||
|
|
||||||
if (
|
if (
|
||||||
end_x > self.world.width - 1
|
end_x > self.world.width - 1
|
||||||
or end_y > self.world.height - 1
|
or end_y > self.world.height - 1
|
||||||
or end_x < 0
|
or end_x < 0
|
||||||
or end_y < 0
|
or end_y < 0
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.world.obstacles[cat.x][cat.y].remove(cat)
|
self.world.obstacles[cat.x][cat.y].remove(cat)
|
||||||
cat.x = end_x
|
cat.x = end_x
|
||||||
cat.y = end_y
|
cat.y = end_y
|
||||||
self.world.obstacles[end_x][end_y].append(cat)
|
self.world.obstacles[end_x][end_y].append(cat)
|
||||||
# endregion cat random movement
|
# endregion cat random movement
|
||||||
|
@ -1,33 +1,33 @@
|
|||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
from domain.commands.command import Command
|
from domain.commands.command import Command
|
||||||
from domain.entities.vacuum import Vacuum
|
from domain.entities.vacuum import Vacuum
|
||||||
from domain.world import World
|
from domain.world import World
|
||||||
|
|
||||||
|
|
||||||
class VacuumMoveCommand(Command):
|
class VacuumMoveCommand(Command):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, world: World, vacuum: Vacuum, move_vector: Tuple[int, int]
|
self, world: World, vacuum: Vacuum, move_vector: Tuple[int, int]
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.world = world
|
self.world = world
|
||||||
self.vacuum = vacuum
|
self.vacuum = vacuum
|
||||||
self.dx = move_vector[0]
|
self.dx = move_vector[0]
|
||||||
self.dy = move_vector[1]
|
self.dy = move_vector[1]
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
end_x = self.vacuum.x + self.dx
|
end_x = self.vacuum.x + self.dx
|
||||||
end_y = self.vacuum.y + self.dy
|
end_y = self.vacuum.y + self.dy
|
||||||
if not self.world.accepted_move(end_x, end_y):
|
if not self.world.accepted_move(end_x, end_y):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.world.is_garbage_at(end_x, end_y):
|
if self.world.is_garbage_at(end_x, end_y):
|
||||||
if self.vacuum.get_container_filling() < 100:
|
if self.vacuum.get_container_filling() < 100:
|
||||||
self.vacuum.increase_container_filling()
|
self.vacuum.increase_container_filling()
|
||||||
self.world.dust[end_x][end_y].pop()
|
self.world.dust[end_x][end_y].pop()
|
||||||
|
|
||||||
if self.world.is_docking_station_at(end_x, end_y):
|
if self.world.is_docking_station_at(end_x, end_y):
|
||||||
self.vacuum.dump_trash()
|
self.vacuum.dump_trash()
|
||||||
|
|
||||||
self.vacuum.x = end_x
|
self.vacuum.x = end_x
|
||||||
self.vacuum.y = end_y
|
self.vacuum.y = end_y
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
from domain.entities.entity import Entity
|
from domain.entities.entity import Entity
|
||||||
from domain.world import World
|
from domain.world import World
|
||||||
|
|
||||||
|
|
||||||
class Cat(Entity):
|
class Cat(Entity):
|
||||||
def __init__(self, x: int, y: int):
|
def __init__(self, x: int, y: int):
|
||||||
super().__init__(x, y, "CAT")
|
super().__init__(x, y, "CAT")
|
||||||
self.last_tick = pygame.time.get_ticks()
|
self.last_tick = pygame.time.get_ticks()
|
||||||
self.cooldown = 1000
|
self.cooldown = 1000
|
||||||
self.velocity = 1
|
self.velocity = 1
|
||||||
self.busy = False
|
self.busy = False
|
||||||
self.sleeping = False
|
self.sleeping = False
|
||||||
self.direction = 0
|
self.direction = 0
|
||||||
|
|
||||||
self.props = [1,2,0,16,1,10,25]
|
self.props = [4,2,20,0,1,32,37,5]
|
@ -1,10 +1,10 @@
|
|||||||
from domain.entities.entity import Entity
|
from domain.entities.entity import Entity
|
||||||
from domain.world import World
|
from domain.world import World
|
||||||
|
|
||||||
|
|
||||||
class Doc_Station(Entity):
|
class Doc_Station(Entity):
|
||||||
def __init__(self, x: int, y: int):
|
def __init__(self, x: int, y: int):
|
||||||
super().__init__(x, y, "DOC_STATION")
|
super().__init__(x, y, "DOC_STATION")
|
||||||
self.power = True
|
self.power = True
|
||||||
|
|
||||||
# TODO Docing Station: add more properties
|
# TODO Docing Station: add more properties
|
@ -1,8 +1,8 @@
|
|||||||
from domain.entities.entity import Entity
|
from domain.entities.entity import Entity
|
||||||
from domain.world import World
|
from domain.world import World
|
||||||
|
|
||||||
|
|
||||||
class Earring(Entity):
|
class Earring(Entity):
|
||||||
def __init__(self, x: int, y: int):
|
def __init__(self, x: int, y: int):
|
||||||
super().__init__(x, y, "EARRING")
|
super().__init__(x, y, "EARRING")
|
||||||
self.props = [2,1,0,12,0,50,24]
|
self.props = [1,9,0,1,0,1,20,0]
|
@ -1,5 +1,5 @@
|
|||||||
class Entity:
|
class Entity:
|
||||||
def __init__(self, x: int, y: int, type: str):
|
def __init__(self, x: int, y: int, type: str):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.type = type
|
self.type = type
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
from domain.entities.entity import Entity
|
from domain.entities.entity import Entity
|
||||||
|
|
||||||
|
|
||||||
class Garbage(Entity):
|
class Garbage(Entity):
|
||||||
def __init__(self, x: int, y: int):
|
def __init__(self, x: int, y: int):
|
||||||
super().__init__(x, y, "PEEL")
|
super().__init__(x, y, "PEEL")
|
||||||
self.wet = False
|
self.wet = False
|
||||||
self.size = 0
|
self.size = 0
|
||||||
self.props = [1,2,0,16,1,10,25]
|
self.props = [2,2,0,0,1,5,24,1]
|
||||||
|
|
||||||
# TODO GARBAGE: add more properties
|
# TODO GARBAGE: add more properties
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
from domain.entities.entity import Entity
|
from domain.entities.entity import Entity
|
||||||
from domain.world import World
|
from domain.world import World
|
||||||
|
|
||||||
|
|
||||||
class Plant(Entity):
|
class Plant(Entity):
|
||||||
def __init__(self, x: int, y: int):
|
def __init__(self, x: int, y: int):
|
||||||
super().__init__(x, y, "PLANT")
|
super().__init__(x, y, "PLANT")
|
||||||
self.watered = 100
|
self.watered = 100
|
||||||
|
|
||||||
# TODO PLANT: add more properties to
|
# TODO PLANT: add more properties to
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
from domain.entities.entity import Entity
|
from domain.entities.entity import Entity
|
||||||
from domain.world import World
|
from domain.world import World
|
||||||
|
|
||||||
|
|
||||||
class Vacuum(Entity):
|
class Vacuum(Entity):
|
||||||
def __init__(self, x: int, y: int):
|
def __init__(self, x: int, y: int):
|
||||||
super().__init__(x, y, "VACUUM")
|
super().__init__(x, y, "VACUUM")
|
||||||
self.direction = (1, 0)
|
self.direction = (1, 0)
|
||||||
self.battery = 100
|
self.battery = 100
|
||||||
self.cleaning_detergent = 100
|
self.cleaning_detergent = 100
|
||||||
self.container_filling = 0
|
self.container_filling = 0
|
||||||
|
|
||||||
def increase_container_filling(self) -> None:
|
def increase_container_filling(self) -> None:
|
||||||
self.container_filling += 25
|
self.container_filling += 25
|
||||||
|
|
||||||
def dump_trash(self) -> None:
|
def dump_trash(self) -> None:
|
||||||
self.container_filling = 0
|
self.container_filling = 0
|
||||||
|
|
||||||
def get_container_filling(self):
|
def get_container_filling(self):
|
||||||
return self.container_filling
|
return self.container_filling
|
||||||
|
|
||||||
# TODO VACUUM: add more properties
|
# TODO VACUUM: add more properties
|
||||||
|
114
domain/world.py
114
domain/world.py
@ -1,58 +1,58 @@
|
|||||||
from decisionTree.evaluate import evaluate
|
from decisionTree.evaluate import evaluate
|
||||||
from domain.entities.entity import Entity
|
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) -> object:
|
||||||
self.costs = [[1000 for j in range(height)] for i in range(width)]
|
self.costs = [[1000 for j in range(height)] for i in range(width)]
|
||||||
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)]
|
||||||
self.obstacles = [[[] for j in range(height)] for i in range(width)]
|
self.obstacles = [[[] for j in range(height)] for i in range(width)]
|
||||||
|
|
||||||
self.vacuum = None
|
self.vacuum = None
|
||||||
self.cat = None
|
self.cat = None
|
||||||
self.doc_station = 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 == "EARRING":
|
elif entity.type == "EARRING":
|
||||||
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":
|
elif entity.type == "DOC_STATION":
|
||||||
self.doc_station = entity
|
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)
|
||||||
else:
|
else:
|
||||||
self.obstacles[entity.x][entity.y].append(entity)
|
self.obstacles[entity.x][entity.y].append(entity)
|
||||||
|
|
||||||
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:
|
def is_garbage_at(self, x: int, y: int) -> bool:
|
||||||
if len(self.dust[x][y]) == 0:
|
if len(self.dust[x][y]) == 0:
|
||||||
return False
|
return False
|
||||||
tmp = evaluate([self.dust[x][y][0].props])
|
tmp = evaluate([self.dust[x][y][0].props])
|
||||||
return bool(tmp[0])
|
return bool(tmp[0])
|
||||||
|
|
||||||
def is_docking_station_at(self, x: int, y: int) -> bool:
|
def is_docking_station_at(self, x: int, y: int) -> bool:
|
||||||
return bool(self.doc_station.x == x and self.doc_station.y == y)
|
return bool(self.doc_station.x == x and self.doc_station.y == y)
|
||||||
|
|
||||||
def accepted_move(self, checking_x, checking_y):
|
def accepted_move(self, checking_x, checking_y):
|
||||||
if (
|
if (
|
||||||
checking_x > self.width - 1
|
checking_x > self.width - 1
|
||||||
or checking_y > self.height - 1
|
or checking_y > self.height - 1
|
||||||
or checking_x < 0
|
or checking_x < 0
|
||||||
or checking_y < 0
|
or checking_y < 0
|
||||||
):
|
):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.is_obstacle_at(checking_x, checking_y):
|
if self.is_obstacle_at(checking_x, checking_y):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
def get_cost(self, x, y):
|
def get_cost(self, x, y):
|
||||||
return self.costs[x][y]
|
return self.costs[x][y]
|
338
main.py
338
main.py
@ -1,169 +1,169 @@
|
|||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
from domain.commands.random_cat_move_command import RandomCatMoveCommand
|
from domain.commands.random_cat_move_command import RandomCatMoveCommand
|
||||||
from domain.commands.vacuum_move_command import VacuumMoveCommand
|
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.garbage import Garbage
|
from domain.entities.garbage import Garbage
|
||||||
from domain.entities.earring import Earring
|
from domain.entities.earring import Earring
|
||||||
from domain.entities.docking_station import Doc_Station
|
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
|
||||||
# from AI_brain.movement import GoAnyDirectionBFS, State
|
# from AI_brain.movement import GoAnyDirectionBFS, State
|
||||||
# from AI_brain.rotate_and_go_bfs import RotateAndGoBFS, State
|
# from AI_brain.rotate_and_go_bfs import RotateAndGoBFS, State
|
||||||
from AI_brain.rotate_and_go_astar import RotateAndGoAStar, State
|
from AI_brain.rotate_and_go_astar import RotateAndGoAStar, State
|
||||||
|
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read("config.ini")
|
config.read("config.ini")
|
||||||
|
|
||||||
|
|
||||||
class Main:
|
class Main:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
tiles_x = 10
|
tiles_x = 10
|
||||||
tiles_y = 10
|
tiles_y = 10
|
||||||
|
|
||||||
self.renderer = Renderer(800, 800, tiles_x, tiles_y)
|
self.renderer = Renderer(800, 800, tiles_x, tiles_y)
|
||||||
|
|
||||||
self.world = generate_world(tiles_x, tiles_y)
|
self.world = generate_world(tiles_x, tiles_y)
|
||||||
|
|
||||||
self.commands = []
|
self.commands = []
|
||||||
|
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
self.running = True
|
self.running = True
|
||||||
self.fps = 60
|
self.fps = 60
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
self.process_input()
|
self.process_input()
|
||||||
self.update()
|
self.update()
|
||||||
self.renderer.render(self.world)
|
self.renderer.render(self.world)
|
||||||
self.clock.tick(self.fps)
|
self.clock.tick(self.fps)
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|
||||||
def run_robot(self):
|
def run_robot(self):
|
||||||
self.renderer.render(self.world)
|
self.renderer.render(self.world)
|
||||||
|
|
||||||
start_state = State(self.world.vacuum.x, self.world.vacuum.y)
|
start_state = State(self.world.vacuum.x, self.world.vacuum.y)
|
||||||
end_state = State(self.world.doc_station.x, self.world.doc_station.y)
|
end_state = State(self.world.doc_station.x, self.world.doc_station.y)
|
||||||
|
|
||||||
# path_searcher = GoAnyDirectionBFS(self.world, start_state, end_state)
|
# path_searcher = GoAnyDirectionBFS(self.world, start_state, end_state)
|
||||||
# path_searcher = RotateAndGoBFS(self.world, start_state, end_state)
|
# path_searcher = RotateAndGoBFS(self.world, start_state, end_state)
|
||||||
path_searcher = RotateAndGoAStar(self.world, start_state, end_state)
|
path_searcher = RotateAndGoAStar(self.world, start_state, end_state)
|
||||||
if not path_searcher.search():
|
if not path_searcher.search():
|
||||||
print("No solution")
|
print("No solution")
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
path_searcher.actions.reverse()
|
path_searcher.actions.reverse()
|
||||||
while self.running:
|
while self.running:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
||||||
if len(path_searcher.actions) > 0:
|
if len(path_searcher.actions) > 0:
|
||||||
action_direction = path_searcher.actions.pop()
|
action_direction = path_searcher.actions.pop()
|
||||||
# self.handle_action1(action_direction)
|
# self.handle_action1(action_direction)
|
||||||
self.handle_action2(action_direction)
|
self.handle_action2(action_direction)
|
||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
self.renderer.render(self.world)
|
self.renderer.render(self.world)
|
||||||
self.clock.tick(5)
|
self.clock.tick(5)
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|
||||||
def handle_action1(self, action):
|
def handle_action1(self, action):
|
||||||
if action == "UP":
|
if action == "UP":
|
||||||
self.commands.append(
|
self.commands.append(
|
||||||
VacuumMoveCommand(self.world, self.world.vacuum, (0, -1))
|
VacuumMoveCommand(self.world, self.world.vacuum, (0, -1))
|
||||||
)
|
)
|
||||||
elif action == "DOWN":
|
elif action == "DOWN":
|
||||||
self.commands.append(
|
self.commands.append(
|
||||||
VacuumMoveCommand(self.world, self.world.vacuum, (0, 1))
|
VacuumMoveCommand(self.world, self.world.vacuum, (0, 1))
|
||||||
)
|
)
|
||||||
elif action == "LEFT":
|
elif action == "LEFT":
|
||||||
self.commands.append(
|
self.commands.append(
|
||||||
VacuumMoveCommand(self.world, self.world.vacuum, (-1, 0))
|
VacuumMoveCommand(self.world, self.world.vacuum, (-1, 0))
|
||||||
)
|
)
|
||||||
elif action == "RIGHT":
|
elif action == "RIGHT":
|
||||||
self.commands.append(
|
self.commands.append(
|
||||||
VacuumMoveCommand(self.world, self.world.vacuum, (1, 0))
|
VacuumMoveCommand(self.world, self.world.vacuum, (1, 0))
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle_action2(self, action):
|
def handle_action2(self, action):
|
||||||
if action == "GO":
|
if action == "GO":
|
||||||
self.commands.append(
|
self.commands.append(
|
||||||
VacuumMoveCommand(self.world, self.world.vacuum, self.world.vacuum.direction)
|
VacuumMoveCommand(self.world, self.world.vacuum, self.world.vacuum.direction)
|
||||||
)
|
)
|
||||||
elif action == "RR":
|
elif action == "RR":
|
||||||
self.world.vacuum.direction = (-self.world.vacuum.direction[1], self.world.vacuum.direction[0])
|
self.world.vacuum.direction = (-self.world.vacuum.direction[1], self.world.vacuum.direction[0])
|
||||||
elif action == "RL":
|
elif action == "RL":
|
||||||
self.world.vacuum.direction = (self.world.vacuum.direction[1], -self.world.vacuum.direction[0])
|
self.world.vacuum.direction = (self.world.vacuum.direction[1], -self.world.vacuum.direction[0])
|
||||||
|
|
||||||
def process_input(self):
|
def process_input(self):
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
self.running = False
|
self.running = False
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_LEFT:
|
if event.key == pygame.K_LEFT:
|
||||||
self.commands.append(
|
self.commands.append(
|
||||||
VacuumMoveCommand(self.world, self.world.vacuum, (-1, 0))
|
VacuumMoveCommand(self.world, self.world.vacuum, (-1, 0))
|
||||||
)
|
)
|
||||||
if event.key == pygame.K_RIGHT:
|
if event.key == pygame.K_RIGHT:
|
||||||
self.commands.append(
|
self.commands.append(
|
||||||
VacuumMoveCommand(self.world, self.world.vacuum, (1, 0))
|
VacuumMoveCommand(self.world, self.world.vacuum, (1, 0))
|
||||||
)
|
)
|
||||||
if event.key == pygame.K_UP:
|
if event.key == pygame.K_UP:
|
||||||
self.commands.append(
|
self.commands.append(
|
||||||
VacuumMoveCommand(self.world, self.world.vacuum, (0, -1))
|
VacuumMoveCommand(self.world, self.world.vacuum, (0, -1))
|
||||||
)
|
)
|
||||||
if event.key == pygame.K_DOWN:
|
if event.key == pygame.K_DOWN:
|
||||||
self.commands.append(
|
self.commands.append(
|
||||||
VacuumMoveCommand(self.world, self.world.vacuum, (0, 1))
|
VacuumMoveCommand(self.world, self.world.vacuum, (0, 1))
|
||||||
)
|
)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if config.getboolean("APP", "cat"):
|
if config.getboolean("APP", "cat"):
|
||||||
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()
|
||||||
|
|
||||||
|
|
||||||
def generate_world(tiles_x: int, tiles_y: int) -> World:
|
def generate_world(tiles_x: int, tiles_y: int) -> World:
|
||||||
world = World(tiles_x, tiles_y)
|
world = World(tiles_x, tiles_y)
|
||||||
for _ in range(35):
|
for _ in range(35):
|
||||||
temp_x = randint(0, tiles_x - 1)
|
temp_x = randint(0, tiles_x - 1)
|
||||||
temp_y = randint(0, tiles_y - 1)
|
temp_y = randint(0, tiles_y - 1)
|
||||||
world.add_entity(Garbage(temp_x, temp_y))
|
world.add_entity(Garbage(temp_x, temp_y))
|
||||||
world.vacuum = Vacuum(1, 1)
|
world.vacuum = Vacuum(1, 1)
|
||||||
world.doc_station = Doc_Station(9, 8)
|
world.doc_station = Doc_Station(9, 8)
|
||||||
if config.getboolean("APP", "cat"):
|
if config.getboolean("APP", "cat"):
|
||||||
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"))
|
||||||
world.add_entity(Entity(4, 1, "PLANT1"))
|
world.add_entity(Entity(4, 1, "PLANT1"))
|
||||||
world.add_entity(Entity(3, 4, "PLANT2"))
|
world.add_entity(Entity(3, 4, "PLANT2"))
|
||||||
world.add_entity(Entity(8, 8, "PLANT2"))
|
world.add_entity(Entity(8, 8, "PLANT2"))
|
||||||
world.add_entity(Entity(9, 3, "PLANT3"))
|
world.add_entity(Entity(9, 3, "PLANT3"))
|
||||||
world.add_entity(Earring(5, 5))
|
world.add_entity(Earring(5, 5))
|
||||||
|
|
||||||
|
|
||||||
for x in range(world.width):
|
for x in range(world.width):
|
||||||
for y in range(world.height):
|
for y in range(world.height):
|
||||||
if world.is_garbage_at(x, y):
|
if world.is_garbage_at(x, y):
|
||||||
world.costs[x][y] = 1
|
world.costs[x][y] = 1
|
||||||
else:
|
else:
|
||||||
world.costs[x][y] = 10
|
world.costs[x][y] = 10
|
||||||
return world
|
return world
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = Main()
|
app = Main()
|
||||||
if config["APP"]["movement"] == "human":
|
if config["APP"]["movement"] == "human":
|
||||||
app.run()
|
app.run()
|
||||||
elif config["APP"]["movement"] == "robot":
|
elif config["APP"]["movement"] == "robot":
|
||||||
app.run_robot()
|
app.run_robot()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
pygame
|
pygame
|
||||||
configparser
|
configparser
|
||||||
pandas
|
pandas
|
||||||
scikit-learn
|
scikit-learn
|
||||||
joblib
|
joblib
|
||||||
# formaFormatting: Provider - black
|
# formaFormatting: Provider - black
|
396
view/renderer.py
396
view/renderer.py
@ -1,198 +1,198 @@
|
|||||||
import random
|
import random
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
import configparser
|
import configparser
|
||||||
from pygame import Color
|
from pygame import Color
|
||||||
|
|
||||||
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.world import World
|
from domain.world import World
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read("config.ini")
|
config.read("config.ini")
|
||||||
|
|
||||||
|
|
||||||
class Renderer:
|
class Renderer:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
width=800,
|
width=800,
|
||||||
height=800,
|
height=800,
|
||||||
tiles_x=10,
|
tiles_x=10,
|
||||||
tiles_y=10,
|
tiles_y=10,
|
||||||
):
|
):
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
|
|
||||||
self.tiles_x = tiles_x
|
self.tiles_x = tiles_x
|
||||||
self.tiles_y = tiles_y
|
self.tiles_y = tiles_y
|
||||||
|
|
||||||
self.tile_width = self.width / self.tiles_x
|
self.tile_width = self.width / self.tiles_x
|
||||||
self.tile_height = self.height / self.tiles_y
|
self.tile_height = self.height / self.tiles_y
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
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.font = pygame.font.SysFont("Arial", 26, bold=True)
|
||||||
|
|
||||||
self.sprites = {
|
self.sprites = {
|
||||||
"VACUUM": pygame.transform.scale(
|
"VACUUM": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/vacuum.png"),
|
pygame.image.load("media/sprites/vacuum.png"),
|
||||||
(self.tile_width, self.tile_height),
|
(self.tile_width, self.tile_height),
|
||||||
),
|
),
|
||||||
"DOC_STATION": pygame.transform.scale(
|
"DOC_STATION": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/docking_station.png"),
|
pygame.image.load("media/sprites/docking_station.png"),
|
||||||
(self.tile_width, self.tile_height),
|
(self.tile_width, self.tile_height),
|
||||||
),
|
),
|
||||||
"WALL": pygame.transform.scale(
|
"WALL": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/wall.png"),
|
pygame.image.load("media/sprites/wall.png"),
|
||||||
(self.tile_width, self.tile_height),
|
(self.tile_width, self.tile_height),
|
||||||
),
|
),
|
||||||
"TILE": pygame.transform.scale(
|
"TILE": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/tile_cropped.jpeg"),
|
pygame.image.load("media/sprites/tile_cropped.jpeg"),
|
||||||
(self.tile_width, self.tile_height),
|
(self.tile_width, self.tile_height),
|
||||||
),
|
),
|
||||||
"PEEL": pygame.transform.scale(
|
"PEEL": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/peel.webp"),
|
pygame.image.load("media/sprites/peel.webp"),
|
||||||
(self.tile_width, self.tile_height),
|
(self.tile_width, self.tile_height),
|
||||||
),
|
),
|
||||||
"CAT_FRONT": pygame.transform.scale(
|
"CAT_FRONT": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/cat/standing_front.png"),
|
pygame.image.load("media/sprites/cat/standing_front.png"),
|
||||||
(self.tile_width, self.tile_height),
|
(self.tile_width, self.tile_height),
|
||||||
),
|
),
|
||||||
"CAT_BACK": pygame.transform.scale(
|
"CAT_BACK": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/cat/standing_back.png"),
|
pygame.image.load("media/sprites/cat/standing_back.png"),
|
||||||
(self.tile_width, self.tile_height),
|
(self.tile_width, self.tile_height),
|
||||||
),
|
),
|
||||||
"CAT_LEFT": pygame.transform.scale(
|
"CAT_LEFT": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/cat/standing_left.png"),
|
pygame.image.load("media/sprites/cat/standing_left.png"),
|
||||||
(self.tile_width, self.tile_height),
|
(self.tile_width, self.tile_height),
|
||||||
),
|
),
|
||||||
"CAT_RIGHT": pygame.transform.scale(
|
"CAT_RIGHT": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/cat/standing_right.png"),
|
pygame.image.load("media/sprites/cat/standing_right.png"),
|
||||||
(self.tile_width, self.tile_height),
|
(self.tile_width, self.tile_height),
|
||||||
),
|
),
|
||||||
"PLANT1": pygame.transform.scale(
|
"PLANT1": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/plants/plant1.png"),
|
pygame.image.load("media/sprites/plants/plant1.png"),
|
||||||
(
|
(
|
||||||
self.tile_width + self.tile_width / 4,
|
self.tile_width + self.tile_width / 4,
|
||||||
self.tile_height + self.tile_height / 4,
|
self.tile_height + self.tile_height / 4,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
"PLANT2": pygame.transform.scale(
|
"PLANT2": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/plants/plant2.png"),
|
pygame.image.load("media/sprites/plants/plant2.png"),
|
||||||
(
|
(
|
||||||
self.tile_width + self.tile_width / 4,
|
self.tile_width + self.tile_width / 4,
|
||||||
self.tile_height + self.tile_height / 4,
|
self.tile_height + self.tile_height / 4,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
"PLANT3": pygame.transform.scale(
|
"PLANT3": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/plants/plant3.png"),
|
pygame.image.load("media/sprites/plants/plant3.png"),
|
||||||
(
|
(
|
||||||
self.tile_width + self.tile_width / 4,
|
self.tile_width + self.tile_width / 4,
|
||||||
self.tile_height + self.tile_height / 4,
|
self.tile_height + self.tile_height / 4,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
"EARRING": pygame.transform.scale(
|
"EARRING": pygame.transform.scale(
|
||||||
pygame.image.load("media/sprites/earrings.webp"),
|
pygame.image.load("media/sprites/earrings.webp"),
|
||||||
(
|
(
|
||||||
self.tile_width + self.tile_width / 4,
|
self.tile_width + self.tile_width / 4,
|
||||||
self.tile_height + self.tile_height / 4,
|
self.tile_height + self.tile_height / 4,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
self.cat_direction_sprite = {
|
self.cat_direction_sprite = {
|
||||||
0: self.sprites["CAT_BACK"],
|
0: self.sprites["CAT_BACK"],
|
||||||
1: self.sprites["CAT_RIGHT"],
|
1: self.sprites["CAT_RIGHT"],
|
||||||
2: self.sprites["CAT_FRONT"],
|
2: self.sprites["CAT_FRONT"],
|
||||||
3: self.sprites["CAT_LEFT"],
|
3: self.sprites["CAT_LEFT"],
|
||||||
}
|
}
|
||||||
|
|
||||||
def render(self, world: World):
|
def render(self, world: World):
|
||||||
self.render_floor()
|
self.render_floor()
|
||||||
self.render_board()
|
self.render_board()
|
||||||
for x in range(world.width):
|
for x in range(world.width):
|
||||||
for y in range(world.height):
|
for y in range(world.height):
|
||||||
for entity in world.dust[x][y]:
|
for entity in world.dust[x][y]:
|
||||||
self.draw_entity(entity)
|
self.draw_entity(entity)
|
||||||
for x in range(world.width):
|
for x in range(world.width):
|
||||||
for y in range(world.height):
|
for y in range(world.height):
|
||||||
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.doc_station)
|
||||||
if config.getboolean("APP", "cat"):
|
if config.getboolean("APP", "cat"):
|
||||||
self.draw_entity(world.cat)
|
self.draw_entity(world.cat)
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
def line(self, x_1, y_1, x_2, y_2, color=None):
|
def line(self, x_1, y_1, x_2, y_2, color=None):
|
||||||
pygame.draw.line(self.screen, color, (x_1, y_1), (x_2, y_2))
|
pygame.draw.line(self.screen, color, (x_1, y_1), (x_2, y_2))
|
||||||
|
|
||||||
def render_board(self, color=Color("black")):
|
def render_board(self, color=Color("black")):
|
||||||
for i in range(1, self.tiles_x):
|
for i in range(1, self.tiles_x):
|
||||||
self.line(
|
self.line(
|
||||||
self.tile_width * i, 0, self.tile_width * i, self.height, color=color
|
self.tile_width * i, 0, self.tile_width * i, self.height, color=color
|
||||||
)
|
)
|
||||||
|
|
||||||
for i in range(1, self.tiles_y):
|
for i in range(1, self.tiles_y):
|
||||||
self.line(
|
self.line(
|
||||||
0, self.tile_height * i, self.width, self.tile_height * i, color=color
|
0, self.tile_height * i, self.width, self.tile_height * i, color=color
|
||||||
)
|
)
|
||||||
|
|
||||||
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:
|
if "PEEL" in entity.type:
|
||||||
draw_pos = (
|
draw_pos = (
|
||||||
(entity.x - 0.1) * self.tile_width,
|
(entity.x - 0.1) * self.tile_width,
|
||||||
(entity.y - 0.25) * self.tile_height,
|
(entity.y - 0.25) * self.tile_height,
|
||||||
)
|
)
|
||||||
if "PLANT" in entity.type:
|
if "PLANT" in entity.type:
|
||||||
draw_pos = (
|
draw_pos = (
|
||||||
(entity.x - 0.1) * self.tile_width,
|
(entity.x - 0.1) * self.tile_width,
|
||||||
(entity.y - 0.25) * self.tile_height,
|
(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:
|
if "VACUUM" in entity.type:
|
||||||
# Add text displaying container filling level
|
# Add text displaying container filling level
|
||||||
text_surface = self.font.render(
|
text_surface = self.font.render(
|
||||||
f"Filling: {entity.container_filling}%", True, Color("black")
|
f"Filling: {entity.container_filling}%", True, Color("black")
|
||||||
)
|
)
|
||||||
text_pos = (
|
text_pos = (
|
||||||
draw_pos[0] + self.tile_width / 2 - text_surface.get_width() / 2,
|
draw_pos[0] + self.tile_width / 2 - text_surface.get_width() / 2,
|
||||||
draw_pos[1] + self.tile_height,
|
draw_pos[1] + self.tile_height,
|
||||||
)
|
)
|
||||||
self.screen.blit(text_surface, text_pos)
|
self.screen.blit(text_surface, text_pos)
|
||||||
sprite = self.create_vacuum_sprite(entity)
|
sprite = self.create_vacuum_sprite(entity)
|
||||||
if "DOC_STATION" in entity.type:
|
if "DOC_STATION" in entity.type:
|
||||||
draw_pos = (
|
draw_pos = (
|
||||||
(entity.x - 0.1) * self.tile_width,
|
(entity.x - 0.1) * self.tile_width,
|
||||||
(entity.y - 0.25) * self.tile_height,
|
(entity.y - 0.25) * self.tile_height,
|
||||||
)
|
)
|
||||||
self.screen.blit(sprite, draw_pos)
|
self.screen.blit(sprite, draw_pos)
|
||||||
|
|
||||||
def create_vacuum_sprite(self, vacuum):
|
def create_vacuum_sprite(self, vacuum):
|
||||||
angles = {
|
angles = {
|
||||||
(1, 0): 0,
|
(1, 0): 0,
|
||||||
(-1, 0): 180,
|
(-1, 0): 180,
|
||||||
(0, 1): 270,
|
(0, 1): 270,
|
||||||
(0, -1): 90,
|
(0, -1): 90,
|
||||||
}
|
}
|
||||||
init_sprite = self.sprites.get(vacuum.type, None)
|
init_sprite = self.sprites.get(vacuum.type, None)
|
||||||
return pygame.transform.rotate(init_sprite, angles[vacuum.direction])
|
return pygame.transform.rotate(init_sprite, angles[vacuum.direction])
|
||||||
|
|
||||||
def draw_sprite(self, x: int, y: int, sprite_name: str):
|
def draw_sprite(self, x: int, y: int, sprite_name: str):
|
||||||
self.screen.blit(
|
self.screen.blit(
|
||||||
self.sprites[sprite_name], (x * self.tile_width, y * self.tile_height)
|
self.sprites[sprite_name], (x * self.tile_width, y * self.tile_height)
|
||||||
)
|
)
|
||||||
|
|
||||||
def fill_grid_with_sprite(self, sprite):
|
def fill_grid_with_sprite(self, sprite):
|
||||||
for tile_x in range(self.tiles_x):
|
for tile_x in range(self.tiles_x):
|
||||||
for tile_y in range(self.tiles_y):
|
for tile_y in range(self.tiles_y):
|
||||||
self.draw_sprite(tile_x, tile_y, sprite)
|
self.draw_sprite(tile_x, tile_y, sprite)
|
||||||
|
|
||||||
def render_floor(self):
|
def render_floor(self):
|
||||||
self.fill_grid_with_sprite("TILE")
|
self.fill_grid_with_sprite("TILE")
|
||||||
|
Loading…
Reference in New Issue
Block a user