Wired has an excellent article delving into the scientific approach to fun developed by the game testers at Bungie Studios.

Taking it to a whole new level, the game testing lab helps Bungie developers pinpoint problems in the game, such as levels that are too easy or hard, weapons or enemies that are too deadly, or areas where gamers are getting frustrated or lost.
It's a long read, but it's worth it. You'll up your gaming IQ and you'll get excited for Halo 3 all over again.