Skip to content

Commit 011163f

Browse files
authored
Merge pull request #4 from atainter/master
Update readme
2 parents 05dbe6f + 4ac4ebf commit 011163f

File tree

2 files changed

+75
-8
lines changed

2 files changed

+75
-8
lines changed

README.md

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Gym Setup Guide
22

3-
## Installation Guide
3+
### Installation Guide
44
First, make sure to follow the install instructions for OpenAI Gym at this [link](https://gym.openai.com/docs).
55

66
You'll need to have [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and [pip](https://pip.pypa.io/en/stable/installing/) installed on your machine.
@@ -10,7 +10,7 @@ Next, make sure to install the proper python packages for this project.
1010
pip install scipy neat-python argparse
1111
```
1212

13-
## Running the Program
13+
### Running the Program
1414

1515
There are two files used to solve the gym environment: `gym_config` and `gym_solver.py`. `gym_config` contains the config for the neuroevolution process and `gym_solver.py` is the program the creates the neural networks and solves the game. You will need to adjust parameters in both to solve a game.
1616

@@ -30,10 +30,15 @@ There will be a variable for a game name. This can be any game on the [OpenAI Gy
3030
To run the program, navigate to the project's directory in your terminal. This will be the same folder you cloned into (OpenAI-Neat). There are several different parameters that you can run the program with.
3131

3232
`--max-steps`: The max number of steps to take per genome (timeout)
33+
3334
`--episodes`: The number of times to run a single genome. This takes the average fitness score over all episodes for one genome
35+
3436
`--render`: Renders the game while the algorithm is learning
37+
3538
`--generations`: The number of generations to evolve the network
39+
3640
`--checkpoint`: Uses a checkpoint to start the simulation
41+
3742
`--num-cores`: The number cores on your computer for parallel execution (not in `--render` mode)
3843

3944
To run the simulation, execute this command:
@@ -43,7 +48,7 @@ python gym_solver.py --max-steps=1000 --episodes=10 --generations=50 --render
4348
```
4449
This tells the program to run 50 generations with 10 episodes per species in the population and render the game while the algorithm is learning.
4550

46-
## Editing Parameters
51+
### Editing Parameters
4752
If you want to change the game, you will need to edit a few parameters. As an example, let's say we want to play Pacman. In order to play Atari games, we must use the ram version. Currently only ram versions are compatible with my program. On the Atari [page](https://gym.openai.com/envs#atari), scroll down and find the name of the ram version of Pacman (`MsPacman-ram-v0`).
4853

4954
Open the `gym_solver.py` file and edit the `game_name` parameter so that it is `'MsPacman-ram-v0'`.
@@ -83,7 +88,7 @@ python gym_solver.py --episodes=3 --generations=100 --num-cores=8 --max-steps=10
8388

8489
It will take a few hours to simulate this game.
8590

86-
## Starting from a Checkpoint
91+
### Starting from a Checkpoint
8792

8893
My program also gives you the ability to continue a simulation after it finishes. When your simulation finishes, it will generate a `checkpoint` file. If you start a new simulation on the same game, you can use this checkpoint file to pick up where your simulation left off. In the Pacman example, after my simulation finishes, I can run:
8994

@@ -98,6 +103,68 @@ First, make sure to follow the installation guide for gym (above).
98103

99104
Then, make sure you follow the installation instructions for universe at this [link](https://github.com/openai/universe#installation).
100105

101-
## Running the Program
106+
### Running the Program
107+
108+
There are two files that are used to solve universe environments: `universe_config` and `universe_solver.py`.
109+
110+
You can run the simulation with the same parameters as `gym_solver`
111+
112+
`--max-steps`: The max number of steps to take per genome (timeout)
113+
114+
`--episodes`: The number of times to run a single genome. This takes the average fitness score over all episodes for one genome
115+
116+
`--render`: Renders the game while the algorithm is learning
117+
118+
`--generations`: The number of generations to evolve the network
119+
120+
`--checkpoint`: Uses a checkpoint to start the simulation
121+
122+
`--num-cores`: The number cores on your computer for parallel execution (not in `--render` mode)
123+
124+
`universe_solver.py` is initially setup to run with `flashgames.DriftRunners-v0`. You can run it with the following arguments:
125+
126+
```shell
127+
python universe_solver.py --max-steps=10000 --generations=50 --render
128+
```
129+
### Simulating Other Games
130+
131+
You can also modify the program to run with any universe [environment](https://universe.openai.com/envs#flash_games).
132+
133+
Open up the `universe_solver.py` file. There is a section at the top with parameters that should be modified.
134+
135+
```
136+
### User Params ###
137+
138+
# The name of the game to solve
139+
game_name = 'flashgames.DriftRunners-v0'
140+
141+
# Change these to define the available actions in the game
142+
action_sheet = [('KeyEvent', 'ArrowUp'), ('KeyEvent', 'ArrowLeft'), ('KeyEvent', 'ArrowRight')]
143+
144+
# Rules for actions that can't be taken at the same time
145+
rules = [['ArrowLeft', 'ArrowRight'], ['ArrowUp', 'ArrowDown']]
146+
147+
### End User Params ###
148+
```
149+
150+
`game_name` should be changed to the name of the game you want to simulate.
151+
152+
`action_sheet` holds all of the actions that can be taken in the game. A list of actions can be found [here](https://github.com/openai/universe/blob/master/universe/vncdriver/constants.py)
153+
154+
`rules` is an array of rules which are basically actions that can't be taken at the same time during one step. For example, the left and right key in a racing game cannot be pressed at the same time.
155+
156+
Adjust these paramters according to the game enviroment you choose.
157+
158+
Next, open the `universe_config` and edit
159+
```
160+
output_nodes = 3
161+
```
162+
to be the length of the action sheet array.
163+
164+
Also edit
165+
```
166+
max_fitness_threshold = 6000
167+
```
168+
to an appropriate target fitness score.
102169

103-
_TODO_
170+
*Note* - `universe_solver.py` creates a checkpoint file like `gym_solver.py`

universe_config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ activation_functions = sigmoid
1919
weight_stdev = 1.0
2020

2121
[genetic]
22-
pop_size = 5
22+
pop_size = 30
2323
max_fitness_threshold = 6000
2424
prob_add_conn = 0.988
2525
prob_add_node = 0.25
@@ -48,4 +48,4 @@ max_stagnation = 15
4848

4949
[DefaultReproduction]
5050
elitism = 2
51-
survival_threshold = 0.1
51+
survival_threshold = 0.1

0 commit comments

Comments
 (0)