Home About Eric Topics SourceGear

2007-04-26 18:41:02

Poker or Citizen Kane?

Modern developer tools have made it tremendously faster to create what I call "raw code".  Raw code is code that just got written.  It barely works. 

In a professional setting, the problem is that raw code just isn't very useful.  It's the starting point, but we can't sell a product or service based on raw code.  Creating the initial raw code is maybe 10 percent of the job.  With modern dev tools, maybe that's down to 5 percent.  Most of our time is spent sanding and finishing and polishing.

But anyway, it's still just amazing how quickly we can use today's dev tools to get something barely working.  In fact, I sometimes think of small coding projects in the same time frames as watching a movie.

A few weeks ago I saw an enticing little flash game on Reddit.  It's called Virus.  After playing it just a couple of times, I wished that it had a solver.  It took me 25 turns to win that round?  How fast could a computer do it with 3 levels of look-ahead?

That night, the question was still nagging me.  The kids are in bed.  My wife turned in early.  Should I pop in a DVD and watch X-Men 3 again?  Or, I wonder how quickly I could clone that Flash game?

My version is called Contagion.  You can download a zip file which contains the source code (C# and WPF) as well as a compiled binary.  I had the game to a playable state before X-Men 3 would have ended. 

The next evening, I thought about watching Anakin get barbecued for the ninth time, but instead I wrote the solver.

I've done a little polishing of the code since then, but mostly this was a "two movie project".  It's very raw code.  (Gameplay notes:  In the original Flash game, your starting cell is in the lower left, but in Contagion, it's in the upper left.  Also, the Flash version had a scoring system, a highlight of the first cell, and sound effects, none of which I felt motivated to do.)

It happened again a couple of days ago.  Tuesday evening I planned to watch Citizen Kane, but first I grabbed my GBA to play a quick game of Texas Hold 'Em.  And I found a bug!  On one particular hand, I should have tied for a share of the pot, but the game said I lost.  :-(

I stared at my Citizen Kane DVD.  It's supposed to be one of the greatest movies of all time, and I've never seen it.  I really should watch it, but I mean seriously -- how long can it take to write code that correctly compares a couple of 7-card poker hands?

Not that long.  This code (C# 2.0 again) is slightly less raw than Contagion, since I included a few NUnit tests as well.  But it's still quite rough.  I haven't checked, but I wouldn't be surprised if the ratio of code lines to comment lines triggered a division by zero exception.

Anyway, I've got this raw code sitting around, so I figured I might as well post it here.  Enjoy!