From e2a2bf6c3f106909ec82924c69640bf82ffebb3a Mon Sep 17 00:00:00 2001
From: Omar <s-omarkhaled@zewailcity.edu.eg>
Date: Tue, 7 Jan 2020 03:04:42 +0200
Subject: [PATCH 1/5] fixed grabbing behaviour in agent

---
 agents.py | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/agents.py b/agents.py
index 084a752e1..a4cf88af9 100644
--- a/agents.py
+++ b/agents.py
@@ -510,14 +510,16 @@ def execute_action(self, agent, action):
             agent.direction += Direction.L
         elif action == 'Forward':
             agent.bump = self.move_to(agent, agent.direction.move_forward(agent.location))
-        #         elif action == 'Grab':
-        #             things = [thing for thing in self.list_things_at(agent.location)
-        #                     if agent.can_grab(thing)]
-        #             if things:
-        #                 agent.holding.append(things[0])
+        elif action == 'Grab':
+            things = [thing for thing in self.list_things_at(agent.location)]
+            if agent.can_grab(things[0]):
+                if things:
+                    agent.holding.append(things[0])
+                    self.delete_thing(things[0])
         elif action == 'Release':
             if agent.holding:
-                agent.holding.pop()
+                dropped = agent.holding.pop()
+                self.add_thing(dropped, location=agent.location)
 
     def default_location(self, thing):
         location = self.random_location_inbounds()
@@ -569,10 +571,11 @@ def random_location_inbounds(self, exclude=None):
     def delete_thing(self, thing):
         """Deletes thing, and everything it is holding (if thing is an agent)"""
         if isinstance(thing, Agent):
-            for obj in thing.holding:
-                super().delete_thing(obj)
-                for obs in self.observers:
-                    obs.thing_deleted(obj)
+            # for obj in thing.holding:
+            #     super().delete_thing(obj)
+            #     for obs in self.observers:
+            #         obs.thing_deleted(obj)
+            del thing.holding
 
         super().delete_thing(thing)
         for obs in self.observers:

From f660166e76f08543d15a49af6f847a6382e8af4b Mon Sep 17 00:00:00 2001
From: Omar <s-omarkhaled@zewailcity.edu.eg>
Date: Tue, 7 Jan 2020 14:53:53 +0200
Subject: [PATCH 2/5] fixed the grabbing issues and itegrated into wumpus
 environment

---
 agents.py | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/agents.py b/agents.py
index a4cf88af9..0998d81ab 100644
--- a/agents.py
+++ b/agents.py
@@ -511,14 +511,15 @@ def execute_action(self, agent, action):
         elif action == 'Forward':
             agent.bump = self.move_to(agent, agent.direction.move_forward(agent.location))
         elif action == 'Grab':
-            things = [thing for thing in self.list_things_at(agent.location)]
-            if agent.can_grab(things[0]):
-                if things:
-                    agent.holding.append(things[0])
-                    self.delete_thing(things[0])
+            things = [thing for thing in self.list_things_at(agent.location) if agent.can_grab(thing)]
+            if things:    
+                agent.holding.append(things[0])
+                print("Grabbing ", things[0].__class__.__name__)
+                self.delete_thing(things[0])
         elif action == 'Release':
             if agent.holding:
                 dropped = agent.holding.pop()
+                print("Dropping ", dropped.__class__.__name__)
                 self.add_thing(dropped, location=agent.location)
 
     def default_location(self, thing):
@@ -571,10 +572,6 @@ def random_location_inbounds(self, exclude=None):
     def delete_thing(self, thing):
         """Deletes thing, and everything it is holding (if thing is an agent)"""
         if isinstance(thing, Agent):
-            # for obj in thing.holding:
-            #     super().delete_thing(obj)
-            #     for obs in self.observers:
-            #         obs.thing_deleted(obj)
             del thing.holding
 
         super().delete_thing(thing)
@@ -970,21 +967,16 @@ def execute_action(self, agent, action):
 
         agent.bump = False
         if action == 'TurnRight':
