Recursing For Bike Polo

This week I got to write a recursive function for the second time in my programming career. I’m always excited when this happens, and the event is so rare that it gets a blog post every time.

If you don’t know or care what recursion is, now’s the time to stop reading. Otherwise, we’re about to get technical, so pause your music and pay attention.

Recursion is a programming concept where a piece of code calls itself. It’s kinda hard to come up with a metaphor to explain this in non-programming terms – maybe think of a 3D printer that prints copies of itself. I dunno.

Anyway, I’ve been making a scoring application for my bike polo club. We’re having a tournament in January, and we’re not satisfied with the software options that are currently available.

Normal polo clubs use Podium. To use that, we have to get all our players to sign up for the League of Bike Polo and register themselves in our tournament with their teams, before the day of. The trouble is, our club hasn’t got its shit together. Hardly any of our players even know how to operate a computer, let alone sign up for LOBP. Besides that, our tournaments are traditionally mixers. That means you don’t choose your team – you throw your name in a hat and play with whoever you draw. We like it that way, because it keeps things low-key and egalitarian. The weakest player in the tournament still has a chance of scoring a few goals, and the winners are likely to be three strangers who have never played together before. It gives the Victoria players a chance to do okay, even though we’re playing against some of the best players in the world, who come over from Seattle and Vancouver.

So we don’t like Podium that much. (Though it is an excellent piece of software and a great contribution to the polo community!)

Jawn asked me to come up with something better last year. I think he asked me the year before as well. He asked a third time this year, with 4 months of run-up time, and this year I’m actually experienced enough to pull it off.

Instead of trying to master Javascript on the spot to create a fully browser-based application (that’s what I tried and choked on last time), I used the tools I’ve used on the job for the last three years – CakePHP and MySql. I use an older version of Cake, 1.3, at work, but my boss has been making noises about upgrading to 3.0 lately, and this was a good chance to learn how to use the newer version. So CakePHP 3.0 is the framework.

Setting up the framework on a borrowed server from work took a day or two. Figuring out how to create a plugin from the command line, then controllers, models, and views, took another week or so. Once the wiring was sorted out, I started on logic. Our user, in this case one Jawn Fawn, creates teams. Each team can have three players. They’re drawn out of a hat (in real life) then entered on a form (in the app). The teams are added to a tournament, and then you get a nice table with all your teams displaying.

Click a big plus sign to start a round, and you get… what?

Well, in the first version, you got a list of teams matched up at random. Winners get two points, ties get one point each, losers get nothing. So after a round, teams are sorted by how many points they’ve got, and then the teams with more points play each other and the teams with less points play each other. This makes sense to me, it’s a fair way of determining who the best player in a tournament is.

Except, that’s not really our goal. No one who plays polo in Victoria cares who the best player is. We’re here to get rowdy and drink in public. The weather is always terrible. Sometimes there’s soup, but the soup is usually cold. Showing each other up is the last thing on our minds.

No, the goal is to make sure that every team plays every other team, and that repeats happen as seldom as possible. Last week, I demoed the app to Jawn, and to my total shock, he didn’t care about my pretty ajax interface or the nice bubble display of complete matches. The first thing he asked was, “So if Big Country and the Beavers have the same score in round three…. they play each other again?”

And I’m like, “Yeah, I guess so?”

“Well that’s no good”, said Jawn. “The whole problem is that I don’t want to have to keep track of making sure teams don’t play each other too often.”

“Ok, I’ll give it another try.”

As usual in programming, the last 10% of the problem takes 80% of the development time. That’s basically what happened here, and it took another whole week to come up with an algorithm and an implementation that worked. Here it is, with lots of comments. It appears to be working, according to my tests, but I haven’t tested much. Still have to bug Jawn to kick it until it breaks. For some reason, he doesn’t drop what he’s doing and immediately start testing when I send him a demo, I have no idea what’s up with that.

Two things frustrated me for a whole day each. One was the part where the function calls itself. I was calling the function and then returning the array of matches. Instead, I need to return the function call within a conditional statement (if there are more unmatched teams, recurse…), and only return the matches when the condition is not met.

Second, I forgot the “break;” at the end of the foreach loop. It’s important. That was the “break”-through that let me finish it today.

Finally, the reason it had to be recursive in the first place. You grab the first item on the list of teams, then iterate the rest of the list until a match is found. What if no match is found? You have to iterate again. And so, you call the function again.

The tournament is set for January 21st. If you live anywhere near Victoria, I hope you can make it to see my work in action!

In Starbucks Next Week

This story is about kombucha. The first time I ever played bike polo was winter 2010… I think. I played 2 matches on my front suspension, department store mountain bike, then sat down in exhaustion. A man named Fish, who had a handlebar mustache, started talking to me. He was travelling south from Alaska with his friend, whose name I can’t recall, who looked like every lumberjack – thick, solid, beardy and plaid.

Around midnight, polo was breaking up and Fish’s friend asked if I would like to join them at their host’s house for kombucha and nut butter. Terrified, I said yes and followed them on their bicycles up what seemed to be the steepest hill I had ever encountered.

(Years later I learned that it was halfway up the hill Hillside is named for, and moved into a condo at the peak of it. Moved out 3 months later when I got tired of biking up it every damn day. I currently live at the base. But I digress.)

At the home of (again, I learned this much later) Luke Postle and most of his band (Slam Dunk, unGoogleable), a young blond person of indeterminate gender, with a bicycle chain tattooed on her/his face, offered me a large mason jar.

A soft, pink jellyfish-shaped fungus floated in the jar. “What’s this again?” I asked.

Kombucha Day 3

You may recall that I’m hard of hearing – when I encounter new words, it often takes three or four repetitions with increasing volume, and sometimes a spelling using either the Air Force alphabet or pen and paper.

We did get to Air Force alphabet stage on this one before I got it. Then I asked, and Fish provided, a detailed explanation of just what the hell kombucha is, while I made the sort of facial expressions that a back-country hick makes during their first real-life lesbian sighting.

The stuff seems to be of Japanese origin, and is made of fermented tea. It’s a little fizzy and tastes a little boozy though it doesn’t have alcohol in it, and it’s great for drinking at parties where you don’t want to accidentally forget that you’ve sworn off alcohol forever because of what happened last time. (No more merlot. Never again.)

It’s the cheapest thing in the world to make, and you can get good results without much effort. If you ever find yourself in an anarchist commune and wonder what all the glass jars filled with jellyfish fungus are, that’s probably it. Anarchists like kombucha.

OK, so that was my first in-person encounter with the stuff. My second one was tonight. Outside of Fairway Market in Quadra Village, I ran into my friend Lee and two women friends of his.

Lee is a dumpster diver and brought in a massive haul of eggs the other night. I already got my dozen and hardboiled them. One of his friends said, “Have you ever heard of tea eggs?”

She tells us, you hardboil the eggs, crack the shell a little, soak it in tea for a few days, and it tastes yummy. I want to try it, but with coffee.

“They’ll be in Starbucks next week” says Lee.

“Starbucks doesn’t have kombucha yet, though,” I pointed out.

I went inside for a beverage.

As I stood thinking hard about beverage choices, my eyes slowly focussed on the bottles right in front of me. Yeah, you guessed it. Not one, but three different brands of kombucha were there, surrounded by root beer and ginger ale. They had multiple flavours, including “classic” and “green”.

I goggled at the bottles, thinking about the blog post I am even now writing for you, and at least 5 hipsters grabbed some from in front of me while I did so.

I bought the kombucha. It’s pretty tasty. I am living in the future.

What exactly is a polo bike, anyway?

… as young men often ask me, as they struggle to maintain interest while I spin off on a bike related tangent.

Well, I’ll tell you. A polo bike is a rough looking, scratched up, bomb proof, 90’s style rigid mountain bike with a few modifications that make it easier to beat around on a basketball court while trying to smack an orange hockey ball with a mallet made out of ABS pipe and a ski pole.

Jackie Kanyuck recently let me have her old one, and it is seriously the bomb. Just gonna take a sec to brag here, but I used to score maybe once in three games if I was lucky. These days I’m scoring usually once or twice in every game, and doing a much better job of preventing Ryan, Ryan and Greg from scoring on me.

And I’ll show it to you.

Drive side
Drive side

Non drive side
Non drive side

We’ll go through this bit by bit. The frame is a Surly 1×1, a modern design, but a throwback to the old 90’s mountain bikes, you know the ones with the absurdly long stems and the gently curved forks, as ridden by nerds like this.

