I often have competitions in class. I try to use them primarily for motivation, not assessment.
Let me give an example: I was teaching an image processing class and we had some images of x-rays of "old master" canvas paintings. The goal was to create an algorithm that could count the density of the thread weave patterns. The quality of the answers could be assessed by comparing the algorithmic answers to manual counts, and I had about 200 locations where I knew the answer. I gave them 100 to train the algorithms. After about two weeks, there were 25 different algorithms submitted (most people worked in pairs) and then I ran the submitted codes on the 100 "unknown" locations.
I called it the "2010 Thread Counting Olympics" and made a big deal about giving out "medals". I created several different ways of measuring the quality of the algorithms: closest in least squares error, number of answers within +/-1 mm per thread, number within +/-2 mm per thread, closest in absolute value of error, closest on the canvases by Van Gogh and closest on the canvases by Vermeer. Then there were bronze, silver, gold, and titanium medals in each category. As I presented the results to the class, I described the various approaches and pitfalls of each of the algorithms, and often asked for clarifications and comments by the authors of the algorithms. By the end of the competition, well over half of the students had won "prizes"... plus they had the recognition of their peers.
The amount of effort that the students put into this project and into the class were amazing, and I think the "competition" aspect was a prime motivating factor.