Skip to content

Commit

Permalink
Merge pull request #9 from Kinds-of-Intelligence-CFI/add-play
Browse files Browse the repository at this point in the history
Add play function (and fix spelling errors with decoyGoal raycast parsing)
  • Loading branch information
kozzy97 committed Jun 25, 2024
2 parents 6b8a30f + 55042c2 commit c187213
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ For more information about the ways you can contribute to Animal-AI, visit our w
If you are new to contributing to open source, [this](https://github.com/Kinds-of-Intelligence-CFI/animal-ai/blob/main/CONTRIBUTING.md) guide helps explain why, what, and how to successfully get involved.

## Version History
* v4.1.0
+ Updated `RaycastParser` to accept new object:
- `HollowBox`.
+ Added a new low-level random agent implemented on Braitenberg model.
+ Bug fixes and performance improvements, specifically on improving the reliability of the Braitenberg model.
+ Added built-in functionality to run yaml configuration files directly via Python.
* v4.0.1
+ Updated RaycastParser to accept two new objects:
- `DecoyGoal` and `DecoyGoalBounce`.
Expand Down
33 changes: 33 additions & 0 deletions animalai/play.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import random

from pathlib import Path

from animalai import AnimalAIEnvironment, arenas
from animalai.executable import find_executable

def play(configuration_file: str = None, env_path: str = None) -> None:
"""
Load a config file and play
:param configuration_file: str path to a yaml configuration. Plays animalai.arenas.GoodGoal_Random.yml by default
:param env_path: str path to AAI environment executable. Looks for it in root by default.
:return: None
"""

print("Initializing AAI environment")
environment = AnimalAIEnvironment(
file_name=env_path if env_path is not None else str(find_executable(Path(""))),
base_port=5005 + random.randint(0, 1000),
arenas_configurations=configuration_file if configuration_file is not None else arenas.GOOD_GOAL_RANDOM_POS,
play=True,
)

print("Press Q in the Unity window then Ctrl+C in the command line to close the environment effectively.")

# Run the environment until signal is lost
try:
while environment._process: # type: ignore
continue
except KeyboardInterrupt:
pass
finally:
environment.close()
4 changes: 2 additions & 2 deletions animalai/raycastparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class RayCastObjects(enum.Enum):
RAMP = 9
PILLARBUTTON = 10
SIGNPOSTER = 11
DECAYGOAL = 12
DECAYGOALBOUNCE = 13
DECOYGOAL = 12
DECOYGOALBOUNCE = 13
HOLLOWBOX = 14


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "animalai"
version = "4.0.1"
version = "4.1.0"
description = "Animal AI Python API"
license = "MIT"
readme = "README.md"
Expand Down
4 changes: 4 additions & 0 deletions test/play.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from animalai.play import play

if __name__ == "__main__":
play()

0 comments on commit c187213

Please sign in to comment.