Monday, May 18, 2009

Version 2 Goals

MTG Forge version 2 is just gigantic so I have been trying to figure out what is the most important feature that version 2 will have that version 1 doesn’t? The two main contenders are more cards and a better AI. Hopefully version 2 will have both more cards and a better AI but sometimes you have to make difficult choices.

Having more cards is a fairly simple. Cards could be programmed using text instead of Java. The targeting and resolve code could be separated into separate blocks of code and used over and over again. (Currently much of the card code is copy and pasted.)

Implementing a better AI could be at odds with having more cards. Improving the AI might hinder other parts of the program since the AI influences everything. Having a better AI might mean having fewer cards. (And when I say “fewer cards” I mean having the current number of cards which is about 1,600 instead of 5,000.)

The AI is really interesting so I’m going to work on it first. I’m going to get a few cards working and see how much better I can make the AI. I know the AI could really improve the basic creature combat but I’m not sure how well the AI will handle combat in a full-blown game of Magic with activated abilities and instants.

I’m hoping that the AI will be very competitive and will help you improve as a Magic player. (Let’s also hope that I can find a good Java implementation of the alpha-beta algorithm.)

p.s.
I tried using Google for about 15 minutes to find a good Java alpha-beta algorithm but I didn't have any luck. If you have any ideas please let me know, thanks.

p.s.s.
I think I found a good implementation by downloading the source code from a Java algorithm book. I would like to find an optimized version though.

Friday, May 15, 2009

High Quality Scans - Alara Reborn

Magic has wonderful artwork and you can download large, high quality scans of Alara Reborn here (25 MB). The card picture to the left is actually reduced and you can see the card at full size here.

Wednesday, May 13, 2009

High Level Programming

When you program, you should always try to program at the highest level. "This level provides the abstractive power to work with a problem on its own terms. Your code at this level should be somewhat readable by someone who's not a computer-science whiz. At this level your code depends more on the tools you've built than on the capabilities of the language you're using." [1]

Basically your goal is layer computer-science data structures until you can use language similar to the problem domain. If your problem domain is Magic: The Gathering hopefully you have methods like startGame() and drawCard(player). These methods are "high level" because they can be understood by a Magic player who isn't a computer programmer.

Thankfully MTG Forge has a number of high level methods and objects. In the beginning I didn't have drawCard() and I would just duplicate the code. Needless to say this isn't the best solution, so I created drawCard() out of convenience.

Not all methods and object can be defined by the Magic glossary. Paying the mana cost involves a number of "artificial steps" that the computer has to do which are trivial in a real world game such as checking to see if the mana is necessary as well as untapping lands when the user cancels and doesn't pay for the spell. Combat also involves many artificial steps that the computer needs in order to make combat work correctly such as assigning damage and triggering combat abilities like Hypnotic Specter.

In closing, write high level code because it will save you time and frustration in the long run.

p.s.
[1] - Code Complete by Steve McConnell. This is a great programming book that is one of my major influences. This book is better than all of the books that I had to read for my computer degree, bachelor's in information science. I suggest that you try to find it at your local library.

The book has both a first and second edition. I still have the first edition but the second edition has probably 10% new and updated material. If you are cheap buy a used copy of the first edition.

Monday, May 11, 2009

New Version

MTG Forge now has 1606 cards, which is about 100 more cards than the previous version. All the credit goes to Dennis and Chris from the forums. It is nice to sit back and let someone else do all of the hard work, lol. MTG Forge now has a ton of new creatures that have protection.

MTG Forge now also supports deathtouch and changeling. Deathtouch makes attacking and blocking more complicated while changeling helps Shapeshifters fit into any tribal deck. I had Avian Changeling in my quest deck and I kept fetching it with abilities that got Mercenaries. MTG Forge also has the brand new card Jenara, Asura of War which is a killer. (I should know because the computer has beaten me with her.)

Questing is improved. (MTG Forge has a quest mode where you start out with a few cards and then you win more cards.) The AI quest decks are divided up into easy, medium, and hard. When you play on the easy mode, you face 3 easy decks, 3 medium decks, and 4 hard decks. In the medium, hard, and very hard modes you win new cards after you win or lose 2 matches, this should make these modes a little bit easier.

You may also want to download the token art which is the real artwork from Wizards. And if you are having trouble downloading the card pictures, I have a link below. And for those who want to know, this is just the 05/03 version that was posted on the forums. (Yes the forums get the new version before anyone else.)

Downloads:

MTG Forge 05-06 (2 MB)

Token Art (1.5 MB)

Readme (which is included in the main download)

Card Pictures (41 MB)


List of changes:

- Merged rares' quest changes code (if I understand correctly, AI opponents encountered are divided between easy, medium and hard), and included Chris' latest quest files.
- Fixed lands with tap abilities being able to use mana to pay for those abilities (Mikokoro, Center of the Sea, Kher Keep, Pendelhaven, etc.).
- Added different images for basic lands (change them to your favorites in card-pictures.txt).
- Fixed some problem with fetching Rebels/Mercenaries if cancel is pressed.
- Fixed Hush Cycling.
- Fixed Cover of Darkness.
- Fixed Guardian of Cloverdell AI lifegain?
- Lightning Helix cast by the AI should not cause crashes anymore.
- Fixed Stalker Hag.
- Added "Changeling" keyword (only works on creatures for now though I think?), and fixed existing cards that were supposed to have Changeling, thank you Chris for pointing them out.
- Added "Deathtouch" keyword (only tested this for a bit).
- Added "Protection from creatures" keyword (haven't tested this a lot either).
- Fixed Demonic Tutor (can only cast it during your own turn now).
- Fixed display of -1/-1 counters (it would show a negative number).
- Fixed Lockjaw Snapper.
- Fixed some issues with the AI targeting side of Oblivion Ring.
- AI Guiltfeeder should attack now.
- Fixed crash with Aether Vial for AI... however, turns out the thing is still broken, for now, don't put this card in any AI decks.
- Fixed Zur the Enchanter, will only be able to get enchantments with manacost 3 or less.
- Vampiric creatures should not receive +1/+1 counters as they're hitting the graveyard anymore.
- Fixed a crash with Faceless Butcher when its target is null, and the AI shouldn't play it when there's no targetable creatures in play...

New cards:

A lot (60+ if I'm not mistaken) more Protection from {color} cards (thanks Chris!)
Terminate, Unmake
Maelstrom Pulse
Jenara, Asura of War
Fable of Wolf and Owl
Sighted-Caste Sorcerer
Brainbite
Vithian Renegades
Steely Resolve
Cloudchaser Eagle, Aven Cloudchaser, Monk Realist
Commander Eesha, Beloved Chaplain
Wirewood Lodge
Bunch of deathtouch cards
Bunch of changeling cards

Wednesday, May 6, 2009

Name Mutator

The MTG Forge zip file contains the curiously named file "name-mutator.txt". MTG Forge can use this file to rename all of the cards. I added this functionality after a cease-and-desist letter was send to Sourceforge.net, my previous hosting website. I figured if my program used different card names it would still be legal, I have no idea if this is really true.

Renaming all of the cards has certain drawbacks which makes it unappealing. First, the user has to read the card text for every card. Magic has been around for a long time and people enjoy using their favorite card. If their favorite card is renamed, the user won't know if MTG Forge has it. Second, if MTG Forge showed the originally named card picture it would still be confusing.

I do have to say that creating new card names for the 441 cards in name-mutator.txt was quite challenging. Let me share with you some of the names that I am most proud of. Zombify became Rise Again and Wrath of God turned into Peaceful Solution. I worked the hardest on the lands because I wanted them to make sense.

Mountain : Rock
Forest : Grass
Swamp : Bog
Plains : White Sand
Island : Underwater

Since Mountains make R mana, Rock is a decent substitute. I tried to make each renamed land match the mana color that is makes. Thinking of a synonym for Plains was very hard, so that explains White Sand.

Basically the name mutator file could be used but it makes the game less interesting.

Monday, May 4, 2009

Stuck in the Middle

Have you ever started a computer programming project with high hopes only to become lost and disillusioned? Usually this happens after you've written a few thousand lines of code and have put a fair amount of effort into the project. Somewhere you realize that things aren't working how they should and the code becomes all tangled in your mind. Currently I'm "stuck in the middle" while working on MTG Forge 2.0.

This is my third attempt at MTG Forge 2.0 and I have a fair amount of things working, like the user interface, but the devil is always in the details. All of the millions of details have to be worked out and somewhere in the middle things tend to get worse before they get better. (You have to observe which parts need to be fixed, which is why things seem to get temporarily worse.)

The key to programming (and life) is to only worry about the major details and handle the small details one at a time as needed. When I program I don't plan much. I like the idea of UML and other diagrams, but to me the code is what is really important. Each object solves one big problem while each method solves a smaller sub-problem.

Sometimes the problem with "2.0 software" is that it tries to add too many features. Initially this was my problem but even when you cut features, the overall problem is still hard. Magic is a tough, but interesting, nut to crack and this explains why many Magic projects are started but never finished. MTG Forge is usable because so many features were cut, like phase stops. I knew I couldn't do everything right the first time, so I didn't try. Hopefully MTG Forge 2.0 will solve many of the deficiencies of 1.0 but it certainly won't be perfect. (Perfect software doesn't exist.)

p.s.
I've only had a sinking feeling after I've written a 5,000 or so lines of code. I feel sorry for programmers who spend any portion of their life on code that is never used or thrown away. (I would love to get my hands on the Magic Online 2.0 code which isn't being used any more. It would be interesting just to see the documentation.)

Friday, May 1, 2009

What is MTG Forge?

MTG Forge lets you play the card game Magic: The Gathering against a computer opponent using all of the rules. This is very different than playing solitare Magic with Apprentice or Magic Workstation because the AI will attack and play spells. Currently there are over 1,600 cards ranging from old power cards like Ancestral Recall and Lightning Bolt to newer cards like planeswalkers. The user interface is basic, but it does let you download all of the cards pictures and view them while playing the game.

You can also play sealed deck, draft, or the new quest mode. In draft mode the AI drafts for the 7 other opponents and builds the decks from the cards that it chooses. In the quest mode you start out with a few cards and the more games that you play the more that you win. As you get more cards you can update and change your deck.

Download - MTG Forge uses Java and works on Windows, Mac, Linux, etc...

Tutorial (85 MB) - If you don't know how to play Magic: The Gathering download this windows demo.

MTG Forge requires Java, if your computer doesn't have Java you can get it from here, java.com/getjava