From a73e9ee7491fea7d236597857c629b8b5b2a8711 Mon Sep 17 00:00:00 2001
From: Jon <vitale.jonathan@ymail.com>
Date: Tue, 6 Jun 2023 21:06:38 +1000
Subject: [PATCH] Add the material for workshop week 2

---
 week2/material/agent_programs.py | 80 ++++++++++++++++++++++++++++++++
 week2/material/vacuum_agent.py   | 55 ++++++++++++++++++++++
 week2/material/vacuum_app.py     | 13 ++++++
 3 files changed, 148 insertions(+)
 create mode 100644 week2/material/agent_programs.py
 create mode 100644 week2/material/vacuum_agent.py
 create mode 100644 week2/material/vacuum_app.py

diff --git a/week2/material/agent_programs.py b/week2/material/agent_programs.py
new file mode 100644
index 0000000..d704263
--- /dev/null
+++ b/week2/material/agent_programs.py
@@ -0,0 +1,80 @@
+import math
+import random 
+import numpy as np
+
+from une_ai.vacuum import DISPLAY_HEIGHT, DISPLAY_WIDTH, TILE_SIZE
+from une_ai.models import GridMap
+from vacuum_agent import VacuumAgent
+
+DIRECTIONS = VacuumAgent.WHEELS_DIRECTIONS
+
+"""
+Test agent:
+- If the vacuum power is off, it starts cleaning
+- At each time, it chooses a random direction for the wheels
+"""
+def test_behaviour(percepts, actuators):
+    actions = []
+
+    return actions
+
+"""
+Simple reflex agent: 
+- If the vacuum power is off, it starts cleaning
+- If there is dirt on the current tile (i.e. 'dirt-sensor-center'), 
+it activates the suction mechanism
+- If the agent hits a wall, it changes the direction of the wheels randomly
+- If the agent senses dirt on the surrounding tiles, 
+it changes the direction of the wheels towards the dirt
+"""
+def simple_reflex_behaviour(percepts, actuators):
+    actions = []
+
+    return actions
+
+"""
+Model-based reflex agent: 
+- The agent keeps track of the walls it crashed against by using a GridMap
+- Based on the current wheels direction, if the next tile is a wall,
+the agent will change direction
+- In all the other situations, the agent will behave like the simple-reflex agent
+"""
+def model_based_reflex_behaviour(percepts, actuators):
+    actions = []
+
+    return actions
+
+"""
+Goal-based agent:
+- The agent keeps track of previously explored tiles by using a GridMap
+- Based on the current wheels direction, if the next tile was already explored,
+the agent will change direction towards an unexplored tile (if any, otherwise 
+it will proceed in the same direction)
+- In all the other situations, the agent will behave like the model-based reflex agent
+- The agent will stop cleaning once the environment is fully explored
+"""
+def goal_based_behaviour(percepts, actuators):
+    actions = []
+
+    return actions
+
+"""
+Utility-based agent:
+The agent also stores information about dirt on the adjacent cells detected by the dirt sensors.
+The agent then chooses the next direction via a utility function.
+This utility function takes a direction as input, and implement the following steps:
+- The agent examines its internal model of the world and retrieves a list of cell values 
+in the specified direction.
+- It filters out any cells that are obstructed by a wall, considering only the unobstructed cells.
+- If there is dirt in the considered direction, the utility is returned as a high value such as 999
+otherwise
+- The agent calculates the minimum distance (min_dist) from an unexplored cell in this 
+filtered list. If there are no unexplored cells, min_dist is set to a high value such as 999.
+- The utility value is determined as -1 multiplied by min_dist, 
+reflecting the notion that the agent values smaller distances to unexplored cells.
+"""
+def utility_based_behaviour(percepts, actuators):
+    actions = []
+    
+    return actions
+    
\ No newline at end of file
diff --git a/week2/material/vacuum_agent.py b/week2/material/vacuum_agent.py
new file mode 100644
index 0000000..5bf02fc
--- /dev/null
+++ b/week2/material/vacuum_agent.py
@@ -0,0 +1,55 @@
+from une_ai.models import Agent
+
+class VacuumAgent(Agent):
+
+    WHEELS_DIRECTIONS = ['north', 'south', 'west', 'east']
+
+    def __init__(self, agent_program):
+        super().__init__(
+            agent_name='vacuum_agent',
+            agent_program=agent_program
+        )
+        
+    # TODO: add all the sensors
+    def add_all_sensors(self):
+        pass
+    
+    # TODO: add all the actuators
+    def add_all_actuators(self):
+        pass
+
+    # TODO: add all the actions
+    def add_all_actions(self):
+        pass
+
+    # TODO: implement the following methods
+
+    def get_pos_x(self):
+        # It must return the x coord of the agent 
+        # based on the location-sensor value
+        pass
+    
+    def get_pos_y(self):
+        # It must return the y coord of the agent 
+        # based on the location-sensor value
+        pass
+    
+    def get_battery_level(self):
+        # It must return the rounded (as int) sensory value 
+        # from the sensor battery-level
+        pass
+    
+    def is_out_of_charge(self):
+        # It must return True if the sensor battery-level
+        # is 0 and False otherwise
+        pass
+    
+    def collision_detected(self):
+        # It must return the direction of the bumper
+        # sensor collided with a wall if any, or None otherwise
+        pass
+
+    # This function is already implemented
+    # so you do not need to change it
+    def did_collide(self):
+        return False if self.collision_detected() is None else True
\ No newline at end of file
diff --git a/week2/material/vacuum_app.py b/week2/material/vacuum_app.py
new file mode 100644
index 0000000..4bb0fff
--- /dev/null
+++ b/week2/material/vacuum_app.py
@@ -0,0 +1,13 @@
+from une_ai.vacuum import VacuumGame
+from vacuum_agent import VacuumAgent
+from agent_programs import test_behaviour, simple_reflex_behaviour, model_based_reflex_behaviour, goal_based_behaviour, utility_based_behaviour
+
+if __name__ == "__main__":
+    # creating the vacuum agent
+    # To test the different agent programs, change the function passed 
+    # as parameter when instantiating the class VacuumAgent
+    agent = VacuumAgent(test_behaviour)
+
+    # running the game with the instantiated agent
+    # DO NOT EDIT THIS INSTRUCTION!
+    game = VacuumGame(agent)
\ No newline at end of file
-- 
GitLab