Skip to content

Conversation

@darshi1337
Copy link

Description

I added a step-based Minesweeper model as a new example in mesa-examples. This model reframes Minesweeper as an autonomous spatial diffusion process rather than an interactive game, making it suitable as an educational and analytical Mesa example.

The model demonstrates how local neighborhood rules and a frontier-based propagation mechanism can produce emergent spatial patterns on a discrete grid.


Motive

  • Demonstrate frontier-based spatial propagation
    The model uses an explicit frontier to control which cells are processed at each step, illustrating wave-like expansion and natural termination.

  • Show neighborhood-driven dynamics
    Cell behavior depends entirely on local neighborhood state (number of adjacent mines), highlighting classic cellular automaton principles.

  • Combine spatial and temporal analysis
    In addition to grid visualization, the example includes a DataCollector to track and plot how the system evolves over time.

  • Provide a clear, non-interactive reference model
    The example avoids user interaction and instead focuses on step-wise dynamics, aligning with current SolaraViz capabilities.


Implementation

The model is split across three files:

model.py

  • Orthogonal grid with one agent per cell
  • Random mine placement via PropertyLayer
  • Frontier-based reveal logic (flood-fill–like propagation)
  • Automatic reseeding of unrevealed safe regions
  • DataCollector tracking:
    • Total revealed cells
    • Frontier size per step

agents.py

  • MineCell agent storing:
    • Revealed state
    • Number of neighboring mines

app.py

  • Matplotlib-based grid visualization
  • Time-series plot showing reveal dynamics
  • Parameter controls for grid size, mine density, and seed

Notes

  • This model is non-interactive by design and does not implement player clicks.
  • I was wondering whether click-based interaction can currently be implemented for more complex models. From what I understand, Mesa does not yet support this functionality. I would also appreciate any suggestions or guidance on how click handling might be implemented within Mesa itself.

Running the example

solara run examples/minesweeper/app.py

Copy link
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

Interesting to see a game here, not the primary target of Mesa but certainly fun!

I noticed I couldn't interact with it. That would be quite cool. Maybe with our Altair visualisation that would be easier than with matplotlib, but not sure.

@Sahil-Chhoker do you know if interactivity / clicking on a cell is possible at all?

@darshi1337
Copy link
Author

@EwoutH I’ve made the changes as suggested. Let me know if anything else is needed.

@EwoutH
Copy link
Member

EwoutH commented Jan 24, 2026

Thanks!

We don't have games yet, we might want to give those a dedicated place. Will loop back.

@Sahil-Chhoker
Copy link
Collaborator

@Sahil-Chhoker do you know if interactivity / clicking on a cell is possible at all?

I don't think it's possible, currently we serve a solara's FigureMatplotlib or FigureAltair on the frontend, while they have a on_click listener for the whole object, it doesn't provide an interface to expose only cells or other properties that can be clicked.

Maybe a custom component that makes grid using solara buttons with image overlays can work, because the user has granular control over a custom component. Can't say anything for sure though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants