Thursday, June 04, 2015

Taking Things To Another Level

Many of my Explorations in Computer Science students are creating a version of the Lights Out game as their final project. (Instructions at the bottom if you’re curious.)  In this course we are only able to cover some very basic pieces of coding but they have enough information to write this game. Unfortunately they don’t have enough to write it very efficiently.

They have twenty five buttons so they create 25 click event handlers. Each event handler has between three and five if statements to toggle the squares. It works and works just fine. Well as long as they avoid making simple errors and that takes some concentration and paying of attention. Did I mention that most of these students are freshmen? Teachers know what that means. Of course this is an example of why brute force methods are seldom the best way to implement most programs. But when you have limited tools (and we don’t have time to teach every tool) one has to made do.

Some of these students will take our next programming course which is a full semester of programming. In that course we’ll get a deeper understanding of objects, we’ll learn about multi-dimensional arrays, and we’ll be able to implement this program with far fewer lines of code. For example,. creating an array of boxes means that three lines of code can do a complete reset of all box colors rather than the 25 lines of code my students use today. That code will have a lot less chance of missing a box as well.

One of the things I want to do next year, that I didn’t do this year, is to have students look at simple programs and find ways to make them better using new language features and new programming concepts as they learn them.  I’m hoping for a few “ah ha” moments.

More and more I want one thing to lead to another in a way that makes sense.

Image of Lights Out game boardLights Out – The game starts with 25 red buttons arranged in 5x5 grid. Each button pressed toggles itself and the four buttons around it (above, below, to the right, and to the left) between green and red. The object of the game is to get all 25 buttons green.

No comments: