Games are motivators
This quarter I have been teaching Programming I. One thing I can confirm as a result of this experience is that games are great motivators for new programming students. They certainly are more relevant to the students than calculating interest rates or tax rates. The four programming examples that piqued my students interests more than any others included:
1. an implementation of the Caesar Cipher, which is a simple substitution cipher. Our text by D.S. Malik introduces reading and writing files early (in Chapter 3). The Caesar Cipher is a good way to get students to work with files. I introduced the cipher by giving the students a program, “DecoderRing.cpp” and three text files that contained these phrases:
message1.txt: “Tgcf{”kp”vjg”pqtvj0″
message2.txt:”Vjg”gcuv”ku”tgcf{0″
message3.txt:”Yg”ujcnn”cvvcem”cv”fcyp0″
Students were asked to run the DecoderRing.cpp program on each of these files and investigate the results. The program created three new files with these words:
Plain text 1: “Ready in the north.”
Plain text 2: “The east is ready.”
Plain text 3: “We shall attack at dawn.”
I was very pleased with the reaction of the students! This exercise demonstrated many important but tedious programming concepts: reading and writing files, integer arithmatic on character data types, and I think they got a glimpse of what power they would wield if they mastered programming.
2. An implementation of the XOR hashing algorithm. Granted, this required some time on my part to implement, but it provided my students with an example of a program that implements a very important error-detecting algorithm and gets them to think at the bit-level. Since the second quarter of programming will be going into objects, I figured this was my only chance to get them to look at integers as the 32 bits (on our machines) that they are. Students then used my program as a template to write their own hashing algorithm that has some of the features of the more cryptographically secure algorithms (like the MD5 checksum algorithm has). It will be my task (hopefully enjoyable!) to grade these this weekend.
3. An implementation of a tic-tac-toe game. I introduced this only after arrays and enumerated data types, but this was much more popular than either the XOR hash or the Caesar Cipher. Next time around, I think I can introduce tic-tac-toe even earlier–during the unit on functions. You don’t really need an array to represent nine squares on a board.
4. Rock-paper-scissors (lizard-Spock). This was a hoot. I provided the source code for the game Rock-Paper-Scissors (thank you D.S. Malik and Cengage Learning for this and other excellent programs with your text). Students were directed to modify it to accomodate Lizard and Spock as player actions (see these sites:http://www.samkass.com/theories/RPSSL.html and YouTube video of the Big Bang Theory). This was just a laboratory assignment this quarter. Next time, I will make it a homework assignment, and have the students add a computer player.
In summary, whenever possible I suggest that we design our programming examples and homework assignments around things that students may find interesting. Games top the list clearly in my experience–but be careful–many games and game features (such as an artificial intelligence) are very difficult to implement in code for first year programming students. I recommend that you try writing the game yourself before you recommend that your students attempt it.
1 Comment
Other Links to this Post
RSS feed for comments on this post. TrackBack URI
By Michael Fransen, March 5, 2010 @ 1:30 pm
You are completly correct that using games for teaching is much more interesting than the typical finance calculator. Your post made me think of a time in a computer science course where I wrote a version of Yahtzee in Java. It was a desktop application and after I was done I modified a few lines of code and made it an applet that could run on the web. While doing this project I learned a lot about graphics, arrays, random number generation and more. Nice post!