-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from rradules/item-gathering
Item gathering added to main
- Loading branch information
Showing
12 changed files
with
483 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""Item Gathering environment. | ||
Johan Källström and Fredrik Heintz. 2019. Tunable Dynamics in Agent-Based Simulation using Multi-Objective | ||
Reinforcement Learning. Presented at the Adaptive and Learning Agents Workshop at AAMAS 2019. | ||
https://liu.diva-portal.org/smash/record.jsf?pid=diva2%3A1362933&dswid=9018 | ||
Notes: | ||
- In contrast to the original environment, the observation space is a 2D array of integers, i.e., | ||
the map of the environment, where each integer represents either agents (1 for the agent receiving the observation, | ||
2 for the other agents) or items (3, 4, etc., depending on the number of items). | ||
- The number of agents and items is configurable, by providing an initial map. | ||
- If no initial map is provided, the environment uses a default map | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""disgracefully stolen. | ||
https://stackoverflow.com/questions/73956440/python-to-change-image-into-a-color-that-is-not-one-of-the-images-dominant-colo | ||
""" | ||
|
||
import os | ||
|
||
import numpy as np | ||
from PIL import Image | ||
|
||
|
||
def get_colored(asset: str, count: int): | ||
"""Generating random colored visual assets for dynamic environment variables. | ||
Args: | ||
asset: `str` value. Either "item" or "agent". | ||
count: `int` value. The amount of total agents/items in the environment. | ||
Returns: | ||
numpy.ndarray with RGB values for the new colored assets. | ||
""" | ||
assert asset == "item" or asset == "agent", "You must specify an asset to get colored versions of." | ||
|
||
path = os.path.dirname(os.path.realpath(__file__)) | ||
seed = 1 if asset == "item" else 2 | ||
rng = np.random.default_rng(seed) # local seed | ||
im = Image.open(f"{path}/assets/{asset}.png").convert("RGBA") | ||
alpha = im.getchannel("A") | ||
im = im.convert("RGB") | ||
|
||
for i in range(count - 1): # subtracting the default asset | ||
rgb = rng.random((3, 3)) | ||
matrix = (rgb[0, 0], rgb[1, 0], rgb[2, 0], 0, rgb[0, 1], rgb[1, 1], rgb[2, 1], 0, rgb[0, 2], rgb[1, 2], rgb[2, 2], 0) | ||
|
||
# Apply above transform, reinsert alpha and save | ||
colored_im = im.convert("RGB", matrix) | ||
colored_im.putalpha(alpha) | ||
colored_im.save(f"{path}/assets/colored/{asset}{i}.png") | ||
|
||
|
||
def del_colored(asset: str, count: int): | ||
"""Deleting the previously random colored visual assets. | ||
Args: | ||
asset: `str` value. Either "item" or "agent". | ||
count: `int` value. The amount of total agents/items in the environment. | ||
""" | ||
assert asset == "item" or asset == "agent", "You must specify an asset to delete colored versions of." | ||
|
||
path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
for i in range(count - 1): # subtracting the default asset | ||
os.remove(f"{path}/assets/colored/{asset}{i}.png") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.