DEV Community

Cover image for Control a Farming Drone with C++ — Play It in Your Browser (Cropbot)
Alex
Alex

Posted on

Control a Farming Drone with C++ — Play It in Your Browser (Cropbot)

Preview

What if a farming game didn’t let you click anything?

What if the only way to control the world… was to write C++?

I built exactly that.

A browser-based game where you control a farming drone entirely through C++ code — compiled to WebAssembly and executed live in the game.

👉 Play it here:

https://cropbot.fly.dev/

No install.

No setup.

Just open and start coding.


You Don’t Play. You Program.

The world is a grid.

Each cell can be:

  • Empty
  • Tilled
  • Planted
  • Growing
  • Ready to harvest
  • Base station

The drone can:

  • Move across the grid
  • Till soil
  • Plant different crops
  • Water them
  • Harvest them
  • Buy seeds
  • Manage energy and water
  • Earn gold
  • Increase score

But here’s the key difference:

You never click to move.

You never press a harvest button.

You write the logic — and the drone executes it.


It Quickly Stops Being “Farming”

At first, it feels simple:

If a cell is empty — plant.

If it’s ready — harvest.

But then systems start stacking:

  • Water tank capacity
  • Energy limits
  • Seeds cost gold
  • Crops grow over time
  • Grid traversal must be efficient
  • Score depends on smart decisions

Suddenly, it’s not a farming game.

It’s an optimization problem.


It’s About Designing Behavior

You don’t react.

You design.

You write loops.
You define conditions.
You structure traversal.
You manage resources.

If your logic is inefficient:

  • You waste ticks
  • You waste energy
  • You miss harvest windows
  • Your score drops

The game becomes about algorithm design.


Why C++?

Most programming games use Python.

I deliberately chose C++.

Because C++ forces clarity:

  • Strong typing
  • Explicit control flow
  • Deterministic execution
  • Clear system boundaries

It feels less like scripting.

More like engineering a machine.

And your drone is that machine.


Under the Hood

  • Your C++ code is compiled to WebAssembly
  • A restricted drone API is injected
  • The simulation runs in a sandbox
  • Grid size is provided dynamically
  • Only safe functions are exposed

Your code becomes the AI brain.

The game becomes the environment.

Clean separation.

Deterministic simulation.

Pure logic.


Where This Can Go

This is just the first version.

But the concept has serious room to grow:

  • Competitive bot leaderboards
  • Optimization tournaments
  • Different maps with obstacles
  • Energy-constrained challenges
  • Multi-drone simulations
  • Profit-maximizing strategies
  • Time-based scoring competitions

It could evolve into a full C++ automation strategy game.

Or even a competitive AI arena in the browser.


Try It

If you enjoy:

  • Automation
  • Systems thinking
  • Algorithm design
  • Programming-driven gameplay

You might like this.

Open it.

Write some C++.

Watch your drone think.

👉 https://cropbot.fly.dev/
repo: https://github.com/pioner92/cropbot

This started as a small experiment.

But “control a drone with C++” feels like a concept with real potential.

Top comments (0)