DEV Community

Cover image for Block-Reign: A Player vs AI Grid Game That Learns From You
Puneet-Kumar2010
Puneet-Kumar2010

Posted on

Block-Reign: A Player vs AI Grid Game That Learns From You

Most game AIs are fake smart.

Patterns, scripts, predictable behavior.

Block-Reign isn’t.

This is 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 plays on the server.

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
  • 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.

Delete the training folder, and the AI forgets 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:

training/
Enter fullscreen mode Exit fullscreen mode

or:

training/models/simple_ai.pkl
Enter fullscreen mode Exit fullscreen mode

Restart the server and play again.

The AI starts from scratch.


🛠️ Why I Built This

This project wasn’t about graphics or polish.

It was 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 nah — this isn’t the end.
Wilder strategies. Sharper gameplay. Better graphics.
Something crazier is coming. Wait for it 👀
Have any suggestions? comment

Top comments (8)

Collapse
 
johnbaker profile image
John Baker • • Edited

Jei ieškote patogios vietos susipažinti su internetinio kazino pasiūla, verta pradėti nuo pagrindinio puslapio ir peržiūrėti, kaip išdėstytos skirtingos kategorijos. Twinsbet Casino galima rasti įvairių žaidimų bei informacijos apie platformoje siūlomas pramogas. Man patinka pirmiausia apžiūrėti bendrą svetainės struktūrą, o tik tada rinktis konkrečius žaidimus. Taip pat verta atkreipti dėmesį į aktualias taisykles, mokėjimo sąlygas ir atsakingo žaidimo informaciją. Skirtingų platformų palyginimas padeda geriau suprasti, kokios funkcijos jums iš tikrųjų svarbios.

Collapse
 
puneetkumar2010 profile image
Puneet-Kumar2010 •

Thanks, but I’m not interested in online casinos or gambling platforms. I’ll pass.

Collapse
 
puneetkumar2010 profile image
Puneet-Kumar2010 •

... what... ...

Collapse
 
timm8190 profile image
Timm David •

Love it

Collapse
 
puneetkumar2010 profile image
Puneet-Kumar2010 •

Thanks! Glad you liked it 🙌

Collapse
 
copyleftdev profile image
Don Johnson •

love the creativity

Collapse
 
puneetkumar2010 profile image
Puneet-Kumar2010 •

Thanks a ton! Tried something different, glad it worked 😄

Some comments may only be visible to logged-in visitors. Sign in to view all comments.