Fork

First, notice the fork and headtube. See how straight that line is? So straight. That’s so you can turn in tiny, tiny circles at very low speeds. Kona forks in particular are well known for being relatively common as salvage (i.e., cheap), but also tough and decent quality. And straight as straight can be. Queer people are welcome, but queer forks are not. We call that “zero offset fork” and “no rake”.

The wheel covers are to prevent balls and mallets from getting stuck in your spokes, and preventing damage to the spokes. Balls make a very satisfying *smack* as they bounce off the corrugated plastic. I am always surprised when I see people playing without them – they’re essential, in my opinion.

4 item(s)

Brakes are the most important polo mod. You have to brake with your non-dominant hand so you can swing with the other. These days all the big deals in polo seem to be using either dual brakes or just a front brake. In the past I just had a single rear, rim brake, with the lever moved to the left side of the bars. Back brakes give you less stopping power, but you’re also less likely to flip yourself over, as our man Greg does frequently.

But, Jackie had some awesome BB7 disc brakes on the Surly, and who am I to argue? They are amazing. It’s my first experience with disc brakes and I can confirm that they stop me on a dime regardless of how wet they get.

Jackie also hacked up this dual brake lever, for double the stopping power. It helps with the flipping-over problem.

3 item(s)

For the drive train, we want a nice loooow gear ratio, for quick accelerating. 32-22 is perfect, anyone who says otherwise is lying and wrong. In the past I used a cassette cog from some Shimano 10 speed sprocket, which worked okay, except for how it skipped all the time. This bike came with roughly the same deal. First thing I did upon receiving it was replace the entire drive train. The chain and front chain ring were direct replacements, but I put this beautiful Surly single-speed cog on instead of the cassette mess. As long as I replace the chain often enough, it should never skip again.

SeatNot much to say about the seat; it’s cheap and comfy. The seatpost is more interesting. It’s like, the longest seatpost ever. With my old bike I needed the whole thing. This frame is a bit more reasonably sized. Fully half the seatpost is inside the frame. More stability? Sure.

Stickers

 

Stickers are important, obv, they add 5hp each.

2 item(s)

Pedal straps are perfect for attaching your mallet to the bike.

Tire with flashAnd finally, the shoes. See that yellow? That’s the inside of the tire. Jackie says she’s giving me a new one, but honestly, we ride old tires as long as they hold air. This is the one place where I’m a cheapskate. (Ha! I’m always a cheapskate! But especially on tires.)

Ultimately, the player is more important than the bike. But hey, I’m a bike nerd, I love this stuff. I could write an essay on each individual part. In fact I might do so. I also rode a cheap, old, flexy, badly-handling polo bike for quite a long time, and I got good on it. Now that I’m a good enough player to justify the decent bike, it makes a huge difference, and I feel that I’ve earned it. And I feel like a rockstar when I’m riding it, and that’s the most you can ask of any vehicle.

A Bike Polo Tournament

Vic Winter Mixer 2013

If you play bike polo, you have to have a tournament once in a while.

We were talking about it since Jawn Fawn put one on in spring, in Nanaimo. Around October Ryan started getting serious about doing it. I got put in charge the usual way – no one else wanted the job. But I’m mainly surprised at how little work I actually had to do, and how many problems solved themselves.

Anna got as a venue and insurance, and gave me a lot of tips.
Brett volunteered to help, so I put him in charge of food. That was probably the best decision I made, because he locked it down real good. Potato soup, huge loaves of bread, snacks, corporate sponsors.
Greg was captain of the boards without any intervention from me, and Ryan H. hired a truck to move the boards. The boards were beautiful.
Jawn kept score and ran the competition, an unexpectedly (to me) big job.
Ryan H. also helped by supplying a lot of money for tshirts and beer at the after party. And by being calm and chill when I was panicking.
Cordelia was incredibly encouraging, and opened her house up to visitors.

The boards, assembled the night before, by hands and feet that were like bricks of ice in -8 degree weather.
The boards, assembled the night before, by hands and feet that were like bricks of ice in -8 degree weather.

Some things that went really well: there were no fights or drama at any point during the planning or the actual tournament. Or if there was, I didn’t know about it.
Volunteers showed up to move the boards… it was a hella big job.

