Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

pychology

Simple Python implementations of popular game AI techniques.

Current State: Very alpha. Only behavior trees are implemented.

Behavior Trees

Behavior trees are tree structures that represent the logic of choosing and switching the current task. Each node in the tree can be considered as a function that is called, and returns an indication of the current task's state; Whether it is active, done, or has failed.

The tasks themselves are the leafs of the tree. pychology expects you to provide functions to call when a task is started or continued, and that it returns one of the above mentioned node states, namely NodeState.ACTIVE, NodeState.DONE, or NodeState.FAILED. These functions then are plugged into pychology.behavior_trees.Action.

Inner nodes either have a single child and do some logic; These are called decorators, and do a lot of heavy lifting. They can change the returning node state, prevent sub-trees from being executed, check for conditions, count how often or for how long a sub-tree has been active, provide debug information, and much more.

There's also nodes that have multiple children. The two most popular are the Chain (usually called Sequence), which executes a series of tasks (or rather sub-trees) one after the other, and Priorities (also called Selector or Fallback) which tries running one sub-tree after the other until one reports something other than failure.

The class pychology.behavior_trees.BehaviorTree can act as a root node that automatically resets the tree's state after it has finished or failed, and can also run arbitrary code to integrate with the wider environment that the tree is embedded in.

An example on how to go through a door:

BehaviorTree(
    Chain(
        DoneOnPrecondition(                  # The first task is done
            is_door_open,                    # if the door is open,
            Priorities(                      # otherwise try to
                Action(open_door),           # open it
                ReturnActiveOnDone(          # or try again after
                    Action(unlock_door),     # unlocking it,
                ),
                ReturnActiveOnDone(          # or try again after
                    Action(pick_door_lock),  # picking the lock,
                ),
                FailOnPrecounter(            # or try
                    4,                       # three times to
                    Action(kick_in_door),    # kick in the door.
                ),
            ),
        ),
        Action(walk_through_door),           # Afterwards, go through.
    ),
)

TODO

  • Project
    • Packaging
  • Behavior Trees
    • Multinodes: Parallel, weighted random choice
    • Decorators: More return value logic
    • Blackboard support
    • Debug tools
    • Visualization
    • De-/Serialization
    • Tests
  • Hierarchical Finite State Machines (HFSM): Everything
  • Goal-Oriented Action Planning (GOAP): Everything
  • Hierarchical Task Planning (HTN): Everything
  • Whatever this is

Release files for pychology 0.1a0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pychology 0.1a0
File Interpreter ABI Platform
pychology-0.1a0-py3-none-any.whl Python 3 none any Details

Release files / pychology-0.1a0-py3-none-any.whl

Download URL pychology-0.1a0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b70fd245101a91ff78c41ca270ce0ccbeeacf66e1c6c947a2cd7adb00ac3d64
BLAKE2b-256 checksum
How to use checksums
c60d0d8cdd9da046419e5b02ef6325b5c323dc4381cc87dec3dffa597b502ec3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1

Release history Release notifications | RSS feed

This release

0.1a0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page