Introduction
I recently booted up an offline card game I used to love — and couldn't clear the hardest difficulty anymore.
I used to be able to beat it.
That frustration sparked an idea: what if I trained an AI to help me figure it out? I had three constraints going in:
- It had to work offline
- I wanted to try reinforcement learning while I was at it
- It had to be lightweight enough to run on an 8-year-old MacBook Air
After a lot of trial and error, I landed on building a custom engine in Rust and running the training on Google Colab. This article focuses on the Google Colab side of that setup.
What Is Google Colab?
Google Colab is a free Python execution environment provided by Google (this article assumes the free tier). All you need is a browser — no installation required.
What made it useful for this project:
- Free GPU/CPU access
- Integrates with Google Drive
- Runs heavy workloads regardless of your local hardware
Training that would've been painful on an old MacBook Air ran smoothly once I moved it to Colab.
⚠️ Note: On the free tier, the session disconnects after a period of inactivity or after a maximum of 12 hours, and runtime data is reset.
What I Did
The goal was to train an AI to play an offline deck-building card game using reinforcement learning.
Here's the overall flow:
- Translate the game rules and card effects into language
- Convert that into numerical data the AI can work with
- Build a custom training engine in Rust
- Upload the training data to Google Drive
- Mount Google Drive in Colab and run it
Steps 1–3 are all on the Rust side — I'll cover those in a follow-up. This article focuses on steps 4 and 5.
Mounting Google Drive in Colab
Run the following code in a Colab cell:
from google.colab import drive
drive.mount('/content/drive')
You'll see a prompt asking to authorize access to Google Drive. Click "Connect to Google Drive", choose your account, and allow access. Once done, a drive/MyDrive folder will appear in the left sidebar.
After mounting, your Drive is accessible at:
/content/drive/MyDrive/
💡 You can also mount Drive without writing any code — just click the folder icon in the left sidebar and hit the "Mount Drive" button. It inserts the code automatically.
⚠️ If Google Drive's cache is stale, updates to your Drive may not reflect in Colab. If that happens, force a remount:
drive.flush_and_unmount()
drive.mount('/content/drive', force_remount=True)
Running the Binary and Starting Training
Once Drive is mounted, you can execute the file you uploaded directly from Colab.
subprocess is Python's standard library for calling external programs — in this case, the Rust binary:
import subprocess
result = subprocess.run(
['/content/drive/MyDrive/your_binary'],
capture_output=True,
text=True
)
print(result.stdout)
Replace your_binary with your actual filename.
💡 If you get a permission error, run this first.
0o755grants execute permission on Linux:
import os
os.chmod('/content/drive/MyDrive/your_binary', 0o755)
Stuck? Ask Gemini
Colab has Gemini built in — just click the icon in the top right. Paste your error message directly and it'll suggest a fix. Don't hesitate to just dump the error and let it figure it out 😊
Closing
I covered the Google Colab basics, mounting Google Drive, and running a Rust binary — all from a browser, on hardware that couldn't have handled the training locally.
If this was useful, the follow-up covers the reinforcement learning setup and how I represented the game state. I'll write it if there's interest 😊
👇 Part 2 here
(coming soon)
Top comments (0)