-            agent.direction += Direction.R
+            super().execute_action(agent,action)
             agent.performance -= 1
         elif action == 'TurnLeft':
-            agent.direction += Direction.L
+            super().execute_action(agent,action)
             agent.performance -= 1
         elif action == 'Forward':
-            agent.bump = self.move_to(agent, agent.direction.move_forward(agent.location))
+            super().execute_action(agent,action)
             agent.performance -= 1
         elif action == 'Grab':
-            things = [thing for thing in self.list_things_at(agent.location)
-                      if agent.can_grab(thing)]
-            if len(things):
-                print("Grabbing", things[0].__class__.__name__)
-                if len(things):
-                    agent.holding.append(things[0])
+            super().execute_action(agent,action)
             agent.performance -= 1
         elif action == 'Climb':
             if agent.location == (1, 1):  # Agent can only climb out of (1,1)

From 6da942db82e85138d6973700b6cace6db724de15 Mon Sep 17 00:00:00 2001
From: omar659 <s-omarkhaled@zewailcity.edu.eg>
Date: Tue, 18 Feb 2020 22:22:05 +0200
Subject: [PATCH 3/5] cleaned the code a bit

---
 agents.py | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/agents.py b/agents.py
index 0998d81ab..68d1fa631 100644
--- a/agents.py
+++ b/agents.py
@@ -27,11 +27,6 @@
 """
 
 # TODO
-# Implement grabbing correctly.
-# When an object is grabbed, does it still have a location?
-# What if it is released?
-# What if the grabbed or the grabber is deleted?
-# What if the grabber moves?
 # Speed control in GUI does not have any effect -- fix it.
 
 from utils import distance_squared, turn_heading
@@ -966,16 +961,7 @@ def execute_action(self, agent, action):
             return
 
         agent.bump = False
-        if action == 'TurnRight':
-            super().execute_action(agent,action)
-            agent.performance -= 1
-        elif action == 'TurnLeft':
-            super().execute_action(agent,action)
-            agent.performance -= 1
-        elif action == 'Forward':
-            super().execute_action(agent,action)
-            agent.performance -= 1
-        elif action == 'Grab':
+        if action in ['TurnRight', 'TurnLeft', 'Forward','Grab']:
             super().execute_action(agent,action)
             agent.performance -= 1
         elif action == 'Climb':

From 679ab34d212b03e68207543607ea410d3290ca1b Mon Sep 17 00:00:00 2001
From: omar659 <s-omarkhaled@zewailcity.edu.eg>
Date: Thu, 20 Feb 2020 22:24:00 +0200
Subject: [PATCH 4/5] fixing the code space formatting

---
 agents.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/agents.py b/agents.py
index 68d1fa631..ce922da28 100644
--- a/agents.py
+++ b/agents.py
@@ -959,9 +959,9 @@ def execute_action(self, agent, action):
 
         if isinstance(agent, Explorer) and self.in_danger(agent):
             return
-
+            
         agent.bump = False
-        if action in ['TurnRight', 'TurnLeft', 'Forward','Grab']:
+        if action in ['TurnRight', 'TurnLeft', 'Forward', 'Grab']:
             super().execute_action(agent,action)
             agent.performance -= 1
         elif action == 'Climb':

From 20188951cae13e9d6b8b74691e89698c55b15014 Mon Sep 17 00:00:00 2001
From: omar659 <s-omarkhaled@zewailcity.edu.eg>
Date: Fri, 6 Mar 2020 18:37:02 +0200
Subject: [PATCH 5/5] fixing format

---
 agents.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/agents.py b/agents.py
index ce922da28..6ab9ea814 100644
--- a/agents.py
+++ b/agents.py
@@ -962,7 +962,7 @@ def execute_action(self, agent, action):
             
         agent.bump = False
         if action in ['TurnRight', 'TurnLeft', 'Forward', 'Grab']:
-            super().execute_action(agent,action)
+            super().execute_action(agent, action)
             agent.performance -= 1
         elif action == 'Climb':
             if agent.location == (1, 1):  # Agent can only climb out of (1,1)