diff --git a/docs/graphAgent.md b/docs/graphAgent.md index fd547a3..899afca 100644 --- a/docs/graphAgent.md +++ b/docs/graphAgent.md @@ -73,23 +73,23 @@ The getHeatMapColor method determines and returns the color representation corre - **Returns**: - `tuple`: The RGB color value for the given value on the heat map. -### `checkGoalState(self, node)` +### `checkGoalState(self, nodeId)` -This method checks whether a given node within the graph represents a goal state for the agent. It takes a GraphNode object as its parameter and evaluates whether the node's isGoalState attribute is True. If the node is identified as a goal state, the method returns True; otherwise, it returns False. This check allows the agent to assess its progress towards predefined objectives within the graph. +This method checks whether a given node within the graph represents a goal state for the agent. - **Parameters**: - - `node` (`GraphNode`): The node to be checked. + - `nodeId`: The ID of the node to be checked. - **Returns**: - `bool`: True if the node is a goal state, False otherwise. -### `moveAgent(self, node, delay:int=1)` +### `moveAgent(self, nodeId, delay:int=1)` The moveAgent method directs the agent to navigate from its current node to a specified node within the graph. It includes an optional delay parameter that introduces a pause (in seconds) before the agent proceeds to the next node. During the movement process, the method updates the heat map visualization to reflect the agent's path and increments the heat map value of the current node. If successful, the method returns True; otherwise, it returns False if the specified node is None, indicating a failed attempt to move. - **Parameters**: - - `node` (`GraphNode`): The node to which the agent should be moved. - - `delay` (`int`, optional): The delay (in seconds) before moving to the next node. Defaults to 1 second. + - `nodeId`: The ID of the node to which the agent should be moved. + - `delay` (`float`, optional): The delay (in seconds) before moving to the next node. Defaults to 1 second. - **Returns**: - `bool`: True if the agent was successfully moved to the node, False otherwise. diff --git a/docs/treeAgent.md b/docs/treeAgent.md index c7755bd..259a00e 100644 --- a/docs/treeAgent.md +++ b/docs/treeAgent.md @@ -77,20 +77,20 @@ This method returns the color corresponding to a given value on a heat map. It u - **Returns**: - `tuple`: The RGB color value for the given value on the heat map. -#### `checkGoalState(self, node)` +#### `checkGoalState(self, nodeId)` This method checks if the specified node is a goal state. - **Parameters**: - - `node` (`TreeNode`): The node to be checked. + - `nodeId`: The ID of the node to be checked. - **Returns**: - `bool`: True if the node is a goal state, False otherwise. -#### `moveAgent(self, node, delay:int=1)` +#### `moveAgent(self, nodeId, delay:int=1)` This method moves the agent to the specified node after a given delay. It updates the heat map and the agent's current position. - **Parameters**: - - `node` (`TreeNode`): The node to which the agent should be moved. + - `nodeId`: The ID of the node to which the agent should be moved. - `delay` (`int`, optional): The delay (in seconds) before moving to the next node. Defaults to 1 second. - **Returns**: diff --git a/setup.py b/setup.py index a3bbfa1..152dc88 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='TraverseCraft', - version='0.7.5', + version='0.8.0', author='Srajan Chourasia, Varun Patrikar', author_email='srajanstark.ash@gmail.com, patrikarvarun@gmail.com', maintainer='Srajan Chourasia, Varun Patrikar', diff --git a/src/traverseCraft/agent.py b/src/traverseCraft/agent.py index d90ae40..063515f 100644 --- a/src/traverseCraft/agent.py +++ b/src/traverseCraft/agent.py @@ -498,34 +498,39 @@ def _modifyCellColor(self, node, color): self._worldObj.changeNodeColor(node.id, color) self._root.update() - def checkGoalState(self, node): + def checkGoalState(self, nodeId): """ Check if the given node is a goal state. Parameters: - - node: The node to be checked. + - nodeId: The node Id to be checked. Returns: - True if the node is a goal state, False otherwise. """ - if(node.isGoalState): - return True + if(nodeId in self._worldObj.nodeMap.keys()): + node = self._worldObj.getNode(nodeId) + if(node.isGoalState): + return True + else: + return False else: return False - def moveAgent(self, node, delay:int=1): + def moveAgent(self, nodeId, delay:int=1): """ Moves the agent to the specified node. Args: - node: The node to which the agent should be moved. + nodeId: The node Id to which the agent should be moved. delay (optional): The delay (in seconds) before moving to the next node. Default is 1 second. Returns: bool: True if the agent was successfully moved to the node, False otherwise. """ - if(node is not None): + if(nodeId in self._worldObj.nodeMap.keys()): + node = self._worldObj.nodeMap[nodeId] time.sleep(delay) parent = self._currentNode self._updateHeatMap(parent) @@ -753,34 +758,39 @@ def _modifyCellColor(self, node, color): self._worldObj.changeNodeColor(node.id, color) self._root.update() - def checkGoalState(self, node): + def checkGoalState(self, nodeId): """ Check if the given node is a goal state. Parameters: - node: The node to be checked. + node: The ID of the node to be checked. Returns: bool: True if the node is a goal state, False otherwise. """ - if(node.isGoalState): - return True + if(nodeId in self._worldObj.nodeMap.keys()): + node = self._worldObj.getNode(nodeId) + if(node.isGoalState): + return True + else: + return False else: return False - def moveAgent(self, node, delay:int=1): + def moveAgent(self, nodeId, delay:int=1): """ Moves the agent to the specified node. Args: - node: The node to which the agent should be moved. + nodeId: The ID of the node to which the agent should be moved. delay (optional): The delay (in seconds) before moving to the next node. Default is 1 second. Returns: bool: True if the agent was successfully moved to the node, False otherwise. """ - if(node is not None): + if(nodeId in self._worldObj.nodeMap.keys()): + node = self._worldObj.nodeMap[nodeId] time.sleep(delay) parent = self._currentNode self._updateHeatMap(parent) diff --git a/src/traverseCraft/world.py b/src/traverseCraft/world.py index a2ec1df..3611c5d 100644 --- a/src/traverseCraft/world.py +++ b/src/traverseCraft/world.py @@ -189,6 +189,8 @@ def aboutWorld(self): about.add_row(["Cell Size", self._cellSize]) about.add_row(["Cell Padding", self._cellPadding]) about.add_row(["Window Size", f"{self._windowHeight}x{self._windowWidth}"]) + about.add_row(["Goal Cells", self._goalCells]) + about.add_row(["Block Cells", self._blockCells]) about.add_row(["Path Color", self._pathColor]) about.add_row(["Block Color", self._blockColor]) about.add_row(["Goal Color", self._goalColor]) diff --git a/tests/test_graph_agent.py b/tests/test_graph_agent.py index 2ce2ec1..ec87542 100644 --- a/tests/test_graph_agent.py +++ b/tests/test_graph_agent.py @@ -88,10 +88,8 @@ def sample_algorithm(): self.assertTrue(True) def test_check_goal_state(self): - goal_node = self.graphWorld.getNode("G") - non_goal_node = self.graphWorld.getNode("A") - self.assertTrue(self.agent.checkGoalState(goal_node)) - self.assertFalse(self.agent.checkGoalState(non_goal_node)) + self.assertTrue(self.agent.checkGoalState("G")) + self.assertFalse(self.agent.checkGoalState("A")) def test_set_start_state(self): self.agent.setStartState("B") @@ -104,18 +102,12 @@ def test_set_start_state_invalid(self): self.agent.setStartState("Z") # Assuming "Z" is not a valid node ID def test_move_agent(self): - # Get pointers to nodes 'B', 'D', and 'E' using self.graphWorld.getNode() - node_B = self.graphWorld.getNode('B') - node_C = self.graphWorld.getNode('C') - node_D = self.graphWorld.getNode('D') - node_E = self.graphWorld.getNode('E') - # Move the agent self.assertFalse(self.agent.moveAgent(None)) # Move to None should fail - self.assertTrue(self.agent.moveAgent(node_B)) # Move to node 'B' should succeed - self.assertTrue(self.agent.moveAgent(node_C)) # Move to node 'C' should succeed - self.assertTrue(self.agent.moveAgent(node_D)) # Move to node 'D' should succeed - self.assertTrue(self.agent.moveAgent(node_E)) # Move to node 'E' should succeed + self.assertTrue(self.agent.moveAgent("B")) # Move to node 'B' should succeed + self.assertTrue(self.agent.moveAgent("C")) # Move to node 'C' should succeed + self.assertTrue(self.agent.moveAgent("D")) # Move to node 'D' should succeed + self.assertTrue(self.agent.moveAgent("E")) # Move to node 'E' should succeed if __name__ == '__main__': unittest.main() diff --git a/tests/test_tree_agent.py b/tests/test_tree_agent.py index 3db224a..5fcdfe5 100644 --- a/tests/test_tree_agent.py +++ b/tests/test_tree_agent.py @@ -87,22 +87,16 @@ def sample_algorithm(): def test_check_goal_state(self): # Check goal state - self.assertFalse(self.agent.checkGoalState(self.agent._treeRoot)) # The root node should be a goal state - self.assertTrue(self.agent.checkGoalState(self.treeWorld.getNode('G'))) # The node 'G' should be a goal state + self.assertFalse(self.agent.checkGoalState(self.agent._treeRoot.id)) # The root node should be a goal state + self.assertTrue(self.agent.checkGoalState("G")) # The node 'G' should be a goal state def test_move_agent(self): - # Get pointers to nodes 'B', 'D', and 'E' using self.treeWorld.getNode() - node_B = self.treeWorld.getNode('B') - node_C = self.treeWorld.getNode('C') - node_D = self.treeWorld.getNode('D') - node_E = self.treeWorld.getNode('E') - # Move the agent self.assertFalse(self.agent.moveAgent(None)) # Move to None should fail - self.assertTrue(self.agent.moveAgent(node_B)) # Move to node 'B' should succeed - self.assertTrue(self.agent.moveAgent(node_C)) # Move to node 'C' should succeed - self.assertTrue(self.agent.moveAgent(node_D)) # Move to node 'D' should succeed - self.assertTrue(self.agent.moveAgent(node_E)) # Move to node 'E' should succeed + self.assertTrue(self.agent.moveAgent("B")) # Move to node 'B' should succeed + self.assertTrue(self.agent.moveAgent("C")) # Move to node 'C' should succeed + self.assertTrue(self.agent.moveAgent("D")) # Move to node 'D' should succeed + self.assertTrue(self.agent.moveAgent("E")) # Move to node 'E' should succeed if __name__ == '__main__': unittest.main() \ No newline at end of file