Friday, February 27, 2009

New Version

I'm happy to announce there is a new version of MTG Forge with 1304 cards. All of the credit goes to DennisBergkamp and others who have contributed. There are even a couple of really new Conflux cards that surprised me like Nicol Bolas, Planeswalker and Child of Alara.

On a side note I had a great time creating a rat deck and a solider deck. It was nice that MTG Forge had enough cards to support decks that featured rats and soliders. You can download and post your decks on the forums. And don't worry, I'm still working on the quest mode.

(Link updated - it was the 02/26 version and now it is the 02/27 version which is the very latest.)

Tuesday, February 24, 2009

Magic Statistics

Magic seems to attract a large number of computer and math geeks. I, myself, am a computer guy that has taken way too many math classes. So naturally computer people want to program Magic and math people want to generate statistics.

Occasionally I get an e-mail talking about how they would like to write a program that would play two decks against each other and determine which deck is the best. I like this idea in theory and while I can write a program to solve every Sudoku puzzle, I’m not sure that Magic falls into the same category.

Hypothetically let’s say that you wrote a program to test two decks against each other and one deck wins 80% of the time and this was tested for 1000 games. You and your friend now use those two decks and you use the winning deck. Let’s say you played 10 games and you lost 6 of them. Is the 80% winning percentage wrong? No, because statistics only applies to a large number of games. Your measly 10 games is too small.

I’m not saying that Magic statistics can still be fun. I wrote a program to figure out land counts in your opening hand for decks with 2 types of basic lands. I believe a computer program could really help determine the number of land/mana sources as well as when to mulligan.

p.s.
I got the card art from this article about Magic’s 2010 Core Edition which will have 50% new cards, yeah.

Monday, February 23, 2009

Handling Errors

The unfortunate side effect of any program is errors and we’ve all had encounters with confusing error messages like “There was an error in variable callSec() F2b2”. Error messages are used to give the programmer information as well as the user. The information that the programmer needs is very different from the message that users want to see.

In my program, MTG Forge, I don’t really have an error handling strategy, like always writing the error to a file. When I am programming MTG Forge shows errors on the command line which my IDE (Word for programmers) displays. Unfortunately when MTG Forge is running as a normal program and an error occurs, nothing is displayed to the user. Obviously this is a major oversight and is a result bad planning.

The best way to handle errors is to have them automatically uploaded into a database on the Internet. This presumes that the program will always be online. Another good strategy is to have the program write the error message to a file, so the program can send the file when it is connected to the Internet or have the user e-mail the file.

In order to fix an error I need to know what the error message is (such as variable cardList is null), what is the line number, and what caused the error (like was the computer trying to use Elvish Piper?). Errors will happen in any computer program and you have to consider how your program will handle them.

Thursday, February 19, 2009

Posts Once a Week

I love posting twice a week, but I'll going to scale it back to just one post a week. I may post something extra occansionally, but I don't want to commit myself to anything.

And as a side note, what do you think of Conflux? What do you like or dislike about it? Personally I don't have much feelings either way because I enjoy programming Magic. I haven't played a real, cardboard game of Magic in awhile.

Tuesday, February 17, 2009

Quest Mode

I’ve talked about adding a quest mode before but now I am actually working on the code. The code itself isn’t all that tricky but trying to design a simple videogame is very challenging.

The quest mode will have 4 levels of difficultly: easy, medium, hard, and very hard. To begin with you will have 75 random cards to construct your deck. As you win, you will get more cards, booster packs. Also to give you a sense of progression, you will advance in “rank” from “Card Flopper” to “Pro-Tour Winner” to “World Champion.”

I’m trying to make the quest mode long enough but still interesting. The easy difficultly will take 100 matches, medium 150, hard 250, and hard 400. In easy mode you will get a booster pack after every win, medium takes 3 wins, hard takes 6 and very hard requires 9. Right now these numbers are approximate and may be tweaked in the future.

Ideally your opponents would get harder as you advance. In this case you will have the option of playing an opponent with an unknown deck or a generated sealed deck or a random sealed deck, decks that you have built in the sealed deck mode. Hopefully you won’t win all the time with your initial 75 cards, in order to make the game seem a little difficult. (I may have to cut the initial 75 cards down to 50 in order to make things more challenging.)

Hopefully I’ll get done with the quest mode in a week or two.

Thursday, February 12, 2009

I'm Back!

Sorry for the 2 week hiatus but it couldn't be helped. Conflux has arrived and checkout this visual spoiler in case you haven't heard the good news.

(By the way, protection from everything is crazy. You can't target it (duh), you can't block it, the only thing you have to worry about is getting it in play, thank you Elvish Piper (which has been putting overcosted creatures into play since 1996).

Enjoy the article below about Mana Flare.

And as a side note, now you can easily edit the files common.txt, uncommon.txt, and rare.txt which are used to create booster packs for sealed and draft games. I just finished by set editor and you can get it here, and also check out Rob Cashwalker's editor here.

Mana Flare and cards that change the rules

Cards like Mana Flare and other cards that change the “core rules” of Magic are some of the hardest cards to program. I’m going to briefly talk about how to program these cards.

Let’s say that there is a method called “getMana(Card c) : String” that takes a card as an argument and returns a string representing the mana which that card generates. If getMana() was passed a Forest, “G” would be returned. (For this example we are presuming that a card can only generate one type of mana like basic lands not Birds of Paradise) The method getMana() is relatively simple so far.

One of the ways to program Mana Flare is to have getMana() check to see is Mana Flare on the board. While this approach isn’t elegant, it gets the job done.
`String getMana(Card c){String s = c.getMana()if Mana Flare is in play  s = s + sreturn s}`
This approach is cumbersome if there are many cards that modify getMana(), because getMana() could become very complicated. Even though I use this approach in MTG Forge I dislike it because it means that the code for Mana Flare isn’t in only one place, it would be best if all the code relating to a card is together.

The second way I know of implementing Mana Flare is by “stacking methods” or adding “modifiers”. Let me show a brief example.

`abstract class ChangeGetMana{getMana(String mana) : String}class Mana{addModifier(ChangeGetMana c)getMana(Card c) : String}`
I’ve created a “blank” class called ChangeGetMana which has one method, this class can be “added” to Mana and will be called in the getMana() method.

`String getMana(Card c){String s = c.getMana()loop through all ChangeGetMana that were added  s = changeGetMana(s);return s }`
In essence you are adding code that will be executed in the getMana() method. This approach is good because it automatically handles multiple Mana Flares in play.

Some languages like Python let you actually change another object’s method, so object A can change object’s B method. Python also lets you “stack” methods easier than languages like Java. Python is more flexible than languages based on C, like Java, because all types are checked at runtime versus compile time.

I’m sure there are better ways to implement Mana Flare but these are the only two that I know of. Feel free to share your ideas.