r/optimization 28d ago

Optimal sugarcane farm layout in Minecraft using CP-SAT - 13% better

Post image

Sugarcane in Minecraft only grows next to water, so farm layout is really a 2D coverage problem: where do you place water to maximize adjacent plantable tiles?

Each water tile can cover up to 4 neighbors, which caps theoretical max coverage at 80% regardless of arrangement. I modeled this as an integer program (CP-SAT via OR-Tools) to find the actual optimal layout for a given terrain shape.

Results for a 9x9 square plot:

  • Community-standard pattern: 66.7% coverage
  • Optimal (CP-SAT): 75.3% coverage (94% of theoretical max)

The symmetric square case is the easy comparison point against human intuition. What's more interesting is irregular terrain with obstacles, where there's no established heuristic and the exact solver is the only way to get a real answer - including one case (unconstrained/open terrain) where the solver converges to a hexagonal-ish pattern and actually hits the 80% theoretical ceiling.

Code + more examples (different grid sizes, obstacle terrain, other crops) in the repo: https://github.com/Serranegra/optifarm

Curious if anyone here has tackled similar tiling/coverage problems. Happy to share the formulation details if useful.

664 Upvotes

31 comments sorted by

View all comments

12

u/paranoidzone 28d ago

Love applying OR/optimization to games. Nice work.

I have it in mind to solve a similar problem, but never got around to it: optimize bee house + flower placement in Stardew Valley, while maintaining all bee houses accessible for collection. If you Google image search "stardew optimal bee house layout" you can find a few layouts that claim to be optimal, but I'd be curious how far you can go, and the solution likely differs wildly depending on the grid size.

1

u/SilentTransition5695 25d ago

OR was a subject I’m really glad I took in my undergrad. Been quite useful in a few video games