Skip to content

Commit

Permalink
made changes in the graph and tree agents methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
srajan-kiyotaka committed Jun 19, 2024
1 parent 77d8c54 commit d266a6b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
12 changes: 6 additions & 6 deletions docs/graphAgent.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions docs/treeAgent.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='TraverseCraft',
version='0.7.5',
version='0.8.0',
author='Srajan Chourasia, Varun Patrikar',
author_email='[email protected], [email protected]',
maintainer='Srajan Chourasia, Varun Patrikar',
Expand Down
38 changes: 24 additions & 14 deletions src/traverseCraft/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/traverseCraft/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit d266a6b

Please sign in to comment.