Wednesday, May 27, 2009

Unusual Needs

As a guy who programs Magic, unofficially of course, I want to do things that are unusual. For example, I want to sort all of the cards in MTG Forge by putting the newest cards first. And by newest I mean putting the "Alara Reborn" cards first and then the "Conflux" cards second and so on. I really enjoy playing with the new cards and even though MTG Forge may only have a few cards from a given set, they are still fun to use.

OK, back to my task of putting all of the cards in MTG Forge in print order. My first idea was to put all of the card names for each set into separate files. While this would have worked, I found a better solution. When I was playing around with Nate's Deckbuilder I found out that it could produce a file with all of the card names sorted by the set that it was in. While this isn't perfect because I have to reorder the file by putting Alpha first and Beta second, it does get me closer to my solution.

Now all I have to do is to read the "master file" and then sort the cards according to their relative location, if card A is after card B, I would swap them. Nate's Deckbuilder isn't really designed for what I'm using it for but it is versatile enough to still be helpful. It didn't have an option for saving only the card names but it lets you tinker with how it saves decks so I eventually came up with a working solution.

Sorting cards isn't a monumental task but it is certainly hard enough. Every computer program is an accrual of man-hours, it is easier to modify a 100 line program than a 1,000 line program. MTG Forge has 21,000 lines of code not including CardFactory and 37,000 lines of code with it. CardFactory creates all of the cards but it has a lot of redundant code.

No comments: