Define a parent 'body' object. It'll contain the basic physics to work as a moving object. In pseudopython (2.7) it would look a lot like:
class body:
def __init__(self, mass, velocity, position):
self.mass = mass
self.velocity = velocity
self.position = position
def move_step(self, time_scale):
#Basically, steps the object along the simulation.
self.position += self.velocity * time_scale
#Not actually that simple, but time_scale is used to change
#how accurate the simulation is.
Note that I'm just gonna assume that velocity and position are defined as vectors, so that we can easily get their x, y, or z components, or get the magnitude and direction. Writing the vector object will be left up to the reader. Note that I didn't include any references to gravity or other objects. I've found that object-to-object interaction is annoying to deal with, so it would be better to simply have an object that handles the simulation.
Essentially, it loops through each body in the simulation and calculates the forces on the body. Since $\Sigma F = m*a$, you can get the $\Delta V$ of the object and apply it to that body's velocity. After every body's velocity is updated, the simulator loops through again and triggers their move_step method.
Sounds good, right? All you need is to define all the gravities acting on an object, then sum them and update.
Not so fast. 499
You gotta factor in relativity if you want increased accuracy. In general it doesn't change much, but when you get to the scale of the Sun and Mercury, it becomes noticeable. I'd implement a method (or a lambda) that calculates Lorentz factors, and a conditional that chooses whether to use Newtonian or relativistic math based on some fancy factor.
Collisions
Ok, so I can't do this one without making things simpler. Stuff where their sizes are massively different is easy. larger.mass += smaller.mass; del smaller
After that, there's so much complexity that I'm not really sure how to proceed. In essence, objects need to break apart, and they need to have shape. That's hard to do. I'd recommend stealing a lot of stuff from the bpy package.
Gotta go, sorry! 24