Archive for the ‘Simulation’ Category

Summer Project: October

Sunday, October 24th, 2010

Status of the Project

Summer has passed, and I took a break from working on the space artillery game. Not because I had other time commitments (although I did find other ways to fill my days), but rather because I just didn’t see how what I was making was supposed to be fun. Fortunately, stepping back for a while let me get my bearings again, and I did some work in the last couple of days and am much closer to having something I’d consider the early working stages of an enjoyable game.


Now that I’m not doing physics tests all the time, I re-scaled the solar system so that everything is a lot further away and moves more slowly. This fixes the problem I was having where every time your turn came up you were shooting from a completely new position. While the constant orbital motion is supposed to add a challenge, the player needs to have some ability to make adjustments based on what he saw his missile do the prior turn. I also moved the asteroids into a normally-distributed belt beyond the orbit of the last planet. With both of these changes in place, the only time the collision detection actually gets used is when a missile strikes something. While having planets bounce around like billiards balls was amusing, its time has passed.


I have prepared a series of screenshots that tell a little story of a red and blue planet trying to kill one another:

Red planet about to shoot:

Red planet about to shoot.

Blue fires his shot as well:

Blue fires his shot as well.

Red defends against a prior shot of blue’s:

Red defends against a prior shot of blue\'s.

Red survives; blue lines up another shot:

Red survives; blue lines up another shot.

As you can see, it takes several turns for a missile to arrive at its target, and you so you can have a lot of them on screen at once. The one that red shoots out of the air to protect itself was fired several turns earlier by blue. I’m still working out things like the best speed for the projectiles. But I definitely had a lot more fun playing this round against myself than I had been at the end of September.

Summer Project, Weeks 4-9

Tuesday, August 24th, 2010

Continued from part one, more details about my quest to make a fun game about shooting things into space.

Week 4

Took the week off.

Week 5

I only got a little bit done this week, but it makes things look better. Each astronomical body has a rotational rate that controls how it is drawn, and projectiles always rotate to face the direction of their movement. I know that you actually need an aerodynamic projectile which is inside an atmosphere to have this happen, but it’s aesthetically pleasing, so I’m keeping it for now. I’ll revisit it if I have any clever ideas when I’m making self-propelled projectiles.

Weeks 6 & 7

These two weeks got eaten up preparing for and recovering from Otakon.

Week 8

This week I rejiggered a bunch of the numbers for the solar system I was using so that my planets were actually close enough to one another and large enough that you can actually see them all. Previously I was using values from our real solar system, which gave me a set of stable orbits, but everything was so far apart that I had to assign the planets pixel-based sizes to make them even be visible. I now have a much smaller set of numbers, where everything is in much closer together. I then made a random map generator based on these new numbers. I also added a whole mess of asteroids to the maps so that I can have them swinging around. So that I can get the same random numbers and thus the same map on any platform, I grabbed a Mersenne Twister library to use in the project. No more crappy libc rand() implementations for me.

After that, I started on something a lot cooler – collisions between objects. Objects now bounce off of each other like pool balls, which can result in a fun mess if I send a planet careening through a mass of asteroids. I also had a bit of fun bouncing two planets in the same orbit off of each other, although slight imprecisions in the math resulted in their orbits eventually degenerating into an unusual arrangement, as you can see in these screenshots:

Planets bouncing off of each other Planets in new orbits

Finally, as you may have noticed if you were playing a lot of attention to those screenshots, I ported my work over to the Mac. Now that I have a laptop again, it only makes sense to keep this project cross-platform. Since all the tools and libraries I’m using are cross platform, it was only a minor inconveniece to set everything up.

Week 9

Didn’t get anything done again. I’m rapidly running out of summer.

Summer Project, Weeks 1-3

Saturday, July 10th, 2010


This summer I’ve decided to dedicate some time to working on programming a game. For eight weeks, from June 20th to August 14th, I am planning to put in at least a couple of hours three nights a week. At the end of this time I will evaluate my progress and the state of my project and set further goals.

Now, what is this game that I’m making? At its heart, it’s a 2 dimensional artillery game, like everything from Scorched Earth to Worms to the one with the gorillas that came with QBasic. The twist to what I’m doing is that the entire thing is set in space. Your planet, orbiting the nearby star, is firing upon other planets, also orbiting the same star. Everything is constantly moving. In order to keep confusion under control and to counter the fact that shots aren’t repeatable, I have plans for an interface to allow player’s to simulate where their shots will land. To the best of my knowledge, this sort of game hasn’t been built before. We shall find out if it was for good reason or not.

I’m going to try to post an update on my progress every week or so. Here’s a quick recap of what I’ve done so far.

Indeterminate Past

Before this all started, I decided one day to write an orbital simulator, just for the fun of it. As I played around with it, I started thinking about making it into an artillery game. After I finished my initial project, and could sit and watch the planets of our solar system make their way through the sky, I wrote some game design ideas and set some development milestones, but didn’t do any more coding.

Week 1

I got off to a rather slow start. All I finished in the first week was rearranging my old code some so that it looked a bit less like a weekend hack (which it was) and a bit more like the groundwork for a project that could maybe go somewhere.

Week 2

I’d picked out a few UI libraries I wanted to try integrating things with, so I tried them out to see which to use. At first I tried Agar. I was finding it a bit heavy, and wasn’t sure it was what I wanted, so I decided to try out my other contender, GiGi. I couldn’t even get GiGi to compile (on Windows), so back to Agar it was. I then had to struggle significantly to get my existing Cairo-based drawing code to output things onto a graphics surface Agar was happy pushing onto the screen. Eventually I got all that done and was left with a solar system app that no longer supported any sort of user input and used more CPU than it used to. All around, a success!

Week 3

This week I actually started tackling some of the new functionality I wanted to include. I’ve been pulling items off of my to-do list for a (very!) minimally playable demo. I’m going to stick with the philosophy of getting things “playable” as quickly as I can and then keeping them so at all times. This week I have added a placeholder UI, and established the basis of a turn structure by having the physical simulation hooked up to the “Fire” button. Today I finished up support for loading texture images off disk so that my planets don’t have to be flat colored circles anymore.

As a reward for a job well done I set two planets on the same orbit in opposite directions and watched them pull each other into the sun.

Ants Intro

Friday, October 10th, 2008

Inspired by the brave explorers that found their way into my kitchen via means unknown, I’ve been working on a simulation of ants with their actions being based on the pheremone trails they leave behind. Given that I could represent their decision making process with a simple table of values, I decided to use a genetic algorithm to refine the values over successive generations and attempt to breed better and better ants. I wrote up an initial design before I began coding, although I found some issues with it and have strayed somewhat as time has gone by.

As of writing this, I have covered most of the basic functionality necessary to prove the function of the simulator to myself. I have ants that run around and bring food back home, I use a version of a genetic algorithm to make future generations better than prior ones, and I have a visualizer that lets me see how the ants move and how the pheremones are distributed.

Speed is an issue, and it is a limiting factor in running larger simulations and having multiple teams of ants fight one another. In the name of making things run faster, I’m probably going to have to greatly simplify or entirely remove the code for diffusing pheremones across the map. More on this once I come up with a solution, but my initial method required touching every cell on the map 9 times, which just won’t do when I’m trying to run hundreds of thousands of iterations in a timely manner.

So as to provide historical context, I will link to the current revision of the repository. Several aspects of the code have grown beyond my original plans for them and everything needs a bit of a cleanup. As I address the deficiencies of various features I plan to write up the changes I made here.