And Even More Turtles!

(Wow, two posts in a just a few days! Must be something really exciting to report.)

And yes, it is something really exciting. This Turtle Graphics project has captured my attention, and I can’t help but work on it. Fortunately, there’s been lots of success, so I can write enthusiastically about recent milestones.

The other day (see last post) I got as far as creating a simple LOGO language parser that could move the turtle forward and backward, turn right or left, and loop a number of times. That was cool, but somewhat limited. Based on the various web articles I’ve found (and even some of the comments to my last post), there’s way more potential awaiting. All I need to do is get variables and procedures functioning, because then I can explore recursive algorithms and fractal geometry.

Procedures turned out to be fairly simple; the layout of the parser mechanism I built adapted nicely to interpreting from different “source” arrays. In my design, the LOGO program is parsed into a String array, which is passed to the Parser with an index pointer saying where to translate next. A “pre-parser” would scan for functions (code that begins with “TO” and ends with “END”), and would copy the function to another array before removing it from the program. Thus, when the parser encounters a call to a function, the code merely locates the function “code” in the other array and calls the parser with it.

Variables were initially simple … until they got complicated. Well, okay, things were fine until I got into recursion. Without recursion, the code that handled variables was straightforward: As the parser encounters a variable, it would add the variable to an array. Each time that variable gets referenced elsewhere it gets retrieved from the array. In effect, every variable was global. No problem.

One of the websites I found (www.turtlegraphics.net) shows this lovely fractal tree, and that was what I was using as a guide for my efforts. I quickly found (or should I say, remembered?) that recursive routines don’t work with global variables. Recursive routines need local (i.e., stack based) variables because each iteration of the recursive routine needs its own data. Figuring a solution to this took a day or two of thinking (no coding). Late last night it dawned on me: I store variables in an array, but that array can contain multiple copies of the same variable. So I quickly wrote a “CreateLocalVariable” function that forcibly adds another copy of a variable to the end of the variable storage array. The “variable retrieval” function scans the entire array, looking for the variable in question. If there happens to be multiple copies, it will report the last one it finds, which will in effect be the local variable! (The only caveat is that I need to remember to remove those “local” variables from the array when the procedure is done.)

Moments later, I had my fractal tree:

Fractal Tree

So now I have a functional Turtle Graphics / LOGO interpreter. There’s still more that could be added (changeable colors, text support, etc.), but that’s only if I want to turn this into a full blown effort. My intention was to provide high school freshmen with a chance to get a computer to “do what they tell it to do”, as a gentle way of introducing the idea of programming. I don’t think they’ll spend more than a day or two at the most on this, which raises the question of why bother with more.

But, yeah, I’ll probably add more later.

Posted in Uncategorized | Leave a comment

It’s Turtles All The Way Down

As a high school computer science teacher, I’m always trying to find ways to increase interest in this rich subject. Of course, there’s the obvious “the more students who take CS courses, the more my school will need my services to teach CS classes” aspect. But aside from that, I have long recognized that CS is a subject that a lot of students shy away from because they don’t know anything about it. I’ve got a growing list of students who, after taking their first programming class, discover a new passion. The unfortunate reality in my school is that the majority of students take just one class, and making matters worse is that it’s Microsoft Office. (Granted, it’s important that students be functional in Word, PowerPoint, and Excel, but this class hardly qualifies as “Computer Science”.) And since my state only requires one semester of CS to graduate high school, this is all the majority of students will ever see of the computer lab.

About two years ago, my fellow teacher and I began to realize that by carefully changing the Office class, we could do something about this. By selectively trimming away some of the less critical parts of the curriculum, we opened up 4 or 5 days in the semester’s schedule that we could use for enrichment, or as I call it, Explorations in Computer Science. Borrowing ideas from CS Unplugged, I used these days in the past few semesters to teach the fundamentals of binary (thus letting the kids figure out for themselves the “There are 10 kinds of people” poster in my lab), sorting algorithms (they sort themselves by their phone numbers without ever letting anyone see theirs!), and data encryption (sending messages using a simplified ASCII), and we ultimately get into a day or two of extremely basic programming in VB. The students find the material fascinating, and we’ve seen an uptick in enrollment in our programming classes.

This year we have a bit of a problem, however. Doing these lessons after the Christmas Holidays makes the most sense, as I don’t have to worry about anyone forgetting anything important that they learned two weeks of vacation earlier, and I can usually count on a week and a half to two weeks before the start of midterm exams. The nature of this year’s calendar means that there’s two and a half weeks between these milestones, which means … I need a couple three more “out of curriculum” lessons.

Think, think … what can I do, what can I add? The only rough spot I’ve noticed in the past year or so was when starting up VB. The students seemed to have a good footing with the “unplugged” concepts I showed them, they just had a mental hurdle when we got to “now let’s add some instructions to this VB Form we created.” And I’d rather NOT pack more VB lessons on the end, because I don’t want to have the students who DO decide to enroll in a VB class to essentially start over too much when they start that class. So I started thinking about the various “gentle introduction to programming” paradigms I’ve seen or heard of over the decades. Alice is an option, but it seems too big an infrastructure to tackle (from my perspective), and I don’t have a good feel for what can be done in 2-3 days. Kodu similarly looks like a lot to add to a computer system (in the lab or at home); but maybe I just don’t understand it well enough. I even thought about ChipWits (see several past blog entries), but neither my (now ancient) version nor the (forever under development) commercial version seemed finished enough; plus, like Alice, I’m not sure how those lessons could be applied in a real programming environment.

Suddenly the words “turtle graphics” popped into my mind. This was something introduced decades ago, intended to be the “gentle introduction to programming” for the world. The theory was you have a canvass (the computer screen), with a “robot” turtle in the middle. You give the turtle simple commands (“forward 100” pixels, “right 90” degrees, etc.), and the turtle moves on the screen. The permitted instructions make up what was called the LOGO language. The turtle has a pen attached to its tail, so lines are drawn as it moves. Without a great deal of effort, you can create some fairly complex drawings with very simple instructions. Obviously, it never went anywhere, but could I find use here, I wondered. A quick web search turned up a number of links to sites describing the various programs available (Wikipedia says nearly 200 implementations over the years), but I couldn’t find any self-standing versions (not that I looked that long). Geek that I am, my first thoughts were, “I wonder if I could write one?”

I must admit, I impressed myself. Starting from scratch, and a few websites to describe the LOGO language, I had a simple Turtle Graphics program with LOGO interpreter written in VB in about 2 hours. An hour later I had looping. Another half hour and I had file capability (to save and restore your creations).And about three hours later (2.5 spent “thinking”, half hour coding) procedures were working. There’s still more to add (variables, and the “turtle” icon itself come to mind), but it’s quite amazing how quickly this came together. (Click on the image to zoom in.)
Turtle Graphics
The pretty pattern of circles was generated from the eight lines of LOGO program on the left side. Aside from knowing that “forward 2” means draw a line two pixels long, and “right 1” means turn one degree to the right, the rest is entirely easy to understand even for non-programmers, which is the whole point!

Now, how will it be received in the classroom …

Posted in Computers and Internet, Programming, Visual Studio | 5 Comments

Still here?

Wow … I’ve been away for a while … again.

I need to get better at writing in this thing.

Posted in Life in general, The Blog | Leave a comment

Windows Phone apps?

It’s been about a year since I wrote here. I can’t say “had anything to write”, because I’m ALWAYS thinking of things to write, but I never seem to get off my duff and write. I suppose I have to chalk it up to laziness.

Anyway, after a fairly successful FIRST Robotics season (lots to write there), and before I sink into the annual hell called Scheduling (see my last post on that one), I think I found something to write about. Every year in my AP Computer Science class I strive to get as many kids as possible as full of CS knowledge as possible so that they can take a three-hour test and get the highest score possible. Since the AP Exam takes place in early May, it means I have to figure out what to do with my students for the 4-6 weeks (depending on if they’re juniors or seniors) between the test and the end of the school year. Every year I try to find some large-scale, challenging, and above all else interesting programming assignment for them. Over the years I’ve tried Pocket PC applications, XBox games, Facebook apps (that didn’t go over too well), and last year I even tried a text-based Adventure style game. This year a new option presented itself: We’re gonna try Windows Phone App Programming.

My friend Alfred Thompson has blogged for ages about cool things to do in Visual Studio, and recently has been describing how to develop apps for Windows Phones in Visual Basic or C#. Having recently acquired a Windows Phone, this seems to be a fortitous alignments of planets.

So over the next few days or weeks, I might just find a reason to write more. (Who knows, it may just become a regular event.) In any event, I’ll be sure to describe the apps that my students create; there’s some good talent there.

Posted in APCS, Programming, Visual Studio, Windows Phone | Tagged , , , , | Leave a comment

My Annual Scheduling Adventure

 Like every year for the past five, May brings the joys of Scheduling. I get to work with the school’s Registrar, and together we sift through all the course requests and teacher assignments and concoct a schedule for next year that is acceptable to parents, students, teachers, and the administration. For a variety of reasons, the process takes a week or more, and can result in more than a few sleepless nights for all involved.

This year started with a bit of a twist: the woman I’ve worked for the past five Mays announced that she would be retiring at the end of the school year. With those simple words, my world was thrown into a tizzy, because an obvious next announcement could very easily be “And Mr. I will be taking over her duties as Registrar.” That would not have gone over well; I like teaching, and I will fight anyone who decides I’d be better elsewhere.

Fortunately, a quick word with the school President put that fear to rest; the school would be hiring a new Registrar. In fact, in all likelihood I would continue to work with the new Registrar on scheduling, unless s/he decides I’m not needed. This meant that this year I’d better take on the role of the Chief Scheduler, and not just the Registrar’s Assistant.

The normal process of scheduling actually begins in March, when the students of the school go through the course selection process. Working with their Guidance Counselors, they pick and choose from the menu of available courses, aiming to fulfill their graduation requirements and take electives that match their interests. In mid-April, the school sends out the Letters of Intent to the teachers, or invitations to return next year. (Yes, on rare occasions, the Letters of Intent could more properly be called Letters of No Thanks.) My peers and I have a few days to respond with “Yes, I’d like to return” or “No, I’m moving on.” This information would be combined with the student course selections by the administration to figure out how many sections of each class are needed next year, and the Department Chairs would then decide which of their teachers would be in each section. By mid-May these issues are ironed out, and Scheduling can begin in earnest. A week or two of effort later, and the students have their new schedules in hand by the first week of June. That’s how things have run in the past, anyway.

This year, the Letters of Intent were several days late in coming. This lead to the return letters being a week behind (we had Spring Break during that time), and the delays just kept cascading. When all was said and done, we started the process the day before Memorial Day weekend, roughly two weeks later than usual, or about the time we typically target for completion.

I mentioned that the process can take a week or more; this is much longer than most schools, because we take a different approach to scheduling. Most schools employ what’s called Arena Scheduling, which means that a schedule is created based primarily on what the teachers want to teach. The school administration decides on how many sections of each course there should be, based on projected enrollments, and teachers are assigned to those sections. Once everything is finalized, the schedule is opened up to the students, who then build their personal class list from the menu available. If a student can’t make their desired classes fit into the published schedule, or if a class is not available in the semester that they need it, they are out of luck. Their only hope would be to swap out one or more other courses until they can make things fit.

At my school, the administration takes a different view of scheduling. Working with their Guidance Counselors, the students pick the courses they want. The counselors help assure that the students meet all prerequisites, and that they are not overloading their courses to the point of failure. Once all course selections are made, it is up to the school to find a way to make a schedule that will meet most if not all of these desires. It means a great deal of work for us, but a lot more success for the students.

Anyway, the Friday before Memorial Day weekend we loaded the 7,738 course requests made by 859 students from a list of 122 courses (with anywhere from 1 to 10 sections apiece, for a total of 416 sections) taught by 68 teachers in 7 periods and 2 semesters into the school’s database system. I also loaded much of the same data into a number of applications that I’ve developed over the past few years to facilitate the process.

Ah, yes, the process. As I said, the goal is to get as many course successes for the students. What this means is that we to try to arrange the courses (all 416 sections of them) in such a way so that as to get as few schedule conflicts as possible. To achieve this result, we start with the courses that have only 1 section apiece (“singletons” in our vernacular). We place each of them in the blank schedule grid so that no student taking Singleton “A”, who is also taking Singleton “B”, finds a conflict because “A” and “B” are in the same time slot. When this is done, we move to the “doubletons”, then “tripletons”, etc., all the way up to the courses with 10 or more sections (we don’t have a word for that, I’m afraid). Doing things in this order means that we have the greatest chance of getting the least conflicts. The downside is that when we get to the last courses (the ones with the most number of sections apiece), we have the hardest time shoe-horning them into place with fairly even enrollments. When the last course is placed, the schedules of all the students are essentially set, and there’s not much room for adjustments. So if one section of the last course has only 3 students and another has 57, we have little recourse but to “unwind” the schedule a dozen or two courses and try a different pattern. (Yes, backups are a critical way of life for us.)

Extreme variations in enrollment is where we found ourselves last Friday, one week into the process. When the last course was placed, we had wild swings in enrollments in a number of courses, and no options appeared open to us. So Sunday afternoon, shortly after graduation ceremonies for the seniors, the Registrar and I sat down and began a long process of restoring from a very early checkpoint (about 25% through the process) and trying again. Fortunately we were able to “fly” through the task, because several of the key decisions that we agonized over during the week (such as seeing the effects of poor choices, and the resulting unwinding and correcting of those choices) followed the same paths. We worked from about 4pm until after 11, and got to within the last four courses when we called it quits because vision was going cross-eyed. Monday morning, things went remarkably well for us, and by noon we were done. In fact, the schedule looked a whole lot better once completed than it was looking the evening before.

A thorough walk-through followed, checking every enrollment in every section, searching for hidden dangers in the tall grass. Fortunately, we didn’t find any. In the end, only about a dozen students couldn’t get everything they wanted. (Typically this is where the guidance counselor calls the student in to say “you have a conflict, you can’t take AP English and underwater basket weaving,” and the student inevitably drops the lesser course.) We threw the schedule up to the administration, and with their approval the students had their schedules delivered this morning.

Next year, things will be different. All I know today is that I can’t imagine how different they will be.

Posted in Programming | Leave a comment

Well, this is interesting …

Okay, not quite 7 years ago I started a blog. Nothing too exciting or Earth-shattering, just the “Random musings from a former PC Software Engineer now High School Computer Teacher”. Considering what and where I was teaching, and based on the recommendations of a friend, I chose to locate it on theSpoke.com. That gave me a relatively interested audience of students, teachers, and others in the high tech field.

About three years into it, a funny thing happened: theSpoke died. Never got the whole story of why, but it started when management stopped, and the various blogs started filling with spam and other annoyances. When it became obvious that there was no hope for recovery, I jumped ship to a new site, Microsoft Live Spaces. My audience, unfortunately, didn’t seem to follow me, and most of my blog posts were, well, to myself. Fortunately, I happened to stumble upon a tool somewhere (not even sure anymore) that allowed me to transfer the dozens of my posts that I thought would simply go poof when the powers that be deleted theSpoke, so I was able to preserve my own past.

The other day, as I was posting a far-too-infrequent tale, I saw a screen that said “Live Spaces is going away.” Sigh … here we go again. Again, fortunately this transition was almost painless, and I was able to trnasfer my posts here. (Not sure if ALL of them got transfered, theSpoke history might be history!)

Anyway, welcome to my new home. Perhaps someone out there will discover my ramblings, and I’ll get an audience again.

Posted in The Blog | Leave a comment

Crazy Train – Update

Sometimes I surprise myself with how easy a project comes together. Let me throw this picture at you:
What you see here is my own recreation of the Candy Train game that was available on the web up until a few years ago. My version is an object oriented version written in VB.NET 2005, and is quickly becoming my favorite arcade-style game that I’ve written, even though it’s not even finished! Right now, the grid of track segments is randomly generated, each segment can be rotated right or left (via mouse clicks) to construct a longer continuous track. The “train” starts off as a red square (actually just a Label object, nothing fancy yet), and it follows the path that you arrange. You can control the speed using the speed adjustment (right now just two speeds, perhaps the finished version will have more?), and your score goes up faster as your train goes faster. Periodically (about 5 seconds) a new “rail car” will appear (shown as the purple square in the middle tile in the bottom row), and you have to flip track segments until your train travels through that tile. When it does, your train gets one car longer, and play continues. About every 10 seconds, one of the tiles starts flashing (the white bordered tile) for a few seconds, and then that tile gets replaced with a new randomly selected tile. This is to prevent you from just arranging a closed circle and racking up points! In fact, when I took the screen shot above, the tile flipped a split second and caused my train to crash.
Okay, I still have much more to go. Most importantly, I want to add better graphic images than just square labels. (Presumably, the code won’t need much modification with this change.) Then there’s all sorts of little things, like level control (have a “station” appear when the train reaches a predetermined length; bringing the train to the station completes the level), better score keeping, and perhaps even sound effects.
Not bad for a week’s worth of coding. This is fun.
Posted in Programming | Leave a comment