diff --git a/.gitignore b/.gitignore index c9f2933..71fd5c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ venv envs -*.ipynb +test.ipynb */*/__pycache__ src/traverseCraft/__pycache__ tests/__pycache__ @@ -12,3 +12,4 @@ test.py build dist *.egg-info +*.in diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index e6d2e16..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,48 +0,0 @@ -[build-system] -requires = ["setuptools>=61.0"] -build-backend = "setuptools.build_meta" - -[project] -name = "traverseCraft" -version = "0.6.0" -authors = [ - {name = "Srajan Chourasia", email = "srajanstark.ash@gmail.com"}, - {name = "Varun Patrikar", email = "patrikarvarun@gmail.com"}, -] -maintainers = [ - {name = "Srajan Chourasia", email = "srajanstark.ash@gmail.com"}, - {name = "Varun Patrikar", email = "patrikarvarun@gmail.com"}, -] -description = "TraverseCraft: Cross-Platform Real-Time Algorithm Simulation Tool" -readme = "README.md" -dependencies = ['prettytable',] -license = { text = "MIT" } -keywords = ["simulation", "real-time", "algorithm", "visualization", "education", "research", "AI", "ML", "reinforcement learning"] -requires-python = ">=3.6" -classifiers = [ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - 'Topic :: Education', - 'Topic :: Software Development :: Libraries', - 'Topic :: Software Development :: Libraries :: Python Modules', - 'Topic :: Scientific/Engineering :: Artificial Intelligence', - 'Topic :: Scientific/Engineering :: Visualization', - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'Intended Audience :: Education', -] - -[project.urls] -"Documentation" = "https://docs.traverseCraft.com" -"Source" = "https://github.com/srajan-kiyotaka/TraverseCraft/tree/main" -"Tracker" = "https://github.com/srajan-kiyotaka/TraverseCraft/tree/main/issues" -"Reference" = "https://reference.traverseCraft.com" -"Official website" = "https://official-website.com" - -[tool.hatch.metadata] -allow-direct-references = true - -[tool.hatch.build.targets.wheel] -include = ["traverseCraft"] - diff --git a/setup.py b/setup.py index e2e010e..52ea6ef 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='TraverseCraft', - version='0.6.0', + version='0.7.0', author='Srajan Chourasia, Varun Patrikar', author_email='srajanstark.ash@gmail.com, patrikarvarun@gmail.com', maintainer='Srajan Chourasia, Varun Patrikar', @@ -22,6 +22,7 @@ }, package_dir={'': 'src'}, packages=find_packages(where='src'), + include_package_data=True, python_requires='>=3.6', install_requires=[ 'prettytable', diff --git a/src/traverseCraft/world.py b/src/traverseCraft/world.py index 2cadb2c..421f2c8 100644 --- a/src/traverseCraft/world.py +++ b/src/traverseCraft/world.py @@ -79,7 +79,7 @@ class CreateGridWorld: coordinate = List[int] worldID = "GRIDWORLD" - def __init__(self, worldName:str, rows:int, cols:int, cellSize:int=10, pathColor:str="gray", blockColor:str="red", goalColor:str="green", cellPadding:int=2, borderWidth:int=1, buttonBgColor:str="#7FC7D9", buttonFgColor:str="#332941", textFont:str="Helvetica", textSize:int=24, textWeight:str="bold", buttonText:str="Start Agent", logoPath:str=None): + def __init__(self, worldName:str, rows:int, cols:int, cellSize:int=20, pathColor:str="gray", blockColor:str="red", goalColor:str="green", cellPadding:int=2, borderWidth:int=1, buttonBgColor:str="#7FC7D9", buttonFgColor:str="#332941", textFont:str="Helvetica", textSize:int=24, textWeight:str="bold", buttonText:str="Start Agent", logoPath:str=None): """ Initializes the Grid World. diff --git a/tutorials/Grid World/beginner.ipynb b/tutorials/Grid World/beginner.ipynb new file mode 100644 index 0000000..a038f63 --- /dev/null +++ b/tutorials/Grid World/beginner.ipynb @@ -0,0 +1,823 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Import required modules\n", + "\n", + "Let's start by importing the required module form the main library.\n", + "\n", + "It's always a good idea to check whether the library is installed or not.\n", + "\n", + "This command will install if the library is not already installed." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Looking in indexes: https://test.pypi.org/simple/\n", + "Requirement already satisfied: TraverseCraft in /media/srajan/Data/Project/LibraryTests/envs/lib/python3.8/site-packages (0.6.5)\n", + "Requirement already satisfied: prettytable in /media/srajan/Data/Project/LibraryTests/envs/lib/python3.8/site-packages (from TraverseCraft) (0.7.3.dev122)\n" + ] + } + ], + "source": [ + "!pip install -i https://test.pypi.org/simple/ TraverseCraft" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Let's import Grid World and Grid Agent\n", + "we will import the `CreateGridWorld` class from the `world` module and `GridAgent` class from the `agent` module.\n", + "\n", + "It is very important to call the right agent for the given world, otherwise the module will through an error. \n", + "Each world behave differently and each agent is tailored for that world only." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "OS Type: Linux\n" + ] + } + ], + "source": [ + "from traverseCraft.world import CreateGridWorld\n", + "from traverseCraft.agent import GridAgent" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Hello Grid World\n", + "Let's start with a simple *Hello Grid World* program to get familiarize with the library.\n", + "\n", + "We will create a simple grid world of dimension (8 x 8) with the default settings on." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "# First let's Create a grid world object!\n", + "gridWorld = CreateGridWorld(worldName=\"Hello World\", rows=8, cols=8)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Compile our Hello Grid World\n", + "since, we are just creating a simple grid world with all the default settings, we are ready to compile our world.\n", + "\n", + "> **Note:** *It is recommended to do all the changes in the world before compiling the world. Although you can change the world even after the compilation but then the world will take time to update the changes as it will have more process to run now.*" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "gridWorld.constructWorld()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "> *Don't worry if the window showed up or if you are unable to cut the window. This is due to the fact that the cell in jupyter notebook is running the process.*\n", + "\n", + "### Let's see some basic information about our *Hello World*!\n", + "you can use a simple `print()` statement or you can use the builtin function `aboutWorld()` to get the world information as a string." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-------------------------+-------------+\n", + "| Attribute | Value |\n", + "+-------------------------+-------------+\n", + "| World Name | Hello World |\n", + "| Rows | 8 |\n", + "| Columns | 8 |\n", + "| Cell Size | 10 |\n", + "| Cell Padding | 2 |\n", + "| Window Size | 164x200 |\n", + "| Path Color | gray |\n", + "| Block Color | red |\n", + "| Goal Color | green |\n", + "| Border Width | 1 |\n", + "| Button Background Color | #7FC7D9 |\n", + "| Button Foreground Color | #332941 |\n", + "| Button Text | Start Agent |\n", + "| Text Font | Helvetica |\n", + "| Text Size | 24 |\n", + "| Text Weight | bold |\n", + "+-------------------------+-------------+\n" + ] + } + ], + "source": [ + "print(gridWorld)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-------------------------+-------------+\n", + "| Attribute | Value |\n", + "+-------------------------+-------------+\n", + "| World Name | Hello World |\n", + "| Rows | 8 |\n", + "| Columns | 8 |\n", + "| Cell Size | 10 |\n", + "| Cell Padding | 2 |\n", + "| Window Size | 164x200 |\n", + "| Path Color | gray |\n", + "| Block Color | red |\n", + "| Goal Color | green |\n", + "| Border Width | 1 |\n", + "| Button Background Color | #7FC7D9 |\n", + "| Button Foreground Color | #332941 |\n", + "| Button Text | Start Agent |\n", + "| Text Font | Helvetica |\n", + "| Text Size | 24 |\n", + "| Text Weight | bold |\n", + "+-------------------------+-------------+\n" + ] + } + ], + "source": [ + "print(gridWorld.aboutWorld())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Help\n", + "If you want to know more information about any method, or variable, you can simple use the `help()` function to get more information. Or you can visit our official [website]() to get more information." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on CreateGridWorld in module traverseCraft.world object:\n", + "\n", + "class CreateGridWorld(builtins.object)\n", + " | CreateGridWorld(worldName: str, rows: int, cols: int, cellSize: int = 10, pathColor: str = 'gray', blockColor: str = 'red', goalColor: str = 'green', cellPadding: int = 2, borderWidth: int = 1, buttonBgColor: str = '#7FC7D9', buttonFgColor: str = '#332941', textFont: str = 'Helvetica', textSize: int = 24, textWeight: str = 'bold', buttonText: str = 'Start Agent', logoPath: str = None)\n", + " | \n", + " | Class representing the world created using Grids.\n", + " | \n", + " | Attributes:\n", + " | setOfCoordinates (List[List[int]]): A list of coordinates.\n", + " | coordinate (List[int]): A list representing a coordinate.\n", + " | worldID (str): The ID of the world.\n", + " | \n", + " | Args:\n", + " | _worldName (str): The name of the world.\n", + " | _rows (int): The number of rows in the world. (Between 0 and 50)\n", + " | _cols (int): The number of columns in the world. (Between 0 and 50)\n", + " | _logoPath (str): The path to the logo image.\n", + " | _world (List[List[int]]): A 2D list representing the world.\n", + " | _blockCells (setOfCoordinates): A set of coordinates representing the block cells.\n", + " | _cellSize (int): The size of each cell in pixels.Defaults to 10. (Between 10 and 60)\n", + " | _pathColor (str): The color of the path cells. Defaults to \"gray\".\n", + " | _cellPadding (int): The padding around each cell in pixels. Defaults to 2.\n", + " | _blockColor (str): The color of the block cells. Defaults to \"red\".\n", + " | _borderWidth (int): The width of the cell borders in pixels. Defaults to 1.\n", + " | _goalColor (str): The color of the goal cells. Defaults to \"green\".\n", + " | _goalCells (setOfCoordinates): A set of coordinates representing the goal cells.\n", + " | _buttonBgColor (str): The background color of the button. Defaults to \"#7FC7D9\".\n", + " | _buttonFgColor (str): The foreground color of the button. Defaults to \"#332941\".\n", + " | _textFont (str): The font of the button text. Defaults to \"Helvetica\".\n", + " | _textSize (int): The size of the button text. Defaults to 24.\n", + " | _textWeight (str): The weight of the button text. Defaults to \"bold\".\n", + " | _buttonText (str): The text displayed on the button. Defaults to \"Start Agent\".\n", + " | _root (Tk): The root window of the world.\n", + " | _agent (Agent): The agent object.\n", + " | _logoPath (str): The path to the logo image.\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | __init__(self, worldName: str, rows: int, cols: int, cellSize: int = 10, pathColor: str = 'gray', blockColor: str = 'red', goalColor: str = 'green', cellPadding: int = 2, borderWidth: int = 1, buttonBgColor: str = '#7FC7D9', buttonFgColor: str = '#332941', textFont: str = 'Helvetica', textSize: int = 24, textWeight: str = 'bold', buttonText: str = 'Start Agent', logoPath: str = None)\n", + " | Initializes the Grid World.\n", + " | \n", + " | __str__(self)\n", + " | Describes the attributes of the world.\n", + " | \n", + " | Parameters:\n", + " | None\n", + " | \n", + " | Returns:\n", + " | function(): The attributes of the world.\n", + " | \n", + " | aboutWorld(self)\n", + " | Describes the attributes of the world.\n", + " | \n", + " | Parameters:\n", + " | None\n", + " | \n", + " | Returns:\n", + " | str: The attributes of the world.\n", + " | \n", + " | addBlockPath(self, blockCells: List[List[int]])\n", + " | Adds block cells to the world grid.\n", + " | \n", + " | Parameters:\n", + " | blockCells (setOfCoordinates): A set of coordinates representing the block cells.\n", + " | \n", + " | Returns:\n", + " | None\n", + " | \n", + " | addGoalState(self, goalState: List[List[int]])\n", + " | Adds the goal state to the world grid.\n", + " | \n", + " | Parameters:\n", + " | goalState (setOfCoordinates): A set of coordinates representing the goal state.\n", + " | \n", + " | Returns:\n", + " | None\n", + " | \n", + " | constructWorld(self)\n", + " | Constructs the world by creating and arranging cells in the GUI.\n", + " | If the goal cells are not set, it creates a goal cell at the bottom-right corner of the grid.\n", + " | It also creates cells for each row and column in the grid, and binds a left-click event to toggle the cells.\n", + " | Finally, it creates a \"Start Agent\" button at the bottom of the grid.\n", + " | \n", + " | Parameters:\n", + " | None\n", + " | \n", + " | Returns:\n", + " | None\n", + " | \n", + " | setAgent(self, agent)\n", + " | Set the agent for the world.\n", + " | \n", + " | Parameters:\n", + " | agent (Agent): The agent object to set.\n", + " | \n", + " | Returns:\n", + " | None\n", + " | \n", + " | showWorld(self)\n", + " | Displays the world.\n", + " | \n", + " | Parameters:\n", + " | None\n", + " | \n", + " | Returns:\n", + " | None\n", + " | \n", + " | summary(self)\n", + " | Generates a summary of the world.\n", + " | \n", + " | Parameters:\n", + " | None\n", + " | \n", + " | Returns:\n", + " | str: The summary of the world.\n", + " | \n", + " | updateWorld(self)\n", + " | Updates the world by positioning the cells in a grid layout and updating the root window.\n", + " | \n", + " | This method iterates over each cell in the world and positions it in a grid layout using the row and column indices.\n", + " | It also updates the root window to reflect any changes made to the world.\n", + " | \n", + " | Note:\n", + " | - The cells are positioned using the `grid` method with the specified row and column indices.\n", + " | - The `sticky` parameter is set to \"nsew\" to make the cells stick to all sides of their respective grid cells.\n", + " | - The `padx` and `pady` parameters specify the padding around each cell.\n", + " | \n", + " | Parameters:\n", + " | None\n", + " | Returns:\n", + " | None\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors defined here:\n", + " | \n", + " | __dict__\n", + " | dictionary for instance variables (if defined)\n", + " | \n", + " | __weakref__\n", + " | list of weak references to the object (if defined)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data and other attributes defined here:\n", + " | \n", + " | coordinate = typing.List[int]\n", + " | The central part of internal API.\n", + " | \n", + " | This represents a generic version of type 'origin' with type arguments 'params'.\n", + " | There are two kind of these aliases: user defined and special. The special ones\n", + " | are wrappers around builtin collections and ABCs in collections.abc. These must\n", + " | have 'name' always set. If 'inst' is False, then the alias can't be instantiated,\n", + " | this is used by e.g. typing.List and typing.Dict.\n", + " | \n", + " | setOfCoordinates = typing.List[typing.List[int]]\n", + " | The central part of internal API.\n", + " | \n", + " | This represents a generic version of type 'origin' with type arguments 'params'.\n", + " | There are two kind of these aliases: user defined and special. The special ones\n", + " | are wrappers around builtin collections and ABCs in collections.abc. These must\n", + " | have 'name' always set. If 'inst' is False, then the alias can't be instantiated,\n", + " | this is used by e.g. typing.List and typing.Dict.\n", + " | \n", + " | worldID = 'GRIDWORLD'\n", + "\n" + ] + } + ], + "source": [ + "help(gridWorld)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Let's create our agent which will interact with the world.\n", + "here also we will create a simple grid agent with the default settings." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "gridAgent = GridAgent(agentName=\"Grid Agent\", world=gridWorld)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Let's see some basic information about our `grid Agent`.\n", + "you can use a simple `print()` statement or you can use the builtin function `aboutAgent()` to get the agent information as a string." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+----------------+-------------+\n", + "| Attribute | Value |\n", + "+----------------+-------------+\n", + "| Agent Name | Grid Agent |\n", + "| Agent Color | blue |\n", + "| World Name | Hello World |\n", + "| World ID | GRIDWORLD |\n", + "| Start Position | (0, 0) |\n", + "+----------------+-------------+\n" + ] + } + ], + "source": [ + "print(gridAgent)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+----------------+-------------+\n", + "| Attribute | Value |\n", + "+----------------+-------------+\n", + "| Agent Name | Grid Agent |\n", + "| Agent Color | blue |\n", + "| World Name | Hello World |\n", + "| World ID | GRIDWORLD |\n", + "| Start Position | (0, 0) |\n", + "+----------------+-------------+\n" + ] + } + ], + "source": [ + "print(gridAgent.aboutAgent())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Connect Our Agent with the World\n", + "Now, we have our world ready and constructed and we also have our agent ready, but the world doesn't know the agent and the agent does't know the world. We have to connect the agent with the world. We will use the `.setAgent()` method of the world to connect the agent with the world. " + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "gridWorld.setAgent(gridAgent)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Algorithm\n", + "Now, we have connected the agent with the world, but we did not told the agent what to do in the world.\n", + "\n", + "The agent have a method `setAlgorithmCallBack()` which takes a function as a argument.\n", + "This function will be run during the simulation.\n", + "> *Note:* ***Make sure that the function you are passing in the `setAlgorithmCallBack()` method does not take any argument.***\n", + "\n", + "## Let's first create our function which will tell the agent what to do.\n", + "We will start from position (0,0), which is the start position of the agent by default and we will move the agent in the following manner:\n", + "\n", + "(0, 0) -> (0, 1) -> (0, 2) -> (0, 3) -> (0, 4) -> (1, 4) -> (1, 5) -> (2, 5) -> (3, 5) -> (3, 4) -> (3, 3) -> (2, 3) -> (1, 3) -> (0, 3) -> (0, 2) -> (0, 1) -> (0, 2) -> (1, 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "def whatToDo():\n", + " print(\"I am a Grid Agent and I am going to move around the world!\")\n", + " gridAgent.moveAgent(0, 1)\n", + " gridAgent.moveAgent(0, 2)\n", + " gridAgent.moveAgent(0, 3)\n", + " gridAgent.moveAgent(0, 4) \n", + " gridAgent.moveAgent(1, 4)\n", + " gridAgent.moveAgent(1, 5)\n", + " gridAgent.moveAgent(2, 5)\n", + " gridAgent.moveAgent(3, 5)\n", + " gridAgent.moveAgent(3, 4)\n", + " gridAgent.moveAgent(3, 3)\n", + " gridAgent.moveAgent(2, 3)\n", + " gridAgent.moveAgent(1, 3)\n", + " gridAgent.moveAgent(0, 3)\n", + " gridAgent.moveAgent(0, 2)\n", + " gridAgent.moveAgent(0, 1)\n", + " gridAgent.moveAgent(0, 2)\n", + " gridAgent.moveAgent(1, 2)\n", + " print(\"I am done moving around the world!\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### We are ready with our algorithm\n", + "Lets set the algorithm to tell the agent what to do. " + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "gridAgent.setAlgorithmCallBack(whatToDo)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Display the world and Start the Simulation!\n", + "Now, we are all set. We will first show the world using the `showWorld()` method and then on the world there is a button at the bottom to start the simulation.\n", + "> *Warning:* ***Always make sure that the method `showWorld()` is called when you are ready to simulate, because after this no change can be made on the world or the agent.***" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I am a Grid Agent and I am going to move around the world!\n", + "I am done moving around the world!\n" + ] + } + ], + "source": [ + "gridWorld.showWorld()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the window You can see the heatmap forming where the agent is going. This is the default function of the agent, but you can switch off this feature also by simple changing the value of `heatMapView` to `False` during the grid agent object creation.\n", + "\n", + "You can also see there is a slight delay in the movement of the agent, this is also a feature of agent, you can control the delay while calling the `moveAgent` method by the parameter `delay`.\n", + "\n", + "## Let's see the summary\n", + "\n", + "The agent and the world keep some records, that we can generate and see.\n", + "\n", + "### The Agent have information about the time taken to run the whole simulation.\n", + "We can see this information using the `summary` method." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+--------------+---------------------------+\n", + "| Attribute | Value |\n", + "+--------------+---------------------------+\n", + "| Start Time | Mon, 17 Jun 2024 17:25:04 |\n", + "| End Time | Mon, 17 Jun 2024 17:25:13 |\n", + "| Elapsed Time | 8.539 sec |\n", + "+--------------+---------------------------+\n" + ] + } + ], + "source": [ + "print(gridAgent.summary())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### The World have information about the visited count after the whole simulation.\n", + "We can see this information using the `summary` method." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+------+---+---+---+---+---+---+---+---+\n", + "| Cell | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n", + "+------+---+---+---+---+---+---+---+---+\n", + "| 0 | 1 | 2 | 3 | 2 | 1 | 0 | 0 | 0 |\n", + "| 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |\n", + "| 2 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |\n", + "| 3 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |\n", + "| 4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |\n", + "| 5 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |\n", + "| 6 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |\n", + "| 7 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |\n", + "+------+---+---+---+---+---+---+---+---+\n" + ] + } + ], + "source": [ + "print(gridWorld.summary())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Help\n", + "If you want to know more information about any method, or variable, you can simple use the `help()` function to get more information. Or you can visit our official [website]() to get more information." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on GridAgent in module traverseCraft.agent object:\n", + "\n", + "class GridAgent(builtins.object)\n", + " | GridAgent(world, agentName: str, agentColor: str = 'blue', heatMapView: bool = True, heatMapColor: str = '#FFA732', agentPos: tuple = (0, 0), heatGradient: float = 0.05)\n", + " | \n", + " | The Grid Agent class.\n", + " | \n", + " | Parameters:\n", + " | - world (CreateGridWorld): The grid world object in which the agent operates.\n", + " | - agentName (str): The name of the agent.\n", + " | - agentColor (str, optional): The color of the agent. Defaults to \"blue\".\n", + " | - heatMapView (bool, optional): Whether to enable the heat map view. Defaults to True.\n", + " | - heatMapColor (str, optional): The color of the heat map. Defaults to \"#FFA732\".\n", + " | - agentPos (tuple, optional): The initial position of the agent. Defaults to (0, 0).\n", + " | - heatGradient (float, optional): The gradient value for the heat map. Defaults to 0.05.\n", + " | \n", + " | Attributes:\n", + " | _worldObj (CreateGridWorld): The grid world object.\n", + " | _worldID (str): The ID of the world.\n", + " | _root (Tk): The root Tkinter object from the grid world.\n", + " | _agentName (str): The name of the agent.\n", + " | _agentColor (str): The color of the agent.\n", + " | _heatMapView (bool): Indicates if the heat map view is enabled.\n", + " | _heatMapColor (str): The color of the heat map.\n", + " | _heatMapBaseColor (str): The base color of the heat map.\n", + " | _heatGradient (float): The gradient value for the heat map.\n", + " | _startState (tuple): The initial position of the agent.\n", + " | _currentPosition (tuple): The current position of the agent.\n", + " | _startTime (float): The start time of the agent.\n", + " | _endTime (float): The end time of the agent.\n", + " | algorithmCallBack (function): Callback function for the agent's algorithm.\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | __init__(self, world, agentName: str, agentColor: str = 'blue', heatMapView: bool = True, heatMapColor: str = '#FFA732', agentPos: tuple = (0, 0), heatGradient: float = 0.05)\n", + " | Initialize self. See help(type(self)) for accurate signature.\n", + " | \n", + " | __str__(self)\n", + " | Describes the attributes of the world.\n", + " | \n", + " | Parameters:\n", + " | None\n", + " | \n", + " | Returns:\n", + " | function(): The attributes of the world.\n", + " | \n", + " | aboutAgent(self)\n", + " | Prints information about the agent.\n", + " | \n", + " | Parameters:\n", + " | None\n", + " | \n", + " | Returns:\n", + " | str: A string containing information about the agent.\n", + " | \n", + " | checkBlockState(self, i, j)\n", + " | Check the state of a block in the world.\n", + " | \n", + " | Parameters:\n", + " | i (int): The row index of the block.\n", + " | j (int): The column index of the block.\n", + " | \n", + " | Returns:\n", + " | bool: True if the block is empty (-1), False otherwise.\n", + " | \n", + " | checkGoalState(self, i, j)\n", + " | Check if the given position (i, j) is a goal state.\n", + " | \n", + " | Parameters:\n", + " | i (int): The row index of the position.\n", + " | j (int): The column index of the position.\n", + " | \n", + " | Returns:\n", + " | bool: True if the position is a goal state, False otherwise.\n", + " | \n", + " | getHeatMapColor(self, value: float)\n", + " | Maps a value to a color on a heat map.\n", + " | \n", + " | Args:\n", + " | value (float): The value to be mapped.\n", + " | \n", + " | Returns:\n", + " | tuple: The RGB color tuple representing the mapped value on the heat map.\n", + " | \n", + " | moveAgent(self, i, j, delay: float = 0.5)\n", + " | Moves the agent to the specified position (i, j) on the grid.\n", + " | \n", + " | Args:\n", + " | i (int): The row index of the target position.\n", + " | j (int): The column index of the target position.\n", + " | delay (int, optional): The delay in seconds before moving the agent. Defaults to 1.\n", + " | \n", + " | Returns:\n", + " | bool: True if the agent successfully moves to the target position, False otherwise.\n", + " | \n", + " | runAlgorithm(self)\n", + " | Executes the algorithm callback function.\n", + " | \n", + " | Raises:\n", + " | ValueError: If the algorithm callback function is not set.\n", + " | \n", + " | setAlgorithmCallBack(self, algorithmCallBack)\n", + " | Set the callback function for the algorithm.\n", + " | \n", + " | Parameters:\n", + " | algorithmCallBack (function): The callback function to be set.\n", + " | \n", + " | Returns:\n", + " | None\n", + " | \n", + " | setStartState(self, i: int, j: int)\n", + " | Sets the start state of the agent to the specified position (i, j).\n", + " | \n", + " | Args:\n", + " | i (int): The row index of the start position.\n", + " | j (int): The column index of the start position.\n", + " | \n", + " | Raises:\n", + " | ValueError: If the specified start position is invalid.\n", + " | \n", + " | summary(self)\n", + " | Returns a summary of the agent run.\n", + " | \n", + " | Parameters: \n", + " | None\n", + " | Returns:\n", + " | str: A summary of the agent run.\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors defined here:\n", + " | \n", + " | __dict__\n", + " | dictionary for instance variables (if defined)\n", + " | \n", + " | __weakref__\n", + " | list of weak references to the object (if defined)\n", + "\n" + ] + } + ], + "source": [ + "help(gridAgent)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This covers the basic of how to create a simple Grid World and Grid Agent. How to connect the created agent with the world and how to run a simple algorithm to simulate the agent on the world.\n", + "\n", + "Next, in the `Intermediate Section` we will learn about how to use advance features and settings to customize the world according to your need.\n", + "\n", + "Thanks!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.19" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}