Categories
Game Development Personal Development

Thousander Club Update: January 8th

For this week’s Thousander Club update:

Game Hours: 262.25 + 1 = 263.25 / 1000
Game Ideas: 616 + 0 = 616 / 1000

On Wednesday, I wrote down an entry in my todo list: Create 384 game ideas.

Months ago, I entered into crunch mode at my day job and neglected a number of things in the rest of my life. I had a ritual of coming up with three game ideas per day, but once I hit crunch, my routine was destroyed, and I never did get back into it.

I thought I could catch up before December was through. After all, coming up with ideas is fairly easy, especially since my game ideas are just one-liners that indicate a concept or theme. It is not as if I am coming up with 500+ page game design documents or anything. In one sitting, I threw together over 100 ideas at once. I figure if I do it a few times this week, I can hit my 1,000 ideas goal and be done with it. Actually, I could probably dedicate an entire afternoon to creating all 384 ideas. Afterwards, I can post the entire list, along with the 161 ideas I had before I started the Thousander Club last year.

Categories
Game Development

The Carnival of Game Production

Juuso announced the creation of the Carnival of Game Production.

What is this Carnival of Game Production?
Simply put: a monthly gathering of game developers and producers at a central location. The idea is similar to those other “Blog Carnivals” – but here we present quality articles dedicated to game production. Anyone wishing to participate in the Carnival is welcome. The Carnival is hosted by a different blog each time.

If you have an article related to game production or game development, go ahead and submit it. If you want to host the carnival one month, contact Juuso.

Categories
Personal Development

The Thousander Club in 2007

Scott Hsu-Storaker founded The Thousander Club about a year ago, and he recently posted a summary of his year in the article Thousander Club Take 2.

For those of you who have no idea what the club is, the idea is to become an expert at something. How do you become an expert at something? Practice. A lot of it.

Let’s recall what was said about how much time is required to become an expert. 10,000 hours over the course of 10 years might make you a master, and that seems like a lot of time to put in. It is, and you’ll note that the experts at chess or dance or baseball or writing invest that time anyway. Of course, if you break it down, it can seem more manageable:

  • 1,000 hours is doable within a year if you work full time, and you can be an experienced expert.
  • 100 hours can be done on the side, and you can still be somewhat of an expert.
  • 10 hours could be a dedicated weekend or spread over a few of them, and you’ll definitely learn enough to be dangerous.
  • Even dedicating an hour to a task will give you practice with the basics.

Can you do 1,000 hours in the coming year? That translates into almost 3 hours per day if you include weekends, or about 20 hours per week. You can easily accomplish it if your full-time job involves becoming an expert at a certain skill, but even a dedicated, part-time effort can get you there.

You don’t even necessarily need to dedicate hours. Scott had a goal of creating 1,000 3D models. I had a goal last year to create 1,000 game ideas. Maybe you’ll try to create 1,000 doodles, or 1,000 songs, or 1,000 pages for a novel.

The main idea is that by practicing a lot, you can’t help but become an expert. So will you join the Thousander Club and gain expertise in your chosen skill?

Like Scott, I didn’t hit my Thousander Club goals for the year, but I am going to continue towards my goal of 1,000 game development hours. I will keep track of my hours for this year separately from last year’s hours, but I will total them to count towards my goal. After all, the main point is to do many hours. Doing them sooner rather than later is ideal, but doing them at all is better than not.

Categories
Personal Development

Resolutions for 2007

Last year’s resolutions didn’t all work out. I have to admit that I forgot about them, and a week or so ago I remembered that I had written a post listing my resolutions for the year.

I did actually form a formal company, but it took me months later than I originally planned. Instead of Oracle’s Eye, I finished Pong and will finish Space Invaders. I played a number of games over the course of the year, including games that I never had a chance to play when they were originally released such as Mega Man and Prince of Persia: Sands of Time. Once again, I didn’t read 52 books for the year, but there was a period of time towards the end of the year when eating and breathing were all I could do between sleep cycles.

But what about for the coming year?

  • I want to sell my first game.
  • I want to create a backup system to replace the one that died last year.
  • I want to become proficient with autotools, such as autoconf and automake.
  • I want to be able to walk up multiple flights of stairs without feeling winded.
  • I want to form at least one good, productive, and/or useful habit per month.

I will try to post about my plans to accomplish each of these resolutions later in the week. I am keeping these resolutions in a list that I will check daily instead of keeping them solely in this blog post. B-)

Happy New Year!

Categories
Game Development Personal Development

Thousander Club Update: December 25th

For this week’s Thousander Club update:

Game Hours: 262.25 / 1000
Game Ideas: 616 / 1000

Target: 1008

Merry Christmas! Apparently I was off a bit in my calculations, as there is almost another week to go before the year’s end…hmm…

In any case, I managed to hit over 25% of my goal for the year, which isn’t too bad. It’s not very good compared to actually doing 1,000 hours, but it wasn’t bad.

Space Invaders is playable as a real game, but I am amazed at the long list of things I have left to do! There is no real animation to speak of, there are no menus or text, there is no way to get to a game over state, and you can’t restart from in-game.

Still, you can continue to shoot enemies for as long as you have ships left. There is no indicator, but you start with the standard three ships. If you lose them all, you need to shutdown the game and start it over if you want to continue playing.

Categories
Geek / Technical

Interesting Results from Testing Random Number Generation Assertions

Taking Ken’s advice from my previous post, I decided to write a small test program to verify that the RNG method touted as the best really was the best.

To recap, there are three methods:
The first method involves using the modulus operator: int pickedNum = rand() % range;
The better method involves some trickery to get past the low-order bits problem: int pickedNum = rand() / (RAND_MAX / range + 1 )
And the best method involves a loop discarding the values that are not within the range:

int randDivisor = RAND_MAX / MAX_RANGE;
unsigned int numPicked;
do
{
numPicked = rand() / randDivisor;
}
while (numPicked >= MAX_RANGE);

I wrote up some code to seed the C++ random number generator, run through the loop for a certain sample size for each method, and then output the results. I was expecting that the best method described in the article would show a better, more even distribution. My test checked the distribution over a range of numbers. I had a vector that stored the number of times a value within that range was picked. That is, if the RNG method output a value of 3, I would increment the value in the vector associated with 3.

I also stored the start time and end time for each loop. Besides accuracy, I think speed would be important for game developers.

I ran it with different sample sizes and different seeds, and each time I seem to come to the same conclusion.

The supposedly “best” method was actually slightly worse than the “better” method.

How did I define what was good and what was bad? I already think that the method described in the article was simpler to write and understand, which means that it wins when it comes to readability and maintainability. Of course, this code will likely be written once and left in some utility class, and the other methods are fairly easy to understand, so we’ll look at other criteria.

How flat is the distribution? If an RNG picks one number much more often than the rest, then it wouldn’t be very good. We would ideally like something that was truly random, so the method that gives us the distribution that was closest to random would be best. Now, I am no expert on statistics, but my check was to subtract the maximum number of times a value was picked from the minimum number of times a value was picked. For an ideal distribution, the answer would be 0. If one distribution’s min to max range is closer to 0 than another, then we can probably assume that the method used to create that first distribution is closer to truly random.

How long does it take to compute a result? If a method produces superior results but takes multiple seconds to calculate each time, it won’t really be useful in a video game which generally tries to calculate results within milliseconds.

So those were my two criteria. If you are very familiar with statistics, perhaps you have already seen a flaw with my test. Please let me know because I would rather have the truth than be correct.

Here are the results when run over a range of 10000 numbers and a sample size of 100000000, using a seed of time(NULL) (the same value was used for each method, so the seed value was created at the start of the program):


Time to finish first method: 9
Time to finish better method: 8
Time to finish best method: 12


Diff between min and max values:
First: 10398 - 9641 = 757
Better: 10414 - 9626 = 788
Best: 10416 - 9621 = 795

I ran it multiple times, and the Best method seemed to always have a large range between the minimum and the maximum number of times a value was picked. It also consistently ran 2 or 3 seconds slower than the other methods.

And using a seed of 0:


Time to finish first method: 9
Time to finish better method: 8
Time to finish best method: 11


