Project 8 of 12, for Caitlin
Tide Gate Controller
Caitlin's Tide Gate game as a Gymnasium environment, kept by a keeper that learned it: a harbour balanced between the mud and the quay, at home.
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
- CaitlinThis is my new cabinet, it's called Tide Gate. There's a little harbour, a sea wall and one gate.
- CaitlinShut it at high water and the river fills the harbour, but if you open it at low water it drains.
- YahyaIf you just leave it alone you last about eight hours of game time. I've tried, trust me.
- CaitlinI want a keeper that plays it properly, and a table that says why it did what it did.
- PaulIt's a balancing job really, a bit like keeping a pole up on a cart, only wetter.
First, in the workshop: the racing grid in Gymnasium's shape, reset and step, as a plain class.
Then, at home, with real Gymnasium:
gate_env.py:TideGateEnv, agymnasium.Env. Every quarter of an hour the keeper winds the gate down a notch, leaves it, or winds it up (actions 0, 1, 2). The observation is four numbers: harbour level, sea level, the gate's notch, and how far the sea rose since the last step. The reward is 1.0 for each quarter hour the harbour stays between 2 m and 4 m. Outside that, the episode is terminated; after 200 quarter hours, truncated.agent.py: a keeper that learns the gate by tabular Q-learning and beats leaving it alone.
(.venv) $ python agent.py Do nothing: safe for 34.5 of 200 quarter hours, on average The keeper: safe for 200.0 of 200 quarter hours, on average (.venv) $ pytest .................... [100%] 20 passed in 16.75s
What you learn
What's in it
- One shape for every world
- Finished, or stopped
- Stopped or finished
- The same seed, the same run
- The real Gymnasium class
- How Paul would do it
- Make the grid Gymnasium-shaped
- Two flags, not one
- Readings into bins
- Tide Gate, at home
- Ship it