Skip to content

Commit

Permalink
fixed a bug and tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason committed Mar 2, 2024
1 parent 4241102 commit 8385def
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,5 @@ THINKING ABOUT:
* people move
* things growing/shrinking
* things getting destroyed
* discover actions

17 changes: 0 additions & 17 deletions src/actions/fine_move_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,4 @@ def act(cls,agent, pre_processed_direction):
agent.x = new_x
agent.y = new_y

class TestFineMoveAction(unittest.TestCase):
def setUp(self):
self.agent = MagicMock()
self.agent.x = 0
self.agent.y = 0

def test_act_up(self):
FineMoveAction.act(self.agent, "up with random text")
self.assertEqual(self.agent.x, 0)
self.assertEqual(self.agent.y, -1)

def test_act_invalid_direction(self):
FineMoveAction.act(self.agent, "invalid-direction")
self.assertEqual(self.agent.x, 0)
self.assertEqual(self.agent.y, 0)

if __name__ == '__main__':
unittest.main()
4 changes: 3 additions & 1 deletion src/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def __init__(self, agent_data={}):
self.x = agent_data.get("x", None)
self.y = agent_data.get("y", None)
self.actions = list(set(agent_data.get("actions", []) + DEFAULT_ACTIONS))
self.actions = list(dict.fromkeys(agent_data.get("actions", []) + DEFAULT_ACTIONS))
#self.actions = list(dict.fromkeys(agent_data.get("actions", []) + DEFAULT_ACTIONS))
#old one
self.actions = list(dict.fromkeys(agent_data.get("actions",DEFAULT_ACTIONS )))

self.memory = agent_data.get("memory", [])
self.short_memory = agent_data.get("short_memory", [])
Expand Down
4 changes: 2 additions & 2 deletions src/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def llm_action(self, agent, unix_time):
"agents_available_to_talk": [a.name for a in agents_available_to_talk],
'objects': [obj.name.lower() for obj in perceived_objects] + [a.name.lower() for a in perceived_agents if a.kind != "human"],
'examples': example_strings,
'directions': perceived_directions,
'perceived_directions': perceived_directions,
'actions': valid_actions,
'location': current_location.name if current_location is not None else "",
'area': current_area if current_area is not None else "",
Expand All @@ -562,7 +562,7 @@ def llm_action(self, agent, unix_time):
return "stay", ""

decision, parameters = msg.split(" ", 1) + [""] * (1 - msg.count(" "))
print(f"decision {decision} params {parameters}")
print(f"decision {decision} params {parameters} explanation {explanation}")

if decision == "talk":
if len(agents_available_to_talk) > 0:
Expand Down
25 changes: 25 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,32 @@
import random
import re

from unittest.mock import MagicMock
from src.actions.fine_move_action import FineMoveAction

class TestMemoryFunctions(unittest.TestCase):
def test_fine_move_action_direction(self):
agent = MagicMock(x=0, y=0)
FineMoveAction.act(agent, "up with random text")
self.assertEqual(agent.x, 0)
self.assertEqual(agent.y, -1)

def test_fine_move_action_invalid_direction(self):
agent = MagicMock(x=0, y=0)
FineMoveAction.act(agent, "invalid-direction")
self.assertEqual(agent.x, 0)
self.assertEqual(agent.y, 0)

def test_fine_move_action_moves_away(self):
#real agent here, real zombie here. decide
matrix = Matrix({"environment":"configs/small.tmj"})
real_agent = Agent({ "name": "John", "actions": ["fine_move"],"x":5,"y":5,"matrix":matrix })
matrix.add_agent_to_simulation(real_agent)
zombie = Agent({ "name": f"Zombie", "kind": "zombie", "actions": ["kill"],"x":6,"y":5,"matrix":matrix })
matrix.add_agent_to_simulation(zombie)
matrix.llm_action(real_agent, matrix.unix_time)
self.assertEqual(real_agent.x, 4)

def test_memory(self):
agent_data = {
"name": "John",
Expand Down

0 comments on commit 8385def

Please sign in to comment.