Monday, October 29, 2012

Gridiron Solitaire #27

On the Team Hub, you see league standings, last week's results, and the upcoming week's schedule.

When I first wrote the code (it was about nine months ago), I had no idea that there were automatic sorting commands in VB.Net. This is kind of typical for me, not knowing that an easier way exists to do something. So I just sat down and figured out how to sort fifteen items of data.

I loaded an array, compared each element, moved elements when necessary. What I wrote was, much to my surprise, called a "bubble sort". To sort fifteen elements (like wins, or rushing yards) took about 300 lines of code.

Okay, quite a few of you are breaking ribs from laughing right now. Hopefully you can stop gasping before you puncture a lung. It's funny to me, too, although (surprisingly) I've learned quite a bit from learning to do things "by hand", so to speak, when much better tools were available.

This code all works fine, so I left it alone. Then I decided a couple of weeks ago to change how ratings are displayed in the offseason screen. Before, I showed the explicit rating for each team in each category. It's a full reveal, so to speak.

Why would I want to do that, though?

Real football doesn't have a full reveal, ever. Rough ideas of a team's ability can be discerned from statistics, and in the offseason, from an analysis of the team's personal, but teams aren't really rated on a 1-10 basis. Usually, it's more a comparison versus another team, so Team A definitely has a more productive passing attack than Team B.

Ability is irrelevant without context in relation to other teams.

I was talking about this to John Harwood, if I remember correctly, and he said, "Why don't you show a team's ranking for a particular rating versus the rest of the league?" Well, that's a great idea. It makes perfect sense in the context of providing information, but not absolute information.

To do that, though, takes a lot of sorting. Five ratings sorted into rankings and displayed, then the ratings themselves change as part of the GM AI, then the new ratings have to be sorted into rankings and displayed. Plus I can add a tab to the Team Hub so that these relative rankings are available all season, because they're not a full reveal.

At first, I thought that I would just adapt the existing code I'd written, but when I realized it would be over 3,000 lines long, I decided that was crazy. I'm entirely OCD about writing efficient code--or trying, at least--so I sat down and tried to figure out a better way to structure what I was doing.

Two hours later, what would have been 3,000 lines of code was 26, thanks to a liberal use of For-Next loops. And while I'm pretty embarrassed that the original code was so incredibly wasteful, the new version is very useful, because I'll be able to use it with all the original sorts to compact the code significantly.

So now, in the offseason, you'll see a team's ranking in each rating versus the rest of the league. Then when you hit the "Run Franchise G.M." button, you'll see the broadcaster do a 15-20 second summary of the biggest offseason ratings changes, and then you'll see the revised team rankings after all the ratings changes were applied (almost every rating on a team will change every year, although the vast majority of those changes will be in 1-point increments).

I'd like to get this rewrite finished so that I can focus on adding a few more niceties based on beta comments, but this is very grindy, so it may take the rest of the week to complete.

Site Meter