-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Clément Bonnet <[email protected]> Co-authored-by: Sasha <[email protected]>
- Loading branch information
1 parent
8168c5c
commit 0ba80dc
Showing
26 changed files
with
2,359 additions
and
38 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,9 @@ | ||
::: jumanji.environments.routing.pac_man.env.PacMan | ||
selection: | ||
members: | ||
- __init__ | ||
- observation_spec | ||
- action_spec | ||
- reset | ||
- step | ||
- render |
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.
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,65 @@ | ||
# PacMan Environment | ||
|
||
<p align="center"> | ||
<img src="../env_anim/pac_man.gif" width="600"/> | ||
</p> | ||
|
||
We provide here a minimal Jax JIT-able implementation of the game [PAC-MAN](https://pacman.com/en/history/). The game is played in a 2D matrix where a cell is a free space (black), a wall (dark blue), pacman (yellow) or a ghost. | ||
|
||
|
||
The goal is for the agent (yellow) to collect all of the pellets (small pink blocks) on the map without touching any of the ghosts. The agent receives a reward of +10 when collecting a pellet for the first time and pellets are removed from the map after being collected. | ||
|
||
The power-ups (large pink blocks) trigger a 'scatter mode' which changes the colour of the ghosts to dark blue for 30 in game steps. When the ghosts are in this state, the player can touch them which causes them to return to the center of the map. This gives a reward of +200 for each unique ghost. | ||
|
||
The agent selects an action at each timestep (up, left, right, down, no-op) which determines the direction they wil travel for that step. However, even if an action is in an invalid direction it will still be taken as input and the player will remain stationary. If the no-op action is used the player will not stop but instead take the last action that was selected. | ||
|
||
The game takes place on a fixed map and the same map is generated on each reset. The generator can be used to generate new maps based on an ASCII representation of the desired map. This ASCII generator is deterministic and will always initialise to the same state as long as the same ASCII diagram is is use. | ||
|
||
## Observation | ||
As an observation, the agent has access to the current maze configuration in the array named | ||
`grid`. It also has access to its current position `player_locations`, the ghosts' locations | ||
`ghost_locations`, the power-pellet locations `power_up_location`, the time left for the scatter state `frightened_state_time`, the pellet locations `pellet_locations` and the action | ||
mask `action_mask`. | ||
|
||
- `agent_position`: Position(row, col) (int32) each of shape `()`, agent position in the maze. | ||
|
||
- `ghost_locations`: jax array (int32) of shape `(4,2)`, with the (y,x) coordinates of each ghost | ||
|
||
- `power_up_locations`: jax array (int32) of shape `(4,2)`, with the (y,x) coordinates of each power-pellet | ||
|
||
- `pellet_locations`: jax array (int32) of shape `(4,2)`, with the (y,x) coordinates of each pellet | ||
|
||
- `frightened_state_time`: jax array (int32) of shape `()`, number of steps left of the scatter state. | ||
|
||
- `action_mask`: jax array (bool) of shape `(5,)`, binary values denoting whether each action is | ||
possible. | ||
- `frightened_state_time`: (int32) tracking the number of steps for the scatter state. | ||
- `score`: (int32) tracking the total points accumulated since the last reset. | ||
|
||
An example 5x5 observation `grid` array, is shown below. 1 represents a wall, and 0 represents free | ||
space. | ||
|
||
``` | ||
[0, 1, 0, 0, 0], | ||
[0, 1, 0, 1, 1], | ||
[0, 1, 0, 0, 0], | ||
[0, 0, 0, 1, 1], | ||
[0, 0, 0, 0, 0] | ||
``` | ||
|
||
|
||
## Action | ||
The action space is a `DiscreteArray` of integer values in the range of [0, 4]. I.e. the agent can | ||
take one of four actions: up (`0`), right (`1`), down (`2`), left (`3`) or no-op (`4`). If an invalid action is | ||
taken, or an action is blocked by a wall, a no-op is performed and the agent's position remains | ||
unchanged. Additionally if a no-op is performed the agent will use the last normal action used. | ||
|
||
|
||
## Reward | ||
PacMan is a dense reward setting, where the agent receives a reward of +10 for each pellet collected. The agent also recieve a reward of 20 for collecting a power pellet. The game ends when the agent has collected all 316 pellets on the map or touches a ghost. | ||
|
||
Eating a ghost when scatter mode is enabled also awards +200 points but, points are only awarded the first time each unique ghost is eaten. | ||
|
||
|
||
## Registered Versions 📖 | ||
- `PacMan-v0`, PacMan in a 31x28 map with simple grid observations. |
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
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,16 @@ | ||
# Copyright 2022 InstaDeep Ltd. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from jumanji.environments.routing.pac_man.env import PacMan | ||
from jumanji.environments.routing.pac_man.types import Observation, State |
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,55 @@ | ||
# Copyright 2022 InstaDeep Ltd. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import jax.numpy as jnp | ||
|
||
MOVES = jnp.array( | ||
[[0, -1], [-1, 0], [0, 1], [1, 0], [0, 0]] | ||
) # Up, Right, Down, Left, No-op | ||
|
||
|
||
# Default Maze design | ||
DEFAULT_MAZE = [ | ||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXX", | ||
"X S XX S X", | ||
"X XXXX XXXXX XX XXXXX XXXX X", | ||
"X XXXXOXXXXX XX XXXXXOXXXX X", | ||
"X XXXX XXXXX XX XXXXX XXXX X", | ||
"X X", | ||
"X XXXX XX XXXXXXXX XX XXXX X", | ||
"X XXXX XX XXXXXXXX XX XXXX X", | ||
"X XX TXXT XX X", | ||
"XXXXXX XXXXX XX XXXXX XXXXXX", | ||
"XXXXXX XXXXX XX XXXXX XXXXXX", | ||
"XXXXXX XXT TXX XXXXXX", | ||
"XXXXXX XX XXX XXXX XX XXXXXX", | ||
"XXXXXX XX X G X XX XXXXXX", | ||
" GXXXXG ", | ||
"XXXXXX XX X G X XX XXXXXX", | ||
"XXXXXX XX XXX XXXX XX XXXXXX", | ||
"XXXXXX XX XX XXXXXX", | ||
"XXXXXX XX XXXXXXXX XX XXXXXX", | ||
"XXXXXX XX XXXXXXXX XX XXXXXX", | ||
"X XX X", | ||
"X XXXX XXXXX XX XXXXX XXXX X", | ||
"X XXXX XXXXX XX XXXXX XXXX X", | ||
"X XX S P S XX X", | ||
"XXX XX XX XXXXXXXX XX XX XXX", | ||
"XXX XX XX XXXXXXXX XX XX XXX", | ||
"X XX XX XX X", | ||
"X XXXXXXXXXX XX XXXXXXXXXX X", | ||
"X XXXXXXXXXX XX XXXXXXXXXX X", | ||
"X O O X", | ||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXX", | ||
] |
Oops, something went wrong.