The Independent Study Unit (ISU or ISP in some schools) usually involves an independent programming project at the end of the year, to demonstrate what students have learned. More often than not, it turns out to be a troublesome excercise as advanced students try to show off and over-complicate their assignment, while others are having difficulty figuring out the practical application of all those if statements and for loops. Inevitably the presentation is due the next day, and a sense of panic sets in – there is not enough time to write all that code.
So a couple of years back we had a competition over at the CompSci.ca forums, to see what could be accomplished in just a few lines of code – say no more than 20. The submissions were limited to Object Oriented Turing, and started off with some nifty looking effects and animations, but soon after full out games (types of which are suggested for grade 10 or 11 ISU projects) began to appear. All in 20 lines of code or less! Here are some highlights from the original competition.
beard0 has put together a full out TicTacToe game (top), with mouse controls, and checks for win/tie conditions in just 17 lines of code.
zylum developed greenspace (left) – all adjacent squares flip colour at a click, the objective is to make the entire screen green. 20 lines of code
My own submission at the time was a stripped down version of a Snake game (right). There was no actual food pellets for the snake to eat, but the game did include full controls, collision checks against the walls, and having the snake run into itself. The score was also kept, and reflected the life-span of this cruelly confined game sprite – all in 20 lines of code.
Though the most talked about game was Catalyst’s Pong (bottom). 2 player controls, bouncing ball, scores. The game was complete. The game had everything one would expect from a grade 10 or 11 ISU project submission. The game was 19 lines long…
The above was achieved by chaining a number of generic if-condition-assign-value into a single exit when statement.
fcn sa (cond : boolean, var a : int, b : int) : boolean if cond then a := b end if result false end sa
The above was used as
loop exit when sa(true, x, 0) or sa(chars('w'), x, x+1) end loop
Since the function always returns false, the loop never exit, but the statement still needs to check every function to make sure. Passing true as a condition will always assign the value of b, to a, so in the above example the value of x will always be set to 0 at the beginning of the statement. Alternatively a condition statement could be employed, and so if key W has been recorded to have been pressed, the value of x will increase by 1.
This year we are revisiting the competition with another round. There is a month to put something together (the deadline is October 13th, 2006), and this time it is also open to your favorite programming language (any). I suspect that things could take an odd turn if any Perl Golf hackers show up, so I will be mainly watching for Turing submissions.
My prediction for this year is that while the above described methology of chained statements will still be a popular way to join lines of code, I hope that someone would raise a bar and employ some bitwise operations. Zylum has written an excellent tutorial on using bitwise operations in Turing.
if (player & (rign1 | ring2 | amulet)) > 0 then
A single condition to check if a player is wearing at least one piece of jewelery. Nifty.