Skip to content

About

Resource allocation and scheduling experiments - Q-learning agent that plays Snake

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Learn2Slither

A Q-learning agent that plays Snake on a 10x10 board, seeing only the cross through its own head. After 1000 training sessions it reaches a length of about 29 against an objective of 10. A 42 Abu Dhabi project.

Run

python3 snake.py -visual on -load models/1000sess.json -sessions 5 -dontlearn

Training:

python3 snake.py -sessions 1000 -save models/1000sess.json

Flags: -sessions -save -load -visual on|off -dontlearn -step-by-step -speed -seed.

Test

python3 test_snake.py

Trained models

model max length max duration
1sess 4 36
10sess 5 11
100sess 7 27
1000sess 29 1000 (step cap)

Notes

  • State is the snake's vision only, reduced per direction to danger, green apple in line, red apple in line. Nothing outside the vision cross is used.
  • Rewards: green +20, red -15, death -50, plus a shaping term of plus or minus 1 toward the nearest green apple.
  • Step cap of 1000 per session, since a snake that never dies would loop forever.
  • Modules: environment.py, agent.py, gui.py (tkinter), snake.py (CLI).
  • PROGRESS.md is the development log.

About

Resource allocation and scheduling experiments - Q-learning agent that plays Snake

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages