├── .gitignore ├── LICENSE ├── README.md ├── docs ├── Makefile ├── _build │ ├── doctrees │ │ ├── blended.doctree │ │ ├── environment.pickle │ │ ├── example_game.doctree │ │ ├── gameobject.doctree │ │ ├── guide.doctree │ │ ├── index.doctree │ │ ├── kinematic.doctree │ │ ├── path.doctree │ │ ├── priority.doctree │ │ └── static.doctree │ └── html │ │ ├── .buildinfo │ │ ├── _modules │ │ ├── gameobject.html │ │ ├── index.html │ │ └── steering │ │ │ ├── blended.html │ │ │ ├── kinematic.html │ │ │ ├── path.html │ │ │ ├── priority.html │ │ │ └── static.html │ │ ├── _sources │ │ ├── blended.rst.txt │ │ ├── example_game.rst.txt │ │ ├── gameobject.rst.txt │ │ ├── guide.rst.txt │ │ ├── index.rst.txt │ │ ├── kinematic.rst.txt │ │ ├── path.rst.txt │ │ ├── priority.rst.txt │ │ └── static.rst.txt │ │ ├── _static │ │ ├── alabaster.css │ │ ├── basic.css │ │ ├── custom.css │ │ ├── doctools.js │ │ ├── documentation_options.js │ │ ├── file.png │ │ ├── jquery-3.2.1.js │ │ ├── jquery.js │ │ ├── language_data.js │ │ ├── minus.png │ │ ├── plus.png │ │ ├── pygments.css │ │ ├── searchtools.js │ │ ├── underscore-1.3.1.js │ │ └── underscore.js │ │ ├── blended.html │ │ ├── example_game.html │ │ ├── gameobject.html │ │ ├── genindex.html │ │ ├── guide.html │ │ ├── index.html │ │ ├── kinematic.html │ │ ├── objects.inv │ │ ├── path.html │ │ ├── priority.html │ │ ├── py-modindex.html │ │ ├── search.html │ │ ├── searchindex.js │ │ └── static.html ├── blended.rst ├── conf.py ├── example_game.rst ├── gameobject.rst ├── guide.rst ├── index.rst ├── kinematic.rst ├── make.bat ├── path.rst ├── priority.rst └── static.rst ├── pygame_ai ├── __init__.py ├── colors.py ├── gameobject.py ├── steering │ ├── __init__.py │ ├── blended.py │ ├── kinematic.py │ ├── path.py │ ├── priority.py │ └── static.py ├── tests │ ├── __init__.py │ └── test_joke.py └── utils │ ├── __init__.py │ ├── list_utils.py │ └── math_utils.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled python modules. 2 | *.pyc 3 | 4 | # Setuptools distribution folder. 5 | /dist/ 6 | 7 | # Python egg metadata, regenerated from source files by setuptools. 8 | /*.egg-info 9 | 10 | # Python cache 11 | __pycache__/ 12 | 13 | # Built 14 | build/ 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PyGame AI 2 | ========= 3 | 4 | PyGame AI is a package built on PyGame that aims at implementing a bunch of common algorithms and techniques often used in Videogame AI. It is still a work in progress. 5 | 6 | You can install it with pip: 7 | 8 | pip install pygame-ai 9 | 10 | And import it by doing: 11 | 12 | import pygame_ai 13 | 14 | or 15 | 16 | import pygame_ai as pai 17 | 18 | Please [Read The Docs](https://pygame-ai.readthedocs.io/) to learn all about the library. You can download an [Example Game](https://pygame-ai.readthedocs.io/en/latest/example_game.html) to see what the library can do and follow the [Pygame AI Guide](https://pygame-ai.readthedocs.io/en/latest/guide.html) to learn how to use it. 19 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help 23 | help: 24 | @echo "Please use \`make ' where is one of" 25 | @echo " html to make standalone HTML files" 26 | @echo " dirhtml to make HTML files named index.html in directories" 27 | @echo " singlehtml to make a single large HTML file" 28 | @echo " pickle to make pickle files" 29 | @echo " json to make JSON files" 30 | @echo " htmlhelp to make HTML files and a HTML help project" 31 | @echo " qthelp to make HTML files and a qthelp project" 32 | @echo " applehelp to make an Apple Help Book" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | @echo " coverage to run coverage check of the documentation (if enabled)" 49 | 50 | .PHONY: clean 51 | clean: 52 | rm -rf $(BUILDDIR)/* 53 | 54 | .PHONY: html 55 | html: 56 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 57 | @echo 58 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 59 | 60 | .PHONY: dirhtml 61 | dirhtml: 62 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 63 | @echo 64 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 65 | 66 | .PHONY: singlehtml 67 | singlehtml: 68 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 69 | @echo 70 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 71 | 72 | .PHONY: pickle 73 | pickle: 74 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 75 | @echo 76 | @echo "Build finished; now you can process the pickle files." 77 | 78 | .PHONY: json 79 | json: 80 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 81 | @echo 82 | @echo "Build finished; now you can process the JSON files." 83 | 84 | .PHONY: htmlhelp 85 | htmlhelp: 86 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 87 | @echo 88 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 89 | ".hhp project file in $(BUILDDIR)/htmlhelp." 90 | 91 | .PHONY: qthelp 92 | qthelp: 93 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 94 | @echo 95 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 96 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 97 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PygameAI.qhcp" 98 | @echo "To view the help file:" 99 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PygameAI.qhc" 100 | 101 | .PHONY: applehelp 102 | applehelp: 103 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp 104 | @echo 105 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." 106 | @echo "N.B. You won't be able to view it unless you put it in" \ 107 | "~/Library/Documentation/Help or install it in your application" \ 108 | "bundle." 109 | 110 | .PHONY: devhelp 111 | devhelp: 112 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 113 | @echo 114 | @echo "Build finished." 115 | @echo "To view the help file:" 116 | @echo "# mkdir -p $$HOME/.local/share/devhelp/PygameAI" 117 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/PygameAI" 118 | @echo "# devhelp" 119 | 120 | .PHONY: epub 121 | epub: 122 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 123 | @echo 124 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 125 | 126 | .PHONY: latex 127 | latex: 128 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 129 | @echo 130 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 131 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 132 | "(use \`make latexpdf' here to do that automatically)." 133 | 134 | .PHONY: latexpdf 135 | latexpdf: 136 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 137 | @echo "Running LaTeX files through pdflatex..." 138 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 139 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 140 | 141 | .PHONY: latexpdfja 142 | latexpdfja: 143 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 144 | @echo "Running LaTeX files through platex and dvipdfmx..." 145 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 146 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 147 | 148 | .PHONY: text 149 | text: 150 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 151 | @echo 152 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 153 | 154 | .PHONY: man 155 | man: 156 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 157 | @echo 158 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 159 | 160 | .PHONY: texinfo 161 | texinfo: 162 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 163 | @echo 164 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 165 | @echo "Run \`make' in that directory to run these through makeinfo" \ 166 | "(use \`make info' here to do that automatically)." 167 | 168 | .PHONY: info 169 | info: 170 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 171 | @echo "Running Texinfo files through makeinfo..." 172 | make -C $(BUILDDIR)/texinfo info 173 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 174 | 175 | .PHONY: gettext 176 | gettext: 177 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 178 | @echo 179 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 180 | 181 | .PHONY: changes 182 | changes: 183 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 184 | @echo 185 | @echo "The overview file is in $(BUILDDIR)/changes." 186 | 187 | .PHONY: linkcheck 188 | linkcheck: 189 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 190 | @echo 191 | @echo "Link check complete; look for any errors in the above output " \ 192 | "or in $(BUILDDIR)/linkcheck/output.txt." 193 | 194 | .PHONY: doctest 195 | doctest: 196 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 197 | @echo "Testing of doctests in the sources finished, look at the " \ 198 | "results in $(BUILDDIR)/doctest/output.txt." 199 | 200 | .PHONY: coverage 201 | coverage: 202 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage 203 | @echo "Testing of coverage in the sources finished, look at the " \ 204 | "results in $(BUILDDIR)/coverage/python.txt." 205 | 206 | .PHONY: xml 207 | xml: 208 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 209 | @echo 210 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 211 | 212 | .PHONY: pseudoxml 213 | pseudoxml: 214 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 215 | @echo 216 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 217 | -------------------------------------------------------------------------------- /docs/_build/doctrees/blended.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/doctrees/blended.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/_build/doctrees/example_game.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/doctrees/example_game.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/gameobject.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/doctrees/gameobject.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/guide.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/doctrees/guide.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/doctrees/index.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/kinematic.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/doctrees/kinematic.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/path.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/doctrees/path.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/priority.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/doctrees/priority.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/static.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/doctrees/static.doctree -------------------------------------------------------------------------------- /docs/_build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: b9af61c3979aaeeadc2cc595e19029b4 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/_build/html/_modules/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Overview: module code — Pygame AI 0.1 documentation 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
29 | 30 | 31 |
32 | 33 |

All modules for which code is available

34 | 41 | 42 |
43 | 44 |
45 |
46 | 96 |
97 |
98 | 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /docs/_build/html/_modules/steering/priority.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | steering.priority — Pygame AI 0.1 documentation 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
29 | 30 | 31 |
32 | 33 |

Source code for steering.priority

 34 | # -*- coding: utf-8 -*-
 35 | """ Priority Steering Behaviors
 36 | 
 37 | This module implements a class that holds a list of
 38 | :py:class:`~.kinematic.KinematicSteeringBehavior`\ s and applies them in order,
 39 | keeping only the first one that produces an output greater than a certain
 40 | treshold. This means that some behaviors which are considered more important
 41 | (like :py:class:`~.kinematic.ObstacleAvoidance` and 
 42 | :py:class:`~.kinematic.CollisionAvoidance`) but are not always neccesary 
 43 | to reach the character's goal can be ignored when they don't produce a 
 44 | meaningful output, it also means that when they do produce a meaningful 
 45 | output they will be the only ones in action.
 46 | 
 47 | This is a very simple form of decision making that involves only steering
 48 | algorithms, and therefore it is classified as a steering behavior.
 49 | 
 50 | Derives from :py:class:`~.kinematic.KinematicSteeringBehavior`.
 51 | 
 52 | 
 53 | Example
 54 | --------
 55 | 
 56 | This is how you would normally create your own :py:class:`~PrioritySteering`\ ,
 57 | in this case we are making a behavior that will most of the time **Pursue**
 58 | a target, but will prioritize **Avoiding Obstacles** when that behavior
 59 | returns a steering greater than the treshold.
 60 | 
 61 | .. code-block:: python
 62 | 
 63 |     mybehavior = PrioritySteering(
 64 |         behaviors = [
 65 |             kinematic.ObstacleAvoidance(character, obstacles),
 66 |             kinematic.Pursue(character, target),
 67 |         ],
 68 |     )
 69 | 
 70 | """
 71 | 
 72 | from . import kinematic
 73 | from . import blended
 74 | from . import path
 75 | 
 76 | 
 77 | 
