Skip to content

Commit

Permalink
Merge branch 'release/1.2.35'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed Feb 16, 2022
2 parents 53557bc + 22ca80c commit b9b9b3b
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. mac/linux/windows]
- Version [e.g. 1.2.34]
- Version [e.g. 1.2.35]

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10.0)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")
project(Griddly VERSION 1.2.34)
project(Griddly VERSION 1.2.35)

set(BINARY ${CMAKE_PROJECT_NAME})

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ The most awesome part of Griddly is the ability to easily customize and build yo
* Configure interactions between objects based on their distance.
* [Projectiles](https://griddly.readthedocs.io/en/latest/tutorials/Projectiles/index.html)
* Objects that move under their own power.
* [Level Design](https://griddly.readthedocs.io/en/latest/tutorials/Level Design/index.html)
* [Level Design](https://griddly.readthedocs.io/en/latest/tutorials/Level%20Design/index.html)
* How to design levels for single and multi-agent environments.
* [Stochasticity](https://griddly.readthedocs.io/en/latest/tutorials/Stochasticity/index.html)
* How to make environments with stochastic mechanics.
* [A* Search](https://griddly.readthedocs.io/en/latest/tutorials/AStarSearch/index.html)
* Use A* pathfinding for mobs in Griddly


## [Custom Shaders](https://griddly.readthedocs.io/en/latest/tutorials/Custom%20Shaders/index.html)
Expand Down
1 change: 0 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install vulkan-sdk vulkan-headers
vulkaninfo
displayName: Installing Vulkan
- task: CMake@1
inputs:
Expand Down
2 changes: 1 addition & 1 deletion bindings/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace griddly {

PYBIND11_MODULE(python_griddly, m) {
m.doc() = "Griddly python bindings";
m.attr("version") = "1.2.34";
m.attr("version") = "1.2.35";

#ifndef NDEBUG
spdlog::set_level(spdlog::level::debug);
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Chris Bamford'

# The full version, including alpha/beta/rc tags
release = '1.2.34'
release = '1.2.35'


# -- General configuration ---------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Griddly documentation.
tutorials/Projectiles/index
tutorials/Stochasticity/index
tutorials/Level Design/index
tutorials/AStarSearch/index

.. toctree::
:maxdepth: 10
Expand Down
130 changes: 130 additions & 0 deletions docs/tutorials/AStarSearch/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
.. _doc_a_star_search:

##########
A* Search
##########

In this tutorial we will learn how to give objects in the environment a small amount of intelligence by allowing them to use the A-Star Search algorithm to do pathfinding.

.. raw:: html

<div class="figure align-center" id="vid1">
<video onloadeddata="this.play();" playsinline loop muted height="10%">

<source src="../../_static/video/tutorials/astar/global_video_test.mp4"
type="video/mp4">

Sorry, your browser doesn't support embedded videos.
</video>
<p class="caption"><span class="caption-text"></span><a class="headerlink" href="#vid1">¶</a></p>
</div>

We build a simple environment where the agent must find a goal state while being chased by a gross spider. We build two versions of this environment where the ``spider`` has different movement characteristics.

In the first environment the ``spider`` can only move up, down left and right. In the second environment the ``spider`` can only rotate left and right and move forwards.


*************************
Defining Spider Movement
*************************

Firstly we need to define how the ``spider`` moves. In the example where we just want the ``spider`` to be able to move UP, DOWN, LEFT and RIGHT, we can just define a default ``chase`` action:


.. code:: yaml
- Name: chase
InputMapping:
Internal: true
This action will have the default action mapping of UP, DOWN, LEFT and RIGHT. Also note that this action has ``Internal: true`` so that this action cannot be performed by any controlling agents.

Alternatively for the environment where we want our ``spider`` to rotate left and right, and only move in the direction that it is travelling you can do the following:

.. code:: yaml
- Name: chase
InputMapping:
Inputs:
1:
Description: Rotate left
OrientationVector: [ -1, 0 ]
2:
Description: Move forwards
OrientationVector: [ 0, -1 ]
VectorToDest: [ 0, -1 ]
3:
Description: Rotate right
OrientationVector: [ 1, 0 ]
Relative: true
Internal: true
.. seealso:: You can find much more information about action spaces :ref:`here <doc_action_spaces>`

****************************
Using the ``Search`` option
****************************

The goal of out environment is to make the ``spider`` object find a path from its current location to a particular destination using the mocements we defined in ``chase``.
In GDY this is super simple to do and is the same for both of the cases above. You just need to tell the Griddly engine which actions it can use and which objects are `impassable`.

We can do that by using the ``Search`` option in an ``exec`` command.


.. code:: yaml
- exec:
Action: chase
Delay: 10
Search:
ImpassableObjects: [ wall ]
TargetObjectName: catcher
In the Griddly engine, this uses the A* search algorithm to find the best ``actionId`` (in this case which direction) to get the ``spider`` closer to the ``catcher`` object.
In this case the ``catcher`` object is the name of the avatar we control. We also tell the A* algorithm that you cannot move through ``wall`` objects.

Now all we need to do is make sure the ``exec`` command is called when the ``spider`` moves. We can do that by adding to the ``Behaviours`` of the ``chase`` action:


.. code:: yaml
- Name: chase
...
Behaviours:
- Src:
Object: spider
Commands:
- mov: _dest
- exec:
Action: chase
Delay: 10
Search:
ImpassableObjects: [ wall ]
TargetObjectName: catcher
Dst:
Object: _empty
# We only need this Behaviour if we are using the rotating version of the chase action
- Src:
Object: spider
Commands:
- rot: _dir
- exec:
Action: chase
Delay: 0
Search:
ImpassableObjects: [ wall ]
TargetObjectName: catcher
Dst:
Object: spider
What we are doing here is telling telling the Griddly engine to execute another search operation every time the ``spider`` moves, (or rotates).
We also only execute the ``chase`` action after a small delay of 10 if the spider actually moves to a new location. If the spider just rotates on the spot, we immediately execute another ``chase`` action so it moves as well as rotates.

*******************
Full Code Example
*******************

`Full code examples can be found here! <https://github.com/Bam4d/Griddly/tree/develop/python/examples/AStar%20Search>`_


11 changes: 9 additions & 2 deletions python/examples/AStar Search/astar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@
current_path = os.path.dirname(os.path.realpath(__file__))

# Uncommment to see normal actions (not rotated) being used

# env = GymWrapper('astar_opponent_environment.yaml',
# player_observer_type=gd.ObserverType.VECTOR,
# global_observer_type=gd.ObserverType.SPRITE_2D,
# level=0)

# env = GymWrapper('astar_opponent_rotation_actions_environment.yaml',
# player_observer_type=gd.ObserverType.VECTOR,
# global_observer_type=gd.ObserverType.SPRITE_2D,
# level=0)

# Uncommment to see multiple spiders chasing!
env = GymWrapper('astar_opponent_rotation_actions_environment.yaml',
player_observer_type=gd.ObserverType.VECTOR,
global_observer_type=gd.ObserverType.SPRITE_2D,
level=0)
level=1)

env.reset()

Expand All @@ -39,4 +46,4 @@
if done:
env.reset()

global_recorder.close()
global_recorder.close()
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ Environment:
W . . . . . . . . . . W . . W
W c . . . . . . . . . W . s W
W W W W W W W W W W W W W W W
- |
W W W W W W W W W W W W W W W
W . . . . . . . . . . . . . W
W . . . . . . W W W . W . . W
W . . . W W W W . . . W . . W
W s . W . . . . . . . W . . W
W . . W . . s W . . . W . . W
W . . W . W W W . . . W . . W
W . . W . . . W . . . W . . W
W . . W W . . W . . . W . . W
W g . W . . . W W W W W . . W
W W W W . W W . . . . W . . W
W . . . . . . . . . . W . . W
W . . . . . . . . . . W . . W
W c . . . . . . . . . W . s W
W W W W W W W W W W W W W W W
Actions:

Expand Down
Binary file removed python/examples/AStar Search/output.gif
Binary file not shown.
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def griddly_package_data(config='Debug'):

setup(
name='griddly',
version="1.2.34",
version="1.2.35",
author_email="[email protected]",
description="Griddly Python Libraries",
long_description=long_description,
Expand Down
7 changes: 5 additions & 2 deletions src/Griddly/Core/AStarPathFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ SearchOutput AStarPathFinder::search(glm::ivec2 startLocation, glm::ivec2 endLoc
startNode->scoreToGoal = 0;
orderedBestNodes.push(startNode);

uint32_t steps = 0;

while (!orderedBestNodes.empty()) {
auto currentBestNode = orderedBestNodes.top();

orderedBestNodes.pop();

spdlog::debug("Current best node at location: [{0},{1}]. score: {2}, action: {3}", currentBestNode->location.x, currentBestNode->location.y, currentBestNode->scoreFromStart, currentBestNode->actionId);

if (currentBestNode->location == endLocation) {
if (currentBestNode->location == endLocation || steps >= maxDepth) {
return reconstructPath(currentBestNode);
}

Expand Down Expand Up @@ -95,7 +97,8 @@ SearchOutput AStarPathFinder::search(glm::ivec2 startLocation, glm::ivec2 endLoc
neighbourNode->scoreToGoal = nextScoreToGoal;
neighbourNode->scoreFromStart = nextScoreToGoal + glm::distance(static_cast<glm::vec2>(endLocation), static_cast<glm::vec2>(nextLocation));

spdlog::debug("New scores for location: [{0},{1}], scoreToGoal: {2}, scoreFromStart: {3}, action: {4}", nextLocation.x, nextLocation.y, neighbourNode->scoreToGoal, neighbourNode->scoreFromStart, actionId);
steps++;
spdlog::debug("New scores for location: [{0},{1}], scoreToGoal: {2}, scoreFromStart: {3}, action: {4}. Steps: {5}", nextLocation.x, nextLocation.y, neighbourNode->scoreToGoal, neighbourNode->scoreFromStart, actionId, steps);
orderedBestNodes.push(neighbourNode);
}
}
Expand Down

0 comments on commit b9b9b3b

Please sign in to comment.