Diff between min and max values
First: 10445 - 9629 = 816
Better: 10409 - 9586 = 823
Best: 10395 - 9621 = 774

I ran the test using a much smaller range of values. Instead of 10,000, I used 10.


Time to finish first method: 9
Time to finish better method: 8
Time to finish best method: 10


Diff between min and max values
First: 10006453 - 9992621 = 13832
Better: 10001752 - 9998124 = 3628
Best: 10001752 - 9998124 = 3628

Over a smaller range of values, it seems that the Best and Better methods have the same difference between the minimum and maximum number of times a value was picked. Best was still consistently slower, though.

So what do these results mean?

The trick of dividing by RAND_MAX uses the high order bits of a random number produced by rand(), thus alleviating the old problem of poor rand() implementations with non-random low order bits. But as I said, these days that problem has been largely fixed by library vendors, so the only thing you have managed to do is make the code more complicated. It buys you nothing, and before you start thinking that doing the same thing with floating-point will help, I assure you that it will not.

Well, it seems that according to my tests it buys time, but then the article does mention using a uniform deviate from the random number. I then added that version to my test, and recomputed the results.

For a small range, I found that it ran at the same speed as the first two methods while also providing the same difference between minimum and maximum number of times a value is picked as the Better or Best method.

For a very large range (100000 values), however, I got the following results:

Time to finish first method: 11
Time to finish better method: 11
Time to finish best method: 13
Time to finish deviate method: 11


Diff between min and max values
First: 1178 - 860 = 318
Better: 1140 - 238 = 902
Best: 1135 - 861 = 274
Deviate: 1142 - 865 = 277

As you can see, the uniform deviate method was computed at about the same speed as the non-looping methods. While being only slightly worse at flattening the distribution as compared to the Best method, it blew away the Better method.

However, I also would like to note that the original method, which was supposedly so bad, seems to have a fairly flat distribution, too. Of course, once you get to a smaller range of values, it got much, much worse. If you only checked a range of 10 values, the first method came back with over 3 times the difference of the other methods, and the deviate method worked about as well as the Best, coming back with the same flatness in distribution.

Apparently which method you use depends on what range of values you are checking. If you are checking a small range of values, then you would do well NOT to use the First method. If you are checking a large range of values, it doesn’t seem to matter as much. In any case, the “Best” method is not named right, but the uniform deviate does correct its speed problem.

Potential Problems with These Tests:
Subtracting the minimum number of times a value is picked from the minimum number of times a value is picked might not really give me a meaningful value like I think it does. If you can think of a better way to handle this test, please feel free to correct me.

If you would like the C++ source, you can download it:
randomtest.tar.gz
randomtest.zip

Categories
Game Development Geek / Technical

The Best Random Number Generation Explanation Ever

Thanks go to Uhfgood in #gamedevelopers for finding the article Using rand(). I thought I already knew about the problems with using rand(). This article was great at clarifying the actual problems people have with using rand() as well as faults with “good” solutions people use. It also documents a simpler way to use rand() that actually produces better results! It turns out that rand() is better than many programmers thought.

For those of you who don’t know, the classic way people are taught to use rand() to get a random number between 0 and maxRange is as follows:


int picked = rand() % maxRange;

The problem with the above is that the value you get in picked will not be as random as it could be. Something about lower order bits repeating too often. So usually the “better” way to solve the problem is through some slightly more complicated code:


int picked = lowerBound + rand() / ( RAND_MAX / ( maxRange - lowerBound ) + 1 );

The article explains that this example also has problems!

So what do you do? Stop fighting rand()! I wasn’t happy with the example given as I don’t understand why simple variables have to be used with simple examples since they only make it more confusing. The following is my own code:


int highest = 100;
int randDivisor = RAND_MAX / highest;
int pickedValue;
do
{
pickedValue = rand() / randDivisor;
}
while ( pickedValue >= highest );

It may seem like you would waste too many cycles waiting for pickedValue to be within the range you desire, but it really doesn’t take long at all. It is more pseudorandom than the other examples and needs less complex code, too!

The document also explains the problem with the usual code to seed the random number generator:


srand(time(NULL));

