An extension to jgubert's Python frogger game that can be integrated with OpenAI's Gym (Gym) via PyGame Learning Environment (PLE).
This extension allows Frogger to be treated as a Reinforcement Learning problem and solved using any standard algorithm.
Tested with Python 3.5 (pygame v1.9.4, ple 0.0.1 and gym v0.10.9)
Please cite this repository if you use the code in your research:
@software{pedro_sequeira_2020_3637654,
author = {Pedro Sequeira and
João Gubert},
title = {Frogger python implementation},
month = feb,
year = 2020,
publisher = {Zenodo},
version = {v1.0.0},
doi = {10.5281/zenodo.3637654},
url = {https://doi.org/10.5281/zenodo.3637654}
}
pip install -e git+https://github.com/pedrodbs/frogger.git
-
pip install Pygame
-
pip install -e git+https://github.com/ntasfi/PyGame-Learning-Environment.git
-
pip install gym
The agent controlls frogs trying to cross a road and then a river in order to reach an available water lilly. To cross to the other side, the frog has to move upwards, avoiding cars on the road and using the platforms floating on the river. It also has a limit on the number of time-steps (actions it can perform) to move each frog into a water lilly. The interval with which cars and platforms appear is randomized.
The agent has a limited number of lives available. When a frog hits a car, goes into the water, or the maximum number of time-steps has been reached, the agent looses a life.
A certain number of frogs have to reach water lillies for the game to achieve a new level. When that occurs, the speed at which the cars and platforms move gets increased.
In this task, an episode ends when the agent looses all lives. As long as the agent keeps crossing all frogs within the available number of time-steps, the game does not terminate.
The following parameters can be defined in both the PLE and Gym game interfaces:
- actions: customizable dictionary of the agent's actions in the form
(action_name:key)
. Use the keys for each desired direction according to the constants defined infrogger_ple.py
- rewards: customizable dictionary of the agent's rewards in the form
(reward_name:value)
. Use the names for each reward according to the constants defined infrogger_ple.py
- lives: the number of lives of the agent
- speed: the initial speed of the game (increased when agent passes a new level)
- level: the initial level at which the game starts
- num_arrived_frogs: the number of frogs that have to reach a water lilly for the agent to pass a new level
- max_steps: the maximum number of steps (actions) that the agent has to put each frog in a water lilly
- show_stats: whether to show the game information at the bottom of the screen
The following scripts are available to be run (python script.py
):
random_ple.py
: a random agent using the PLE interfacerandom_gym.py
: a random agent using the Gym interfacemanual_gym.py
: a keyboard-controlled agent using the Gym interface