Ironcoder V Reflections
As some of you know, I participated in Ironcoder V last weekend. It was an absolutely fantastic experience. I would have written about it sooner, but this last week was the first week of the new term, and, as it usually is, it was extremely busy.
First and foremost, I should extend my congratulations to Ben Gottlieb for his winning entry WikiPath. Although I was technically in the #macsb channel on irc.freenode.net when the winners were announced, I was also at work, and thus not able to properly congratulate Mr. Gottlieb. I would also like to congratulate the others who made it to the top five: Adam Leonard for Blurred Life, Josh Freeman for CrepuscularLife, Ian Gowen for LifeLike, and Joseph Wardell for Pixure. (I would include a link to each participant’s blog, but I could not find a link for everyone.) I would be tempted to congratulate everyone who completed an entry, as it is not a trivial task, but I do not want to appear to be tooting my own horn.
I am proud of my entry though. For this Ironcoder I submitted an application which implements Conway’s Game of Life using crudely drawn pieces of Life Cereal as cells. I called it Conway’s Game of Life Cereal. I even spent half an hour or so whipping up a custom icon which plays on the ambiguity of the name: Instead of depecting Conway’s Game of Life using cereal pieces, it depicts a box of cereal with pieces shaped like patterns from Conway’s Game of Life.
Because I had decided to use pieces of Life Cereal as cells, I ended up with a 50 x 30 grid of cells. This ended up being both a blessing and a curse. With such a small board, I could get away with a fairly simple algorithm, and do all of my drawing without the speed advantage of OpenGL. However, this put me at a disadvantage in comparison to some of the other entries which implemented Conway’s Game of Life more efficiently. However, I really liked the pun, and so I stuck with it. And after all, there are a few really great Conway’s Game of Life programs out there. I wasn’t going to be able to compete with them in 48 hours, and I have enough on my plate that I won’t get back to this project for quite a while, so I focused instead on
It took me less than 24 hours to complete the basic implementation of the program. I tried to program in stages. First I implemented the basic program, and then I added features one-by-one until the deadline. Each time I completed a feature, I made a zip archive of the program and source. The idea was that if any feature took too long to implement, then I would still have something to turn in. In the end, I finished almost everything I wanted. After completing the initial program, I added the following:
- Adjustable Speed from 1 to 60 generations per second. I didn’t want to create something that might melt someone’s computer, so 60 seemed like a reasonable limit. Setting limits is a hard thing to do as a programmer, but sometimes, it must be done.
- Allow the user to decide whether cells die when the leave the field or wrap to the opposite side.
- Allow the user to choose from three different flavors of Life Cereal.
- Create a custom icon for the application.
- Write documentation for the application.
- Allow the user to add or remove cells by dragging the mouse, instead of requiring the user to click each cell individually.
- Allow the user to save and open patterns. Although there is a de facto standard for these patterns, because my field was so limited, I opted instead for just a char by char dump of the 2D array used to hold the pattern.
- Custom rules for the death and birth of cells.
My application was the only Conway’s Game of Life submission which allowed the user to draw their own pattern and save it for later, but it did not, as the other implementations did, have a random pattern generator. This is probably because mine was the only non-screensaver, and the screensavers required random patterns to be interesting. I thought I could be clever by making an application instead of a screen saver, but when you look at the screensaver framework, all it contains a custom subclass of NSView with methods to set the delay between frames, a class to handle reading and writing preferences, and some functions for getting random numbers. When all is said and done, the equivalent of ScreenSaverView can be achieved with a regular NSView and an NSTimer, applications can just use NSUserDefaults, and there are plenty of ways to get random numbers. However, ScreenSaverViews can be easily made into screensavers, and since NSUserDefaults doesn’t automatically read and write defaults to the screensaver’s bundle identifier, these classes are useful to screensavers. Still, I did find it easier to use ScreenSaverView than to implement my own equivalent with NSTimer.
There were also a few things I didn’t have time for. All of the code for Conway’s Game of Life Cereal is inside a custom subclass of ScreenSaverView. I actually had a separate controller class early on, but scrapped it for efficiency reasons. I planned to later re-factor the code, but did not have time. I also wanted to implement a networking feature which would allow everyone to draw on their own screen, and when everyone was finished, the cells would animate, and if they left one player’s screen, they arrived on the next player’s. Unfortunately, I was running out of time, had only one computer to test with, and no prior experience with distributed objects in Cocoa.
But for all the small drawbacks, I feel good about my entry. I last entered Ironcoder during the Ironcoder 2/3 competition, having just begun Cocoa programming. I approached everything from a C perspective, and had no familiarity with the Cocoa classes. The result was a very embarrassing application accompanied by a text file apologizing for its lack of quality. In contrast, this was a complete application with a custom icon, extensive documentation and quite a few features for something coded up in less than two days. It was very rewarding to create and submit, as I gained more familiarity with Cocoa, and felt proud to submit an entry that didn’t look like a complete joke next to the entries of the professional Cocoa programmers.