Cribbage in 64kb

Cribbage SplashIn 2003, fresh out of university and anxious to get coding games for a living (yeah, my fellow grads were jealous, suck it! =) I had the opportunity to basically pick any game I wanted that was doable. I thought I picked something easy, I thought I picked something that would have no problem running on all the J2ME devices and BlackBerries… I was sort of right.I picked Cribbage as my first project; mainly because I like playing Cribbage, I figured I could implement it quick, make it fit on all the devices in the market, and there wasn’t another Cribbage game on the carriers we were shipping to.

The basic game of Cribbage is pretty simple to implement. A deck of cards, a couple hands, dealing, scores tracking and some simple animations to keep it fun. A statistical AI for Cribbage is not too hard to develop because even on low processing power, low memory devices, you can run through all possible outcomes of playing a particular card from your hand, give each a weight and then pick the best statistical option available. In general, it results in a solid, if not spectacular AI, but solid was good enough for an experienced Cribbage player like myself to enjoy playing the game and not feel like I was playing against some newbie.

Cribbage Screenshot 1Putting the cards, animations, scoring system and table in place was not much work and I decided that I wanted to have the iconic symbol of playing Cribbage, which makes it different from most card games, the Crib board in the game.

Now, before I go on, recall that this was in 2003. The typical phone had only 64Kb of memory available for the game to use (RAM in PC terms) and limited the entire game download size to 64Kb as well. The limits were practical — flash memory was expensive and data networks slow (2G) so to provide a lower cost phone and good customer experience (who wants to wait 15 min to download a game on your tiny little phone?) these limitations made sense. For games developers…. they sucked.

And by ‘sucked’ I mean REALLY sucked. For a 128×128 resolution phone screen (and yeah, there were smaller, 96×54 was the minimum resolution… w 1-bit graphics) using 16-bit images, it took 32Kb of memory for ONE full screen image. That doesn’t leave much for code, variables and other images. How was I going to get an entire Cribbage board to load let alone fit on screen?

Along with the memory limitations, the processors on these 2G phones didn’t really have the power to be redrawing the entire screen very frequently. And even less so if you had to tell it to draw a lot of images on the screen. The more images it had to access and then draw, the slowed each frame was to render.

The solution here was a combination of things:

  1. First, I sectioned the screen into two parts: the playing area (on the left) and the Cribbage board (on the right). This allowed me to do a couple of things, the most important was that when moving the Cribbage board, I would only have to re-draw half the screen (thereby effectively doubling the frame rate).
  2. Second, we had some nifty buffering solutions designed at Magmic that we used in many games (though each game using the solutions tweaked and improved upon them — I seriously think we had the most efficient buffering in mobile for a while). Buffering allows you to compose a larger image (in this case, half my screen) from smaller images and then paint that larger image to screen. Buffering strategies are a whole other post (maybe I’ll write that in the future…) but suffice it to say, they work, and are mandatory for mobile development — even now.
  3. Third, the artist on the project (Erin) and I sat down and designed a way to tile the wood grain of the cribbage board so it would look awesome and still be able to fit in the 64Kb download and memory limits. Not only did we have to tile the wood grain, but we needed to tile the lines and dots on the board as well as THOSE images also took up a bunch of space.

In the end, the board rendering was by far the most complex part of the game to design. Cribbage Screenshot 2The rendering, scrolling and correct clipping of the board ot make sure it didn’t overrun the main gameplay area took a lot of tweaking to get running correctly — and then a lot more to get running efficiently enough to support all the mobile phones in market at the time.

A lot of that Cribbage code is still used in the game today, even though there’s been a graphical overhaul on it and many, many ports and code re-writes to the game.

As it was the first game I designed and built from the ground up, and because the Cribbage board feature looked as good as anything on the market at the time — and was actually quite impressive compared to the competition, it holds a special place in my heart. Awww….. =)

(Images courtesy of an OLD copy of the website. Thank you!)

This entry was posted in Post Mortems and tagged , , , , , , , . Bookmark the permalink.

1 Response to Cribbage in 64kb

  1. the written content on this article is really one particular of the most beneficial substance that We have at any time arrive throughout. I adore your article, I will occur back again to examine for new posts.

Comments are closed.