[docs]class PrioritySteering(kinematic.KinematicSteeringBehavior): 78 | 79 | def __init__(self, behaviors, epsilon = 0.1): 80 | self.behaviors = behaviors 81 | self.epsilon = epsilon 82 | 83 | def __repr__(self): 84 | return 'PrioritySteering '+super(PrioritySteering, self).__repr__() 85 | 86 |
[docs] def draw_indicators(self, screen, offset = (lambda pos: pos)): 87 | for behavior in self.behaviors: 88 | behavior.draw_indicators(screen, offset)
89 | 90 |
[docs] def get_steering(self): 91 | 92 | for behavior in self.behaviors: 93 | # Get behavior's steering 94 | steering = behavior.get_steering() 95 | 96 | # If any of it's components surpases the treshold, return it 97 | if steering.linear.length() > self.epsilon or abs(steering.angular) > self.epsilon: 98 | return steering 99 | 100 | # If we get here, no output surpased the treshold 101 | # Return the last group's steering as small as it is 102 | return steering
103 | 104 | class OscilateHorizontally(PrioritySteering): 105 | 106 | def __init__(self, character, target, solid_entities, width = 160, height = 80, start_x = 0): 107 | 108 | def mypath(self, i): 109 | x, y = self.center() 110 | a = [(x - width//2, y - height), (x, y - height), (x + width//2, y - height)] 111 | return a[i] 112 | 113 | hpath = path.MirroredPath(mypath, domain_end = 2) 114 | hpath.center = lambda: target.position 115 | hpath.x = start_x 116 | behaviors = [ 117 | kinematic.CollisionAvoidance(character, solid_entities), 118 | kinematic.FollowPath(character, hpath), 119 | ] 120 | super(OscilateHorizontally, self).__init__(behaviors, epsilon = 10) 121 | 122 |
123 | 124 |
125 | 126 |
127 |
128 | 180 |
181 |
182 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/blended.rst.txt: -------------------------------------------------------------------------------- 1 | Blended 2 | ===================================== 3 | 4 | .. automodule:: steering.blended 5 | 6 | BehaviorAndWeight 7 | ----------------- 8 | 9 | .. autoclass:: BehaviorAndWeight 10 | :members: 11 | 12 | 13 | BlendedSteering 14 | --------------- 15 | 16 | .. autoclass:: BlendedSteering 17 | :members: 18 | 19 | .. autoclass:: Arrive 20 | 21 | .. autoclass:: Flocking 22 | 23 | .. autoclass:: Wander 24 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/example_game.rst.txt: -------------------------------------------------------------------------------- 1 | .. _example_game: 2 | 3 | Example Game 4 | ============ 5 | 6 | This game shows examples of what things can be done with the library, 7 | to run it just unzip and run main.py while having **pygame** and **pygame_ai** 8 | installed. 9 | 10 | * `Download Example Game `_ 11 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/gameobject.rst.txt: -------------------------------------------------------------------------------- 1 | Game Object 2 | ===================================== 3 | 4 | .. automodule:: gameobject 5 | :members: 6 | :exclude-members: GameObject 7 | 8 | .. autoclass:: GameObject 9 | :members: 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | Welcome to Pygame AI's Documentation! 2 | ===================================== 3 | 4 | Pygame AI is a package that aims at implementing a bunch of common 5 | algorithms and techniques often used in Videogame AI. It is still a work 6 | in progress. 7 | 8 | Installation 9 | ------------ 10 | 11 | The package is available at PyPI, you can simply do: 12 | 13 | pip install pygame-ai 14 | 15 | Usage 16 | ----- 17 | 18 | After installing it you only need to import like: 19 | 20 | import pygame_ai 21 | 22 | or 23 | 24 | import pygame_ai as pai 25 | 26 | Core 27 | ---- 28 | 29 | All of this library's implementations work using this implementation 30 | of :py:class:`~.GameObject`. 31 | 32 | You can see how the library works by downloading our :ref:`example_game`, or 33 | you can visit the :ref:`guide` to see how to implement a simple game 34 | using the library's core functions. 35 | 36 | So far these are the major techniquest that have been implemented: 37 | 38 | Steering Behaviors 39 | ------------------ 40 | 41 | Basic movement behaviors that make in-game characters move in a 42 | pseudo-intelligent way. You will mainly be using 43 | :py:class:`~.BlendedSteering` and :py:class:`~.PrioritySteering`, 44 | but feel free to use any of the behaviors found in 45 | :py:mod:`~steering.kinematic` and :py:mod:`~steering.static` modules. 46 | 47 | * :py:class:`~.StaticSteeringBehavior` 48 | * :py:class:`~.KinematicSteeringBehavior` 49 | * :py:class:`~.BlendedSteering` 50 | * :py:class:`~.PrioritySteering` 51 | 52 | Table of Contents 53 | ================= 54 | 55 | .. toctree:: 56 | :maxdepth: 1 57 | 58 | gameobject 59 | static 60 | kinematic 61 | blended 62 | priority 63 | path 64 | example_game 65 | guide 66 | 67 | Indices and tables 68 | ================== 69 | 70 | * :ref:`genindex` 71 | * :ref:`search` 72 | 73 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/kinematic.rst.txt: -------------------------------------------------------------------------------- 1 | Kinematic 2 | ===================================== 3 | 4 | .. automodule:: steering.kinematic 5 | 6 | SteeringOutput 7 | -------------- 8 | 9 | 10 | .. autoclass:: SteeringOutput 11 | :members: 12 | 13 | .. automethod:: steering.kinematic.negative_steering 14 | 15 | .. autodata:: null_steering 16 | :annotation: 17 | 18 | KinematicSteeringBehavior 19 | ------------------------- 20 | 21 | .. autoclass:: KinematicSteeringBehavior 22 | :members: 23 | 24 | .. autoclass:: Align 25 | 26 | .. autoclass:: Arrive 27 | 28 | .. autoclass:: CollisionAvoidance 29 | 30 | .. autoclass:: Drag 31 | 32 | .. autoclass:: Evade 33 | 34 | .. autoclass:: Face 35 | 36 | .. autoclass:: Flee 37 | 38 | .. autoclass:: FollowPath 39 | 40 | .. autoclass:: LookWhereYoureGoing 41 | 42 | .. autoclass:: NullSteering 43 | 44 | .. autoclass:: ObstacleAvoidance 45 | 46 | .. autoclass:: Pursue 47 | 48 | .. autoclass:: Seek 49 | 50 | .. autoclass:: Separation 51 | 52 | .. autoclass:: VelocityMatch 53 | 54 | .. autoclass:: Wander 55 | 56 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/path.rst.txt: -------------------------------------------------------------------------------- 1 | Path 2 | ==== 3 | 4 | .. automodule:: steering.path 5 | 6 | Path 7 | ---- 8 | 9 | .. autoclass:: Path 10 | :members: 11 | 12 | Special Paths 13 | ------------- 14 | 15 | .. autoclass:: CyclicPath 16 | :members: 17 | 18 | .. autoclass:: MirroredPath 19 | :members: 20 | 21 | Pre-implemented Paths 22 | --------------------- 23 | 24 | .. autoclass:: PathCircumference 25 | :members: 26 | 27 | .. autoclass:: PathParabola 28 | :members: 29 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/priority.rst.txt: -------------------------------------------------------------------------------- 1 | Priority 2 | ===================================== 3 | 4 | .. automodule:: steering.priority 5 | 6 | PrioritySteering 7 | ---------------- 8 | 9 | .. autoclass:: PrioritySteering 10 | :members: 11 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/static.rst.txt: -------------------------------------------------------------------------------- 1 | Static 2 | ===================================== 3 | 4 | .. automodule:: steering.static 5 | 6 | SteeringOutput 7 | -------------- 8 | 9 | .. autoclass:: SteeringOutput 10 | :members: 11 | 12 | .. autodata:: null_steering 13 | :annotation: 14 | 15 | StaticSteeringBehavior 16 | ------------------------- 17 | 18 | .. autoclass:: StaticSteeringBehavior 19 | :members: 20 | 21 | .. autoclass:: Arrive 22 | 23 | .. autoclass:: Flee 24 | 25 | .. autoclass:: Seek 26 | 27 | .. autoclass:: Wander 28 | 29 | -------------------------------------------------------------------------------- /docs/_build/html/_static/alabaster.css: -------------------------------------------------------------------------------- 1 | @import url("basic.css"); 2 | 3 | /* -- page layout ----------------------------------------------------------- */ 4 | 5 | body { 6 | font-family: Georgia, serif; 7 | font-size: 17px; 8 | background-color: #fff; 9 | color: #000; 10 | margin: 0; 11 | padding: 0; 12 | } 13 | 14 | 15 | div.document { 16 | width: 940px; 17 | margin: 30px auto 0 auto; 18 | } 19 | 20 | div.documentwrapper { 21 | float: left; 22 | width: 100%; 23 | } 24 | 25 | div.bodywrapper { 26 | margin: 0 0 0 220px; 27 | } 28 | 29 | div.sphinxsidebar { 30 | width: 220px; 31 | font-size: 14px; 32 | line-height: 1.5; 33 | } 34 | 35 | hr { 36 | border: 1px solid #B1B4B6; 37 | } 38 | 39 | div.body { 40 | background-color: #fff; 41 | color: #3E4349; 42 | padding: 0 30px 0 30px; 43 | } 44 | 45 | div.body > .section { 46 | text-align: left; 47 | } 48 | 49 | div.footer { 50 | width: 940px; 51 | margin: 20px auto 30px auto; 52 | font-size: 14px; 53 | color: #888; 54 | text-align: right; 55 | } 56 | 57 | div.footer a { 58 | color: #888; 59 | } 60 | 61 | p.caption { 62 | font-family: inherit; 63 | font-size: inherit; 64 | } 65 | 66 | 67 | div.relations { 68 | display: none; 69 | } 70 | 71 | 72 | div.sphinxsidebar a { 73 | color: #444; 74 | text-decoration: none; 75 | border-bottom: 1px dotted #999; 76 | } 77 | 78 | div.sphinxsidebar a:hover { 79 | border-bottom: 1px solid #999; 80 | } 81 | 82 | div.sphinxsidebarwrapper { 83 | padding: 18px 10px; 84 | } 85 | 86 | div.sphinxsidebarwrapper p.logo { 87 | padding: 0; 88 | margin: -10px 0 0 0px; 89 | text-align: center; 90 | } 91 | 92 | div.sphinxsidebarwrapper h1.logo { 93 | margin-top: -10px; 94 | text-align: center; 95 | margin-bottom: 5px; 96 | text-align: left; 97 | } 98 | 99 | div.sphinxsidebarwrapper h1.logo-name { 100 | margin-top: 0px; 101 | } 102 | 103 | div.sphinxsidebarwrapper p.blurb { 104 | margin-top: 0; 105 | font-style: normal; 106 | } 107 | 108 | div.sphinxsidebar h3, 109 | div.sphinxsidebar h4 { 110 | font-family: Georgia, serif; 111 | color: #444; 112 | font-size: 24px; 113 | font-weight: normal; 114 | margin: 0 0 5px 0; 115 | padding: 0; 116 | } 117 | 118 | div.sphinxsidebar h4 { 119 | font-size: 20px; 120 | } 121 | 122 | div.sphinxsidebar h3 a { 123 | color: #444; 124 | } 125 | 126 | div.sphinxsidebar p.logo a, 127 | div.sphinxsidebar h3 a, 128 | div.sphinxsidebar p.logo a:hover, 129 | div.sphinxsidebar h3 a:hover { 130 | border: none; 131 | } 132 | 133 | div.sphinxsidebar p { 134 | color: #555; 135 | margin: 10px 0; 136 | } 137 | 138 | div.sphinxsidebar ul { 139 | margin: 10px 0; 140 | padding: 0; 141 | color: #000; 142 | } 143 | 144 | div.sphinxsidebar ul li.toctree-l1 > a { 145 | font-size: 120%; 146 | } 147 | 148 | div.sphinxsidebar ul li.toctree-l2 > a { 149 | font-size: 110%; 150 | } 151 | 152 | div.sphinxsidebar input { 153 | border: 1px solid #CCC; 154 | font-family: Georgia, serif; 155 | font-size: 1em; 156 | } 157 | 158 | div.sphinxsidebar hr { 159 | border: none; 160 | height: 1px; 161 | color: #AAA; 162 | background: #AAA; 163 | 164 | text-align: left; 165 | margin-left: 0; 166 | width: 50%; 167 | } 168 | 169 | div.sphinxsidebar .badge { 170 | border-bottom: none; 171 | } 172 | 173 | div.sphinxsidebar .badge:hover { 174 | border-bottom: none; 175 | } 176 | 177 | /* To address an issue with donation coming after search */ 178 | div.sphinxsidebar h3.donation { 179 | margin-top: 10px; 180 | } 181 | 182 | /* -- body styles ----------------------------------------------------------- */ 183 | 184 | a { 185 | color: #004B6B; 186 | text-decoration: underline; 187 | } 188 | 189 | a:hover { 190 | color: #6D4100; 191 | text-decoration: underline; 192 | } 193 | 194 | div.body h1, 195 | div.body h2, 196 | div.body h3, 197 | div.body h4, 198 | div.body h5, 199 | div.body h6 { 200 | font-family: Georgia, serif; 201 | font-weight: normal; 202 | margin: 30px 0px 10px 0px; 203 | padding: 0; 204 | } 205 | 206 | div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; } 207 | div.body h2 { font-size: 180%; } 208 | div.body h3 { font-size: 150%; } 209 | div.body h4 { font-size: 130%; } 210 | div.body h5 { font-size: 100%; } 211 | div.body h6 { font-size: 100%; } 212 | 213 | a.headerlink { 214 | color: #DDD; 215 | padding: 0 4px; 216 | text-decoration: none; 217 | } 218 | 219 | a.headerlink:hover { 220 | color: #444; 221 | background: #EAEAEA; 222 | } 223 | 224 | div.body p, div.body dd, div.body li { 225 | line-height: 1.4em; 226 | } 227 | 228 | div.admonition { 229 | margin: 20px 0px; 230 | padding: 10px 30px; 231 | background-color: #EEE; 232 | border: 1px solid #CCC; 233 | } 234 | 235 | div.admonition tt.xref, div.admonition code.xref, div.admonition a tt { 236 | background-color: #FBFBFB; 237 | border-bottom: 1px solid #fafafa; 238 | } 239 | 240 | div.admonition p.admonition-title { 241 | font-family: Georgia, serif; 242 | font-weight: normal; 243 | font-size: 24px; 244 | margin: 0 0 10px 0; 245 | padding: 0; 246 | line-height: 1; 247 | } 248 | 249 | div.admonition p.last { 250 | margin-bottom: 0; 251 | } 252 | 253 | div.highlight { 254 | background-color: #fff; 255 | } 256 | 257 | dt:target, .highlight { 258 | background: #FAF3E8; 259 | } 260 | 261 | div.warning { 262 | background-color: #FCC; 263 | border: 1px solid #FAA; 264 | } 265 | 266 | div.danger { 267 | background-color: #FCC; 268 | border: 1px solid #FAA; 269 | -moz-box-shadow: 2px 2px 4px #D52C2C; 270 | -webkit-box-shadow: 2px 2px 4px #D52C2C; 271 | box-shadow: 2px 2px 4px #D52C2C; 272 | } 273 | 274 | div.error { 275 | background-color: #FCC; 276 | border: 1px solid #FAA; 277 | -moz-box-shadow: 2px 2px 4px #D52C2C; 278 | -webkit-box-shadow: 2px 2px 4px #D52C2C; 279 | box-shadow: 2px 2px 4px #D52C2C; 280 | } 281 | 282 | div.caution { 283 | background-color: #FCC; 284 | border: 1px solid #FAA; 285 | } 286 | 287 | div.attention { 288 | background-color: #FCC; 289 | border: 1px solid #FAA; 290 | } 291 | 292 | div.important { 293 | background-color: #EEE; 294 | border: 1px solid #CCC; 295 | } 296 | 297 | div.note { 298 | background-color: #EEE; 299 | border: 1px solid #CCC; 300 | } 301 | 302 | div.tip { 303 | background-color: #EEE; 304 | border: 1px solid #CCC; 305 | } 306 | 307 | div.hint { 308 | background-color: #EEE; 309 | border: 1px solid #CCC; 310 | } 311 | 312 | div.seealso { 313 | background-color: #EEE; 314 | border: 1px solid #CCC; 315 | } 316 | 317 | div.topic { 318 | background-color: #EEE; 319 | } 320 | 321 | p.admonition-title { 322 | display: inline; 323 | } 324 | 325 | p.admonition-title:after { 326 | content: ":"; 327 | } 328 | 329 | pre, tt, code { 330 | font-family: 'Consolas', 'Menlo', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; 331 | font-size: 0.9em; 332 | } 333 | 334 | .hll { 335 | background-color: #FFC; 336 | margin: 0 -12px; 337 | padding: 0 12px; 338 | display: block; 339 | } 340 | 341 | img.screenshot { 342 | } 343 | 344 | tt.descname, tt.descclassname, code.descname, code.descclassname { 345 | font-size: 0.95em; 346 | } 347 | 348 | tt.descname, code.descname { 349 | padding-right: 0.08em; 350 | } 351 | 352 | img.screenshot { 353 | -moz-box-shadow: 2px 2px 4px #EEE; 354 | -webkit-box-shadow: 2px 2px 4px #EEE; 355 | box-shadow: 2px 2px 4px #EEE; 356 | } 357 | 358 | table.docutils { 359 | border: 1px solid #888; 360 | -moz-box-shadow: 2px 2px 4px #EEE; 361 | -webkit-box-shadow: 2px 2px 4px #EEE; 362 | box-shadow: 2px 2px 4px #EEE; 363 | } 364 | 365 | table.docutils td, table.docutils th { 366 | border: 1px solid #888; 367 | padding: 0.25em 0.7em; 368 | } 369 | 370 | table.field-list, table.footnote { 371 | border: none; 372 | -moz-box-shadow: none; 373 | -webkit-box-shadow: none; 374 | box-shadow: none; 375 | } 376 | 377 | table.footnote { 378 | margin: 15px 0; 379 | width: 100%; 380 | border: 1px solid #EEE; 381 | background: #FDFDFD; 382 | font-size: 0.9em; 383 | } 384 | 385 | table.footnote + table.footnote { 386 | margin-top: -15px; 387 | border-top: none; 388 | } 389 | 390 | table.field-list th { 391 | padding: 0 0.8em 0 0; 392 | } 393 | 394 | table.field-list td { 395 | padding: 0; 396 | } 397 | 398 | table.field-list p { 399 | margin-bottom: 0.8em; 400 | } 401 | 402 | /* Cloned from 403 | * https://github.com/sphinx-doc/sphinx/commit/ef60dbfce09286b20b7385333d63a60321784e68 404 | */ 405 | .field-name { 406 | -moz-hyphens: manual; 407 | -ms-hyphens: manual; 408 | -webkit-hyphens: manual; 409 | hyphens: manual; 410 | } 411 | 412 | table.footnote td.label { 413 | width: .1px; 414 | padding: 0.3em 0 0.3em 0.5em; 415 | } 416 | 417 | table.footnote td { 418 | padding: 0.3em 0.5em; 419 | } 420 | 421 | dl { 422 | margin: 0; 423 | padding: 0; 424 | } 425 | 426 | dl dd { 427 | margin-left: 30px; 428 | } 429 | 430 | blockquote { 431 | margin: 0 0 0 30px; 432 | padding: 0; 433 | } 434 | 435 | ul, ol { 436 | /* Matches the 30px from the narrow-screen "li > ul" selector below */ 437 | margin: 10px 0 10px 30px; 438 | padding: 0; 439 | } 440 | 441 | pre { 442 | background: #EEE; 443 | padding: 7px 30px; 444 | margin: 15px 0px; 445 | line-height: 1.3em; 446 | } 447 | 448 | div.viewcode-block:target { 449 | background: #ffd; 450 | } 451 | 452 | dl pre, blockquote pre, li pre { 453 | margin-left: 0; 454 | padding-left: 30px; 455 | } 456 | 457 | tt, code { 458 | background-color: #ecf0f3; 459 | color: #222; 460 | /* padding: 1px 2px; */ 461 | } 462 | 463 | tt.xref, code.xref, a tt { 464 | background-color: #FBFBFB; 465 | border-bottom: 1px solid #fff; 466 | } 467 | 468 | a.reference { 469 | text-decoration: none; 470 | border-bottom: 1px dotted #004B6B; 471 | } 472 | 473 | /* Don't put an underline on images */ 474 | a.image-reference, a.image-reference:hover { 475 | border-bottom: none; 476 | } 477 | 478 | a.reference:hover { 479 | border-bottom: 1px solid #6D4100; 480 | } 481 | 482 | a.footnote-reference { 483 | text-decoration: none; 484 | font-size: 0.7em; 485 | vertical-align: top; 486 | border-bottom: 1px dotted #004B6B; 487 | } 488 | 489 | a.footnote-reference:hover { 490 | border-bottom: 1px solid #6D4100; 491 | } 492 | 493 | a:hover tt, a:hover code { 494 | background: #EEE; 495 | } 496 | 497 | 498 | @media screen and (max-width: 870px) { 499 | 500 | div.sphinxsidebar { 501 | display: none; 502 | } 503 | 504 | div.document { 505 | width: 100%; 506 | 507 | } 508 | 509 | div.documentwrapper { 510 | margin-left: 0; 511 | margin-top: 0; 512 | margin-right: 0; 513 | margin-bottom: 0; 514 | } 515 | 516 | div.bodywrapper { 517 | margin-top: 0; 518 | margin-right: 0; 519 | margin-bottom: 0; 520 | margin-left: 0; 521 | } 522 | 523 | ul { 524 | margin-left: 0; 525 | } 526 | 527 | li > ul { 528 | /* Matches the 30px from the "ul, ol" selector above */ 529 | margin-left: 30px; 530 | } 531 | 532 | .document { 533 | width: auto; 534 | } 535 | 536 | .footer { 537 | width: auto; 538 | } 539 | 540 | .bodywrapper { 541 | margin: 0; 542 | } 543 | 544 | .footer { 545 | width: auto; 546 | } 547 | 548 | .github { 549 | display: none; 550 | } 551 | 552 | 553 | 554 | } 555 | 556 | 557 | 558 | @media screen and (max-width: 875px) { 559 | 560 | body { 561 | margin: 0; 562 | padding: 20px 30px; 563 | } 564 | 565 | div.documentwrapper { 566 | float: none; 567 | background: #fff; 568 | } 569 | 570 | div.sphinxsidebar { 571 | display: block; 572 | float: none; 573 | width: 102.5%; 574 | margin: 50px -30px -20px -30px; 575 | padding: 10px 20px; 576 | background: #333; 577 | color: #FFF; 578 | } 579 | 580 | div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p, 581 | div.sphinxsidebar h3 a { 582 | color: #fff; 583 | } 584 | 585 | div.sphinxsidebar a { 586 | color: #AAA; 587 | } 588 | 589 | div.sphinxsidebar p.logo { 590 | display: none; 591 | } 592 | 593 | div.document { 594 | width: 100%; 595 | margin: 0; 596 | } 597 | 598 | div.footer { 599 | display: none; 600 | } 601 | 602 | div.bodywrapper { 603 | margin: 0; 604 | } 605 | 606 | div.body { 607 | min-height: 0; 608 | padding: 0; 609 | } 610 | 611 | .rtd_doc_footer { 612 | display: none; 613 | } 614 | 615 | .document { 616 | width: auto; 617 | } 618 | 619 | .footer { 620 | width: auto; 621 | } 622 | 623 | .footer { 624 | width: auto; 625 | } 626 | 627 | .github { 628 | display: none; 629 | } 630 | } 631 | 632 | 633 | /* misc. */ 634 | 635 | .revsys-inline { 636 | display: none!important; 637 | } 638 | 639 | /* Make nested-list/multi-paragraph items look better in Releases changelog 640 | * pages. Without this, docutils' magical list fuckery causes inconsistent 641 | * formatting between different release sub-lists. 642 | */ 643 | div#changelog > div.section > ul > li > p:only-child { 644 | margin-bottom: 0; 645 | } 646 | 647 | /* Hide fugly table cell borders in ..bibliography:: directive output */ 648 | table.docutils.citation, table.docutils.citation td, table.docutils.citation th { 649 | border: none; 650 | /* Below needed in some edge cases; if not applied, bottom shadows appear */ 651 | -moz-box-shadow: none; 652 | -webkit-box-shadow: none; 653 | box-shadow: none; 654 | } 655 | 656 | 657 | /* relbar */ 658 | 659 | .related { 660 | line-height: 30px; 661 | width: 100%; 662 | font-size: 0.9rem; 663 | } 664 | 665 | .related.top { 666 | border-bottom: 1px solid #EEE; 667 | margin-bottom: 20px; 668 | } 669 | 670 | .related.bottom { 671 | border-top: 1px solid #EEE; 672 | } 673 | 674 | .related ul { 675 | padding: 0; 676 | margin: 0; 677 | list-style: none; 678 | } 679 | 680 | .related li { 681 | display: inline; 682 | } 683 | 684 | nav#rellinks { 685 | float: right; 686 | } 687 | 688 | nav#rellinks li+li:before { 689 | content: "|"; 690 | } 691 | 692 | nav#breadcrumbs li+li:before { 693 | content: "\00BB"; 694 | } 695 | 696 | /* Hide certain items when printing */ 697 | @media print { 698 | div.related { 699 | display: none; 700 | } 701 | } -------------------------------------------------------------------------------- /docs/_build/html/_static/basic.css: -------------------------------------------------------------------------------- 1 | /* 2 | * basic.css 3 | * ~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- basic theme. 6 | * 7 | * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /* -- main layout ----------------------------------------------------------- */ 13 | 14 | div.clearer { 15 | clear: both; 16 | } 17 | 18 | /* -- relbar ---------------------------------------------------------------- */ 19 | 20 | div.related { 21 | width: 100%; 22 | font-size: 90%; 23 | } 24 | 25 | div.related h3 { 26 | display: none; 27 | } 28 | 29 | div.related ul { 30 | margin: 0; 31 | padding: 0 0 0 10px; 32 | list-style: none; 33 | } 34 | 35 | div.related li { 36 | display: inline; 37 | } 38 | 39 | div.related li.right { 40 | float: right; 41 | margin-right: 5px; 42 | } 43 | 44 | /* -- sidebar --------------------------------------------------------------- */ 45 | 46 | div.sphinxsidebarwrapper { 47 | padding: 10px 5px 0 10px; 48 | } 49 | 50 | div.sphinxsidebar { 51 | float: left; 52 | width: 230px; 53 | margin-left: -100%; 54 | font-size: 90%; 55 | word-wrap: break-word; 56 | overflow-wrap : break-word; 57 | } 58 | 59 | div.sphinxsidebar ul { 60 | list-style: none; 61 | } 62 | 63 | div.sphinxsidebar ul ul, 64 | div.sphinxsidebar ul.want-points { 65 | margin-left: 20px; 66 | list-style: square; 67 | } 68 | 69 | div.sphinxsidebar ul ul { 70 | margin-top: 0; 71 | margin-bottom: 0; 72 | } 73 | 74 | div.sphinxsidebar form { 75 | margin-top: 10px; 76 | } 77 | 78 | div.sphinxsidebar input { 79 | border: 1px solid #98dbcc; 80 | font-family: sans-serif; 81 | font-size: 1em; 82 | } 83 | 84 | div.sphinxsidebar #searchbox form.search { 85 | overflow: hidden; 86 | } 87 | 88 | div.sphinxsidebar #searchbox input[type="text"] { 89 | float: left; 90 | width: 80%; 91 | padding: 0.25em; 92 | box-sizing: border-box; 93 | } 94 | 95 | div.sphinxsidebar #searchbox input[type="submit"] { 96 | float: left; 97 | width: 20%; 98 | border-left: none; 99 | padding: 0.25em; 100 | box-sizing: border-box; 101 | } 102 | 103 | 104 | img { 105 | border: 0; 106 | max-width: 100%; 107 | } 108 | 109 | /* -- search page ----------------------------------------------------------- */ 110 | 111 | ul.search { 112 | margin: 10px 0 0 20px; 113 | padding: 0; 114 | } 115 | 116 | ul.search li { 117 | padding: 5px 0 5px 20px; 118 | background-image: url(file.png); 119 | background-repeat: no-repeat; 120 | background-position: 0 7px; 121 | } 122 | 123 | ul.search li a { 124 | font-weight: bold; 125 | } 126 | 127 | ul.search li div.context { 128 | color: #888; 129 | margin: 2px 0 0 30px; 130 | text-align: left; 131 | } 132 | 133 | ul.keywordmatches li.goodmatch a { 134 | font-weight: bold; 135 | } 136 | 137 | /* -- index page ------------------------------------------------------------ */ 138 | 139 | table.contentstable { 140 | width: 90%; 141 | margin-left: auto; 142 | margin-right: auto; 143 | } 144 | 145 | table.contentstable p.biglink { 146 | line-height: 150%; 147 | } 148 | 149 | a.biglink { 150 | font-size: 1.3em; 151 | } 152 | 153 | span.linkdescr { 154 | font-style: italic; 155 | padding-top: 5px; 156 | font-size: 90%; 157 | } 158 | 159 | /* -- general index --------------------------------------------------------- */ 160 | 161 | table.indextable { 162 | width: 100%; 163 | } 164 | 165 | table.indextable td { 166 | text-align: left; 167 | vertical-align: top; 168 | } 169 | 170 | table.indextable ul { 171 | margin-top: 0; 172 | margin-bottom: 0; 173 | list-style-type: none; 174 | } 175 | 176 | table.indextable > tbody > tr > td > ul { 177 | padding-left: 0em; 178 | } 179 | 180 | table.indextable tr.pcap { 181 | height: 10px; 182 | } 183 | 184 | table.indextable tr.cap { 185 | margin-top: 10px; 186 | background-color: #f2f2f2; 187 | } 188 | 189 | img.toggler { 190 | margin-right: 3px; 191 | margin-top: 3px; 192 | cursor: pointer; 193 | } 194 | 195 | div.modindex-jumpbox { 196 | border-top: 1px solid #ddd; 197 | border-bottom: 1px solid #ddd; 198 | margin: 1em 0 1em 0; 199 | padding: 0.4em; 200 | } 201 | 202 | div.genindex-jumpbox { 203 | border-top: 1px solid #ddd; 204 | border-bottom: 1px solid #ddd; 205 | margin: 1em 0 1em 0; 206 | padding: 0.4em; 207 | } 208 | 209 | /* -- domain module index --------------------------------------------------- */ 210 | 211 | table.modindextable td { 212 | padding: 2px; 213 | border-collapse: collapse; 214 | } 215 | 216 | /* -- general body styles --------------------------------------------------- */ 217 | 218 | div.body { 219 | min-width: 450px; 220 | max-width: 800px; 221 | } 222 | 223 | div.body p, div.body dd, div.body li, div.body blockquote { 224 | -moz-hyphens: auto; 225 | -ms-hyphens: auto; 226 | -webkit-hyphens: auto; 227 | hyphens: auto; 228 | } 229 | 230 | a.headerlink { 231 | visibility: hidden; 232 | } 233 | 234 | a.brackets:before, 235 | span.brackets > a:before{ 236 | content: "["; 237 | } 238 | 239 | a.brackets:after, 240 | span.brackets > a:after { 241 | content: "]"; 242 | } 243 | 244 | h1:hover > a.headerlink, 245 | h2:hover > a.headerlink, 246 | h3:hover > a.headerlink, 247 | h4:hover > a.headerlink, 248 | h5:hover > a.headerlink, 249 | h6:hover > a.headerlink, 250 | dt:hover > a.headerlink, 251 | caption:hover > a.headerlink, 252 | p.caption:hover > a.headerlink, 253 | div.code-block-caption:hover > a.headerlink { 254 | visibility: visible; 255 | } 256 | 257 | div.body p.caption { 258 | text-align: inherit; 259 | } 260 | 261 | div.body td { 262 | text-align: left; 263 | } 264 | 265 | .first { 266 | margin-top: 0 !important; 267 | } 268 | 269 | p.rubric { 270 | margin-top: 30px; 271 | font-weight: bold; 272 | } 273 | 274 | img.align-left, .figure.align-left, object.align-left { 275 | clear: left; 276 | float: left; 277 | margin-right: 1em; 278 | } 279 | 280 | img.align-right, .figure.align-right, object.align-right { 281 | clear: right; 282 | float: right; 283 | margin-left: 1em; 284 | } 285 | 286 | img.align-center, .figure.align-center, object.align-center { 287 | display: block; 288 | margin-left: auto; 289 | margin-right: auto; 290 | } 291 | 292 | .align-left { 293 | text-align: left; 294 | } 295 | 296 | .align-center { 297 | text-align: center; 298 | } 299 | 300 | .align-right { 301 | text-align: right; 302 | } 303 | 304 | /* -- sidebars -------------------------------------------------------------- */ 305 | 306 | div.sidebar { 307 | margin: 0 0 0.5em 1em; 308 | border: 1px solid #ddb; 309 | padding: 7px 7px 0 7px; 310 | background-color: #ffe; 311 | width: 40%; 312 | float: right; 313 | } 314 | 315 | p.sidebar-title { 316 | font-weight: bold; 317 | } 318 | 319 | /* -- topics ---------------------------------------------------------------- */ 320 | 321 | div.topic { 322 | border: 1px solid #ccc; 323 | padding: 7px 7px 0 7px; 324 | margin: 10px 0 10px 0; 325 | } 326 | 327 | p.topic-title { 328 | font-size: 1.1em; 329 | font-weight: bold; 330 | margin-top: 10px; 331 | } 332 | 333 | /* -- admonitions ----------------------------------------------------------- */ 334 | 335 | div.admonition { 336 | margin-top: 10px; 337 | margin-bottom: 10px; 338 | padding: 7px; 339 | } 340 | 341 | div.admonition dt { 342 | font-weight: bold; 343 | } 344 | 345 | div.admonition dl { 346 | margin-bottom: 0; 347 | } 348 | 349 | p.admonition-title { 350 | margin: 0px 10px 5px 0px; 351 | font-weight: bold; 352 | } 353 | 354 | div.body p.centered { 355 | text-align: center; 356 | margin-top: 25px; 357 | } 358 | 359 | /* -- tables ---------------------------------------------------------------- */ 360 | 361 | table.docutils { 362 | border: 0; 363 | border-collapse: collapse; 364 | } 365 | 366 | table.align-center { 367 | margin-left: auto; 368 | margin-right: auto; 369 | } 370 | 371 | table caption span.caption-number { 372 | font-style: italic; 373 | } 374 | 375 | table caption span.caption-text { 376 | } 377 | 378 | table.docutils td, table.docutils th { 379 | padding: 1px 8px 1px 5px; 380 | border-top: 0; 381 | border-left: 0; 382 | border-right: 0; 383 | border-bottom: 1px solid #aaa; 384 | } 385 | 386 | table.footnote td, table.footnote th { 387 | border: 0 !important; 388 | } 389 | 390 | th { 391 | text-align: left; 392 | padding-right: 5px; 393 | } 394 | 395 | table.citation { 396 | border-left: solid 1px gray; 397 | margin-left: 1px; 398 | } 399 | 400 | table.citation td { 401 | border-bottom: none; 402 | } 403 | 404 | th > p:first-child, 405 | td > p:first-child { 406 | margin-top: 0px; 407 | } 408 | 409 | th > p:last-child, 410 | td > p:last-child { 411 | margin-bottom: 0px; 412 | } 413 | 414 | /* -- figures --------------------------------------------------------------- */ 415 | 416 | div.figure { 417 | margin: 0.5em; 418 | padding: 0.5em; 419 | } 420 | 421 | div.figure p.caption { 422 | padding: 0.3em; 423 | } 424 | 425 | div.figure p.caption span.caption-number { 426 | font-style: italic; 427 | } 428 | 429 | div.figure p.caption span.caption-text { 430 | } 431 | 432 | /* -- field list styles ----------------------------------------------------- */ 433 | 434 | table.field-list td, table.field-list th { 435 | border: 0 !important; 436 | } 437 | 438 | .field-list ul { 439 | margin: 0; 440 | padding-left: 1em; 441 | } 442 | 443 | .field-list p { 444 | margin: 0; 445 | } 446 | 447 | .field-name { 448 | -moz-hyphens: manual; 449 | -ms-hyphens: manual; 450 | -webkit-hyphens: manual; 451 | hyphens: manual; 452 | } 453 | 454 | /* -- hlist styles ---------------------------------------------------------- */ 455 | 456 | table.hlist td { 457 | vertical-align: top; 458 | } 459 | 460 | 461 | /* -- other body styles ----------------------------------------------------- */ 462 | 463 | ol.arabic { 464 | list-style: decimal; 465 | } 466 | 467 | ol.loweralpha { 468 | list-style: lower-alpha; 469 | } 470 | 471 | ol.upperalpha { 472 | list-style: upper-alpha; 473 | } 474 | 475 | ol.lowerroman { 476 | list-style: lower-roman; 477 | } 478 | 479 | ol.upperroman { 480 | list-style: upper-roman; 481 | } 482 | 483 | li > p:first-child { 484 | margin-top: 0px; 485 | } 486 | 487 | li > p:last-child { 488 | margin-bottom: 0px; 489 | } 490 | 491 | dl.footnote > dt, 492 | dl.citation > dt { 493 | float: left; 494 | } 495 | 496 | dl.footnote > dd, 497 | dl.citation > dd { 498 | margin-bottom: 0em; 499 | } 500 | 501 | dl.footnote > dd:after, 502 | dl.citation > dd:after { 503 | content: ""; 504 | clear: both; 505 | } 506 | 507 | dl.field-list { 508 | display: flex; 509 | flex-wrap: wrap; 510 | } 511 | 512 | dl.field-list > dt { 513 | flex-basis: 20%; 514 | font-weight: bold; 515 | word-break: break-word; 516 | } 517 | 518 | dl.field-list > dt:after { 519 | content: ":"; 520 | } 521 | 522 | dl.field-list > dd { 523 | flex-basis: 70%; 524 | padding-left: 1em; 525 | margin-left: 0em; 526 | margin-bottom: 0em; 527 | } 528 | 529 | dl { 530 | margin-bottom: 15px; 531 | } 532 | 533 | dd > p:first-child { 534 | margin-top: 0px; 535 | } 536 | 537 | dd ul, dd table { 538 | margin-bottom: 10px; 539 | } 540 | 541 | dd { 542 | margin-top: 3px; 543 | margin-bottom: 10px; 544 | margin-left: 30px; 545 | } 546 | 547 | dt:target, span.highlighted { 548 | background-color: #fbe54e; 549 | } 550 | 551 | rect.highlighted { 552 | fill: #fbe54e; 553 | } 554 | 555 | dl.glossary dt { 556 | font-weight: bold; 557 | font-size: 1.1em; 558 | } 559 | 560 | .optional { 561 | font-size: 1.3em; 562 | } 563 | 564 | .sig-paren { 565 | font-size: larger; 566 | } 567 | 568 | .versionmodified { 569 | font-style: italic; 570 | } 571 | 572 | .system-message { 573 | background-color: #fda; 574 | padding: 5px; 575 | border: 3px solid red; 576 | } 577 | 578 | .footnote:target { 579 | background-color: #ffa; 580 | } 581 | 582 | .line-block { 583 | display: block; 584 | margin-top: 1em; 585 | margin-bottom: 1em; 586 | } 587 | 588 | .line-block .line-block { 589 | margin-top: 0; 590 | margin-bottom: 0; 591 | margin-left: 1.5em; 592 | } 593 | 594 | .guilabel, .menuselection { 595 | font-family: sans-serif; 596 | } 597 | 598 | .accelerator { 599 | text-decoration: underline; 600 | } 601 | 602 | .classifier { 603 | font-style: oblique; 604 | } 605 | 606 | .classifier:before { 607 | font-style: normal; 608 | margin: 0.5em; 609 | content: ":"; 610 | } 611 | 612 | abbr, acronym { 613 | border-bottom: dotted 1px; 614 | cursor: help; 615 | } 616 | 617 | /* -- code displays --------------------------------------------------------- */ 618 | 619 | pre { 620 | overflow: auto; 621 | overflow-y: hidden; /* fixes display issues on Chrome browsers */ 622 | } 623 | 624 | span.pre { 625 | -moz-hyphens: none; 626 | -ms-hyphens: none; 627 | -webkit-hyphens: none; 628 | hyphens: none; 629 | } 630 | 631 | td.linenos pre { 632 | padding: 5px 0px; 633 | border: 0; 634 | background-color: transparent; 635 | color: #aaa; 636 | } 637 | 638 | table.highlighttable { 639 | margin-left: 0.5em; 640 | } 641 | 642 | table.highlighttable td { 643 | padding: 0 0.5em 0 0.5em; 644 | } 645 | 646 | div.code-block-caption { 647 | padding: 2px 5px; 648 | font-size: small; 649 | } 650 | 651 | div.code-block-caption code { 652 | background-color: transparent; 653 | } 654 | 655 | div.code-block-caption + div > div.highlight > pre { 656 | margin-top: 0; 657 | } 658 | 659 | div.code-block-caption span.caption-number { 660 | padding: 0.1em 0.3em; 661 | font-style: italic; 662 | } 663 | 664 | div.code-block-caption span.caption-text { 665 | } 666 | 667 | div.literal-block-wrapper { 668 | padding: 1em 1em 0; 669 | } 670 | 671 | div.literal-block-wrapper div.highlight { 672 | margin: 0; 673 | } 674 | 675 | code.descname { 676 | background-color: transparent; 677 | font-weight: bold; 678 | font-size: 1.2em; 679 | } 680 | 681 | code.descclassname { 682 | background-color: transparent; 683 | } 684 | 685 | code.xref, a code { 686 | background-color: transparent; 687 | font-weight: bold; 688 | } 689 | 690 | h1 code, h2 code, h3 code, h4 code, h5 code, h6 code { 691 | background-color: transparent; 692 | } 693 | 694 | .viewcode-link { 695 | float: right; 696 | } 697 | 698 | .viewcode-back { 699 | float: right; 700 | font-family: sans-serif; 701 | } 702 | 703 | div.viewcode-block:target { 704 | margin: -1px -10px; 705 | padding: 0 10px; 706 | } 707 | 708 | /* -- math display ---------------------------------------------------------- */ 709 | 710 | img.math { 711 | vertical-align: middle; 712 | } 713 | 714 | div.body div.math p { 715 | text-align: center; 716 | } 717 | 718 | span.eqno { 719 | float: right; 720 | } 721 | 722 | span.eqno a.headerlink { 723 | position: relative; 724 | left: 0px; 725 | z-index: 1; 726 | } 727 | 728 | div.math:hover a.headerlink { 729 | visibility: visible; 730 | } 731 | 732 | /* -- printout stylesheet --------------------------------------------------- */ 733 | 734 | @media print { 735 | div.document, 736 | div.documentwrapper, 737 | div.bodywrapper { 738 | margin: 0 !important; 739 | width: 100%; 740 | } 741 | 742 | div.sphinxsidebar, 743 | div.related, 744 | div.footer, 745 | #top-link { 746 | display: none; 747 | } 748 | } -------------------------------------------------------------------------------- /docs/_build/html/_static/custom.css: -------------------------------------------------------------------------------- 1 | /* This file intentionally left blank. */ 2 | -------------------------------------------------------------------------------- /docs/_build/html/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Sphinx JavaScript utilities for all documentation. 6 | * 7 | * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | /** 18 | * make the code below compatible with browsers without 19 | * an installed firebug like debugger 20 | if (!window.console || !console.firebug) { 21 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", 22 | "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", 23 | "profile", "profileEnd"]; 24 | window.console = {}; 25 | for (var i = 0; i < names.length; ++i) 26 | window.console[names[i]] = function() {}; 27 | } 28 | */ 29 | 30 | /** 31 | * small helper function to urldecode strings 32 | */ 33 | jQuery.urldecode = function(x) { 34 | return decodeURIComponent(x).replace(/\+/g, ' '); 35 | }; 36 | 37 | /** 38 | * small helper function to urlencode strings 39 | */ 40 | jQuery.urlencode = encodeURIComponent; 41 | 42 | /** 43 | * This function returns the parsed url parameters of the 44 | * current request. Multiple values per key are supported, 45 | * it will always return arrays of strings for the value parts. 46 | */ 47 | jQuery.getQueryParameters = function(s) { 48 | if (typeof s === 'undefined') 49 | s = document.location.search; 50 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 51 | var result = {}; 52 | for (var i = 0; i < parts.length; i++) { 53 | var tmp = parts[i].split('=', 2); 54 | var key = jQuery.urldecode(tmp[0]); 55 | var value = jQuery.urldecode(tmp[1]); 56 | if (key in result) 57 | result[key].push(value); 58 | else 59 | result[key] = [value]; 60 | } 61 | return result; 62 | }; 63 | 64 | /** 65 | * highlight a given string on a jquery object by wrapping it in 66 | * span elements with the given class name. 67 | */ 68 | jQuery.fn.highlightText = function(text, className) { 69 | function highlight(node, addItems) { 70 | if (node.nodeType === 3) { 71 | var val = node.nodeValue; 72 | var pos = val.toLowerCase().indexOf(text); 73 | if (pos >= 0 && 74 | !jQuery(node.parentNode).hasClass(className) && 75 | !jQuery(node.parentNode).hasClass("nohighlight")) { 76 | var span; 77 | var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg"); 78 | if (isInSVG) { 79 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 80 | } else { 81 | span = document.createElement("span"); 82 | span.className = className; 83 | } 84 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 85 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 86 | document.createTextNode(val.substr(pos + text.length)), 87 | node.nextSibling)); 88 | node.nodeValue = val.substr(0, pos); 89 | if (isInSVG) { 90 | var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); 91 | var bbox = node.parentElement.getBBox(); 92 | rect.x.baseVal.value = bbox.x; 93 | rect.y.baseVal.value = bbox.y; 94 | rect.width.baseVal.value = bbox.width; 95 | rect.height.baseVal.value = bbox.height; 96 | rect.setAttribute('class', className); 97 | addItems.push({ 98 | "parent": node.parentNode, 99 | "target": rect}); 100 | } 101 | } 102 | } 103 | else if (!jQuery(node).is("button, select, textarea")) { 104 | jQuery.each(node.childNodes, function() { 105 | highlight(this, addItems); 106 | }); 107 | } 108 | } 109 | var addItems = []; 110 | var result = this.each(function() { 111 | highlight(this, addItems); 112 | }); 113 | for (var i = 0; i < addItems.length; ++i) { 114 | jQuery(addItems[i].parent).before(addItems[i].target); 115 | } 116 | return result; 117 | }; 118 | 119 | /* 120 | * backward compatibility for jQuery.browser 121 | * This will be supported until firefox bug is fixed. 122 | */ 123 | if (!jQuery.browser) { 124 | jQuery.uaMatch = function(ua) { 125 | ua = ua.toLowerCase(); 126 | 127 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 128 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 129 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 130 | /(msie) ([\w.]+)/.exec(ua) || 131 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 132 | []; 133 | 134 | return { 135 | browser: match[ 1 ] || "", 136 | version: match[ 2 ] || "0" 137 | }; 138 | }; 139 | jQuery.browser = {}; 140 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 141 | } 142 | 143 | /** 144 | * Small JavaScript module for the documentation. 145 | */ 146 | var Documentation = { 147 | 148 | init : function() { 149 | this.fixFirefoxAnchorBug(); 150 | this.highlightSearchWords(); 151 | this.initIndexTable(); 152 | if (DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) { 153 | this.initOnKeyListeners(); 154 | } 155 | }, 156 | 157 | /** 158 | * i18n support 159 | */ 160 | TRANSLATIONS : {}, 161 | PLURAL_EXPR : function(n) { return n === 1 ? 0 : 1; }, 162 | LOCALE : 'unknown', 163 | 164 | // gettext and ngettext don't access this so that the functions 165 | // can safely bound to a different name (_ = Documentation.gettext) 166 | gettext : function(string) { 167 | var translated = Documentation.TRANSLATIONS[string]; 168 | if (typeof translated === 'undefined') 169 | return string; 170 | return (typeof translated === 'string') ? translated : translated[0]; 171 | }, 172 | 173 | ngettext : function(singular, plural, n) { 174 | var translated = Documentation.TRANSLATIONS[singular]; 175 | if (typeof translated === 'undefined') 176 | return (n == 1) ? singular : plural; 177 | return translated[Documentation.PLURALEXPR(n)]; 178 | }, 179 | 180 | addTranslations : function(catalog) { 181 | for (var key in catalog.messages) 182 | this.TRANSLATIONS[key] = catalog.messages[key]; 183 | this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); 184 | this.LOCALE = catalog.locale; 185 | }, 186 | 187 | /** 188 | * add context elements like header anchor links 189 | */ 190 | addContextElements : function() { 191 | $('div[id] > :header:first').each(function() { 192 | $('\u00B6'). 193 | attr('href', '#' + this.id). 194 | attr('title', _('Permalink to this headline')). 195 | appendTo(this); 196 | }); 197 | $('dt[id]').each(function() { 198 | $('\u00B6'). 199 | attr('href', '#' + this.id). 200 | attr('title', _('Permalink to this definition')). 201 | appendTo(this); 202 | }); 203 | }, 204 | 205 | /** 206 | * workaround a firefox stupidity 207 | * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075 208 | */ 209 | fixFirefoxAnchorBug : function() { 210 | if (document.location.hash && $.browser.mozilla) 211 | window.setTimeout(function() { 212 | document.location.href += ''; 213 | }, 10); 214 | }, 215 | 216 | /** 217 | * highlight the search words provided in the url in the text 218 | */ 219 | highlightSearchWords : function() { 220 | var params = $.getQueryParameters(); 221 | var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; 222 | if (terms.length) { 223 | var body = $('div.body'); 224 | if (!body.length) { 225 | body = $('body'); 226 | } 227 | window.setTimeout(function() { 228 | $.each(terms, function() { 229 | body.highlightText(this.toLowerCase(), 'highlighted'); 230 | }); 231 | }, 10); 232 | $('') 234 | .appendTo($('#searchbox')); 235 | } 236 | }, 237 | 238 | /** 239 | * init the domain index toggle buttons 240 | */ 241 | initIndexTable : function() { 242 | var togglers = $('img.toggler').click(function() { 243 | var src = $(this).attr('src'); 244 | var idnum = $(this).attr('id').substr(7); 245 | $('tr.cg-' + idnum).toggle(); 246 | if (src.substr(-9) === 'minus.png') 247 | $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); 248 | else 249 | $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); 250 | }).css('display', ''); 251 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { 252 | togglers.click(); 253 | } 254 | }, 255 | 256 | /** 257 | * helper function to hide the search marks again 258 | */ 259 | hideSearchWords : function() { 260 | $('#searchbox .highlight-link').fadeOut(300); 261 | $('span.highlighted').removeClass('highlighted'); 262 | }, 263 | 264 | /** 265 | * make the url absolute 266 | */ 267 | makeURL : function(relativeURL) { 268 | return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; 269 | }, 270 | 271 | /** 272 | * get the current relative url 273 | */ 274 | getCurrentURL : function() { 275 | var path = document.location.pathname; 276 | var parts = path.split(/\//); 277 | $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { 278 | if (this === '..') 279 | parts.pop(); 280 | }); 281 | var url = parts.join('/'); 282 | return path.substring(url.lastIndexOf('/') + 1, path.length - 1); 283 | }, 284 | 285 | initOnKeyListeners: function() { 286 | $(document).keyup(function(event) { 287 | var activeElementType = document.activeElement.tagName; 288 | // don't navigate when in search box or textarea 289 | if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT') { 290 | switch (event.keyCode) { 291 | case 37: // left 292 | var prevHref = $('link[rel="prev"]').prop('href'); 293 | if (prevHref) { 294 | window.location.href = prevHref; 295 | return false; 296 | } 297 | case 39: // right 298 | var nextHref = $('link[rel="next"]').prop('href'); 299 | if (nextHref) { 300 | window.location.href = nextHref; 301 | return false; 302 | } 303 | } 304 | } 305 | }); 306 | } 307 | }; 308 | 309 | // quick alias for translations 310 | _ = Documentation.gettext; 311 | 312 | $(document).ready(function() { 313 | Documentation.init(); 314 | }); 315 | -------------------------------------------------------------------------------- /docs/_build/html/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '0.1', 4 | LANGUAGE: 'None', 5 | COLLAPSE_INDEX: false, 6 | FILE_SUFFIX: '.html', 7 | HAS_SOURCE: true, 8 | SOURCELINK_SUFFIX: '.txt', 9 | NAVIGATION_WITH_KEYS: false 10 | }; -------------------------------------------------------------------------------- /docs/_build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/html/_static/file.png -------------------------------------------------------------------------------- /docs/_build/html/_static/language_data.js: -------------------------------------------------------------------------------- 1 | /* 2 | * language_data.js 3 | * ~~~~~~~~~~~~~~~~ 4 | * 5 | * This script contains the language-specific data used by searchtools.js, 6 | * namely the list of stopwords, stemmer, scorer and splitter. 7 | * 8 | * :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS. 9 | * :license: BSD, see LICENSE for details. 10 | * 11 | */ 12 | 13 | var stopwords = ["a","and","are","as","at","be","but","by","for","if","in","into","is","it","near","no","not","of","on","or","such","that","the","their","then","there","these","they","this","to","was","will","with"]; 14 | 15 | 16 | /* Non-minified version JS is _stemmer.js if file is provided */ 17 | /** 18 | * Porter Stemmer 19 | */ 20 | var Stemmer = function() { 21 | 22 | var step2list = { 23 | ational: 'ate', 24 | tional: 'tion', 25 | enci: 'ence', 26 | anci: 'ance', 27 | izer: 'ize', 28 | bli: 'ble', 29 | alli: 'al', 30 | entli: 'ent', 31 | eli: 'e', 32 | ousli: 'ous', 33 | ization: 'ize', 34 | ation: 'ate', 35 | ator: 'ate', 36 | alism: 'al', 37 | iveness: 'ive', 38 | fulness: 'ful', 39 | ousness: 'ous', 40 | aliti: 'al', 41 | iviti: 'ive', 42 | biliti: 'ble', 43 | logi: 'log' 44 | }; 45 | 46 | var step3list = { 47 | icate: 'ic', 48 | ative: '', 49 | alize: 'al', 50 | iciti: 'ic', 51 | ical: 'ic', 52 | ful: '', 53 | ness: '' 54 | }; 55 | 56 | var c = "[^aeiou]"; // consonant 57 | var v = "[aeiouy]"; // vowel 58 | var C = c + "[^aeiouy]*"; // consonant sequence 59 | var V = v + "[aeiou]*"; // vowel sequence 60 | 61 | var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0 62 | var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1 63 | var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1 64 | var s_v = "^(" + C + ")?" + v; // vowel in stem 65 | 66 | this.stemWord = function (w) { 67 | var stem; 68 | var suffix; 69 | var firstch; 70 | var origword = w; 71 | 72 | if (w.length < 3) 73 | return w; 74 | 75 | var re; 76 | var re2; 77 | var re3; 78 | var re4; 79 | 80 | firstch = w.substr(0,1); 81 | if (firstch == "y") 82 | w = firstch.toUpperCase() + w.substr(1); 83 | 84 | // Step 1a 85 | re = /^(.+?)(ss|i)es$/; 86 | re2 = /^(.+?)([^s])s$/; 87 | 88 | if (re.test(w)) 89 | w = w.replace(re,"$1$2"); 90 | else if (re2.test(w)) 91 | w = w.replace(re2,"$1$2"); 92 | 93 | // Step 1b 94 | re = /^(.+?)eed$/; 95 | re2 = /^(.+?)(ed|ing)$/; 96 | if (re.test(w)) { 97 | var fp = re.exec(w); 98 | re = new RegExp(mgr0); 99 | if (re.test(fp[1])) { 100 | re = /.$/; 101 | w = w.replace(re,""); 102 | } 103 | } 104 | else if (re2.test(w)) { 105 | var fp = re2.exec(w); 106 | stem = fp[1]; 107 | re2 = new RegExp(s_v); 108 | if (re2.test(stem)) { 109 | w = stem; 110 | re2 = /(at|bl|iz)$/; 111 | re3 = new RegExp("([^aeiouylsz])\\1$"); 112 | re4 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 113 | if (re2.test(w)) 114 | w = w + "e"; 115 | else if (re3.test(w)) { 116 | re = /.$/; 117 | w = w.replace(re,""); 118 | } 119 | else if (re4.test(w)) 120 | w = w + "e"; 121 | } 122 | } 123 | 124 | // Step 1c 125 | re = /^(.+?)y$/; 126 | if (re.test(w)) { 127 | var fp = re.exec(w); 128 | stem = fp[1]; 129 | re = new RegExp(s_v); 130 | if (re.test(stem)) 131 | w = stem + "i"; 132 | } 133 | 134 | // Step 2 135 | re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/; 136 | if (re.test(w)) { 137 | var fp = re.exec(w); 138 | stem = fp[1]; 139 | suffix = fp[2]; 140 | re = new RegExp(mgr0); 141 | if (re.test(stem)) 142 | w = stem + step2list[suffix]; 143 | } 144 | 145 | // Step 3 146 | re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/; 147 | if (re.test(w)) { 148 | var fp = re.exec(w); 149 | stem = fp[1]; 150 | suffix = fp[2]; 151 | re = new RegExp(mgr0); 152 | if (re.test(stem)) 153 | w = stem + step3list[suffix]; 154 | } 155 | 156 | // Step 4 157 | re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/; 158 | re2 = /^(.+?)(s|t)(ion)$/; 159 | if (re.test(w)) { 160 | var fp = re.exec(w); 161 | stem = fp[1]; 162 | re = new RegExp(mgr1); 163 | if (re.test(stem)) 164 | w = stem; 165 | } 166 | else if (re2.test(w)) { 167 | var fp = re2.exec(w); 168 | stem = fp[1] + fp[2]; 169 | re2 = new RegExp(mgr1); 170 | if (re2.test(stem)) 171 | w = stem; 172 | } 173 | 174 | // Step 5 175 | re = /^(.+?)e$/; 176 | if (re.test(w)) { 177 | var fp = re.exec(w); 178 | stem = fp[1]; 179 | re = new RegExp(mgr1); 180 | re2 = new RegExp(meq1); 181 | re3 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 182 | if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) 183 | w = stem; 184 | } 185 | re = /ll$/; 186 | re2 = new RegExp(mgr1); 187 | if (re.test(w) && re2.test(w)) { 188 | re = /.$/; 189 | w = w.replace(re,""); 190 | } 191 | 192 | // and turn initial Y back to y 193 | if (firstch == "y") 194 | w = firstch.toLowerCase() + w.substr(1); 195 | return w; 196 | } 197 | } 198 | 199 | 200 | 201 | 202 | 203 | var splitChars = (function() { 204 | var result = {}; 205 | var singles = [96, 180, 187, 191, 215, 247, 749, 885, 903, 907, 909, 930, 1014, 1648, 206 | 1748, 1809, 2416, 2473, 2481, 2526, 2601, 2609, 2612, 2615, 2653, 2702, 207 | 2706, 2729, 2737, 2740, 2857, 2865, 2868, 2910, 2928, 2948, 2961, 2971, 208 | 2973, 3085, 3089, 3113, 3124, 3213, 3217, 3241, 3252, 3295, 3341, 3345, 209 | 3369, 3506, 3516, 3633, 3715, 3721, 3736, 3744, 3748, 3750, 3756, 3761, 210 | 3781, 3912, 4239, 4347, 4681, 4695, 4697, 4745, 4785, 4799, 4801, 4823, 211 | 4881, 5760, 5901, 5997, 6313, 7405, 8024, 8026, 8028, 8030, 8117, 8125, 212 | 8133, 8181, 8468, 8485, 8487, 8489, 8494, 8527, 11311, 11359, 11687, 11695, 213 | 11703, 11711, 11719, 11727, 11735, 12448, 12539, 43010, 43014, 43019, 43587, 214 | 43696, 43713, 64286, 64297, 64311, 64317, 64319, 64322, 64325, 65141]; 215 | var i, j, start, end; 216 | for (i = 0; i < singles.length; i++) { 217 | result[singles[i]] = true; 218 | } 219 | var ranges = [[0, 47], [58, 64], [91, 94], [123, 169], [171, 177], [182, 184], [706, 709], 220 | [722, 735], [741, 747], [751, 879], [888, 889], [894, 901], [1154, 1161], 221 | [1318, 1328], [1367, 1368], [1370, 1376], [1416, 1487], [1515, 1519], [1523, 1568], 222 | [1611, 1631], [1642, 1645], [1750, 1764], [1767, 1773], [1789, 1790], [1792, 1807], 223 | [1840, 1868], [1958, 1968], [1970, 1983], [2027, 2035], [2038, 2041], [2043, 2047], 224 | [2070, 2073], [2075, 2083], [2085, 2087], [2089, 2307], [2362, 2364], [2366, 2383], 225 | [2385, 2391], [2402, 2405], [2419, 2424], [2432, 2436], [2445, 2446], [2449, 2450], 226 | [2483, 2485], [2490, 2492], [2494, 2509], [2511, 2523], [2530, 2533], [2546, 2547], 227 | [2554, 2564], [2571, 2574], [2577, 2578], [2618, 2648], [2655, 2661], [2672, 2673], 228 | [2677, 2692], [2746, 2748], [2750, 2767], [2769, 2783], [2786, 2789], [2800, 2820], 229 | [2829, 2830], [2833, 2834], [2874, 2876], [2878, 2907], [2914, 2917], [2930, 2946], 230 | [2955, 2957], [2966, 2968], [2976, 2978], [2981, 2983], [2987, 2989], [3002, 3023], 231 | [3025, 3045], [3059, 3076], [3130, 3132], [3134, 3159], [3162, 3167], [3170, 3173], 232 | [3184, 3191], [3199, 3204], [3258, 3260], [3262, 3293], [3298, 3301], [3312, 3332], 233 | [3386, 3388], [3390, 3423], [3426, 3429], [3446, 3449], [3456, 3460], [3479, 3481], 234 | [3518, 3519], [3527, 3584], [3636, 3647], [3655, 3663], [3674, 3712], [3717, 3718], 235 | [3723, 3724], [3726, 3731], [3752, 3753], [3764, 3772], [3774, 3775], [3783, 3791], 236 | [3802, 3803], [3806, 3839], [3841, 3871], [3892, 3903], [3949, 3975], [3980, 4095], 237 | [4139, 4158], [4170, 4175], [4182, 4185], [4190, 4192], [4194, 4196], [4199, 4205], 238 | [4209, 4212], [4226, 4237], [4250, 4255], [4294, 4303], [4349, 4351], [4686, 4687], 239 | [4702, 4703], [4750, 4751], [4790, 4791], [4806, 4807], [4886, 4887], [4955, 4968], 240 | [4989, 4991], [5008, 5023], [5109, 5120], [5741, 5742], [5787, 5791], [5867, 5869], 241 | [5873, 5887], [5906, 5919], [5938, 5951], [5970, 5983], [6001, 6015], [6068, 6102], 242 | [6104, 6107], [6109, 6111], [6122, 6127], [6138, 6159], [6170, 6175], [6264, 6271], 243 | [6315, 6319], [6390, 6399], [6429, 6469], [6510, 6511], [6517, 6527], [6572, 6592], 244 | [6600, 6607], [6619, 6655], [6679, 6687], [6741, 6783], [6794, 6799], [6810, 6822], 245 | [6824, 6916], [6964, 6980], [6988, 6991], [7002, 7042], [7073, 7085], [7098, 7167], 246 | [7204, 7231], [7242, 7244], [7294, 7400], [7410, 7423], [7616, 7679], [7958, 7959], 247 | [7966, 7967], [8006, 8007], [8014, 8015], [8062, 8063], [8127, 8129], [8141, 8143], 248 | [8148, 8149], [8156, 8159], [8173, 8177], [8189, 8303], [8306, 8307], [8314, 8318], 249 | [8330, 8335], [8341, 8449], [8451, 8454], [8456, 8457], [8470, 8472], [8478, 8483], 250 | [8506, 8507], [8512, 8516], [8522, 8525], [8586, 9311], [9372, 9449], [9472, 10101], 251 | [10132, 11263], [11493, 11498], [11503, 11516], [11518, 11519], [11558, 11567], 252 | [11622, 11630], [11632, 11647], [11671, 11679], [11743, 11822], [11824, 12292], 253 | [12296, 12320], [12330, 12336], [12342, 12343], [12349, 12352], [12439, 12444], 254 | [12544, 12548], [12590, 12592], [12687, 12689], [12694, 12703], [12728, 12783], 255 | [12800, 12831], [12842, 12880], [12896, 12927], [12938, 12976], [12992, 13311], 256 | [19894, 19967], [40908, 40959], [42125, 42191], [42238, 42239], [42509, 42511], 257 | [42540, 42559], [42592, 42593], [42607, 42622], [42648, 42655], [42736, 42774], 258 | [42784, 42785], [42889, 42890], [42893, 43002], [43043, 43055], [43062, 43071], 259 | [43124, 43137], [43188, 43215], [43226, 43249], [43256, 43258], [43260, 43263], 260 | [43302, 43311], [43335, 43359], [43389, 43395], [43443, 43470], [43482, 43519], 261 | [43561, 43583], [43596, 43599], [43610, 43615], [43639, 43641], [43643, 43647], 262 | [43698, 43700], [43703, 43704], [43710, 43711], [43715, 43738], [43742, 43967], 263 | [44003, 44015], [44026, 44031], [55204, 55215], [55239, 55242], [55292, 55295], 264 | [57344, 63743], [64046, 64047], [64110, 64111], [64218, 64255], [64263, 64274], 265 | [64280, 64284], [64434, 64466], [64830, 64847], [64912, 64913], [64968, 65007], 266 | [65020, 65135], [65277, 65295], [65306, 65312], [65339, 65344], [65371, 65381], 267 | [65471, 65473], [65480, 65481], [65488, 65489], [65496, 65497]]; 268 | for (i = 0; i < ranges.length; i++) { 269 | start = ranges[i][0]; 270 | end = ranges[i][1]; 271 | for (j = start; j <= end; j++) { 272 | result[j] = true; 273 | } 274 | } 275 | return result; 276 | })(); 277 | 278 | function splitQuery(query) { 279 | var result = []; 280 | var start = -1; 281 | for (var i = 0; i < query.length; i++) { 282 | if (splitChars[query.charCodeAt(i)]) { 283 | if (start !== -1) { 284 | result.push(query.slice(start, i)); 285 | start = -1; 286 | } 287 | } else if (start === -1) { 288 | start = i; 289 | } 290 | } 291 | if (start !== -1) { 292 | result.push(query.slice(start)); 293 | } 294 | return result; 295 | } 296 | 297 | 298 | -------------------------------------------------------------------------------- /docs/_build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/html/_static/minus.png -------------------------------------------------------------------------------- /docs/_build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/html/_static/plus.png -------------------------------------------------------------------------------- /docs/_build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #eeffcc; } 3 | .highlight .c { color: #408090; font-style: italic } /* Comment */ 4 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 5 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #666666 } /* Operator */ 7 | .highlight .ch { color: #408090; font-style: italic } /* Comment.Hashbang */ 8 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ 9 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 10 | .highlight .cpf { color: #408090; font-style: italic } /* Comment.PreprocFile */ 11 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ 12 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ 13 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 14 | .highlight .ge { font-style: italic } /* Generic.Emph */ 15 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 16 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 17 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 18 | .highlight .go { color: #333333 } /* Generic.Output */ 19 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 20 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 21 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 22 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 23 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 24 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 25 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 26 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 27 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 28 | .highlight .kt { color: #902000 } /* Keyword.Type */ 29 | .highlight .m { color: #208050 } /* Literal.Number */ 30 | .highlight .s { color: #4070a0 } /* Literal.String */ 31 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 32 | .highlight .nb { color: #007020 } /* Name.Builtin */ 33 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 34 | .highlight .no { color: #60add5 } /* Name.Constant */ 35 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 36 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 37 | .highlight .ne { color: #007020 } /* Name.Exception */ 38 | .highlight .nf { color: #06287e } /* Name.Function */ 39 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 40 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 41 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 42 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 43 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 44 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 45 | .highlight .mb { color: #208050 } /* Literal.Number.Bin */ 46 | .highlight .mf { color: #208050 } /* Literal.Number.Float */ 47 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */ 48 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */ 49 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */ 50 | .highlight .sa { color: #4070a0 } /* Literal.String.Affix */ 51 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 52 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 53 | .highlight .dl { color: #4070a0 } /* Literal.String.Delimiter */ 54 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 55 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 56 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 57 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 58 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 59 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 60 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 61 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 62 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 63 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 64 | .highlight .fm { color: #06287e } /* Name.Function.Magic */ 65 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 66 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 67 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 68 | .highlight .vm { color: #bb60d5 } /* Name.Variable.Magic */ 69 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /docs/_build/html/_static/underscore.js: -------------------------------------------------------------------------------- 1 | // Underscore.js 1.3.1 2 | // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. 3 | // Underscore is freely distributable under the MIT license. 4 | // Portions of Underscore are inspired or borrowed from Prototype, 5 | // Oliver Steele's Functional, and John Resig's Micro-Templating. 6 | // For all details and documentation: 7 | // http://documentcloud.github.com/underscore 8 | (function(){function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== 9 | c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&q(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&q(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c, 10 | h)&&!f--)break;g=!f}}d.pop();return g}var r=this,G=r._,n={},k=Array.prototype,o=Object.prototype,i=k.slice,H=k.unshift,l=o.toString,I=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,p=k.indexOf,D=k.lastIndexOf,o=Array.isArray,J=Object.keys,s=Function.prototype.bind,b=function(a){return new m(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else r._=b;b.VERSION="1.3.1";var j=b.each= 11 | b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a== 12 | null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect= 13 | function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e= 14 | e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= 15 | function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a, 17 | c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}}; 24 | b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments, 25 | 1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)}; 26 | b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"}; 27 | b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a), 28 | function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+ 29 | u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]= 30 | function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain= 31 | true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); 32 | -------------------------------------------------------------------------------- /docs/_build/html/example_game.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Example Game — Pygame AI 0.1 documentation 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 |
30 |
31 | 32 | 33 |
34 | 35 |
36 |

Example Game

37 |

This game shows examples of what things can be done with the library, 38 | to run it just unzip and run main.py while having pygame and pygame_ai 39 | installed.

40 |
41 |
44 |
45 |
46 | 47 | 48 |
49 | 50 |
51 |
52 | 104 |
105 |
106 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /docs/_build/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Welcome to Pygame AI’s Documentation! — Pygame AI 0.1 documentation 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
30 | 31 | 32 |
33 | 34 |
35 |

Welcome to Pygame AI’s Documentation!

36 |

Pygame AI is a package that aims at implementing a bunch of common 37 | algorithms and techniques often used in Videogame AI. It is still a work 38 | in progress.

39 |
40 |

Installation

41 |

The package is available at PyPI, you can simply do:

42 |
43 |

pip install pygame-ai

44 |
45 |
46 |
47 |

Usage

48 |

After installing it you only need to import like:

49 |
50 |

import pygame_ai

51 |
52 |

or

53 |
54 |

import pygame_ai as pai

55 |
56 |
57 |
58 |

Core

59 |

All of this library’s implementations work using this implementation 60 | of GameObject.

61 |

You can see how the library works by downloading our Example Game, or 62 | you can visit the PyGame AI Guide to see how to implement a simple game 63 | using the library’s core functions.

64 |

So far these are the major techniquest that have been implemented:

65 |
66 |
67 |

Steering Behaviors

68 |

Basic movement behaviors that make in-game characters move in a 69 | pseudo-intelligent way. You will mainly be using 70 | BlendedSteering and PrioritySteering, 71 | but feel free to use any of the behaviors found in 72 | kinematic and static modules.

73 |
74 |
81 |
82 |
83 |
84 |

Table of Contents

85 |
86 | 96 |
97 |
98 |
99 |

Indices and tables

100 |
101 |
105 |
106 |
107 | 108 | 109 |
110 | 111 |
112 |
113 | 164 |
165 |
166 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /docs/_build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/docs/_build/html/objects.inv -------------------------------------------------------------------------------- /docs/_build/html/priority.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Priority — Pygame AI 0.1 documentation 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 |
30 |
31 | 32 | 33 |
34 | 35 |
36 |

Priority

37 |

Priority Steering Behaviors

38 |

This module implements a class that holds a list of 39 | KinematicSteeringBehaviors and applies them in order, 40 | keeping only the first one that produces an output greater than a certain 41 | treshold. This means that some behaviors which are considered more important 42 | (like ObstacleAvoidance and 43 | CollisionAvoidance) but are not always neccesary 44 | to reach the character’s goal can be ignored when they don’t produce a 45 | meaningful output, it also means that when they do produce a meaningful 46 | output they will be the only ones in action.

47 |

This is a very simple form of decision making that involves only steering 48 | algorithms, and therefore it is classified as a steering behavior.

49 |

Derives from KinematicSteeringBehavior.

50 |

Example

51 |

This is how you would normally create your own PrioritySteering, 52 | in this case we are making a behavior that will most of the time Pursue 53 | a target, but will prioritize Avoiding Obstacles when that behavior 54 | returns a steering greater than the treshold.

55 |
mybehavior = PrioritySteering(
 56 |     behaviors = [
 57 |         kinematic.ObstacleAvoidance(character, obstacles),
 58 |         kinematic.Pursue(character, target),
 59 |     ],
 60 | )
 61 | 
62 |
63 |
64 |

PrioritySteering

65 |
66 |
67 | class steering.priority.PrioritySteering(behaviors, epsilon=0.1)[source]
68 |
69 |
70 | draw_indicators(screen, offset=<function PrioritySteering.<lambda>>)[source]
71 |

Draws appropiate indicators for each KinematicSteeringBehavior

72 |
73 |
Parameters
74 |
    75 |
  • screen (pygame.Surface) – Surface in which to draw indicators, normally this would be the screen Surface

  • 76 |
  • offset (function, optional) –

    Function that applies an offset to the object’s position

    77 |

    This is meant to be used together with scrolling cameras, 78 | leave empty if your game doesn’t implement one,it defaults 79 | to a linear function f(pos) -> pos

    80 |

  • 81 |
82 |
83 |
84 |
85 | 86 |
87 |
88 | get_steering()[source]
89 |

Returns a steering request

90 |
91 |
Returns
92 |

Requested steering

93 |
94 |
Return type
95 |

SteeringOutput

96 |
97 |
98 |
99 | 100 |
101 | 102 |
103 |
104 | 105 | 106 |
107 | 108 |
109 |
110 | 162 |
163 |
164 | 175 | 176 | 177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /docs/_build/html/py-modindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Python Module Index — Pygame AI 0.1 documentation 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 | 36 | 37 |

Python Module Index

38 | 39 |
40 | g | 41 | s 42 |
43 | 44 | 45 | 46 | 48 | 49 | 50 | 53 | 54 | 56 | 57 | 59 | 62 | 63 | 64 | 67 | 68 | 69 | 72 | 73 | 74 | 77 | 78 | 79 | 82 | 83 | 84 | 87 |
 
47 | g
51 | gameobject 52 |
 
55 | s
60 | steering 61 |
    65 | steering.blended 66 |
    70 | steering.kinematic 71 |
    75 | steering.path 76 |
    80 | steering.priority 81 |
    85 | steering.static 86 |
88 | 89 | 90 |
91 | 92 |
93 |
94 | 144 |
145 |
146 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /docs/_build/html/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Search — Pygame AI 0.1 documentation 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
32 |
33 |
34 | 35 | 36 |
37 | 38 |

Search

39 |
40 | 41 |

42 | Please activate JavaScript to enable the search 43 | functionality. 44 |

45 |
46 |

47 | From here you can search these documents. Enter your search 48 | words into the box below and click "search". Note that the search 49 | function will automatically search for all of the words. Pages 50 | containing fewer words won't appear in the result list. 51 |

52 |
53 | 54 | 55 | 56 |
57 | 58 |
59 | 60 |
61 | 62 |
63 | 64 |
65 |
66 | 106 |
107 |
108 | 116 | 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /docs/_build/html/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({docnames:["blended","example_game","gameobject","guide","index","kinematic","path","priority","static"],envversion:{"sphinx.domains.c":1,"sphinx.domains.changeset":1,"sphinx.domains.cpp":1,"sphinx.domains.javascript":1,"sphinx.domains.math":2,"sphinx.domains.python":1,"sphinx.domains.rst":1,"sphinx.domains.std":1,"sphinx.ext.intersphinx":1,"sphinx.ext.todo":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["blended.rst","example_game.rst","gameobject.rst","guide.rst","index.rst","kinematic.rst","path.rst","priority.rst","static.rst"],objects:{"":{gameobject:[2,0,0,"-"]},"gameobject.GameObject":{get_lines:[2,2,1,""],image:[2,3,1,""],max_accel:[2,3,1,""],max_angular_accel:[2,3,1,""],max_rotation:[2,3,1,""],max_speed:[2,3,1,""],orientation:[2,3,1,""],position:[2,3,1,""],rect:[2,3,1,""],rotation:[2,3,1,""],steer:[2,2,1,""],steer_angular:[2,2,1,""],steer_x:[2,2,1,""],steer_y:[2,2,1,""],velocity:[2,3,1,""]},"steering.blended":{Arrive:[0,1,1,""],BehaviorAndWeight:[0,1,1,""],BlendedSteering:[0,1,1,""],Flocking:[0,1,1,""],Wander:[0,1,1,""]},"steering.blended.BlendedSteering":{draw_indicators:[0,2,1,""],get_steering:[0,2,1,""]},"steering.kinematic":{Align:[5,1,1,""],Arrive:[5,1,1,""],CollisionAvoidance:[5,1,1,""],Drag:[5,1,1,""],Evade:[5,1,1,""],Face:[5,1,1,""],Flee:[5,1,1,""],FollowPath:[5,1,1,""],KinematicSteeringBehavior:[5,1,1,""],LookWhereYoureGoing:[5,1,1,""],NullSteering:[5,1,1,""],ObstacleAvoidance:[5,1,1,""],Pursue:[5,1,1,""],Seek:[5,1,1,""],Separation:[5,1,1,""],SteeringOutput:[5,1,1,""],VelocityMatch:[5,1,1,""],Wander:[5,1,1,""],negative_steering:[5,2,1,""],null_steering:[5,4,1,""]},"steering.kinematic.KinematicSteeringBehavior":{draw_indicators:[5,2,1,""],get_steering:[5,2,1,""]},"steering.kinematic.SteeringOutput":{angular:[5,3,1,""],linear:[5,3,1,""],update:[5,2,1,""]},"steering.path":{CyclicPath:[6,1,1,""],MirroredPath:[6,1,1,""],Path:[6,1,1,""],PathCircumference:[6,1,1,""],PathParabola:[6,1,1,""]},"steering.path.MirroredPath":{as_list:[6,2,1,""]},"steering.path.Path":{as_list:[6,2,1,""],reset:[6,2,1,""]},"steering.priority":{PrioritySteering:[7,1,1,""]},"steering.priority.PrioritySteering":{draw_indicators:[7,2,1,""],get_steering:[7,2,1,""]},"steering.static":{Arrive:[8,1,1,""],Flee:[8,1,1,""],Seek:[8,1,1,""],StaticSteeringBehavior:[8,1,1,""],SteeringOutput:[8,1,1,""],Wander:[8,1,1,""],null_steering:[8,4,1,""]},"steering.static.StaticSteeringBehavior":{draw_indicators:[8,2,1,""],get_steering:[8,2,1,""]},"steering.static.SteeringOutput":{rotation:[8,3,1,""],update:[8,2,1,""],velocity:[8,3,1,""]},gameobject:{DummyGameObject:[2,1,1,""],GameObject:[2,1,1,""],null_surface:[2,4,1,""]},steering:{"static":[8,0,0,"-"],blended:[0,0,0,"-"],kinematic:[5,0,0,"-"],path:[6,0,0,"-"],priority:[7,0,0,"-"]}},objnames:{"0":["py","module","Python module"],"1":["py","class","Python class"],"2":["py","method","Python method"],"3":["py","attribute","Python attribute"],"4":["py","data","Python data"]},objtypes:{"0":"py:module","1":"py:class","2":"py:method","3":"py:attribute","4":"py:data"},terms:{"0x0x32":2,"case":[0,3,7],"catch":3,"class":[0,2,3,5,6,7,8],"default":[0,2,5,6,7,8],"final":3,"float":[5,6,8],"function":[0,3,4,5,6,7,8],"import":[3,4,7],"int":[0,2,3,5,6,8],"public":2,"return":[0,2,3,5,6,7,8],"static":[2,4],"super":[3,6],"true":3,"try":[0,3],"while":[0,1,3,5],And:3,For:3,Going:[0,5],K_s:3,That:3,The:[2,3,4,5,6,8],Then:3,There:6,These:[3,5],Used:2,Uses:6,With:3,__init__:[3,6],__main__:3,__name__:3,abl:3,about:3,abruptli:5,acceler:[2,3,5,8],accordingli:3,achiev:3,act:3,action:[3,7],actual:3,add:3,added:[3,5],adding:3,afect:3,affect:3,after:[4,6,8],again:3,ahead:5,aim:4,algorithm:[3,4,5,7,8],align:5,align_target_radiu:5,align_tim:5,all:[0,3,4,5],allow:[0,3,5,6],almost:5,along:[2,3,5],alpha:3,also:[0,3,5,6,7],alter:6,although:3,alwai:7,angl:[5,6],angular:[2,5,8],angular_strength:5,ani:[0,2,3,4,5],anoth:3,anyth:3,apart:3,appear:2,append:3,appli:[0,3,5,7,8],appropi:[0,3,5,7,8],arbitrari:3,argument:3,ariv:0,around:0,arriv:[0,3,5,8],artifici:3,as_list:6,asign:2,assign:[2,3],aswel:6,attribut:6,avail:4,avoid:[0,3,5,7],avoid_dist:5,awai:5,axi:[2,3],background:3,backtrack:6,base:[0,3,5,8],basic:[3,4],becaus:3,been:4,befor:3,behav:3,behavior:[0,5,7,8],besid:3,better:[3,5,8],between:[3,5],blend:[4,5],blendedst:[3,4,5],blit:3,blite:[2,3],blue:3,bodi:3,bottom:3,bread:0,bunch:4,butter:0,calcul:3,call:[3,5,6,8],camera:[0,5,7,8],can:[1,2,3,4,5,7],center:[2,3,5,6,8],certain:7,chang:[3,8],channel:3,charact:[0,4,5,6,7,8],chase:3,check:3,circl:3,circle2:3,circle3:3,circlenpc:3,circumfer:[5,6],circumference_path:6,circumferencepath:6,classifi:7,clock:3,clutter:3,code:3,collid:5,collis:[3,5],collisionavoid:[5,7],color:3,combin:[0,3,5],common:4,compar:5,complex:0,complic:3,compos:[0,3],comun:3,concept:3,conform:0,consid:[3,5,7],consist:3,constant:[2,5,8],contain:[0,3,5,8],contrari:5,control:3,convert:3,convert_alpha:3,core:[2,3],correctli:3,cos:[3,6],cosin:3,cosine_path:3,coupl:[0,3],creat:[0,2,3,5,6,7],creativ:3,current:[0,2,3,5],custom:3,cyclic:6,cyclicpath:[3,6],data:[5,8],decis:7,def:[3,6],defin:[3,6],definit:3,degre:[2,5],deriv:[0,2,7],describ:6,descript:6,design:3,determin:5,dictat:3,differ:[0,3,5],direct:[3,5,8],directli:3,discret:3,displai:3,distanc:[5,8],doe:[3,5,6],doesn:[0,3,5,7,8],doing:3,domain:[3,6],domain_end:[3,6],domain_start:[3,6],don:[3,7],done:[1,3],down:5,download:[1,3,4],drag:5,draw:[0,3,5,6,7,8],draw_ind:[0,5,7,8],dummi:[2,5],dummygameobject:[2,5],dynam:6,each:[3,5,7,8],eachoth:[0,5],easi:3,easili:0,element:5,els:3,empti:[0,2,3,5,7,8],emul:[5,8],end:6,enemi:3,engin:2,enough:3,enter:3,entiti:[0,2,3],environ:3,epsilon:7,eras:3,error:3,esenti:3,estim:[5,8],evad:5,event:3,everi:[3,5,6],everyth:3,exampl:[0,3,4,6,7],execut:5,exist:3,exit:3,expect:[3,6],explain:[3,5,8],expos:2,extern:3,face:5,fact:3,fall:3,far:[3,4],faul:6,fault:6,featur:3,feel:[4,5],few:5,fill:3,find:3,finit:6,first:[3,7],flee:[5,8],flexibl:6,flock:0,flocking_behavior:0,follow:[2,3,5,6],followpath:[3,5],forc:3,form:[6,7],found:4,frame:3,free:4,from:[0,2,3,5,7,8],front:5,futur:5,game:[0,4,5,6,7,8],gameobejct:2,gameobject:[0,2,3,4,5,8],gener:[2,3,5,6],gentiti:3,get:[3,6],get_lin:2,get_press:3,get_rect:3,get_steer:[0,3,5,7,8],gibberish:3,given:[5,6,8],goal:[3,7],going:[0,3],good:6,gravity_ent:3,gravity_entitit:3,gravitycirclenpc:3,greater:7,green:3,ground:3,grow:3,guarante:3,guess:2,guid:4,half:3,hand:3,handl:3,has:[3,5],have:[1,3,4,5,6],height:[3,6],here:[3,5,8],hold:[2,7],horribl:3,how:[0,3,4,5,7],ignor:[6,7],imag:[2,3],img:3,img_surf:[2,3],implement:[0,2,3,4,5,7,8],improv:3,includ:[0,3],increas:3,increment:[3,6],index:4,indic:[0,5,6,7,8],individu:3,induc:3,infin:6,infinit:[3,6],init:3,initi:[2,3,6],input:3,insid:3,instal:[1,3],instanc:3,instanti:[2,3],instead:3,instruct:3,integr:3,intellig:4,interest:3,interfac:6,involv:[5,7,8],iter:[0,6],its:3,itself:5,just:[1,3,5,8],k_a:3,k_d:3,k_w:3,keep:[0,6,7],kei:3,kind:3,kinemat:[0,2,3,4,7],kinematicsteeringbehavior:[0,3,4,7],know:3,lambda:[0,5,6,7,8],land:3,last:[2,5,8],later:3,learn:3,leav:[0,5,7,8],length:3,less:3,let:3,librai:3,librari:[1,3,4],light:3,like:[0,3,4,6,7],linear:[0,2,3,5,7,8],linear_strength:5,list:[0,3,5,6,7],list_lik:2,littl:3,local:3,locat:0,look:[0,3,5],lookahead:5,lookwhereyourego:[0,5],loop:[2,3,5,8],lot:3,lowest:6,luckili:3,main:[1,3],mainli:4,major:4,make:[0,3,4,5,7,8],mani:3,match:5,math:[2,3,5,6,8],mathemat:3,max_accel:[2,3],max_angular_accel:[2,3],max_prediction_tim:5,max_rot:[2,3,8],max_spe:[2,3],maximum:[2,5,8],mayb:0,mean:[3,5,7],meaning:7,meant:[0,2,3,5,6,7,8],method:[0,2,3,5,6,8],might:[5,8],millisecond:3,mind:6,mirror:6,mirroredpath:[3,6],modifi:3,modul:[0,2,4,5,6,7,8],more:[0,7],most:[3,7],move:[0,3,4,5,8],move_ip:3,movement:[3,4,5,8],multipli:5,mybehavior:7,mypath:6,name:[0,3],neccesari:[0,3,7],need:[3,4,5,8],negat:3,negative_st:5,never:3,nevertheless:6,next:[5,6],non:2,none:[0,5,8],normal:[0,3,5,7,8],note:[3,5,8],noth:3,notic:6,now:[3,6],npc:3,null_steer:[5,8],null_surfac:2,nullsteer:[3,5],number:[5,6],object:[0,4,5,7,8],objectthat:5,obstacl:[0,5,7],obstacleavoid:[0,5,7],off:3,offset:[0,5,7,8],often:[3,4],onc:[3,5,6,8],oncecircumferencepath:6,one:[0,3,5,7,8],ones:[3,7],onli:[2,3,4,6,7],oper:5,opposit:5,option:[0,2,5,7,8],order:[3,6,7],orient:[2,5,8],origin:6,other:[2,5],otherwis:3,our:[3,4],out:3,output:[0,5,7,8],outsid:5,own:[0,3,6,7],packag:4,page:4,pai:[3,4],palcehold:2,parabola:6,parabola_path:6,paramet:[0,2,3,5,6,7,8],particular:[3,5,6,8],pass:[2,3],path:[4,5],path_cosin:3,path_func:[3,6],pathcircumfer:6,pathcosin:3,pathparabola:6,peopl:3,per:[5,8],period:8,perman:5,pick:3,piec:3,pip:4,place:3,placehold:[3,5,8],plain:3,player:[3,5],player_st:3,plu:3,point:[3,5,6],pos:[0,2,3,5,7,8],posit:[0,2,3,5,6,7,8],possibl:3,pre:[0,3],predict:5,prettier:0,previou:3,priorit:7,prioriti:4,priorityst:[3,4],probabbl:6,problem:3,produc:[0,3,6,7],progress:4,properti:[2,3,6],propperli:3,provid:[0,5,6],pseudo:4,purpos:2,purs:5,pursu:[5,7],put:3,pygam:[0,1,2,5,7,8],pygame_ai:[1,3,4],pypi:4,quick:2,quit:3,radian:6,radiu:[5,6,8],random:[5,8],randomli:8,rang:5,reach:[5,6,7],realli:3,recommend:3,rect:[2,3,6],rectangl:3,rectangular:5,red:3,regular:3,relat:3,relev:2,rememb:3,repres:3,request:[0,2,5,7,8],rerun:2,reset:[3,6],rest:[0,3],restart:3,result:6,rotat:[2,5,8],run:[1,3],same:[0,3,6],saw:3,screen:[0,2,3,5,7,8],screen_height:3,screen_width:3,scroll:[0,5,7,8],search:4,second:[3,5,8],see:[3,4,5],seek:[3,5,8],self:[2,3,6],semi:0,separ:[0,3,5],seri:[5,8],set:3,set_capt:3,set_mod:3,sever:0,shape:[3,5],should:[3,5,6,8],show:[1,3],simpl:[4,7],simpli:[3,4],sin:6,sinc:[0,2,3,5,6,8],singl:0,size:[2,5],slightli:[5,6,8],slow:5,slow_radiu:[0,5],smooth:5,smoothli:3,solid:0,some:[3,7],somegameobjectwitharect:6,someth:[3,6],sort:3,sourc:[0,2,5,6,7,8],space:[5,8],special:3,specialis:6,specifi:3,speed:[2,5,8],spooki:3,sprite:[0,2],squar:5,stai:[3,5],start:[3,5,6],staticsteeringbehavior:[0,4],stationari:5,steer:[0,2,5,6,7,8],steer_angular:2,steer_i:2,steer_x:[2,3],steeringoutput:[0,2,3,7],step:6,still:[3,4,5],stop:[3,5,8],stregth:3,strenght:5,strength:[3,5],stuck:3,sub:6,subclass:[3,5,8],submerg:3,sum:0,suppli:[5,8],support:0,sure:3,surfac:[0,2,3,5,7,8],swarm:0,sys:3,take:3,target:[0,5,7,8],target_radiu:[0,5],techniqu:4,techniquest:4,templat:[3,5,8],than:[3,7],thei:[0,3,5,7],them:[3,5,7],therefor:7,thi:[0,1,2,3,4,5,6,7,8],thing:[1,3],those:3,tick:[2,3,5,8],time:[2,3,5,7,8],time_to_arr:8,time_to_target:5,tip:6,togeth:[0,5,7,8],too:5,total:3,transcur:[5,8],transpar:3,travers:[5,6],treshold:[5,7],tri:[0,5],trial:3,trough:3,tupl:[0,6],type:[0,2,3,5,6,7,8],under:3,unexpect:5,unfamiliar:3,unfortun:3,unless:[3,5],until:5,unzip:1,updat:[2,3,5,6,8],use:[0,3,4,5,6],used:[0,2,3,4,5,6,7,8],useful:[2,3,6],useluess:6,user:3,uses:[3,5,6],using:[3,4,8],usual:3,valu:[0,2,3],variabl:3,vector2:[2,5,8],veloc:[2,3,5,8],velocitymatch:5,veri:7,version:0,videogam:4,visit:4,wai:[0,3,4,5,6,8],wander:[0,5,8],wander_offset:5,wander_r:5,wander_radiu:5,water:3,wave:3,weight:[0,3],well:3,were:3,what:[1,2,3],when:[2,3,7],where:[0,5],which:[0,3,5,6,7,8],white:3,whose:3,width:6,wise:5,won:3,word:3,work:[3,4],would:[0,3,5,7,8],wrote:3,you:[0,2,3,4,5,6,7],your:[0,3,5,6,7,8]},titles:["Blended","Example Game","Game Object","PyGame AI Guide","Welcome to Pygame AI\u2019s Documentation!","Kinematic","Path","Priority","Static"],titleterms:{"static":8,behavior:[3,4],behaviorandweight:0,blend:0,blendedst:0,complex:3,content:[3,4],core:4,document:4,drag:3,exampl:1,game:[1,2,3],graviti:3,guid:3,implement:6,indic:4,instal:4,kinemat:5,kinematicsteeringbehavior:5,more:3,object:[2,3],other:3,path:[3,6],pre:6,prioriti:7,priorityst:7,pygam:[3,4],simpl:3,special:6,staticsteeringbehavior:8,steer:[3,4],steeringoutput:[5,8],structur:3,stuff:3,tabl:4,todo:0,usag:4,veri:3,welcom:4}}) -------------------------------------------------------------------------------- /docs/blended.rst: -------------------------------------------------------------------------------- 1 | Blended 2 | ===================================== 3 | 4 | .. automodule:: steering.blended 5 | 6 | BehaviorAndWeight 7 | ----------------- 8 | 9 | .. autoclass:: BehaviorAndWeight 10 | :members: 11 | 12 | 13 | BlendedSteering 14 | --------------- 15 | 16 | .. autoclass:: BlendedSteering 17 | :members: 18 | 19 | .. autoclass:: Arrive 20 | 21 | .. autoclass:: Flocking 22 | 23 | .. autoclass:: Wander 24 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Pygame AI documentation build configuration file, created by 5 | # sphinx-quickstart on Fri May 24 11:36:38 2019. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | import sys 17 | import os 18 | 19 | # If extensions (or modules to document with autodoc) are in another directory, 20 | # add these directories to sys.path here. If the directory is relative to the 21 | # documentation root, use os.path.abspath to make it absolute, like shown here. 22 | sys.path.insert(0, os.path.abspath('../pygame_ai/')) 23 | 24 | # -- General configuration ------------------------------------------------ 25 | 26 | # If your documentation needs a minimal Sphinx version, state it here. 27 | #needs_sphinx = '1.0' 28 | 29 | # Add any Sphinx extension module names here, as strings. They can be 30 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 31 | # ones. 32 | extensions = [ 33 | 'sphinx.ext.autodoc', 34 | 'sphinx.ext.doctest', 35 | 'sphinx.ext.intersphinx', 36 | 'sphinx.ext.todo', 37 | 'sphinx.ext.coverage', 38 | #'sphinx.ext.pngmath', 39 | 'sphinx.ext.ifconfig', 40 | 'sphinx.ext.viewcode', 41 | 'sphinx.ext.extlinks', 42 | 'sphinx.ext.napoleon', 43 | ] 44 | 45 | # Add any paths that contain templates here, relative to this directory. 46 | templates_path = ['_templates'] 47 | 48 | # The suffix(es) of source filenames. 49 | # You can specify multiple suffix as a list of string: 50 | # source_suffix = ['.rst', '.md'] 51 | source_suffix = '.rst' 52 | 53 | # The encoding of source files. 54 | #source_encoding = 'utf-8-sig' 55 | 56 | # The master toctree document. 57 | master_doc = 'index' 58 | 59 | # General information about the project. 60 | project = 'Pygame AI' 61 | copyright = '2019, Nek' 62 | author = 'Nek' 63 | 64 | # The version info for the project you're documenting, acts as replacement for 65 | # |version| and |release|, also used in various other places throughout the 66 | # built documents. 67 | # 68 | # The short X.Y version. 69 | version = '0.1' 70 | # The full version, including alpha/beta/rc tags. 71 | release = '0.1' 72 | 73 | # The language for content autogenerated by Sphinx. Refer to documentation 74 | # for a list of supported languages. 75 | # 76 | # This is also used if you do content translation via gettext catalogs. 77 | # Usually you set "language" from the command line for these cases. 78 | language = None 79 | 80 | # There are two options for replacing |today|: either, you set today to some 81 | # non-false value, then it is used: 82 | #today = '' 83 | # Else, today_fmt is used as the format for a strftime call. 84 | #today_fmt = '%B %d, %Y' 85 | 86 | # List of patterns, relative to source directory, that match files and 87 | # directories to ignore when looking for source files. 88 | exclude_patterns = ['_build'] 89 | 90 | # The reST default role (used for this markup: `text`) to use for all 91 | # documents. 92 | #default_role = None 93 | 94 | # If true, '()' will be appended to :func: etc. cross-reference text. 95 | #add_function_parentheses = True 96 | 97 | # If true, the current module name will be prepended to all description 98 | # unit titles (such as .. function::). 99 | #add_module_names = True 100 | 101 | # If true, sectionauthor and moduleauthor directives will be shown in the 102 | # output. They are ignored by default. 103 | #show_authors = False 104 | 105 | # The name of the Pygments (syntax highlighting) style to use. 106 | pygments_style = 'sphinx' 107 | 108 | # A list of ignored prefixes for module index sorting. 109 | #modindex_common_prefix = [] 110 | 111 | # If true, keep warnings as "system message" paragraphs in the built documents. 112 | #keep_warnings = False 113 | 114 | # If true, `todo` and `todoList` produce output, else they produce nothing. 115 | todo_include_todos = True 116 | 117 | 118 | # -- Options for HTML output ---------------------------------------------- 119 | 120 | # The theme to use for HTML and HTML Help pages. See the documentation for 121 | # a list of builtin themes. 122 | html_theme = 'alabaster' 123 | 124 | # Theme options are theme-specific and customize the look and feel of a theme 125 | # further. For a list of options available for each theme, see the 126 | # documentation. 127 | #html_theme_options = {} 128 | 129 | # Add any paths that contain custom themes here, relative to this directory. 130 | #html_theme_path = [] 131 | 132 | # The name for this set of Sphinx documents. If None, it defaults to 133 | # " v documentation". 134 | #html_title = None 135 | 136 | # A shorter title for the navigation bar. Default is the same as html_title. 137 | #html_short_title = None 138 | 139 | # The name of an image file (relative to this directory) to place at the top 140 | # of the sidebar. 141 | #html_logo = None 142 | 143 | # The name of an image file (relative to this directory) to use as a favicon of 144 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 145 | # pixels large. 146 | #html_favicon = None 147 | 148 | # Add any paths that contain custom static files (such as style sheets) here, 149 | # relative to this directory. They are copied after the builtin static files, 150 | # so a file named "default.css" will overwrite the builtin "default.css". 151 | html_static_path = ['_static'] 152 | 153 | # Add any extra paths that contain custom files (such as robots.txt or 154 | # .htaccess) here, relative to this directory. These files are copied 155 | # directly to the root of the documentation. 156 | #html_extra_path = [] 157 | 158 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 159 | # using the given strftime format. 160 | #html_last_updated_fmt = '%b %d, %Y' 161 | 162 | # If true, SmartyPants will be used to convert quotes and dashes to 163 | # typographically correct entities. 164 | #html_use_smartypants = True 165 | 166 | # Custom sidebar templates, maps document names to template names. 167 | #html_sidebars = {} 168 | 169 | # Additional templates that should be rendered to pages, maps page names to 170 | # template names. 171 | #html_additional_pages = {} 172 | 173 | # If false, no module index is generated. 174 | #html_domain_indices = True 175 | 176 | # If false, no index is generated. 177 | #html_use_index = True 178 | 179 | # If true, the index is split into individual pages for each letter. 180 | #html_split_index = False 181 | 182 | # If true, links to the reST sources are added to the pages. 183 | #html_show_sourcelink = True 184 | 185 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 186 | #html_show_sphinx = True 187 | 188 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 189 | #html_show_copyright = True 190 | 191 | # If true, an OpenSearch description file will be output, and all pages will 192 | # contain a tag referring to it. The value of this option must be the 193 | # base URL from which the finished HTML is served. 194 | #html_use_opensearch = '' 195 | 196 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 197 | #html_file_suffix = None 198 | 199 | # Language to be used for generating the HTML full-text search index. 200 | # Sphinx supports the following languages: 201 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' 202 | # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr' 203 | #html_search_language = 'en' 204 | 205 | # A dictionary with options for the search language support, empty by default. 206 | # Now only 'ja' uses this config value 207 | #html_search_options = {'type': 'default'} 208 | 209 | # The name of a javascript file (relative to the configuration directory) that 210 | # implements a search results scorer. If empty, the default will be used. 211 | #html_search_scorer = 'scorer.js' 212 | 213 | # Output file base name for HTML help builder. 214 | htmlhelp_basename = 'PygameAIdoc' 215 | 216 | # -- Options for LaTeX output --------------------------------------------- 217 | 218 | latex_elements = { 219 | # The paper size ('letterpaper' or 'a4paper'). 220 | #'papersize': 'letterpaper', 221 | 222 | # The font size ('10pt', '11pt' or '12pt'). 223 | #'pointsize': '10pt', 224 | 225 | # Additional stuff for the LaTeX preamble. 226 | #'preamble': '', 227 | 228 | # Latex figure (float) alignment 229 | #'figure_align': 'htbp', 230 | } 231 | 232 | # Grouping the document tree into LaTeX files. List of tuples 233 | # (source start file, target name, title, 234 | # author, documentclass [howto, manual, or own class]). 235 | latex_documents = [ 236 | (master_doc, 'PygameAI.tex', 'Pygame AI Documentation', 237 | 'Nek', 'manual'), 238 | ] 239 | 240 | # The name of an image file (relative to this directory) to place at the top of 241 | # the title page. 242 | #latex_logo = None 243 | 244 | # For "manual" documents, if this is true, then toplevel headings are parts, 245 | # not chapters. 246 | #latex_use_parts = False 247 | 248 | # If true, show page references after internal links. 249 | #latex_show_pagerefs = False 250 | 251 | # If true, show URL addresses after external links. 252 | #latex_show_urls = False 253 | 254 | # Documents to append as an appendix to all manuals. 255 | #latex_appendices = [] 256 | 257 | # If false, no module index is generated. 258 | #latex_domain_indices = True 259 | 260 | 261 | # -- Options for manual page output --------------------------------------- 262 | 263 | # One entry per manual page. List of tuples 264 | # (source start file, name, description, authors, manual section). 265 | man_pages = [ 266 | (master_doc, 'pygameai', 'Pygame AI Documentation', 267 | [author], 1) 268 | ] 269 | 270 | # If true, show URL addresses after external links. 271 | #man_show_urls = False 272 | 273 | 274 | # -- Options for Texinfo output ------------------------------------------- 275 | 276 | # Grouping the document tree into Texinfo files. List of tuples 277 | # (source start file, target name, title, author, 278 | # dir menu entry, description, category) 279 | texinfo_documents = [ 280 | (master_doc, 'PygameAI', 'Pygame AI Documentation', 281 | author, 'PygameAI', 'One line description of project.', 282 | 'Miscellaneous'), 283 | ] 284 | 285 | # Documents to append as an appendix to all manuals. 286 | #texinfo_appendices = [] 287 | 288 | # If false, no module index is generated. 289 | #texinfo_domain_indices = True 290 | 291 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 292 | #texinfo_show_urls = 'footnote' 293 | 294 | # If true, do not generate a @detailmenu in the "Top" node's menu. 295 | #texinfo_no_detailmenu = False 296 | 297 | 298 | # Example configuration for intersphinx: refer to the Python standard library. 299 | intersphinx_mapping = {'https://docs.python.org/': None} 300 | 301 | 302 | # -- Options for ExtLinks ---------------------------------------------- 303 | extlinks = { 304 | 'pgmath': ('https://www.pygame.org/docs/ref/math.html#pygame.math.%s', 'pygame.math.'), 305 | 'pgsurf': ('https://www.pygame.org/docs/ref/surface.html#pygame.%s', 'pygame.'), 306 | 'pgrect': ('https://www.pygame.org/docs/ref/rect.html#pygame.%s', 'pygame.'), 307 | 'pgsprite': ('https://www.pygame.org/docs/ref/sprite.html#pygame.sprite.%s', 'pygame.sprite.'), 308 | } 309 | -------------------------------------------------------------------------------- /docs/example_game.rst: -------------------------------------------------------------------------------- 1 | .. _example_game: 2 | 3 | Example Game 4 | ============ 5 | 6 | This game shows examples of what things can be done with the library, 7 | to run it just unzip and run main.py while having **pygame** and **pygame_ai** 8 | installed. 9 | 10 | * `Download Example Game `_ 11 | -------------------------------------------------------------------------------- /docs/gameobject.rst: -------------------------------------------------------------------------------- 1 | Game Object 2 | ===================================== 3 | 4 | .. automodule:: gameobject 5 | :members: 6 | :exclude-members: GameObject 7 | 8 | .. autoclass:: GameObject 9 | :members: 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to Pygame AI's Documentation! 2 | ===================================== 3 | 4 | Pygame AI is a package that aims at implementing a bunch of common 5 | algorithms and techniques often used in Videogame AI. It is still a work 6 | in progress. 7 | 8 | Installation 9 | ------------ 10 | 11 | The package is available at PyPI, you can simply do: 12 | 13 | pip install pygame-ai 14 | 15 | Usage 16 | ----- 17 | 18 | After installing it you only need to import like: 19 | 20 | import pygame_ai 21 | 22 | or 23 | 24 | import pygame_ai as pai 25 | 26 | Core 27 | ---- 28 | 29 | All of this library's implementations work using this implementation 30 | of :py:class:`~.GameObject`. 31 | 32 | You can see how the library works by downloading our :ref:`example_game`, or 33 | you can visit the :ref:`guide` to see how to implement a simple game 34 | using the library's core functions. 35 | 36 | So far these are the major techniquest that have been implemented: 37 | 38 | Steering Behaviors 39 | ------------------ 40 | 41 | Basic movement behaviors that make in-game characters move in a 42 | pseudo-intelligent way. You will mainly be using 43 | :py:class:`~.BlendedSteering` and :py:class:`~.PrioritySteering`, 44 | but feel free to use any of the behaviors found in 45 | :py:mod:`~steering.kinematic` and :py:mod:`~steering.static` modules. 46 | 47 | * :py:class:`~.StaticSteeringBehavior` 48 | * :py:class:`~.KinematicSteeringBehavior` 49 | * :py:class:`~.BlendedSteering` 50 | * :py:class:`~.PrioritySteering` 51 | 52 | Table of Contents 53 | ================= 54 | 55 | .. toctree:: 56 | :maxdepth: 1 57 | 58 | gameobject 59 | static 60 | kinematic 61 | blended 62 | priority 63 | path 64 | example_game 65 | guide 66 | 67 | Indices and tables 68 | ================== 69 | 70 | * :ref:`genindex` 71 | * :ref:`search` 72 | 73 | -------------------------------------------------------------------------------- /docs/kinematic.rst: -------------------------------------------------------------------------------- 1 | Kinematic 2 | ===================================== 3 | 4 | .. automodule:: steering.kinematic 5 | 6 | SteeringOutput 7 | -------------- 8 | 9 | 10 | .. autoclass:: SteeringOutput 11 | :members: 12 | 13 | .. automethod:: steering.kinematic.negative_steering 14 | 15 | .. autodata:: null_steering 16 | :annotation: 17 | 18 | KinematicSteeringBehavior 19 | ------------------------- 20 | 21 | .. autoclass:: KinematicSteeringBehavior 22 | :members: 23 | 24 | .. autoclass:: Align 25 | 26 | .. autoclass:: Arrive 27 | 28 | .. autoclass:: CollisionAvoidance 29 | 30 | .. autoclass:: Drag 31 | 32 | .. autoclass:: Evade 33 | 34 | .. autoclass:: Face 35 | 36 | .. autoclass:: Flee 37 | 38 | .. autoclass:: FollowPath 39 | 40 | .. autoclass:: LookWhereYoureGoing 41 | 42 | .. autoclass:: NullSteering 43 | 44 | .. autoclass:: ObstacleAvoidance 45 | 46 | .. autoclass:: Pursue 47 | 48 | .. autoclass:: Seek 49 | 50 | .. autoclass:: Separation 51 | 52 | .. autoclass:: VelocityMatch 53 | 54 | .. autoclass:: Wander 55 | 56 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | echo. coverage to run coverage check of the documentation if enabled 41 | goto end 42 | ) 43 | 44 | if "%1" == "clean" ( 45 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 46 | del /q /s %BUILDDIR%\* 47 | goto end 48 | ) 49 | 50 | 51 | REM Check if sphinx-build is available and fallback to Python version if any 52 | %SPHINXBUILD% 1>NUL 2>NUL 53 | if errorlevel 9009 goto sphinx_python 54 | goto sphinx_ok 55 | 56 | :sphinx_python 57 | 58 | set SPHINXBUILD=python -m sphinx.__init__ 59 | %SPHINXBUILD% 2> nul 60 | if errorlevel 9009 ( 61 | echo. 62 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 63 | echo.installed, then set the SPHINXBUILD environment variable to point 64 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 65 | echo.may add the Sphinx directory to PATH. 66 | echo. 67 | echo.If you don't have Sphinx installed, grab it from 68 | echo.http://sphinx-doc.org/ 69 | exit /b 1 70 | ) 71 | 72 | :sphinx_ok 73 | 74 | 75 | if "%1" == "html" ( 76 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 77 | if errorlevel 1 exit /b 1 78 | echo. 79 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 80 | goto end 81 | ) 82 | 83 | if "%1" == "dirhtml" ( 84 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 85 | if errorlevel 1 exit /b 1 86 | echo. 87 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 88 | goto end 89 | ) 90 | 91 | if "%1" == "singlehtml" ( 92 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 93 | if errorlevel 1 exit /b 1 94 | echo. 95 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 96 | goto end 97 | ) 98 | 99 | if "%1" == "pickle" ( 100 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 101 | if errorlevel 1 exit /b 1 102 | echo. 103 | echo.Build finished; now you can process the pickle files. 104 | goto end 105 | ) 106 | 107 | if "%1" == "json" ( 108 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 109 | if errorlevel 1 exit /b 1 110 | echo. 111 | echo.Build finished; now you can process the JSON files. 112 | goto end 113 | ) 114 | 115 | if "%1" == "htmlhelp" ( 116 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 117 | if errorlevel 1 exit /b 1 118 | echo. 119 | echo.Build finished; now you can run HTML Help Workshop with the ^ 120 | .hhp project file in %BUILDDIR%/htmlhelp. 121 | goto end 122 | ) 123 | 124 | if "%1" == "qthelp" ( 125 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 129 | .qhcp project file in %BUILDDIR%/qthelp, like this: 130 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\PygameAI.qhcp 131 | echo.To view the help file: 132 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\PygameAI.ghc 133 | goto end 134 | ) 135 | 136 | if "%1" == "devhelp" ( 137 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 138 | if errorlevel 1 exit /b 1 139 | echo. 140 | echo.Build finished. 141 | goto end 142 | ) 143 | 144 | if "%1" == "epub" ( 145 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 146 | if errorlevel 1 exit /b 1 147 | echo. 148 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 149 | goto end 150 | ) 151 | 152 | if "%1" == "latex" ( 153 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 154 | if errorlevel 1 exit /b 1 155 | echo. 156 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 157 | goto end 158 | ) 159 | 160 | if "%1" == "latexpdf" ( 161 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 162 | cd %BUILDDIR%/latex 163 | make all-pdf 164 | cd %~dp0 165 | echo. 166 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 167 | goto end 168 | ) 169 | 170 | if "%1" == "latexpdfja" ( 171 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 172 | cd %BUILDDIR%/latex 173 | make all-pdf-ja 174 | cd %~dp0 175 | echo. 176 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 177 | goto end 178 | ) 179 | 180 | if "%1" == "text" ( 181 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 182 | if errorlevel 1 exit /b 1 183 | echo. 184 | echo.Build finished. The text files are in %BUILDDIR%/text. 185 | goto end 186 | ) 187 | 188 | if "%1" == "man" ( 189 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 190 | if errorlevel 1 exit /b 1 191 | echo. 192 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 193 | goto end 194 | ) 195 | 196 | if "%1" == "texinfo" ( 197 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 198 | if errorlevel 1 exit /b 1 199 | echo. 200 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 201 | goto end 202 | ) 203 | 204 | if "%1" == "gettext" ( 205 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 206 | if errorlevel 1 exit /b 1 207 | echo. 208 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 209 | goto end 210 | ) 211 | 212 | if "%1" == "changes" ( 213 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 214 | if errorlevel 1 exit /b 1 215 | echo. 216 | echo.The overview file is in %BUILDDIR%/changes. 217 | goto end 218 | ) 219 | 220 | if "%1" == "linkcheck" ( 221 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 222 | if errorlevel 1 exit /b 1 223 | echo. 224 | echo.Link check complete; look for any errors in the above output ^ 225 | or in %BUILDDIR%/linkcheck/output.txt. 226 | goto end 227 | ) 228 | 229 | if "%1" == "doctest" ( 230 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 231 | if errorlevel 1 exit /b 1 232 | echo. 233 | echo.Testing of doctests in the sources finished, look at the ^ 234 | results in %BUILDDIR%/doctest/output.txt. 235 | goto end 236 | ) 237 | 238 | if "%1" == "coverage" ( 239 | %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage 240 | if errorlevel 1 exit /b 1 241 | echo. 242 | echo.Testing of coverage in the sources finished, look at the ^ 243 | results in %BUILDDIR%/coverage/python.txt. 244 | goto end 245 | ) 246 | 247 | if "%1" == "xml" ( 248 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 249 | if errorlevel 1 exit /b 1 250 | echo. 251 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 252 | goto end 253 | ) 254 | 255 | if "%1" == "pseudoxml" ( 256 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 257 | if errorlevel 1 exit /b 1 258 | echo. 259 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 260 | goto end 261 | ) 262 | 263 | :end 264 | -------------------------------------------------------------------------------- /docs/path.rst: -------------------------------------------------------------------------------- 1 | Path 2 | ==== 3 | 4 | .. automodule:: steering.path 5 | 6 | Path 7 | ---- 8 | 9 | .. autoclass:: Path 10 | :members: 11 | 12 | Special Paths 13 | ------------- 14 | 15 | .. autoclass:: CyclicPath 16 | :members: 17 | 18 | .. autoclass:: MirroredPath 19 | :members: 20 | 21 | Pre-implemented Paths 22 | --------------------- 23 | 24 | .. autoclass:: PathCircumference 25 | :members: 26 | 27 | .. autoclass:: PathParabola 28 | :members: 29 | -------------------------------------------------------------------------------- /docs/priority.rst: -------------------------------------------------------------------------------- 1 | Priority 2 | ===================================== 3 | 4 | .. automodule:: steering.priority 5 | 6 | PrioritySteering 7 | ---------------- 8 | 9 | .. autoclass:: PrioritySteering 10 | :members: 11 | -------------------------------------------------------------------------------- /docs/static.rst: -------------------------------------------------------------------------------- 1 | Static 2 | ===================================== 3 | 4 | .. automodule:: steering.static 5 | 6 | SteeringOutput 7 | -------------- 8 | 9 | .. autoclass:: SteeringOutput 10 | :members: 11 | 12 | .. autodata:: null_steering 13 | :annotation: 14 | 15 | StaticSteeringBehavior 16 | ------------------------- 17 | 18 | .. autoclass:: StaticSteeringBehavior 19 | :members: 20 | 21 | .. autoclass:: Arrive 22 | 23 | .. autoclass:: Flee 24 | 25 | .. autoclass:: Seek 26 | 27 | .. autoclass:: Wander 28 | 29 | -------------------------------------------------------------------------------- /pygame_ai/__init__.py: -------------------------------------------------------------------------------- 1 | from . import gameobject 2 | from . import steering 3 | from . import utils 4 | -------------------------------------------------------------------------------- /pygame_ai/colors.py: -------------------------------------------------------------------------------- 1 | 2 | WHITE = (255, 255, 255) 3 | BLACK = ( 0, 0, 0) 4 | 5 | RED = (255, 0, 0) 6 | GREEN = ( 0, 255, 0) 7 | BLUE = ( 0, 0, 255) 8 | 9 | YELLOW = (255, 255, 0) 10 | CYAN = ( 0, 255, 255) 11 | PURPLE = (255, 0, 255) 12 | -------------------------------------------------------------------------------- /pygame_ai/gameobject.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ General-Purpose Game Object 3 | 4 | This module implements the GameObject class, core of this AI engine, 5 | along with other useful classes, methods and constants 6 | """ 7 | import pygame 8 | from pygame_ai.utils import list_utils 9 | 10 | null_surface = pygame.Surface((0, 0)) 11 | """ (:pgsurf:`Surface`) : Empty Surface with size 0 """ 12 | 13 | class GameObject(pygame.sprite.Sprite): 14 | """ General-Purpose Game Object. 15 | 16 | Derives from :pgsprite:`Sprite`. 17 | 18 | Holds values relevant to any non-static entity in the game. 19 | 20 | Parameters 21 | ---------- 22 | 23 | img_surf: :pgsurf:`Surface` 24 | It is asigned to self.image, defaults to :const:`null_surface` 25 | pos: list_like(int, int), optional 26 | Initial Position, it is assigned to self.rect.center 27 | max_speed: int, optional 28 | Maximum linear speed 29 | max_accel: int, optional 30 | Maximum linear acceleration 31 | max_rotation: int, optional 32 | Maximum angular speed 33 | max_angular_accel: int, optional 34 | Maximum angular acceleration 35 | 36 | 37 | This class exposes the following public properties and methods 38 | 39 | Attributes 40 | ---------- 41 | 42 | image: :pgsurf:`Surface` 43 | Surface to be blited to screen 44 | rect: :pgrect:`Rect` 45 | Derived from image, it's center is the GameObejct's position 46 | position: :pgmath:`Vector2` 47 | Current position 48 | velocity: :pgmath:`Vector2` 49 | Current velocity 50 | max_speed: int 51 | Maximum linear speed 52 | max_accel: int 53 | Maximum linear acceleration 54 | orientation: int 55 | Current orientation in degrees 56 | rotation: int 57 | Current angular velocity 58 | max_rotation: int 59 | Maximum angular speed 60 | max_angular_accel: int 61 | Maximum angular acceleration 62 | """ 63 | def __init__(self, img_surf = null_surface, pos = (0, 0), max_speed = 30, max_accel = 20, max_rotation = 60, max_angular_accel = 50): 64 | """ 65 | Constructor 66 | """ 67 | super(GameObject, self).__init__() 68 | self.original_image = img_surf 69 | self.image = self.original_image.copy() 70 | self.rect = self.image.get_rect() 71 | self.rect.center = pos 72 | self.velocity = pygame.Vector2(0, 0) 73 | self.max_speed = max_speed 74 | self.max_accel = max_accel 75 | self.orientation = 0 76 | self.rotation = 0 77 | self.max_rotation = max_rotation 78 | self.max_angular_accel = max_angular_accel 79 | 80 | @property 81 | def position(self): 82 | return pygame.Vector2(self.rect.center) 83 | 84 | @position.setter 85 | def position(self, pos): 86 | self.rect.center = pos 87 | 88 | def steer(self, steering, tick): 89 | """ Updates GameObject's velocity and rotation 90 | 91 | Parameters 92 | ---------- 93 | steering: :py:class:`.kinematic.SteeringOutput` or :py:class:.`static.SteeringOutput` 94 | The steering request to update velocity and rotation 95 | tick: int 96 | Time passed since the last loop 97 | """ 98 | self.velocity += steering.linear * tick 99 | self.rotation += steering.angular * tick 100 | 101 | if self.velocity.length() > self.max_speed: 102 | self.velocity.normalize_ip() 103 | self.velocity *= self.max_speed 104 | 105 | def steer_x(self, steering, tick): 106 | """ Updates GameObject's velocity along the x axis 107 | 108 | Parameters 109 | ---------- 110 | steering: :py:class:`.kinematic.SteeringOutput` or :py:class:.`static.SteeringOutput` 111 | The steering request to update velocity and rotation 112 | tick: int 113 | Time passed since the last loop 114 | """ 115 | steering_x = steering.copy() 116 | steering_x.linear[1] = 0 117 | steering_x.angular = 0 118 | 119 | self.velocity += steering_x.linear * tick 120 | 121 | if self.velocity[0] > self.max_speed: 122 | self.velocity[0] = self.max_speed 123 | #self.steer(steering_x, tick) 124 | 125 | def steer_y(self, steering, tick): 126 | """ Updates GameObject's velocity along the y axis 127 | 128 | Parameters 129 | ---------- 130 | steering: :py:class:`.kinematic.SteeringOutput` or :py:class:.`static.SteeringOutput` 131 | The steering request to update velocity and rotation 132 | tick: int 133 | Time passed since the last loop 134 | """ 135 | steering_y = steering.copy() 136 | steering_y.linear[0] = 0 137 | steering_y.angular = 0 138 | 139 | self.velocity += steering_y.linear * tick 140 | 141 | if self.velocity[1] > self.max_speed: 142 | self.velocity[1] = self.max_speed 143 | 144 | #self.steer(steering_y, tick) 145 | 146 | def steer_angular(self, steering, tick): 147 | """ Updates GameObject's rotation 148 | 149 | Parameters 150 | ---------- 151 | steering: :py:class:`.kinematic.SteeringOutput` or :py:class:.`static.SteeringOutput` 152 | The steering request to update velocity and rotation 153 | tick: int 154 | Time passed since the last loop 155 | """ 156 | steering_angular = steering.copy() 157 | steering_angular.linear[0], steering_angular.linear[1] = 0, 0 158 | self.steer(steering_angular) 159 | 160 | def get_lines(self): 161 | """ Reruns what it returns, can you guess what it is? """ 162 | left = [self.rect.topleft, self.rect.bottomleft] 163 | top = [self.rect.topleft, self.rect.topright] 164 | right = [self.rect.topright, self.rect.bottomright] 165 | bottom = [self.rect.bottomright, self.rect.bottomleft] 166 | 167 | return [left, top, right, bottom] 168 | 169 | 170 | class DummyGameObject(GameObject): 171 | """ A Dummy with :py:class:`GameObject` properties 172 | 173 | Derives from :py:class:`GameObject`. 174 | 175 | Used for quick instantiation when creating :py:class:`GameObject` s 176 | that will only be used as palceholders and are not meant to appear 177 | on screen. 178 | 179 | Parameters 180 | ---------- 181 | 182 | position: list_like(int, int) 183 | Current position 184 | """ 185 | def __init__(self, position = (0, 0)): 186 | """ Constructor 187 | """ 188 | super(DummyGameObject, self).__init__(pos = position, max_speed = 0, max_accel = 0, max_rotation = 0, max_angular_accel = 0) 189 | -------------------------------------------------------------------------------- /pygame_ai/steering/__init__.py: -------------------------------------------------------------------------------- 1 | from . import blended 2 | from . import path 3 | from . import priority 4 | from . import static 5 | from . import kinematic 6 | 7 | -------------------------------------------------------------------------------- /pygame_ai/steering/blended.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ Blended Steering Behaviors 3 | 4 | This module implements a class that Blends a list of 5 | :py:class:`~.KinematicSteeringBehavior` s and provides 6 | a weighted sum of their outputs as a steering request. 7 | 8 | This is the bread and butter of **Steering Behaviors** since it easily 9 | combines different behaviors that allow for semi-complex AI behaviors. 10 | 11 | Derives from :py:class:`~.kinematic.KinematicSteeringBehavior`. 12 | 13 | Example 14 | -------- 15 | 16 | This is how you would normally create your own :py:class:`~BlendedSteering` , 17 | in this case we are making a more complex version of :py:class:`~steering.kinematic.Arrive` 18 | where the character looks where it's going and also tries to avoid any 19 | obstacle in the way. 20 | 21 | .. code-block:: python 22 | 23 | flocking_behavior = BlendedSteering( 24 | character = character 25 | behaviors = [ 26 | BehaviorAndWeight(kinematic.Arrive(character, target), weight = 1), 27 | BehaviorAndWeight(kinematic.LookWhereYoureGoing(character), weight = 1), 28 | BehaviorAndWeight(kinematic.ObstacleAvoidance(character, obstacles), weight = 2), 29 | ] 30 | ) 31 | 32 | 33 | This module also includes a couple of pre-implemented :py:class:`BlendedSteering`. 34 | 35 | 36 | .. todo:: Make BehaviorAndWeight prettier, maybe use named tuples? 37 | 38 | """ 39 | 40 | from . import kinematic 41 | from . import path 42 | from pygame_ai.gameobject import DummyGameObject 43 | 44 | class BehaviorAndWeight(object): 45 | """ Container for Behavior and Weight values 46 | 47 | Parameters 48 | ---------- 49 | behavior: :py:class:`~.KinematicSteeringBehavior` 50 | weight: int 51 | """ 52 | 53 | def __init__(self, behavior, weight): 54 | self.behavior = behavior 55 | self.weight = weight 56 | 57 | class BlendedSteering(kinematic.KinematicSteeringBehavior): 58 | """ Base Blended Steering 59 | 60 | This class provides methods neccesary to combine the list of steering 61 | behaviors and produce a single :py:class:`~.kinematic.SteeringOutput`. 62 | 63 | Derives from :py:class:`~.KinematicSteeringBehavior`, currently 64 | :py:class:`BlendedSteering` with :py:class:`~.StaticSteeringBehavior` 65 | is not supported. 66 | 67 | Parameters 68 | ---------- 69 | character: :py:class:`~gameobject.GameObject` 70 | Character with this behavior 71 | behaviors: list(:py:class:`~.BehaviorAndWeight`) 72 | List of behaviors that compose this :py:class:`~.BlendedSteering` 73 | """ 74 | 75 | def __init__(self, character, behaviors): 76 | self.character = character 77 | self.behaviors = behaviors 78 | 79 | def __repr__(self): 80 | return 'BlendedSteering '+super(BlendedSteering, self).__repr__() 81 | 82 | def draw_indicators(self, screen, offset = (lambda pos: pos)): 83 | """ Draws appropiate indicators for this :py:class:`BlendedSteering` 84 | 85 | Draws the indicators of all :py:class:`~.KinematicSteeringBehavior` 86 | that compose this :py:class:`~.BlendedSteering`. 87 | 88 | Parameters 89 | ---------- 90 | screen: :pgsurf:`Surface` 91 | Surface in which to draw indicators, normally this would be the screen Surface 92 | offset: function, optional 93 | Function that applies an offset to the object's position 94 | 95 | This is meant to be used together with scrolling cameras, 96 | leave empty if your game doesn't implement one,it defaults 97 | to a linear function f(pos) -> pos 98 | """ 99 | for behavior in self.behaviors: 100 | behavior.behavior.draw_indicators(screen, offset) 101 | 102 | def get_steering(self): 103 | """ Returns the combined steering request of this :py:class:`~BlendedSteering` 104 | 105 | Returns 106 | ------- 107 | :py:class:`SteeringOutput` 108 | Requested steering 109 | """ 110 | # Output steering for accumulating 111 | steering = kinematic.SteeringOutput() 112 | 113 | # Accumulate all accelerations 114 | for behavior in self.behaviors: 115 | steering += behavior.behavior.get_steering() * behavior.weight 116 | 117 | # Crop the results and return 118 | steering_lin_accel = steering.linear.length() 119 | if steering_lin_accel > self.character.max_accel: 120 | steering.linear /= steering_lin_accel 121 | steering.linear *= self.character.max_accel 122 | 123 | steering_angular_accel = steering.angular 124 | if steering_angular_accel > self.character.max_angular_accel: 125 | steering.angular /= steering_angular_accel 126 | steering.angular *= self.character.max_angular_accel 127 | 128 | return steering 129 | 130 | class Flocking(BlendedSteering): 131 | """ :py:class:`~.BlendedSteering` that makes the character move in a flock-like way 132 | 133 | This behavior is meant to be used with several characters, they will all 134 | try to **Arive** at the same target location while **Looking Where They're Going** 135 | and keeping **Separated** from eachother. 136 | 137 | Parameters 138 | ---------- 139 | character: :py:class:`~.GameObject` 140 | swarm: iterable(:pgsprite:`Sprite`) 141 | Rest of the entities that conform the Flock 142 | target: :py:class:`~.GameObject` 143 | """ 144 | 145 | def __init__(self, character, swarm, target): 146 | behaviors = [ 147 | BehaviorAndWeight(kinematic.Separation(character, swarm), 3), 148 | BehaviorAndWeight(kinematic.Arrive(character, target), 1), 149 | BehaviorAndWeight(kinematic.LookWhereYoureGoing(character), 1), 150 | ] 151 | super(Flocking, self).__init__(character, behaviors) 152 | 153 | class Wander(BlendedSteering): 154 | """ :py:class:`~.BlendedSteering` that makes the character **Wander** around. 155 | 156 | This behaviors is a more complex version of :py:class:`~.kinematic.Wander` 157 | that also tries to **Avoid Obstacles**. 158 | 159 | Parameters 160 | ---------- 161 | character: :py:class:`~.GameObject` 162 | obstacles: iterable(:pgsprite:`Sprite`) 163 | Solid obstacles 164 | """ 165 | 166 | def __init__(self, character, obstacles): 167 | behaviors = [ 168 | # Wander 169 | BehaviorAndWeight( 170 | kinematic.Wander(character), 171 | weight = 1), 172 | # ObstacleAvoidance 173 | BehaviorAndWeight( 174 | kinematic.ObstacleAvoidance(character, obstacles), 175 | weight = 4), 176 | # LookWhereYoureGoing 177 | BehaviorAndWeight( 178 | kinematic.LookWhereYoureGoing(character), 179 | weight = 2), 180 | ] 181 | super(Wander, self).__init__(character, behaviors) 182 | 183 | class Arrive(BlendedSteering): 184 | """ :py:class:`~.BlendedSteering` that makes the character **Arrive** at a target 185 | 186 | This is behavior is a more complex version of :py:class:`~.kinematic.Arrive` 187 | that also **Looks Where it's Going** and tries to **Avoid Obstacles**. 188 | 189 | Parameters 190 | ---------- 191 | character: :py:class:`~.GameObject` 192 | target: :py:class:`~.GameObject` 193 | obstacles: iterable(:pgsprite:`Sprite`) 194 | Solid obstacles 195 | """ 196 | 197 | def __init__(self, character, target, obstacles, target_radius = None, slow_radius = None): 198 | behaviors = [ 199 | # Arrive 200 | BehaviorAndWeight( 201 | kinematic.Arrive(character, target, target_radius, slow_radius), 202 | weight = 1), 203 | # ObstacleAvoidance 204 | BehaviorAndWeight( 205 | kinematic.ObstacleAvoidance(character, obstacles), 206 | weight = 2), 207 | # LookWhereYoureGoing 208 | BehaviorAndWeight( 209 | kinematic.LookWhereYoureGoing(character), 210 | weight = 1), 211 | ] 212 | super(Arrive, self).__init__(character, behaviors) 213 | 214 | class Surround(BlendedSteering): 215 | """ :py:class:`~.BlendedSteering` that makes the character **Surround** a target 216 | 217 | This behavior uses :py:class:`~.FollowPath` and :py:class:`~.Face` 218 | to make the character revolve around the target while looking at it. 219 | 220 | Parameters 221 | ---------- 222 | character: :py:class:`~.GameObject` 223 | target: :py:class:`~.GameObject` 224 | radius: int 225 | The radius of the circle the character will surround the target with 226 | """ 227 | def __init__(self, character, target, radius): 228 | circumpath = path.PathCircumference(lambda: target.position, radius) 229 | behaviors = [ 230 | BehaviorAndWeight( 231 | kinematic.FollowPath(character, circumpath), 232 | weight = 2), 233 | BehaviorAndWeight( 234 | kinematic.Face(character, target), 235 | weight = 1), 236 | ] 237 | super(Surround, self).__init__(character, behaviors) 238 | -------------------------------------------------------------------------------- /pygame_ai/steering/path.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ Iterator that describes a Path 3 | 4 | This module implements an iterator :py:class:`~.path.Path` to be used the 5 | descriptions of the points that form a particular path. There are also 6 | the following classes with specialised paths: 7 | 8 | * :py:class:`~.path.CyclicPath` 9 | * :py:class:`~.path.MirroredPath` 10 | 11 | Aswell as the following pre-implemented useful paths: 12 | 13 | * :py:class:`~.path.PathCircumference` 14 | * :py:class:`~.path.PathParabola` 15 | 16 | """ 17 | import math 18 | 19 | class Path(object): 20 | """ Iterator that describes a **Path** 21 | 22 | Provides a flexible interface to describe dynamic paths as an iterator, 23 | it uses a **Path Function** in the form of f(x) = y to describe 24 | the path. 25 | 26 | Parameters 27 | ---------- 28 | path_func: function number -> number 29 | The function that describes the path 30 | domain_start: int 31 | Start point for the function domain, defaults to 0 32 | domain_end: int 33 | End point for the function domain 34 | increment: int 35 | Step to generate every point on the path 36 | 37 | 38 | Example 39 | ------- 40 | The way this class is meant to be used is by sub-classing it and creating 41 | your own class with your own properties, this is a slightly useluess 42 | implementation of :py:class:`~.path.CircumferencePath` that only 43 | traverses the path once. 44 | 45 | .. code-block:: python 46 | 47 | class OnceCircumferencePath(Path): 48 | 49 | def __init__(self, center, radius): 50 | self.center = center 51 | self.radius = radius 52 | 53 | def circumference_path(self, x): 54 | angle = math.radians(x) 55 | center = self.center 56 | x = center[0] + math.cos(angle)*self.radius 57 | y = center[1] + math.sin(angle)*self.radius 58 | return x, y 59 | 60 | super(OnceCircumferencePath, self).__init__(parabola_path, domain_start = 0, domain_end = 360, increment = 15) 61 | 62 | >>> mypath = OnceCircumferencePath(center = (50, 50), radius = 50) 63 | >>> next(mypath) 64 | (100.0, 50.0) 65 | >>> next(mypath) 66 | (98.29629131445341, 62.940952255126035) 67 | >>> next(mypath) 68 | (93.30127018922194, 75.0) 69 | 70 | 71 | A good tip is to use lambda functions in order to have dynamically 72 | updated paths, this allows to have attributes like 'center' update 73 | with the position of something in the game, which will alter 74 | the points the path will produce 75 | 76 | .. code-block:: python 77 | 78 | class OnceCircumferencePath(Path): 79 | 80 | def __init__(self, center, radius): 81 | self.center = center 82 | self.radius = radius 83 | 84 | def circumference_path(self, x): 85 | angle = math.radians(x) 86 | # Notice that we are now calling the attribute 'center' as a function 87 | center = self.center() 88 | x = center[0] + math.cos(angle)*self.radius 89 | y = center[1] + math.sin(angle)*self.radius 90 | return x, y 91 | 92 | super(OnceCircumferencePath, self).__init__(parabola_path, domain_start = 0, domain_end = 360, increment = 15) 93 | 94 | >>> character = SomeGameObjectWithARect() 95 | # The 'center' parameter is now defined as a lambda functions that gets the position of a character 96 | >>> mypath = OnceCircumferencePath(center = (lambda: character.rect.center), radius = 50) 97 | """ 98 | 99 | def __init__(self, path_func, domain_end, domain_start = 0, increment = 1): 100 | self.path_func = path_func 101 | self.increment = increment 102 | self.x = -increment + domain_start 103 | self.domain_start = domain_start 104 | self.domain_end = domain_end 105 | self.current = None 106 | 107 | def __iter__(self): 108 | return self 109 | 110 | def __next__(self): 111 | if self.x < self.domain_end: 112 | self.x += self.increment 113 | self.current = lambda: self.path_func(self, self.x) 114 | return self.current() 115 | else: 116 | raise StopIteration 117 | 118 | def __repr__(self): 119 | return 'Function Path' 120 | 121 | def reset(self): 122 | """ Returns the iterator to it's initial point """ 123 | self.x = self.domain_start 124 | 125 | def as_list(self): 126 | """ Returns the path as a list of points 127 | 128 | This ignores the infinity of :py:class:`~.path.CyclicPath` 129 | and :py:class:`~.path.MirroredPath` and returns a finite list. 130 | Nevertheless, you should keep in mind that if for your own 131 | sub-classes this methods does not return the expected results, 132 | it's probabbly the method's fault (my faul) and you should 133 | implement your own since this is used for drawing indicators. 134 | 135 | Returns 136 | ------- 137 | list(tuple(float, float)) 138 | """ 139 | path_list = [] 140 | 141 | for x in range(self.domain_start, self.domain_end+1, self.increment): 142 | path_list.append(self.path_func(self, x)) 143 | 144 | return path_list 145 | 146 | 147 | class CyclicPath(Path): 148 | """Iterator that implements Cyclic Paths 149 | 150 | This is a sub-class of :py:class:`~.Path` that returns to the path's 151 | starting point once it reaches the end, this produces an infinite 152 | iterator. 153 | 154 | Uses the same parameters as :py:class:`~.Path`. 155 | """ 156 | 157 | def __init__(self, path_func, domain_end, domain_start = 0, increment = 1): 158 | super(CyclicPath, self).__init__(path_func, domain_end, domain_start, increment) 159 | 160 | def __next__(self): 161 | if self.x >= self.domain_end: 162 | self.reset() 163 | 164 | return super(CyclicPath, self).__next__() 165 | 166 | 167 | class MirroredPath(Path): 168 | """ Iterator that implements Mirrored Paths 169 | 170 | This is a sub-class of :py:class:`~.Path` that **Mirrors** the 171 | path produced by the given function, this produces an infinite 172 | iterator that backtracks on the traversed path once it reaches 173 | it's domain_end, and does the same after it reaches domain_start. 174 | 175 | Uses the same parameters as :py:class:`~.Path`. 176 | """ 177 | 178 | def __init__(self, path_func, domain_end, domain_start = 0, increment = 1): 179 | super(MirroredPath, self).__init__(path_func, domain_end, domain_start, increment) 180 | 181 | def __repr__(self): 182 | return 'Mirrored ' + super(MirroredPath, self).__repr__() 183 | 184 | def __next__(self): 185 | self.x += self.increment 186 | if self.x > self.domain_end or self.x < self.domain_start: 187 | self.increment = -self.increment 188 | self.x += self.increment 189 | 190 | self.current = lambda: self.path_func(self, self.x) 191 | return self.current() 192 | 193 | def as_list(self): 194 | path_list = [] 195 | 196 | if self.increment > 0: 197 | f_range = range(self.domain_start, self.domain_end+1, self.increment) 198 | else: 199 | f_range = range(self.domain_end, self.domain_start-1, self.increment) 200 | 201 | for x in f_range: 202 | path_list.append(self.path_func(self, x)) 203 | 204 | return path_list 205 | 206 | 207 | class PathCircumference(CyclicPath): 208 | """ Circumference-like :py:class:`~.CyclicPath` 209 | 210 | Parameters 211 | ---------- 212 | center: tuple(int, int) or function -> tuple(int, int) 213 | radius: int 214 | """ 215 | 216 | def __init__(self, center, radius, start = 0): 217 | 218 | if not callable(center): 219 | callable_center = lambda : center 220 | else: 221 | callable_center = center 222 | self.center = callable_center 223 | self.radius = radius 224 | 225 | self.start = start 226 | 227 | def circumference_path(self, t): 228 | angle = math.radians(t) 229 | center = self.center() 230 | x = center[0] + math.cos(angle)*self.radius 231 | y = center[1] + math.sin(angle)*self.radius 232 | return x, y 233 | 234 | super(PathCircumference, self).__init__(circumference_path, domain_start = self.start, domain_end = self.start + 360, increment = 15) 235 | 236 | def __repr__(self): 237 | return 'PathCircumference' 238 | 239 | class PathParabola(MirroredPath): 240 | """ Parabola-like :py:class:`~.MirroredPath` 241 | 242 | Parameters 243 | ---------- 244 | origin: tuple(int, int) or function -> tuple(int, int) 245 | Lowest point of the parabola 246 | width: int 247 | height: int 248 | """ 249 | 250 | def __init__(self, origin, width = 400, height = 100): 251 | if not callable(origin): 252 | callable_origin = lambda: origin 253 | else: 254 | callable_origin = origin 255 | self.origin = callable_origin 256 | self.domain_range = int(math.sqrt(height)) 257 | self.amplitude = width/(2*self.domain_range) 258 | 259 | def parabola_path(self, t): 260 | origin = self.origin() 261 | x = origin[0] + t*self.amplitude 262 | y = origin[1] - t**2 263 | return x, y 264 | 265 | super(PathParabola, self).__init__(parabola_path, domain_start = -self.domain_range, domain_end = self.domain_range, increment = 2) 266 | 267 | def __repr__(self): 268 | return 'PathParbola' 269 | -------------------------------------------------------------------------------- /pygame_ai/steering/priority.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ Priority Steering Behaviors 3 | 4 | This module implements a class that holds a list of 5 | :py:class:`~.kinematic.KinematicSteeringBehavior`\ s and applies them in order, 6 | keeping only the first one that produces an output greater than a certain 7 | treshold. This means that some behaviors which are considered more important 8 | (like :py:class:`~.kinematic.ObstacleAvoidance` and 9 | :py:class:`~.kinematic.CollisionAvoidance`) but are not always neccesary 10 | to reach the character's goal can be ignored when they don't produce a 11 | meaningful output, it also means that when they do produce a meaningful 12 | output they will be the only ones in action. 13 | 14 | This is a very simple form of decision making that involves only steering 15 | algorithms, and therefore it is classified as a steering behavior. 16 | 17 | Derives from :py:class:`~.kinematic.KinematicSteeringBehavior`. 18 | 19 | 20 | Example 21 | -------- 22 | 23 | This is how you would normally create your own :py:class:`~PrioritySteering`\ , 24 | in this case we are making a behavior that will most of the time **Pursue** 25 | a target, but will prioritize **Avoiding Obstacles** when that behavior 26 | returns a steering greater than the treshold. 27 | 28 | .. code-block:: python 29 | 30 | mybehavior = PrioritySteering( 31 | behaviors = [ 32 | kinematic.ObstacleAvoidance(character, obstacles), 33 | kinematic.Pursue(character, target), 34 | ], 35 | ) 36 | 37 | """ 38 | 39 | from . import kinematic 40 | from . import blended 41 | from . import path 42 | 43 | 44 | class PrioritySteering(kinematic.KinematicSteeringBehavior): 45 | 46 | def __init__(self, behaviors, epsilon = 0.1): 47 | self.behaviors = behaviors 48 | self.epsilon = epsilon 49 | 50 | def __repr__(self): 51 | return 'PrioritySteering '+super(PrioritySteering, self).__repr__() 52 | 53 | def draw_indicators(self, screen, offset = (lambda pos: pos)): 54 | for behavior in self.behaviors: 55 | behavior.draw_indicators(screen, offset) 56 | 57 | def get_steering(self): 58 | 59 | for behavior in self.behaviors: 60 | # Get behavior's steering 61 | steering = behavior.get_steering() 62 | 63 | # If any of it's components surpases the treshold, return it 64 | if steering.linear.length() > self.epsilon or abs(steering.angular) > self.epsilon: 65 | return steering 66 | 67 | # If we get here, no output surpased the treshold 68 | # Return the last group's steering as small as it is 69 | return steering 70 | 71 | class OscilateHorizontally(PrioritySteering): 72 | 73 | def __init__(self, character, target, solid_entities, width = 160, height = 80, start_x = 0): 74 | 75 | def mypath(self, i): 76 | x, y = self.center() 77 | a = [(x - width//2, y - height), (x, y - height), (x + width//2, y - height)] 78 | return a[i] 79 | 80 | hpath = path.MirroredPath(mypath, domain_end = 2) 81 | hpath.center = lambda: target.position 82 | hpath.x = start_x 83 | behaviors = [ 84 | kinematic.CollisionAvoidance(character, solid_entities), 85 | kinematic.FollowPath(character, hpath), 86 | ] 87 | super(OscilateHorizontally, self).__init__(behaviors, epsilon = 10) 88 | 89 | -------------------------------------------------------------------------------- /pygame_ai/steering/static.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ Static movement 3 | 4 | This module implements a series of classes and methods that emulate 5 | the behavior of objects moving in a 2D space in a static way 6 | (not involving acceleration) 7 | 8 | Notes 9 | ----- 10 | This might need a slightly better explaination 11 | """ 12 | import random 13 | 14 | import pygame 15 | 16 | from pygame_ai.utils import math_utils 17 | 18 | class SteeringOutput(object): 19 | """ Container for Steering data 20 | 21 | This class is used as a container for the output of the 22 | :py:class:`~StaticSteeringBehavior` algorithms. 23 | 24 | Parameters 25 | ---------- 26 | velocity : :pgmath:`Vector2`, optional 27 | Linear velocity, defaults to (0, 0) 28 | rotation : int, optional 29 | Angular velocity, defaults to 0 30 | 31 | Attributes 32 | ---------- 33 | velocity : :pgmath:`Vector2` 34 | Linear velocity 35 | rotation : int 36 | Angular velocity 37 | """ 38 | 39 | def __init__(self, velocity = None, rotation = None): 40 | if velocity is None: 41 | velocity = pygame.Vector2(0, 0) 42 | self.velocity = velocity 43 | if rotation is None: 44 | rotation = 0 45 | self.rotation = rotation 46 | 47 | def update(self, gameobject, tick): 48 | """ Update a :py:class:`~gameobject.GameObject`'s velocity and rotation 49 | 50 | This method should be called once per loop, it updates the given 51 | :py:class:`gameobject.GameObject`'s velocity and rotation based 52 | on this :py:class:`~SteeringOutput`'s acceleration request 53 | 54 | Parameters 55 | ---------- 56 | gameobject : :py:class:`~gameobject.GameObject` 57 | The :py:class:`GameObject` that will be updated 58 | tick : int 59 | Time transcurred since last loop 60 | """ 61 | gameobject.velocity += self.linear * tick 62 | gameobject.rotation += self.rotation * tick 63 | 64 | if gameobject.velocity.length() > gameobject.max_speed: 65 | gameobject.velocity.normalize_ip() 66 | gameobject.velocity *= gameobject.max_speed 67 | 68 | null_steering = SteeringOutput(velocity = pygame.Vector2(0, 0), rotation = 0) 69 | """:py:class:`SteeringOutput` : Constant with 0 linear velocity and 0 angular velocity """ 70 | 71 | class StaticSteeringBehavior(object): 72 | """ Template StaticSteeringBehavior class 73 | 74 | This class is a template to supply base methods for StaticSteeringBehaviors. 75 | This class is meant to be subclassed since the methods here are just placeholders 76 | """ 77 | 78 | def __repr__(self): 79 | """ If not overriden, returns class name """ 80 | return type(self).__name__ 81 | 82 | def draw_indicators(self, screen, offset = (lambda pos: pos)): 83 | """ Draws appropiate indicators for each :py:class:`~StaticSteeringBehavior` 84 | 85 | Parameters 86 | ---------- 87 | screen: :pgsurf:`Surface` 88 | Surface in which to draw indicators, normally this would be the screen Surface 89 | offset: function, optional 90 | Function that applies an offset to the object's position 91 | 92 | This is meant to be used together with scrolling cameras, 93 | leave empty if your game doesn't implement one,it defaults 94 | to a linear function f(pos) -> pos 95 | """ 96 | pass 97 | 98 | def get_steering(self): 99 | """ Returns a steering request 100 | 101 | Returns 102 | ------- 103 | 104 | :py:class:`SteeringOutput` 105 | Requested steering 106 | """ 107 | return null_steering 108 | 109 | class Seek(StaticSteeringBehavior): 110 | """ :py:class:`~StaticSteeringBehavior` that makes the character **Seek** a target 111 | 112 | Parameters 113 | ---------- 114 | character: :py:class:`~gameobject.GameObject` 115 | Character with this behavior 116 | target: :py:class:`~gameobject.GameObject` 117 | Target to **Seek** 118 | """ 119 | 120 | def __init__(self, character, target): 121 | self.character = character 122 | self.target = target 123 | 124 | def get_steering(self): 125 | # Create structure for output 126 | steering = SteeringOutput() 127 | 128 | # Get direction to the target 129 | steering.velocity = self.target.position - self.character.position 130 | # Velocity is along this direction at full speed 131 | if(steering.velocity[0] != 0 or steering.velocity[1] != 0): 132 | steering.velocity.normalize_ip() 133 | steering.velocity *= self.character.max_speed 134 | # Face in the direction of velocity 135 | if(math_utils.is_not_null(steering.velocity)): 136 | self.character.orientation = math_utils.get_angle_from_vector(steering.velocity) 137 | 138 | # Return the steering 139 | steering.rotation = 0 140 | return steering 141 | 142 | class Flee(StaticSteeringBehavior): 143 | """ :py:class:`~StaticSteeringBehavior` that makes the character **Flee** from a target 144 | 145 | Parameters 146 | ---------- 147 | character: :py:class:`~gameobject.GameObject` 148 | Character with this behavior 149 | target: :py:class:`~gameobject.GameObject` 150 | Target to **Flee** from 151 | """ 152 | 153 | def __init__(self, character, target): 154 | self.character = character 155 | self.target = target 156 | 157 | def get_steering(self): 158 | 159 | # Create structure for output 160 | steering = SteeringOutput() 161 | 162 | # Get direction to the target 163 | steering.velocity = self.character.position - self.target.position 164 | # Velocity is along this direction at full speed 165 | if(steering.velocity[0] != 0 or steering.velocity[1] != 0): 166 | steering.velocity.normalize_ip() 167 | steering.velocity *= self.character.max_speed 168 | # Face in the direction of velocity 169 | if(math_utils.is_not_null(steering.velocity)): 170 | self.character.orientation = math_utils.get_angle_from_vector(steering.velocity) 171 | 172 | # Return the steering 173 | steering.rotation = 0 174 | return steering 175 | 176 | class Arrive(StaticSteeringBehavior): 177 | """ :py:class:`~StaticSteeringBehavior` that makes the character **Arrive** at a target 178 | 179 | Parameters 180 | ---------- 181 | character: :py:class:`~gameobject.GameObject` 182 | Character with this behavior 183 | target: :py:class:`~gameobject.GameObject` 184 | Target to **Arrive** at 185 | radius: int, optional 186 | Distance from the center of the target at which the character will stop 187 | time_to_arrive: float, optional 188 | Estimated time, in seconds, to **Arrive** at the target 189 | """ 190 | 191 | def __init__(self, character, target, radius = None, time_to_arrive = 0.25): 192 | # Complete unprovided values 193 | if radius is None: 194 | radius = int(math.sqrt((target.rect.height/2)**2 + (target.rect.width/2)**2)*1.5) 195 | self.character = character 196 | self.target = target 197 | self.radius = radius 198 | self.time_to_arrive = time_to_arrive 199 | 200 | def get_steering(self): 201 | # Create structure for output 202 | steering = SteeringOutput() 203 | 204 | # Get direction to the target 205 | steering.velocity = self.target.position - self.character.position 206 | # Check if we're within radius 207 | if steering.velocity.length() < self.radius: 208 | return null_steering 209 | 210 | # Clip to get there in time_to_arrive 211 | steering.velocity /= self.time_to_arrive 212 | 213 | # If it is too fast, clip it to character's speed 214 | if steering.velocity.length() > self.character.max_speed: 215 | steering.velocity.normalize_ip() 216 | steering.velocity *= self.character.max_speed 217 | 218 | # Face in the direction of velocity 219 | if(math_utils.is_not_null(steering.velocity)): 220 | self.character.orientation = math_utils.get_angle_from_vector(steering.velocity) 221 | 222 | # Return the steering 223 | steering.rotation = 0 224 | 225 | return steering 226 | 227 | class Wander(StaticSteeringBehavior): 228 | """ :py:class:`~StaticSteeringBehavior` that makes the character **Wander** 229 | 230 | This behavior makes the character move with it's maximum speed in a 231 | particular direction for a random period of time, after that the 232 | character's orientation is changed randomly using the character's 233 | :py:attr:`~gameobject.GameObject.max_rotation`. 234 | 235 | Parameters 236 | ---------- 237 | character: :py:class:`~gameobject.GameObject` 238 | Character with this behavior 239 | """ 240 | 241 | def __init__(self, character): 242 | self.character = character 243 | self.counter = 0 244 | self.max_timer = random.randint(7, 13) 245 | 246 | def get_steering(self): 247 | # Output steering 248 | steering = SteeringOutput() 249 | steering.rotation = 0 250 | 251 | # Get velocity from orientation 252 | steering.velocity = math_utils.orientation_asvector(self.character.orientation) 253 | steering.velocity *= self.character.max_speed 254 | 255 | # Change orientation randomly after random amount of iterations 256 | if(self.counter > self.max_timer): 257 | steering.rotation = (random.random() - random.random())*self.character.max_rotation 258 | self.counter = 0 259 | self.max_timer = random.randint(7, 13) 260 | self.counter += 1 261 | 262 | return steering 263 | 264 | 265 | 266 | -------------------------------------------------------------------------------- /pygame_ai/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casillajec/pygame-ai/700179e521dc4080da6d93521e680e438901db72/pygame_ai/tests/__init__.py -------------------------------------------------------------------------------- /pygame_ai/tests/test_joke.py: -------------------------------------------------------------------------------- 1 | from unittest import TestCase 2 | 3 | import pygame_ai 4 | 5 | class TestJoke(TestCase): 6 | def test_is_string(self): 7 | s = pygame_ai.joke() 8 | self.assertTrue(isinstance(s, basestring)) 9 | -------------------------------------------------------------------------------- /pygame_ai/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from . import list_utils 2 | from . import math_utils 3 | -------------------------------------------------------------------------------- /pygame_ai/utils/list_utils.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def remove_if_exists(mylist, item): 4 | """ Remove item from mylist if it exists, do nothing otherwise """ 5 | to_remove = [] 6 | for i in range(len(mylist)): 7 | if mylist[i] == item: 8 | to_remove.append(mylist[i]) 9 | 10 | for el in to_remove: 11 | mylist.remove(el) 12 | 13 | def remove_if_exists_copy(mylist, item): 14 | """ Return new list with item removed """ 15 | new_list = [] 16 | for el in mylist: 17 | if el != item: 18 | new_list.append(el) 19 | 20 | return new_list 21 | 22 | def find_first(mylist, item): 23 | """ Returns index of the first occurence of item in mylist, returns -1 if not found """ 24 | try: 25 | idx = mylist.index(item) 26 | except ValueError: 27 | idx = -1 28 | 29 | return idx 30 | 31 | -------------------------------------------------------------------------------- /pygame_ai/utils/math_utils.py: -------------------------------------------------------------------------------- 1 | import math 2 | import random 3 | import pygame 4 | 5 | def is_not_null(vector2): 6 | """ Returns true if the vector is null, returns false otherwise 7 | 8 | :param vector2: Vector2 9 | :type vector2" pygame.Vector2 10 | 11 | :returns: TTrue if the vector is null, False otherwise 12 | :rtype: bool 13 | """ 14 | return (vector2[0] != 0 or vector2[1] != 0) 15 | 16 | def get_angle_from_vector(vector2): 17 | """ Returns the angle from X+ axis to the given vector """ 18 | return math.atan2(-vector2[1], vector2[0]) * (180/math.pi) 19 | 20 | def orientation_asvector(orientation): 21 | """ Returns a vector representation of the given orientation in degrees """ 22 | return pygame.Vector2(math.cos(math.radians(orientation)), -math.sin(math.radians(orientation))) 23 | 24 | def map_to_range(orientation): 25 | """ Maps the angle orientation in degrees to range [-180, 180) """ 26 | return orientation - 360*math.floor((orientation + 180) * (1/360)) 27 | 28 | def random_binomial(): 29 | """ Returns a random value in the range [-1, 1] """ 30 | return random.random() - random.random() 31 | 32 | def vec2_to_int(vector2): 33 | return pygame.Vector2(int(vector2[0]), int(vector2[1])) 34 | 35 | def lines_intersect(line1, line2): 36 | """ Returns intersection point between line1 and line2, or None if they dont intersect """ 37 | (x1, y1), (x2, y2) = line1 38 | (x3, y3), (x4, y4) = line2 39 | 40 | # Compute coeficients for line1 41 | # where a1 x + b1 y + c1 = 0 42 | a1 = y2 - y1 43 | b1 = x1 - x2 44 | c1 = x2 * y1 - x1 * y2 45 | 46 | # Compute r3 and r4 47 | r3 = a1 * x3 + b1 * y3 + c1 48 | r4 = a1 * x4 + b1 * y4 + c1 49 | 50 | # If r3 and r4 have same signs, lines don't intersect 51 | #if r3 != 0 and r4 != 0 and r3*r4 > 0: 52 | if r3*r4 >= 0: 53 | return None 54 | 55 | # Compute coeficients for line2 56 | # where a2 x + b2 y + c2 = 0 57 | a2 = y4 - y3 58 | b2 = x3 - x4 59 | c2 = x4 * y3 - x3 * y4 60 | 61 | # Compute r1 and r2 62 | r1 = a2 * x1 + b2 * y1 + c2 63 | r2 = a2 * x2 + b2 * y2 + c2 64 | 65 | # If r1 and r2 have same signs, lines don't intersect 66 | if r1*r2 >= 0: 67 | return None 68 | 69 | # Line segments definitely intersect 70 | # Compute intersection point 71 | denom = a1 * b2 - a2 * b1 72 | if denom == 0: 73 | return None # Colinear???? What should I do in this case? Maybe return x1, y1 74 | 75 | offset = abs(denom)//2 76 | 77 | num = b1 * c2 - b2 * c1 78 | x = (num - offset if num < 0 else num + offset) // denom 79 | 80 | num = a2 * c1 - a1 * c2 81 | y = (num - offset if num < 0 else num + offset) // denom 82 | 83 | return pygame.Vector2(x, y) 84 | 85 | def get_perpendicular(line): 86 | """ Returns line perpendicular to line """ 87 | (x1, y1), (x2, y2) = line 88 | x = x2 - x1 89 | y = y2 - y1 90 | 91 | return pygame.Vector2(-y, x), pygame.Vector2(y, -x) 92 | 93 | def get_bound_radius(rect): 94 | """ Returns the radius of a circle that bounds the given rect """ 95 | return math.sqrt((rect.height/2)**2 + (rect.width/2)**2) 96 | 97 | 98 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | def readme(): 4 | with open('README.rst', 'r') as f: 5 | return f.read() 6 | 7 | setup( 8 | name = 'pygame_ai', 9 | version = '0.1.2', 10 | description = 'Videogame AI package for PyGame', 11 | long_description = 'Implements a set of common AI techniques used in videogame development\n\nCheck the docs: https://pygame-ai.readthedocs.io/en/latest/index.html', 12 | classifiers = [ 13 | 'Programming Language :: Python :: 3.6', 14 | 'Topic :: Software Development :: Libraries :: pygame' 15 | ], 16 | keywords = 'pygame ai steering', 17 | url = 'https://github.com/nek2712/pygame-ai', 18 | author = 'Nek', 19 | author_email = 'nek2712@gmail.com', 20 | license = 'GLGPL v2.1', 21 | packages = ['pygame_ai'] + ['pygame_ai.' + pkg for pkg in find_packages('pygame_ai')], 22 | install_requires = [ 23 | 'pygame<2' 24 | ], 25 | include_package_data = True, 26 | zip_safe = False 27 | ) 28 | --------------------------------------------------------------------------------