The problem seems to come from the fact that changes from one time to another aren’t usually enough to change the first randomly generated number. The article explains a way to use time() in a portable manner by hashing the bytes of its return value.

The entire article is a good read, and I believe any game programmer will find it useful.

Categories
Games Politics/Government

Space Invaders and Politics

I have been looking into Space Invaders and how it was like to play the original. I played Love Invaders, which has an amusing intro (1978 was all just a big misunderstanding), and Invasion 3D, which actually had some interesting game mechanics, such as exploding UFOs that also destroyed nearby aliens and aliens that drop down to replace dead allies in the front lines.

During my research, I also found the Wikipedia entry on Space Invaders, and I learned that when it was first introduced in America, it apparently sparked outrage even that many years ago. I thought that the public rallying against video games was a fairly new phenomenon.

From Wikipedia:

This phenomenon led to the first outcries against video games by groups of concerned adults, who felt that the content of video games was a corrupting influence on children. In the case of Space Invaders, the issue was not usually the highly abstract and stylized violence, but with the fact that the game could not be “won” in any familiar sense. As framed by the critics, the player is powerless to do more than to delay an inevitable defeat. They suggested that the game taught an unwholesome life lesson, inculcated defeatism, and possibly was intended to put the United States at a disadvantage in its economic rivalry with Japan by undermining the competitive spirit of American youth.

Space Invaders taught defeatism? So is Grand Theft Auto sending a better message by actually allowing you to overcome the odds and win?

Categories
Game Development

Space Invaders Clone Progress: Finding My Way

I’ve been reading through the source code of a number of games, and I’ve been picking up some good ideas.

Specifically, I had been struggling with the idea of retrofitting a menu system to a finished game. I hadn’t been focused on the task (as I need a finished game first), but I had a vague idea that I would need to design the menu system and run it separately from the game loop. Interestingly enough, I found that a number of games have the menu system as part of the main loop! I was a bit confused by it at first, but apparently the game is paused for one reason or another, and the menu system has its own update() function that gets called if it is active. It seems fairly easy to implement, and there are plenty of code examples for menu system implementations out there.

I now feel more confident that I can leave the menu system to a later time, allowing me to focus on finishing Space Invaders. I have since added functionality to allow the aliens to move down the screen in formation, and once an alien hits the player’s ship, the alien is destroyed, and the player’s ship becomes invisible.

It becomes invisible because I have yet to actually define what it means for the ship to be destroyed. Technically you can still shoot and move the ship. You just can’t see it. To really destroy it, I will need a way to disable the player’s input, and I will also need a way to restore the ship after a few seconds.

Explosion effects would help, too. B-) Currently, the alien and the ship simply disappear when “destroyed”, although the alien sprite really does disappear for all intents and purposes. I am still making small changes, and being very careful with new ideas I come up with. I write them down and put them away, ready for v2.0’s development. I just want to finish v1.0 as quickly as I can.

At one point, I felt stuck. I didn’t know how to proceed, and I found myself sitting in front of the code without any real reason. I stopped, took out some notecards, and came up with a few scenarios. I basically wanted to determine what should happen in specific situations.

For example, what happens when an alien touches the player’s ship? Well, the alien and the player’s ship both get destroyed.

What happens when the alien gets destroyed? Well, some explosion animation should occur, the alien should be removed from the list of active aliens, and if it was the last alien, then the next level should start.

What happens when the player’s ship gets destroyed? What should happen when the game starts up for the first time? What happens if there is no player ship on the screen? What happens if the player has no ships left? What happens if the alien reaches the ground?

Answering each of these questions helps me to see what functionality is missing. I still need animations for the explosions, I think I may make use of a timer for the player’s ship to get restored, and I still need to add some font to display text such as “Game Over” and “Start Game”.

It is amazing how clear everything becomes when you stop and think, “What will happen in this specific circumstance?”

Categories
Game Development General

XNA Being Ported to Mono

Speaking of XNA, Mono.Xna “is an open-source implementation of Microsoft XNA”.

It is still a baby project, but hopefully it will actually allow developers to create truly cross-platform games. The source to it is available in the Mono subversion repository. Mono, of course, is the open source, UNIX version of the .NET development platform.