Skip to content

Instantly share code, notes, and snippets.

@robclewley
Last active August 29, 2015 14:17
Show Gist options
  • Save robclewley/6bf44c94443bbe7e9424 to your computer and use it in GitHub Desktop.
Save robclewley/6bf44c94443bbe7e9424 to your computer and use it in GitHub Desktop.
Brief description of gamified exploratory modeling tool application, Bombardier

Bombardier's Guild is a fun steampunk-like mobile game app that I used to play a lot. Basically, you have to shoot a projectile from one planet to hit another, while navigating a static, 2D n-body problem inbetween. It's a simple setup but a highly nonlinear four-dimensional system with two free parameters. For certain configurations of the n body obstacles, trajectory designs are very hard to intuit and figure out because of chaotic parameter regions (exponentially high sensitivity of final outcome to small changes in parameters). Hence the interest in visual diagnostic tools to assist a player in deconstructing and eventually solving the game.

I was inspired to recreate some of Bombardier's core gameplay as part of a demonstration of innovative new model exploration and algorithm diagnosis tools (see screenshot demo_shot.png below)

Here, you see a trajectory that successfully hits a user-defined target, with heatmap color coding along the line segment trajectory according to the projectile's velocity, and a yellow domain of influence for body #1.

Here's the repo for Fovea with all the backend code for the GUI dev around the modeling exploration.

The equations of motion are created from the YAML via converting the body data into necessary params and then into the equations

The equations are a direct derivation from Newton's Second Law of motion (F=ma) in 2D:

equation

sum of forces F_i/m_i at X = dX^2 / dt^2

where

F_i(x,y) = ( -G*(x-bxi)/pow(d(x,y,bxi,byi),3),
            -G*(y-byi)/pow(d(x,y,bxi,byi),3) )

using the law of universal gravitation for each body #i at (bxi, byi) coordinates and mass mi, and using the Euclidean distance function between two points written as d(x1,y1;x2,y2).

Then, these second order ODEs are turned into a pair of first order equations for each component of X = (x,y) using a standard trick using "dummy" state variables vx and vy (for the velocity components).

d x / dt = vx
d y / dt = vy
d vx /dt = SUM( Fi(x,y)_x / mi )
d vy / dt = SUM( Fi(x,y))_y / mi )

This 4D system can be solved by any standard ODE integrator like Euler's method or RK4.

Presently, Fovea displays the dynamics and an interactive GUI based in matplotlib. Maybe using mpld3, I'd like to get this interaction onto the web.

To keep the project general purpose, I want the browser to hook down into my PyDSTool modeling tool to actually solve the equations of motion, partly because it's also solving event detections and other useful things that I don't want to try to reinvent inside browser code. PyDSTool is the central necessary modeling software to my plans for world domination, and hooking that up live to the web is Step One.

<!doctype html>
<html>
<head>
</head>
<body>
<img src="https://gist.githubusercontent.com/robclewley/6bf44c94443bbe7e9424/raw/cd89e89a25f97169b2986b1c93cd92e662cac0b6/demo_shot.png" width=600></img>
<iframe src="http://nbviewer.ipython.org/gist/bollwyvl/d5a120156216797c7132" width="600" height="800"></iframe>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment