Crazy Train

It dawned on me a week or two ago that I hadn’t written any new games in a long time. A bunch of years ago I started periodically to sit down and write a game, usually a recreation of something I had seen before; all of them get written in Visual Basic .NET (which is my favorite language). I’ve written card games (Four Corners, Nickles), board games (Othello, Sorry), puzzle games (Traffic, Sokoban, MasterMind, 3D Maze), and arcade games (Stacker, Klax, Bejeweled); some are one player, some two or more. Some even got ported to my PocketPC. I do it to keep my programming skills sharp, or to learn new skills (like PocketPC programming), but I guess mostly so I can have my own copy of the game. (I once saw a student playing the same game every day in homeroom, and wrote an equivalent on a dare.)
Anyway, as I said I realized recently that it’s been a while (a few years!) since I’ve done this, so I started looking around for a challenge. Going through my list of favorites from various gaming sites, I found that one particular favorite seems to be gone. If you search for a game called Candy Train, you’ll see lots of hits, but it’s been taken off where I originally found it. This tells me I found my target!
Candy Train (or my version, Crazy Train) has a 7×7 grid of tiles, and each tile has a random train track segments: straights, curves, etc. Clicking on any tile rotates it 90 degrees right or left (based on the mouse button used). A train engine starts in the center tile, and your mission is to keep switching the track tiles to keep the train on the tracks. Periodically a new train car will appear somewhere on the grid, and you have to manuver the train to that tile to pick up the car. The new car will be added to the end of the train, which of course makes it harder to keep a clear path open for the train. After the train reaches a predetermined number of cars, a train station tile appears, and you have to bring the train to the station to go to the next level. Failing to get a tile aligned before the train reaches it will naturally cause the train to crash. Here’s what it used to look like:
So a week ago I started writing the game (actually, modifying my Bejewled equivalent, since it already works with an array of picture box tiles). After a little bit I had the grid of tiles, and got them to rotate right or left. (I even got a few of my FIRST students interested, as they would occasionally walk into the lab and see me working on the game. But alas, none of them are in my programming classes right now.) So it got to the point where I rearrange the tiles to make the track any way I wanted … and then it hit me: I needed to get the tiles to know about the track beyond just the image! Each tile needed to know its track’s shape, so that the train (however that would be programmed) could tell if it was entering from the North, South, East or West, and what side it would exit from.
After pondering this a bit, I came to the conclusion that I needed to rethink my approach. I needed to NOT use an array of PictureBoxes, but an array of TrackSegment objects that were based on PictureBoxes. Each TrackSegment would know internally what its track looked like (straight, curved, etc.), and would also be able to tell the train object (again, however it would be programmed) where it was on the tile as the train moved along.
Tonight, after a few days of start and stop programming (anywhere from five minutes to an hour at a time), I got it working. My train right now is a small red box (just something easily seen), but it will run around the track designed with mouse clicks. (Can’t wait to show the students!) Hopefully there will be more entries in the future to describe my progress.
Posted in Programming | 1 Comment

NH to NYC by bike

I like to ride my bicycle. I’m not a fitness nazi by any stretch of the imagination, but I enjoy getting on my bike and riding for miles at a time. I suppose it started when I was a kid in New York City, and would ride by bike (single speed complete with the sissy-bars and the banana seat) around the block over and over, dozens of times at a shot, because my mother didn’t like us riding in the streets of Queens. As a teen I would ride a salvaged 10-speed bike (which was a lot back then), gradually expanding my range. I brought a bike to college, and during the summers I rode 9+ miles each way to get to my job. After graduating I rode to my job when I lived nearby, or during lunch just for exercise when I didn’t. A dozen years ago I started riding in the Tour de Cure bike-a-thon, raising money for diabetes research 25-100 miles at a time. Riding just seems to always have been part of my life.


A bunch of years ago, I started to dream of really long bike rides. Could ride from home to my fraternity house (150 miles); to my parents’ house (240 miles); to Ohio (700 miles)? What would be involved in shipping a bike to the Pacific Ocean (San Francisco, Seattle, etc.) and riding back? How long would it take? I’ve looked into various websites describing cross country bike tours, mused about going it alone, and even started mapping out potential routes. In the past year or two my now teenage daughter Michelle would muse with me, and we’d imagine where we’d go and what we’d see, just for the fun of it. This past winter I started seriously thinking about biking to New York City, aided by the fact that Google Maps recently added the ability to map a bike route. Entering my address and my parents’ address in Queens instantly produced a tour plan … that turned out to be completely useless. You see, Google Maps is now linked with the Rails to Trails Conservancy, who develops and charts bike paths that used to be abandoned train tracks. And, unfortunately, there’s no standard on the quality of the routes: Some are nicely paved and marked, while others barely have the tracks removed! Google Maps for Bikes, which knows to favor bike paths, doesn’t know the difference, and the first route it provided took me to the intersection of Massachusetts, Connecticut, and Rhode Island, and then directed me down a rail trail to Hartford that is little more than a path through the woods. (Yeah, that’s worth going out of my way for!)


Anyway, I figured out how to tailor the route to my own liking, and eventually found a route that started at my house, cut through Mass just west of Worcester, went through Conn to Hartford, took a (paved) rail trail to New Haven, and followed the coast of Long Island Sound to The Bronx. From there I figured I could jump the Triboro Bridge to Queens, and in around 250 miles get to my parents’ house. I figured I could ride about 150 miles the first day, get a hotel near Hartford, and complete the last 100 miles on the second day. Michelle and I even started planning on making this trek over Spring Break, biking Saturday and Sunday, resting a few days, and returning before the next weekend.


Fortunately, the weather didn’t play nice for us, as it rained both weekends of Spring Break. I say “fortunately” because we really weren’t prepared physically for such a ride, not covering many miles before the end of April. But schedules opened up for us at the start of August, and we decided to give it a shot. We even got an 80 mile practice ride in a few days before hand, to prove to ourselves that we could do it. At my parents’ request, we changed the route a bit, heading for the Bridgeport – Port Jefferson ferry instead of going through The Bronx; this cut the distance to 240 miles or so, making it even more feasible.


With bikes loaded with energy bars, twelve pages of maps, and the complete turn-by-turn Google directions, we headed out bright and early (7am) on Wednesday morning, and for the first half of the day things went great. Heading south through Hollis, we jumped on the Nashua River Rail Trail, a dozen miles of paved path that we know well. Skirting around the former Fort Devens Army Base, we hit our first snag: signs that read “Bridge Closed – Detour”. Opting to ignore the barricades, we found a bridge under repair but otherwise passable, so we stuck to the plan. A few miles later, at the end of a long downhill section, we found another set of signs for another bridge closed. Again we went around the barricades, and while this bridge had people working on the bridge, they didn’t mind as we road on the sidewalk. A dozen miles further on, just past the Wachusett Reservoir, we were directed onto River Road. This seemed at first to be a nice, quiet and level road; a quarter mile later we came upon signs saying “Road Closed Ahead”, followed by more barricades. Asking a cyclist coming the other way, we found that the road was closed because it was significantly deteriorating, but was otherwise passable. We also found that it had some significant hills in its two miles; this would be an omen of what was to come. Returning to “real” roads, we found ourselves in an area of Central Mass that consists of very tall, very long hills. And while rolling hills can be pleasant (using the downhill portion to gain speed to carry you over the following uphill portion), these hills were just obnoxious. You couldn’t go fast enough downhill, due to traffic lights, road conditions, or just wind drag, and the uphill climbs were brutal. (We joked that one hill was best climbed with a ladder.) After several hours and far too many miles of these hills, we turned onto Route 9; while a much busier road, it was also smoother and less hilly, so we could try to make up some lost time.


Unfortunately, after leaving Rt. 9, a missed instruction put us miles off course. When we passed under the Mass Pike (very near to Six Flags), we found we were not where we thought we were, and had difficulty with our limited maps determining where we wanted to be. A passing cyclist helped us out with directions (and even refilled our water supplies!) but we realized that we were not going to make it to Hartford by evening. Crossing into Connecticut, we found a place to eat in the town of Stafford, as well as the only place to stay (Angelina’s Inn Keeper’s Place Bed & Breakfast) within 20 miles.


The next morning we were met with the first rain storm seen in the area in weeks. While this put us about 2½ hours behind schedule, we used the delay to ask the inn keepers about road conditions in the area. They advised strongly to NOT take the roads we were planning, as they had steep hills and numerous switchbacks. Instead they directed us to other roads that began with gentle hills and ended with long stretches of smooth, flat travel; in short, some of these roads qualified as the find of the trip. Heading out at 9:30, we were in Hartford by noon, and a few hours (and a brief rain storm) later we arrived at the Farmington Canal Heritage Trail. This well-maintained, paved trail carries you nearly 30 miles from south-east of Hartford to New Haven … except for a 7 mile stretch in the middle! (Aw, come on guys, you couldn’t connect the pieces?) Arriving in New Haven for dinner, we found a hotel in Milford, and called it a day.


On the last morning of ride, we covered the dozen miles and just missed the 10:30 ferry, so by 1pm we were on Long Island. A slow leak in my front tire and a persistent head wind greeted us, but we pushed through the last 45 miles, arriving at my parents’ home in time for dinner. We stayed there for a couple of days, and then my wife drove down with the van and “rescued” us. (Had we not several other appointments in the following week, we would have ridden back as well.) In any event, 243 miles, three days, and a whole bunch of memories!


Posted in Life in general | Leave a comment

Virtual Bicycling Across the USA

I like to ride bicycle; I’ve done it forever, gone thousands of miles, and have ridden at least a few miles in 11 states (and the Caymen Islands). One eternal life dream is to one day pack up my bike and assorted gear, fly to the west coast, and ride back. I know, it takes tons of planning and practice, but hey, it’s a dream.
Recently I’ve found that a friend from my early years (high school and prior) has a son who’s blogging as he rides from San Francisco to New Jersey. As he tells of his trials and tribulations, he also mentions other riders he encounters and their blogs. So now I’m riding vicariously through three people as they tackle the Sierra Nevada mountains, Utah desserts, and relentless winds. Okay, maybe not the same as actually riding, but its cool to consider how the world has indeed gotten smaller, even if it is still 4500 miles from Pacific to Atlantic via bike.
Posted in Hobbies | 1 Comment

In other news: Scheduling!

Each year at this time I give up my free periods to assist another member of staff (Marcia) in the dreaded Scheduling. My school has about 900 students, and there are (currently) 7 periods, most of which get filled with full year courses. Since each student gets 7-11 courses to pick for next year, there are about 8,000 course requests (one course for one student). At most schools, this translates to something called "arena scheduling": Based on the enrollment, the administration figures out how many sections of each class to run, creates a schedule based on teacher availability, and the students literally duke it out trying to get the courses they want / need in the time slots they want (and potentially with the friends they want). Unfortunately, a frequent side effect of arena scheduling is that a number of students end up last, meaning the courses the want (/ need) are filled, or they can’t make a schedule with everything they desire because two or more courses were inadvertently scheduled for the same time slot. In these situations, the student loses, and has to drop one or more of their choices. At BG, the Brothers have a different approach: The kids pick the classes they want (/ need), and we (Marcia and I) bend over backwards to make a schedule that pleases as close to everyone as possible. Students win, teachers are for the most part happy, and all it costs is Marcia and I going nuts for about 2 weeks.
The good news is that over the years I’ve written a number of neat little (okay, big) applications that help the process. A fair bit of programming, I’ll admit, to read in the 8,000 requests from 900 students selecting from 150 courses in 7 periods, store them, cross reference them (which courses have been selected by students in AP Comp Sci, and therefore can’t be scheduled at the same time as APCS?), and allow logical and easy display of the data. One of the things I like a LOT is something I called Singleton Spotter. A Singleton is a course that has only one section planned. These courses have to be scheduled first, because you don’t want a scenario where most of the schedule is completed and THEN you need to fit the one section of AP Bio (for example), only to find that 3/4 of the students who requested it are busy that period. Anyway, since we need to put the Singletons down first, I wrote some code that asks the user (Marcia or I) to pick the courses to spot, and then randomly picks a course and a period, checks the cross reference data to see if that period is in contention with any other spotted course, and if not, schedule the course in that period. The process is repeated until all the requested courses are spotted.
We used to do this by hand, and it took perhaps 5 minutes per course. When spotting 25 Singletons, this took hours; it now takes seconds. Life is good.
Posted in Programming | Leave a comment

Post AP – Facebook

I suppose I should have been writing for the past one or two weeks, the end result would have looked the same: Not much news here. It took two full class periods to get all the necessary tools downloaded and installed (Visual C# 2010, Visual Web Developer), then we found we had to have IIS installed on the development systems, and THEN we had to create new Facebook accounts.
Of my four students in APCS this year (yeah, that’s a pitifully low number), only one of them had an AP course other than APCS, and she had I think five AP exams, so she was pretty much out of commission last week. Which meant that after the other three were "up and running", she had to start installing the aforementioned tools. Anyway, as of tomorrow (5/19/2010), we might just be able to make it to the tutorial.
Posted in APCS | Leave a comment

Post-AP: Let the fun begin

With the fun and insanity of the AP Computer Science exam behind us (with hopefully successful results, of course), I now face the annual challenge of how to occupy their time between now and the end of the year (2-1/2 weeks for seniors, 4-1/2 weeks for juniors). Over the years I’ve tried a number of different approaches, including Microsoft’s Terrarium project, programming Pocket PC applications, and even XNA (XBox game development); most have had mediocre success rates, primarily because of the limited time to work in.
This year I’m trying something different: Facebook App development. CodePlex has a link describing libraries for C# that allow creation of Facebook Apps through Visual Studio. Since all my AP students are versed in C# (prerequisite), and everybody has a Facebook account nowadays, this seems a natural connection.
While I’m not expecting the next Farmville or Mafia Wars (or worse, Mafia Farmville Wars!), hopefully I’ll have some interesting things to report as the month continues.
Posted in Programming | Leave a comment

Snow Day

We had a Snow Day today. The weather reports yesterday called for snow starting in the middle of the night, with heavy accumulations of 3-6 inches during the day, continuing on into the night. So when I got the call from the school’s president at 5:00am saying school was closed, I wasn’t surprised; I turned off the alarms and went back to sleep.
At 7:00am or so I woke up, pleasantly rested, and noticed something odd: I couldn’t see any snow falling. In fact, yeah, the neighbor’s roof through the window was black. It wasn’t snowing at all. The snow didn’t start falling until 8am, and it didn’t start accumulating until 3pm … an hour AFTER school would have let out!
What bugs me is that, while it eventually did pile up to about 3", and was over by 9pm, we really didn’t need the day off. Especially considering that it’s FIRST Build Season, and tonight was supposed to be our first test of the finished robot. (One week to go until Ship Day!) My daughter is upset, because it’s getting close to the point when they’ll have to extend the school year, which means finals might be in conflict with the Track Camp she wants to go to. (It’s in Colorado Springs, at the Air Force Academy … for some reason she wants to go out that-a-way.)
Gotta love the meterologists: Where else can you be wrong 60% of the time and still be considered good?
Posted in Life in general | Leave a comment