Project 2 of 12, for Neil
Gridworld Simulator
Neil's search for a better racing line on the crab cabinet's grid, as a Markov decision process: tiles, moves, slips, rewards, policies and what a race is worth.
Sign up free to open itLog in
Act 8 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- NeilThis is Caitlin's crab cabinet, and on League night everyone races it on the grid.
- NeilEveryone races the traditional line, along the bottom and then up the far side.
- PaulWhich goes right past the pool.
- NeilIt's the shortest way round, but in karting the shortest is hardly ever the fastest, and I want numbers.
- PaulThen let's work out what it's worth, with the slips included.
Write track.py, the racing grid as a Markov decision process:
...F F the finish: +10, and the race is over
.#.P # a rock: nothing goes through it
S... P the rock pool: -10, and the race is over
S the start, (2, 0). Every other tile costs -1.
A tile is a (row, column) pair. Told up, down, left or right, the crab goes that way with chance 0.8, and sideways with chance 0.1 each way. A step off the edge or into the rock leaves it where it was, and still costs -1.
move(tile, direction): where one step leads.outcomes(tile, action, slip=0.2): a list of every(probability, next tile, reward, over)that can follow.race(policy, rng, start=(2, 0), slip=0.2, limit=100): one race following a policy, a dictionary from tile to action. Returns the rewards in order.discounted_return(rewards, gamma).MY_LINE: your own policy, better than the traditional line.
Run as a program, it races both lines 1000 times and prints each one's average return, with gamma = 0.9.
The traditional line > > > F ^ # ^ P > > > ^ Average return over 1000 races: -7.79 My line > > > F ^ # ^ P ^ < ^ < Average return over 1000 races: 0.92
What you learn
What's in it
- Tiles, moves and rewards
- Where a move can lead
- Into the rock
- A rulebook for every tile
- After a slip
- What a race is worth
- Four tiles, then the finish
- Now or later
- Backwards from the finish
- How Paul would do it
- Fix Caitlin's version
- Make the racing grid
- Ship it