Hello all and welcome to the first ever Warwick AI programming competition!
Don't worry if you're new to programming or AI, there's something here for everyone! For beginners, check out the WAI + Code Soc + UWCS Python course or ask us anything at our weekly code nights. See our website for details.
- 🗺️ Format: Squad up in teams of any size!
- 🧠 Duration: Running officially till week 9 of term 1
- 💰 Prize: The winning team will receive a £50 Tesco Voucher + eternal WAI glory
- 📊 Leaderboard: Live updates on our website throughout the competition
- 🏆 Final Testing: We'll do thorough testing for final results
🤖 We want this repository to become place where future members can explore a variety of AI implementations and archetypes.
❤️ Once the competition is over, we'd love to accept any and all creations as open source contributions! Your AI might even be used as a baseline for scoring future submissions!
✍️ Also, this is a also new project with room for improvement. If you have ideas or suggestions:
- ✉️ Message us directly
- 🚨 Send a pull request with your changes
Open source contributions are great practice and go an long way on a CV!
First, login on our website https://warwick.ai with your GitHub account! Don't worry if you forget, logging in later won't break anything :)
Next, use this template repository to create you own by pressing Use this template: ⬇️
This button is in the top right of the page. You will be prompted to give it a name and choose for it to be public/private. These setting are completely up to you and won't affect anything :)
Then, go to https://github.com/apps/warwickai and press install/configure to authorise the app to view your repository.
This is what allows us to send your score to the leaderboard!
Open your project's repository in a terminal and install the required dependencies:
# Create virtual environment
python -m venv .venv
# Activate it
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -e .With this done, submitting is as easy as pushing a commit to your repository!
If you don't have a development environment set up, an alternative is making a github codespace:
Please note, snake run will not work from a github codespace, instead the code must be run locally.
snake listsnake run easy
snake run hardsnake test 100 medium
snake test 50 all # cycles through every difficultysnake train easy
snake train easy --resume # keep training the model you already havesnake run hard --seed 123
snake test 100 hard --seed 69Your submission is the myAI function in myAI.py:
def myAI(state: GameState) -> Turn:
# Your brilliant strategy here!
return Turn.LEFT # or Turn.STRAIGHT or Turn.RIGHTYour AI function should use the current state of the game state and ouput one of Turn.LEFT, Turn.RIGHT or Turn.STRAIGHT.
The turn you choose will make your snake turn left, right or stay straight before moving.
There's all sorts of ways to write an AI for this competition:
- Rules/heuristics
- Search algorithms
- Reinforcement learning
- and much more!
Rather than writing the rules yourself, you can train a snake to work them out. The project ships a Gymnasium environment and a Stable Baselines 3 training loop, so it's one extra command.
Everything you edit is in myEnv.py: observe, step, reset, observation_space - a real Gymnasium environment. Leave the plumbing at the bottom alone. play_turn() moves the snakes exactly as the scorer does, and changing it means training against a different game to the one you're scored on.
Uncomment these two lines in pyproject.toml, then re-run pip install -e .:
# "gymnasium>=1.0",
# "stable-baselines3>=2.4",
⚠️ Don't skip this. The scorer installs whatever is in yourpyproject.toml. Leave them commented and your trained snake won't run, so you won't get a score.
snake train easyWatch ep_rew_mean in the table that prints — your average reward per game. Climbing means it's learning. The model saves to model.zip.
snake train easy --steps 50000 # ~5s smoke test (the snake will still be awful)
snake train easy --resume # keep training the model you already haveUncomment the two rlAI lines in myAI.py:
from examples.rlAI import rlAI
return rlAI(state)Then snake run easy to watch it and snake test 100 easy to score it.
Commit model.zip along with your code and push. It's scored like any other submission.
🐐 To submit your AI, simply push a commit to your repository.
🧪 This will run some automated tests and your score will automatically appear on the website! https://warwick.ai
Don't change anything in the snake folder as the submission tests use this code!
Other than this, have fun and see you at code nights!
- 📅 Weekly code nights
- 🌐 Visit warwick.ai
- 💬 Message us with questions
