Conversation
EwoutH
left a comment
There was a problem hiding this comment.
Some goofy fun!
We currently don't have games in our repo, but maybe we should. I'm going to discuss that in a bit.
There was a problem hiding this comment.
The convention is to use app.py for Solara visualisations.
There was a problem hiding this comment.
I have already modified the file name.
examples/projectile_attack/run.py
Outdated
|
|
||
| renderer = SpaceRenderer(model, backend="matplotlib") | ||
| renderer.draw_structure() | ||
| renderer.draw_agents(agent_portrayal) |
There was a problem hiding this comment.
FutureWarning: Passing agent_portrayal to draw_agents() is deprecated and will be removed in Mesa 4.0. Use setup_agents(agent_portrayal, **kwargs) before calling draw_agents().
renderer.draw_agents(agent_portrayal)
See mesa/mesa#3202
There was a problem hiding this comment.
The version of Mesa I'm using is 3.3.1, but it seems that there is no "setup_agents" method. Therefore, I adopted a compatibility approach to ensure that my code can run on both Mesa 3.3.1 and Mesa 4.0. :
if hasattr(renderer, "setup_agents"):
renderer.setup_agents(agent_portrayal).draw_agents()
else:
renderer.draw_agents(agent_portrayal)
examples/projectile_attack/run.py
Outdated
| renderer = SpaceRenderer(model, backend="matplotlib") | ||
| renderer.draw_structure() | ||
| renderer.draw_agents(agent_portrayal) | ||
| renderer.draw_propertylayer(propertylayer_portrayal) |
There was a problem hiding this comment.
FutureWarning: Passing propertylayer_portrayal to draw_propertylayer() is deprecated and will be removed in Mesa 4.0. Use setup_propertylayer(propertylayer_portrayal) before calling draw_propertylayer().
There was a problem hiding this comment.
The same modification method as above :
if hasattr(renderer, "setup_propertylayer"):
renderer.setup_propertylayer(propertylayer_portrayal).draw_propertylayer()
else:
renderer.draw_propertylayer(propertylayer_portrayal)
|
@EwoutH Got it! I'll fix this in the next couple of days. |
Summary
This PR adds a Projectile Attack example: a simple 2D projectile mini-game built with Mesa (simulation) + Solara (visualization). Players control a stationary tank, tune angle/power, and fire shells to hit a target. The example includes optional moving target, a fixed wall obstacle, and a trajectory trace overlay.
Motive
Explore the possibility of applying ABM in game. By using agents, the game can simulate physical feedback in the real world, such as the effect of gravity.
Implementation
agents.py: defines Tank, Shell, Target, Wall.model.py: builds the Mesa model, grid, wall, trajectories, firing mechanics, and win/lose state.run.py: Solara UI for controls, rendering the grid and overlays, and user interactions.Some rules:
Usage Examples
From the project root:
solara run run.pyAdditional Notes
To start the game: