Thursday, May 3, 2007

Computer AI

Of course I wanted to make the computer as smart as possible, but AI is terribly hard. Really, really, really hard. Try to write down on a piece of paper how to tie your shoes, now you get my drift. The computer AI has to act smart enough in all circumstances with any possible card combinations already in play. I wanted the AI to be able to “look ahead” and evaluate the outcome of playing a card but that proved too hard.

The AI just tries to play a card in his hand, any card. No other thought process is done. Can I pay for 4B, sure, ok play it. The computer does the same thing with activated abilities. A separate module was written to make the AI attack and block intelligently. The computer basically trades creatures when attacking or blocking. Although trading in all circumstances isn’t optimal, it is certainly very reasonable. It would be best if the AI had a control deck that it wouldn’t trade creatures. The same AI is used for all decks and cards.

Programming Environment

I programmed using JBuilder 7, circa 2003, that used Java 1.3. It worked fine, it was fast and my computer was not top of the line either. JBuilder 7 did well at most things, but it didn’t off packages, yes all your classes were in one long list. At first this didn’t bother me, but later it was too much. My program had 118 classes and 700kb of source code. It is hard to visualize 700kb but written out it would be the size of a thick 500 page novel. Backups were made just zipping up all the source code. No standardized testing was done, but testing was done ad hoc when there was an error. Not knowing what to do with errors, I usually just threw a Runtime Exception with a message about the problem, which is not very friendly but what are the alternatives?

MTG Forge Evolution

I had many ideas about what I wanted to program before I started. One idea was that you could test your deck in preparation for a tournament or that you could setup a situation and have the computer answer the question about card interactions. After I started programming a few cards, I knew I wouldn’t be able to program a lot of cards. I would only be able to program a small subset of all Magic cards. At first I wasn’t able to program any cards that had state effects like Glorious Anthem or upkeep effects like Juzam Djinn, but the program evolved and they were added.

Tuesday, May 1, 2007

Feedback

The feedback I get is erratic and usually consists of wanting more cards. I usually get about one e-mail from users. Most of the time the feedback isn’t useful at all. I have not had any other programmers contribute anything, this isn’t necessarily a bad thing, because I’m not sure exactly how someone else could help. Even with a team of 2, the work would have to be divided up, and currently I just sort of write code off the top of my head, and change anything that is broken or needs to be changed. Hopefully version 2 will a structure that would allow user’s to more easily submit their own card creations.

The most annoying e-mails are the one’s that say, “Have you been shutdown by Wizards of the Coast yet?” Wizards owns Magic: The Gathering. I guess my program is in a gray area, since it implements the rules and cards of a copyrighted game, but I am not profiting from it nor taking money away from Wizards of the Coast. Wizards has their own version of Magic on the computer appropriated named Magic Online.

The other type of annoying feedback that I receive goes like this. “Hi, I’m a programmer and your code looks really ugly. You could have done a lot of things better although it is cool that you can play against the computer.” Hm…interesting. First, an insult. Second, another insult. And then finally a minor praise. Is a praise wrapped in an insult still a praise? I am amazed the number of people who would look at the code and then put me down because I hard code values. They don’t contribute to the project, no they are too good for that, but they can spot bad code from a mile away, thanks. Pardon my French but some things like card names have to be hard coded somewhere.

Postmortem – what went wrong?

Nothing specifically went wrong. The visual interface was gray and more pleasant on my computer because I was using Java 1.3 but Java 1.5 changed the color scheme so the screen seems way too white, and it is hard on the eyes. I have tried to fix this, but that will have to wait until the next version. Currently I could not program any X spells like Fireball, or some combat damage abilities like first strike and trample. Decks do not have a sideboard, because at the time I couldn’t figure out exactly how I would let the user do that.

The biggest complain I’ve had is that the computer cheats when it plays cards. The computer might pay for “W” by tapping an Island. This isn’t an error, in so much as “designed to work that way.” The computer only counts the number of lands it has in play, this was done was a patch and I never updated it. Technically I could fix that, but the computer randomly plays a land, so that would have to be fixed too. Trying to make the computer just a little bit smarter is really hard. 90% of the time the computer is still beatable so I never saw it as much of an issue. Version 2 will have the computer paying the correct mana costs; I’m tired of getting e-mail commenting on this issue.

Postmortem – what went right?

Actually practically everything went right. Sometimes there is a random error message related to the interaction of 2 cards. I find most of those errors and I am able to fix them. The gameplay is addictive, at least I think so, and I regularly play it for 30 minutes or more. You can make and store you deck, which some people might say is a given, but it required some programming, nothing comes free.

The computer AI (artificial intelligence) seems smart enough. Although it sometimes makes a dumb play mistake, usually is seems challenging. I often play in sealed deck mode, and have the program generate both of our deck, games regularly last 10 or more turns. When I play sealed games, I am able to win 90% of the time. I still enjoy seeing the computer beat me over the head with Kiki-Jiki, Mirror Breaker or Elvish Fury. You are also able to draft in my game, which I think is a cool feature. It is a really different way to play Magic, but really fun.

Introduction Redux

Magic is the oldest and more popular card game around that currently has around 8,000 cards. My program currently has 365 cards, which is pretty good. My initial goal was 150 cards, 30 of each color. It was a large project that was written by just me. I don’t eschew other programmers, and I’m sure I could work in a group, but I just programmed it for fun in my free time. Actually, I’m very happy with it.

It works well, so much software, especially free software, seems a little buggy, which I totally understand. Free software is written mostly by computer enthusiasts and bug stopping is usually no fun, personally I hate it. Free software also tends to have a basic user interface or none at all. My program has a simple user interface written all in Java, and it shows, but it is at least a visual interface. It automatically downloads all of the card pictures, which is a nice bonus to the user. I am really proud of the deck editor. It works nicely and is very easy to use.