Greg handled his job and Brett handled his. I’m sure I did a lot of things wrong or insufficiently, but everyone was incredibly encouraging. People had fun! They kept telling me so. And I learned a ton, and met so many cool people.

Some things I’d do differently next time:

  • Have people pre-register/pre-pay to save on running around collecting cash from people.
  • Give people a discount on tshirts if they buy them at the same time as their registration.
  • Maybe don’t get quite so many tshirts.
  • Make sure all the little items like balls, whiteboard markers, timers, and so on, are accounted for.
  • Figure out the competition style and schedule beforehand. Figure out prized beforehand too.
  • Have a cashbox, and appoint someone to be in charge of it.
  • Have a megaphone.
  • Get more people to commit to volunteering – though it’s hard to do. I’m so grateful to the people who did help in the freezing cold, but boy hardy it was one full ton of wood. The more hands the better.
  • Do a better job with the social media stuff – an Instagram handle is a great way of getting all the photos into one place. Live tweets are awesome.
  • Followpodium.com was an amazing resource that I had no idea existed until days before the tournament began. It’s polo-specific tournament software that’s tied into the League of Bike Polo website, so everyone’s names are already in it.

"Call me baby", I don't care what you call yourselves, that's your name now.
“Call Me Baby”, I don’t care what you call yourselves, that’s your name now.

Most of all, I wish I’d played more pickup and talked to more people. I did talk to a lot of them, but the more the better. I’m always too shy. All the people I met from Vancouver and Seattle were super cool and nice, and I only managed to hang on to maybe 1 name out of 5. In some cases I mistook Victorians for Vancouverites and vice versa.

One of the cool people I met was Max from Seattle (hi Max!) great guy, and interestingly, has 2 cochlear implants (I have one) so he’s deaf the same way I am. That is, he can hear quite a lot… enough to fool people a lot of the time. But I could tell when he had only heard maybe 3 words out of 20, and attempted to piece together a whole conversation from that little information.

I do the same thing, often. When I’m feeling shy or tired, it’s often easier to just guess and fake my way through the conversation – but though my guesses are very good considering how little information I’m working with, they are often a little off. It tends to ruin the flow of conversation. Better to come clean and give people instructions on how to talk to me. But still… it’s exhausting.

Max gave me a chance to see what that’s like from the other person’s point of view. He also came second in the tournament, thus demonstrating that being deaf still isn’t an excuse for not being excellent.

The List.
The List.

The tournament was really great experience, and though it will take me quite some time to muster up enough mental energy for the next one, I want to do it again. But only if I’m backed up by a crew as amazing as the one we had this time.

 

Video games, let’s do this

I don’t really play video games. To me, solving hard problems with code is about as interesting as it gets – Call of Duty, by comparison, can’t hold my attention. But making video games? All that is is solving hard problems every day… right?

There’s about ten million teenage boys who are desperate to get into the industry ahead of me, so it’s a pretty long shot, but here are my video game ideas. If you want to hit me up and get rich together on one of em, you know where to find me.

1. Drawing is hard. How about Draw Something! with drag and drop elements?

2. Oregon Trail…. on the moon!

3. Pioneer colony… on the moon! Alternate between first person hydroponic gardening, air duct repairing, moon buggy drifting, whatever, and long term moon-civilizing strategy.

4. Grocery Rush – I used to play Pizza Rush back in grade 7. It wasn’t anything much – you just drove your little car around delivering pizzas. The graphics were basically MS Paint calibre. Whatever. It was better than math class. Grocery Rush is like that but you have to run around filling your grocery cart with nutritious, thrifty choices. OMG, so educational. Maybe add zombies for pizazz? Nah, screw that. It’s a good idea on its own.

5. Bike polo! It’s hockey on bikes! A game is fun not just for the abilities it gives to players, but also the constraints it places upon them. In bike polo, you can only move forward, you have a large turning radius, if you go too slow you’ll tip over, and there is a sharp trade-off between top speed and acceleration.

Madden Hockey is a thing, so it’ll be like that. If you want to level up, you can trade points for foot retention (ability to hop sideways, higher speed), fixie mode (ability to move backward, better low speed balance) or a lighter mallet (more accurate hitting).

Ideas are cheap, execution is expensive. I’ll be over here coding.

gamergirl