Maybe the idea of a coding competition doesn't sound that exciting to you, but I could already see the story lines going. Clock ticking down, thirty minutes left. You've got one last problem to solve, one last error to correct, and you've got to do it now. You've got to put everything into that one shot, achieve your highest level of problem solving in that moment of pressure, and put it all together to type the code that will lead you to glory, to fame, to the title!.. And I laughed at myself as I always did. How often does real life turn out like that? Oh all the time you know. All - the - time, haha.
I could already feel the nervous excitement building in me waiting for the event to start. Although, I wouldn't be surprised if I was the only one who could say that. We would be competing against 7 (I think it was 7 but maybe it was more) other teams from our school, with the top 2 going on to the grand finals. Some of the people, you could tell, weren't that into the event. Some (like one of my teammates, cough cough) were there just for the food. Most of the others were probably there willing to put in a reasonable effort, you know, do what they could. And then there was me. "We're gonna win this, right?" I said, half joking, half serious. Because I wanted to shoot for first. Not first in our school. First internationally. First in the grand finals. Why aim for less? The way I saw it, if there was even the slightest glimmer of hope that we could reach the top, then why not go for it? Why not give it our all? If in the end you find out you couldn't do it, well then, you couldn't do it, but as long as you believe there's a chance, why not give it everything you've got? And I could see that chance, that glimmer of hope. So I let my anticipation grow as we waited to receive the message that would tell us our mission. Still, I couldn't help but feel that I might have been the only one in the room that was seriously considering the possibility of getting 1st in the grand finals.
The email came, along with a video of someone telling us what our goal for the competition was. They introduced a 10 player game where each player controls a car and drives to pick up people and drop them off at their next destination. You get points for dropping people off, with one of the people being worth 3 points, three of them being worth 2 points, and the rest worth one point. To complicate things, each person had a list of enemies, and they wouldn't get off at a destination if one of their enemies were there. In that case, you would either have to wait for someone to pick up the enemy or find a different location to drop off your person and receive no points. The game ends after one player drops off 8 different people, and the person who ends the game by getting their 8th drop off gets a 2 point bonus. Everyone in progress to a destination would get up to a half point more based on how close they were to dropping off their person (like, if you were 1/3 of the way there, you'd get 1/3 of a half point, so .17). Here's how it all looked. Now, our goal was to write a program to play the game. I looked at my friend and said, "Heh, this is all just another game to me," and laughed.
We had decided to do our coding in Java, and because I didn't have that much experience with Java I was fine with leaving the coding to a teammate. I would come up with the ideas behind the program. Somehow, I already knew a solid approach to tackling these kinds of problems (maybe because it really was just another game). First, determine the factor(s) that affect your score, and how important these factors are. Second, create a fundamental approach that works really well most of the time, or works pretty well all the time. Third, deal with the strange cases and make improvements. In this case, I saw the factors being time to pick up/drop off people, and the point value of the people you were dropping off, with time being more important than point value. The travel time would be based on the time to get to the person you wanted to pick up and the time to get them to their destination. With that said, a generally good approach would be to choose your next person to be the one who you could pick up and drop off in the shortest combined time. For improving the approach, I thought of what to do when an enemy was at the destination, and how to avoid picking up people who couldn't be dropped off because of enemies.
I got this foundation down pretty quickly. Then it was down to getting it coded. The coding dragged on and on, with a lot of bugs coming up over and over again. By lunchtime we almost had the general approach completed. Almost, but we took a break for lunch. While the rest of my teammates talked and ate a leisurely lunch, all I could think about was the last like 5 lines we had to put in to finish up the basic idea. It was just like 5 lines. We needed to get this in so we could make sure it worked and then think about the things we could improve. We were losing time. And it's just 5 lines. And I know you guys aren't as serious about it as me, but "Could we just get these last few lines in and see how well it works?" Well eventually we got the basic part done, but we hadn't even gotten to the part of dealing with enemies yet. That and there was this problem with the code they gave us to find the shortest path to our destination, because it didn't always give the shortest path. As the time went on, it became clear that we weren't going to get as much done as I had hoped. I was hoping we'd finish implementing all of my initial ideas by lunch, or like an hour after that at the latest, so we could find new ways to improve the code. Unfortunately, we were already running out of time and we still hadn't finished putting in the ideas I had for dealing with enemies. And eventually we got that done too, but by then the practice runs for the competition were about to start. It was also becoming clear how much of a problem the shortest path code was. There was one map with a lot of small loops in the paths and with their pathing algorithm our car would get stuck in the loops for a long time. The maps were selected randomly, so we just hoped that the maps chosen would be ones that weren't problematic.
The test runs began, and almost every map was one where bad pathing was a serious issue. Because of that, our code performed poorly and we weren't competitive at all. That was just the test run though. There was still an hour left to the actual competition. Suddenly, I realized the position I was in. One hour left, one problem to solve: fix their A* pathing algorithm that I've never heard of before or create a new one. Fail and we're almost guaranteed to lose. Succeed and maybe, just maybe, we have a chance to win. To add to that, they said I was the only one who could do it. There I was, in a situation I could write in a story, only it was actually happening.
I downloaded the code in C++ and looked it over. Then I looked it over again. Then I stared at it some, and it started to make some sense. But even if I figured out a solution, if I wasn't going to code it myself it had to be simple enough that I could tell someone else how to code it in a very short period of time. I mentally ran through the flow of the code a few times and I found my best shot.
"Comment this out. Comment this block out. Add a line here, add another line here. Comment this section out." It was the simplest answer I could come up with on the spot. There was very little that had to be added in. Most of it was just removing code, and it was easy enough to tell someone which parts of code to remove. But it was still crazy. It was an algorithm I've never heard of before, and I had to trust the flow of the code that I saw in my mind, and also trust that the changes I made would lead to the correct result. If there were any errors, I wouldn't be able to fix them in time because I didn't understand the code well enough, and I had no alternate solution. It had to work in one shot. The button was pressed. We held our breaths as our car drove towards the section full of loops... and celebrated as it drove through them with no problem at all.
The school finals began. The competition was for the highest score after 10 rounds. We didn't start out winning, but we hung around 2nd or 3rd each round, and the same team wasn't winning every round. No one was watching our team at first because we didn't do well in the test rounds, but people started to notice that we were hanging around. Suddenly, we won a couple, and we were right there in the running for first. As the rounds went on, we were one of the 2 teams that pulled away. It became pretty clear who the top 2 would be, the only question was, "Who was going to win?" We fell behind but closed the gap with a very strong 8th round. The 9th round went to our opponent, and the score difference seemed to be almost too much to overcome in one round. Almost. We had to win the last round. Not only that, we had to win before our opponent got enough points to keep first place. Our eyes were on our opponent's car as it drove to drop off the 3 point person late in the round. They had 1st place virtually guaranteed if they got the drop off. We watched the number go up. 8.2... 8.3... 8.35... As soon as they reached .5 they would be at their destination and make the drop. My teammates were already giving up hope but I couldn't turn away. 8.45... .46... .49... Their car reached the destination..., stopped..., and turned around. "Are they blocked?!" someone on our team yelled out. "They're blocked!" "They can't do it, there's an enemy there!" Then just after that, out of nowhere the game ended because our car dropped off its 8th passenger. The numbers stopped moving and we saw that we had won. We won the round! We won the round, and we won the competition. I never knew how exciting it could be watching colored circles move around a screen and numbers moving up and down.
The story didn't end there though. I still had my hopes set on taking the whole thing, winning the grand finals. Although I wasn't feeling that confident about it, because all I could think about were all the extra things I would have done if we had more time, if we had coded more efficiently, if we hadn't run into as many errors...
There were 38 teams still in the competition. There would be 4 rounds of 9 or 10 with the top 5 in each moving on to the semis, then 2 rounds of 10 with the top 5 in those moving on to the grand finals. They ran all the competitions and then posted recordings of the matches. I watched our quarterfinal match. We were doing all right, all right, and then, suddenly, we were disconnected from the match. And I watched on, waiting for them to stop running it and add us back in, but they kept on going. They ran all the rest of the matches with our team disconnected. At least a bunch of other teams had gotten disconnected too. Surely they weren't going to just let teams lose because their equipment failed. Too many people were going to be upset. And sure enough, they eventually posted something saying that they hadn't been paying attention but now that they realized so many people disconnected so they were going to run all the matches again.
They ran the quarter finals again, and I watched, celebrating every drop off and anguishing over every poor decision. We finished in a solid second. At least we were moving on. The semifinals were posted, and we were matched with the other team from our school. After the intense match we had had in our school competition we were expecting another really close result... but for some reason, their AI was performing poorly in the rounds. They finished out of the top 5, while we finished second again.
Well, there we were at the grand finals. Second and second, surely if we got a little luck we could have a shot at first. The top 3 got nice prizes, so I wouldn't have been disappointed with 3rd. Surely we had a chance for third at least, right? Well, the first few rounds were enough to convince anyone that that wasn't true. We finished near the bottom in all of them. I wasn't giving up hope yet though. You know, maybe, maybe if we got really really lucky, we could win a couple rounds and be in the running for third... Yeah... it didn't happen that way. We finished a measly seventh. Seventh. That's 4 places away from the top 3. 6 teams finished better than us. I'm sure most people would say it was a good performance. We won in our school. We made it to the grand finals. But... man... more than anything else, I walked away with a bunch of what ifs.
The story didn't end there though. I still had my hopes set on taking the whole thing, winning the grand finals. Although I wasn't feeling that confident about it, because all I could think about were all the extra things I would have done if we had more time, if we had coded more efficiently, if we hadn't run into as many errors...
There were 38 teams still in the competition. There would be 4 rounds of 9 or 10 with the top 5 in each moving on to the semis, then 2 rounds of 10 with the top 5 in those moving on to the grand finals. They ran all the competitions and then posted recordings of the matches. I watched our quarterfinal match. We were doing all right, all right, and then, suddenly, we were disconnected from the match. And I watched on, waiting for them to stop running it and add us back in, but they kept on going. They ran all the rest of the matches with our team disconnected. At least a bunch of other teams had gotten disconnected too. Surely they weren't going to just let teams lose because their equipment failed. Too many people were going to be upset. And sure enough, they eventually posted something saying that they hadn't been paying attention but now that they realized so many people disconnected so they were going to run all the matches again.
They ran the quarter finals again, and I watched, celebrating every drop off and anguishing over every poor decision. We finished in a solid second. At least we were moving on. The semifinals were posted, and we were matched with the other team from our school. After the intense match we had had in our school competition we were expecting another really close result... but for some reason, their AI was performing poorly in the rounds. They finished out of the top 5, while we finished second again.
Well, there we were at the grand finals. Second and second, surely if we got a little luck we could have a shot at first. The top 3 got nice prizes, so I wouldn't have been disappointed with 3rd. Surely we had a chance for third at least, right? Well, the first few rounds were enough to convince anyone that that wasn't true. We finished near the bottom in all of them. I wasn't giving up hope yet though. You know, maybe, maybe if we got really really lucky, we could win a couple rounds and be in the running for third... Yeah... it didn't happen that way. We finished a measly seventh. Seventh. That's 4 places away from the top 3. 6 teams finished better than us. I'm sure most people would say it was a good performance. We won in our school. We made it to the grand finals. But... man... more than anything else, I walked away with a bunch of what ifs.
No comments:
Post a Comment