Wednesday, September 30, 2009

MTG Forge - 2nd Bug Fix and Zendikar Basic Lands

Well MTG Forge seems to have as many flies as Aunt May's pie on a hot, summer afternoon. Downloading the card pictures has caused a few problems to surface. If MTG Forge can't read a link (url) it presumes that you aren't connected to the Internet. MTG Forge doesn't take into account that the link might be dead and like Abraham Lincoln, I cannot tell a lie, I wrote the buggy card picture download code.

You can just download a new file, "card-pictures.txt" from here.

The whole program, MTG Forge, with the fix can be download here.

And here is a link to those wonderful, full-frame Zendikar basic lands. Just unzip them in the /pics/ directory and overwrite the old land pictures.

All 20 Zendikar Basic Lands

p.s. The new user interface "jumps" some and you can prevent that by resizing any of the panels, such as the two "card detail" panels on the right. I hope that makes sense.

p.s. And if downloading all of the pictures in one big file is easier for you, here are these links.

All Card Pictures (47 MB)
New Card Pictures (1.3 MB) - Includes only the 40 new cards pictures.

Cards with Choices

The hardest cards to program are cards that let the player choose something. Probably the most common phrase in all of Magic is “choose target creature.” This is the simplest choice that the user can make and the code for choosing a creature is simple. More complicated cards like Peel from Reality (1 U, Instant, Return target creature you control and target creature you don't control to their owners' hands.) require the input code to be specifically customized for that specific card.

My favorite cards to code are cards that don’t allow the player to choose anything like Wrath of God (destroy all creatures) or Concentrate (draw three cards). Cards that don’t have choices require less lines of code. Another classic card in this category is Soul Warden (cost:W, 1/1, Whenever another creature comes into play, you gain 1 life).

I would kill Wizards if they made Soul Warden’s ability optional, “you may gain 1 life.” But truthfully I would ignore the “may” and make the ability mandatory versus always asking the user, “Do you want to gain 1 life, yes or no?”

The cards that require the most amount of code are optional abilities, which I personally hate from a programming point of view like AEther Vial (At the beginning of your upkeep, you may put a charge counter on AEther Vial). AEther Vial is a great card but every turn the computer has to pop up a window and ask the user a question, which interrupts the flow of the game.

Random odd fact, Wizards has only printed one card with the word “vial”.

Monday, September 28, 2009

MTG Forge - Bug Fix

There was a small problem when you downloaded and tried to download the card pictures, it would give you an error message. You can solve this by creating a sub-directory named "pics" where you unzipped MTG Forge. Sorry about the confusion.

MTG Forge 09-18 - Fixes the problem when downloading the pictures.

Zendikar Has Arrived

Wizards has officially released the full visual spoiler for Zendikar. Today, I thought I would just talk about cards from Zendikar which could be added to MTG Forge. (I have tried to make MTG Forge as flexible as possible but it only supports less complicated cards. And sorry about the weird formatting below, it was the best that I could do.)

Bold Defense looks like it could be added. Basically it only pumps up you creatures for +1/+1 or +2/+2 with first strike if certain conditions are met. MTG Forge supports kicker, so that isn’t a problem either.

Caravan Hurda is a simple creature with lifelink and Cliff Threader has mountainwalk. MTG Forge can easily add these cards just by adding them to the text file “cards.txt”.

Conqueror’s Pledge is just a big sorcery that makes a ton of tokens. It also has a kicker of 6 which is huge but it also creates twelve 1/1 tokens if kicked.

Day of Judgment is just a renamed Wrath of God and Felidar Sovereign has vigilance, lifelink and the ability to win the game if you have 40 or more life, which is a more expensive but improved Test of Endurance which required 50 life.

Windborne Charge is going to be a great finisher for sealed deck and drafts. If you have two generic 2/2s, you can transform them both into flying 4/4’s which usually results in a win for you.

Well thats 235 words and I'm not even done talking about white, *gasp*. The truth is that I and the MTG Forge team will try to add as many Zendikar cards as possible.

Wednesday, September 23, 2009

Software Evolution

When I started programming MTG Forge I didn't program planeswalkers, vigilance, or exalted. I started out with plain, vanilla creatures and then added flying and haste later. MTG Forge "evolved" one step at a time. I didn't know how everything was going to fit together but I wrote good code and didn't worry about the future.

My first big challenged was Glorious Anthem, a staple of white weenie decks. I had no idea how I was going to program it. Anthem is a great card and I wanted my version of Magic to have it. MTG Forge already implemented a simple "check state effects" that moved creatures to the graveyard and I experimented by creating Anthem in that code. It may not be the best way to code it but it worked and I was very happy.

MTG Forge didn't start out supporting flashback but since MTG Forge has a flexible architecture, flashback wasn't too hard to add. MTG Forge easily allows spells and abilities to be played in any zone. Cycling is another ability that works only when the card is in your hand. (Each spell or ability has a canPlay() method which returns true if the spell or ability can be played in the particular zone that it is in.)

Giant Growth and end of turn effects is another good example where I had to experiment a little bit to see what things worked and what didn't. (Giant Growth uses the Command Pattern and executes "at the end of turn" to return the creature to normal.)

The goal of any good computer program is to start with a good architecture (foundation) and then build on it. I think that programming is similar building a house of cards, you have to be extremely careful or everything will fall down and crash the computer. MTG Forge does have its share of bugs and crashes but hopefully they aren't too annoying.

Monday, September 21, 2009

New Version

The guys on the forums have done a great job. The new version of MTG Forge has 40 new cards which brings the total up to 1,881 cards. Other new features include better error reporting which can be saved to a file and upload to the forums or e-mailed to me (mtgrares yahoo com).

The user interface has been improved and allows the player to move the zone dividers so you can customize the appearance. (You can also click on those little lines to the right of the zone and it will "tear" off.) Other new features include support for Internet proxies when downloading the card pictures from Wizards.

The full version is for people who have never installed MTG Forge. The update version doesn't include a few files that never change or the file "all-decks2" which stores all of your decks. The update version will overwrite your quest data though.

Both the full version and the update have revised quest files so there are a few more computer opponents to play against.

09/2009 MTG Forge Full Version
09/2009 MTG Forge Update

All Card Pictures (47 MB)
Picture Update (1.3 MB) - Includes only the 40 new cards pictures.

Saturday, September 19, 2009

New Combat Rules

The new combat rules have been around for a little bit and I just wanted to see what you guys thought of them. I personally haven't had a chance to use them, so although I won't enjoy re-learning combat, I guess sometimes you have to just roll with the punches. Wax on, Wax off.

Wednesday, September 16, 2009

Cons of MTG Forge

As the program's creator I see many, many things that could be improved, which includes the whole program. Most of the cards are hardcoded in Java. While I love Java, it makes it very difficult for the average player to create new cards.

Currently all of the decks are stored in one central file and although individual decks can be imported or exported, it is hard to download multiple decks. (In the future each deck will be stored separately.)

Static effects like Glorious Anthem could be handled better. Activated abilities that tap have to be hacked in order to work correctly, the same goes for planeswalkers. Abilities like Hypnotic Specter have to be hardcoded and it would be nice if those types of abilities were handled by the combat code.

And I would really like to improve the AI and truthfully I'm just going to have to experiment to see what works. In order to use algorithms like alpha-beta you have copy the whole "game state" of Magic which includes all of the end of turn effects and everything else which is very complicated and error prone.

While MTG Forge's user interface isn't perfect, I don't really consider it as a negative. Yes, I wish it looked more like a videogame but truthfully I would prefer working on more cards than improving the user interface. In the code that I have written for MTG Forge 2.0 I have abstracted the user interface so it would be easier for me or some else to update the user interface in the future.

I almost forgot that MTG Forge doesn't support the new combat rules. Maybe I could update MTG Forge to support the new rules but it would be a very big job that doesn't look interesting. The hardest part is updating the AI because everything has to work together perfectly.

Monday, September 14, 2009

Pros of MTG Forge

I'm going to roughly outline the pros and cons of my program MTG Forge. (I'll do cons next time.)

MTG Forge has many strong points including the AI. Even though the AI wouldn't win a Friday Night Tournament, the AI is competent. (AI is similar to a special effect for a movie, it is just an illusion, that guy isn't really on fire.) MTG Forge has a large number of cards, more than 1,800 and includes many planeswalkers. The deck editor is also fully integrated and easy to use.

MTG Forge supports sealed deck, drafting, and a quest mode where you start with a limited number of cards and you have to play matches in order to win more cards. You can also edit the cards that are used to create the booster decks. Recently I talked about how MTG Forge "scripts" cards using the file "cards.txt" which I think is a major innovation and in the future I would like all cards do be "scripted" or reduced to plaintext instead of hardcoded with Java.

And I almost for one of my favorite aspects of MTG Forge, the "Generate Random Deck" feature. I absolutely love playing with and against random decks (I don't really like building decks most of the time, I would rather just play.) Hopefully I can improve the AI in order to make the game more challenging. I really like the idea that MTG Forge can help you improve your Magic skills.

Saturday, September 12, 2009

Abe Sargent and Zendikar

Abe Sargent posted a rather nice write-up about MTG Forge. He wrote that "Quest is the most fun I’ve had playing Magic in a year." Which is quite a strong statement. I'm glad all of the bugs didn't detract too much from the fun. He did have to concede one game because the computer crash, "The computer is thinking bug." (On a side note, he created a 60 card deck while I intended players to build a 40 card one, I guess I need to write better docs.)

Abe may have singlehandly saved MTG Forge 2.0 through his encouragement. This isn't the first time that MTG Forge has been mentioned on, I also wrote an article promoting MTG Forge awhile ago way back in September 2007. Back then MTG Forge had only 400 cards, ha.

And switching topics, there are a ton of very nice Zendikar cards to preview. Checkout the great basic lands. Wizards should have spruced up basic lands years ago, hello, they are the most commonly used cards in Magic.

Abe's Article
My September 2007 Article

Wednesday, September 9, 2009

More Scriptin with Cards.txt

By enabling cards.txt to implement Magic cards it greatly reduces the programming time that is needed to add new cards. Cards.txt supports a number of effects that are commonly used in Magic such as "damage creature or player", "draw N number of cards", "target creature gets X (like haste or unblockable)", or cantrip (Draw 1 card after this card gets done resolving.)

Biomantic Mastery
Draw a card for each creature target player controls, then draw a card for each creature another target player controls.

Biomantic Mastery is a complex card yet it can be added easily by adding it to cards.txt. The card is also more readable than the same code that was coded using Java.

Touch of Invisibility
3 U
Target creature is unblockable this turn. Draw a card.
Draw a card.

Touch of Invisibility has two effects which adds to the complexity.

Ambition's Cost
3 B
You draw three cards and you lose 3 life.

This is another card that combines two different effects.

Thriss, Nantuko Primus
5 G G
Legendary Creature Insect Druid
abTgtPTPump G T:+5/+5

The last line means that Thriss can pump up the target creature's stats by +5/+5. The activated ability taps this creature and costs "G".

By allowing cards.txt to implement cards itself, it makes adding (and creating) Magic cards very easy.

Unfortunately cards.txt doesn't have any error checking, so if you miss around with it and something fails, you probably won't know that it fails. Error checking is very hard.

Monday, September 7, 2009

Scripting Cards with Cards.txt

At first cards.txt was only used to create simple creatures that had "standard" keywords like vigilance and trample but Rob and other people from the forums have contributed code to expand the types of cards that can be added to cards.txt. The best way to understand this is to have a look at Shock, Volcanic Hammer, and Lightning Bolt.

Lightning Bolt

Volcanic Hammer
1 R


Each of these cards deals damage a creature or player and their only difference is their speed (sorcery versus instant) and the amount of damage. By "scripting" these cards it allows MTG Forge to be more flexible. Cards similar to Shock and Lightning Bolt can be easily added without having to add more Java code.

And this is just a tip of the iceberg. Cards.txt supports a number of other special words that allows to players draw cards or destroy creatures. While all cards cannot be scripted be scripted because they are too unique and different, like Warp World, many cards can be implemented this way.

Scripting Magic cards like this is the wave of the future. I also believe that the Wagic project uses Lua to script Magic cards. (Wagic lets you play Magic on your PSP or Windows machine.) A little game called World of Warcraft also uses Lua. Lua can be "embedded" in other languages so the programmer doesn't have to write a new scipting language from scratch (which is hard).

Friday, September 4, 2009

Visitor Statistics

I'm just going to throw out some random statistics about this blog. Hits vary from 220 to 300 hits a day, which I think it amazing. I remember when I was getting 3 hits a day, ha.

Operating Systems
87% Windows
9% Macintosh
3% Linux

I was a little surprised to see that Mac's beat out Linux 3 to 1. I'm just happy that MTG Forge works on Mac and Linux since I did zero testing on them.

And most people return again 56% of the time which I consider very good since Google's Analytic reporting isn't 100% accurate since it probably uses cookies.

Thursday, September 3, 2009

AI vs. AI - Temporal Difference

Initially I decided that MTG Forge version 2 would NOT be able to play itself, but then I changed my mind. I happened to read an article describing how a program named TD-Gammon learned to play backgammon by playing itself. I found this very, very interesting and you can read it for yourself here.

TD stands for “Temporal Difference” which is an algorithm that actually learns. Many times the AI for games like chess, checkers, and Magic’s Xbox game use an algorithm called “min-max” or “minimax” which looks ahead and tries to figure out the best move. The min-max algorithm doesn’t learn, it is “static”, but the temporal difference algorithm actually learns, which is amazing.

The good news is that some very smart people have put together a nice Java library that implements temporal difference and since these people are so smart they also have libraries that work with other programming languages like C, C++, and Python. The website is here. I don’t understand all of the math behind temporal difference but hopefully I should be able to use it in MTG Forge 2.0. (I currently have 0 cards working for it and my goal is a measly 10 or 20.)

This quote comes to mind and I hope it makes sense, “I see further because I stand on the shoulders of giants” which means that I plan to use other people’s code in order to improve MTG Forge’s AI.