Block-Reign: A Player vs AI Grid Game That Learns From You
Source: Dev.to

Most game AIs are fake smart—patterns, scripts, predictable behavior.
Block-Reign isn’t.
It’s a lightweight Player vs AI grid battle game where the AI actually learns from every match you play—wins, losses, mistakes, all of it. No GPU, no fancy engines—just Python, reinforcement learning, and persistence.
🕹️ What Is Block-Reign?
Block-Reign is a 10×10 grid‑based Player vs AI combat game built with:
- Flask + HTML for the frontend
- Python for the game server
- Reinforcement Learning (Q‑Learning) for live gameplay
- DQN for advanced offline experimentation
You play in the browser, the AI runs on the server, and after every match it gets smarter.
🤖 The AI Philosophy
The core idea was simple:
What if the AI learned only from real games—not pre‑trained data?
So the AI:
- Starts dumb
- Learns only from actual matches
- Saves its knowledge permanently
- Adapts to your playstyle
No synthetic data, no scripted behaviors—just experience.
🧠 How Learning Works
The running server uses a Q‑learning AI. After each completed match:
- Match data is sent to the server.
- The AI updates its Q‑table.
- Progress is saved on disk.
If you restart the server, the AI remembers everything.
The project also includes a DQN trainer (ai_trainer.py) for experimentation.
📊 Current AI Progress
As of the latest run:
- Win rate: ~59%
- Matches played: 78
- Record: 46 Wins / 36 Losses
These stats are not hardcoded; they are learned, stored, and persisted. Deleting the training folder makes the AI forget everything.
🎮 Gameplay
- 10×10 grid
- Arrow keys to move
- Space to shoot
- Simple mechanics, strategic positioning
- Fast matches, instant feedback
Minimal visuals, maximum behavior learning.
🔁 Resetting the AI
Delete the training data:
training/
or the specific model file:
training/models/simple_ai.pkl
Then restart the server and play again. The AI starts from scratch.
🛠️ Why I Built This
The project isn’t about graphics or polish. It’s about:
- Understanding reinforcement learning
- Watching an AI evolve organically
- Building adaptive systems without massive compute
🔗 Repository
https://github.com/DeveloperPuneet/Block-Reign
Final Thought
Block-Reign isn’t perfect, but it’s honest—an AI that earns its intelligence one loss at a time.
And this isn’t the end. Wilder strategies, sharper gameplay, better graphics… something crazier is coming. Wait for it 👀
Have any suggestions? Comment below.