Play Magic Against the Computer, or Better Than Apprentice

I’m writing this article to promote a program I’ve written, called “MTG Forge,” that lets you play Magic against a computer opponent using all the rules of a real game. It’s really fun. Currently there are 400 cards available, and you can play in three modes: Constructed (all the cards), Sealed, or Draft.

[Editor’s Note: It’s a quiet time for Magic at the moment. Roll on Lorwyn, say I. In the meantime, here’s something a little different…]

I’m writing this article to promote a program I’ve written, called “MTG Forge,” that lets you play Magic against a computer opponent using all the rules of a real game. It’s really fun. (Self promotion is horrible, I know.) Currently there are 400 cards available, and you can play in three modes: Constructed (all the cards), Sealed, or Draft. Can you believe it… free drafting? Yes, the best things in life are sometimes free.

Side Note: If you want to play against another human player, you have to use this other free software project, called the Magic-Project. Like Apprentice, you have to know the other person’s Internet IP address in order to play them, but unlike Apprentice, the Magic-Project enforces all of the rules of a real game.

MTG Forge Homepage

Good News:
The card set is the best of Magic, and includes such cards like Ancestral Recall; Juzam Djinn; Serendib Efreet; Flametongue Kavu; Man-o’-War; all the Moxes; Kokusho, the Evening Star; Keiga, the Tide Star; as well as old favorites like Wrath of God, Psychic Blast, Serra Angel, and a few Planar Chaos cards like Pyrohemia, Serra Sphinx, and Damnation.

More good news: you can automatically download all of the card pictures with just one click, which makes playing more fun.

This project is written in Java (so you have to have Java installed) and has been tested on Windows and Linux. It should work on Macintosh but I don’t know for sure. You have the option of downloading either a full-featured Window’s installation program, or a plain zip file. To install using the zip file, unzip all the files into a directory and double-click on the file “run-forge.jar”


Limited Good News:
You can play in Sealed deck format or Draft… cool, I know. The Sealed deck format works like usual: you get 5 booster packs, 75 cards, and you have to put your deck together. To make a sealed deck, open the “Deck Editor” and from the menu select “New Deck — Sealed,” and your card pool is generated for you. If you want a different card pool, just select “New Deck — Sealed” again.

In the Sealed format, you can optionally select “Generate Deck” for both you and the computer’s deck. This generates a two-color deck with at least fifteen creatures from a card pool of five booster packs like normal. The deck has 18 lands, a little high I know, with nine lands of each basic type. I like this option because I don’t know what cards are in my deck and I definitely don’t know what cards the computer has. It is really surprising but fun. You can still win 95% of the time using the “Generate Deck” option.

Drafting is fun, but I’m not the biggest fan of the format. It seems like it could be really enjoyable, but it’s a little too money intensive for me. Drafting on MTG Forge works like normal: you open one pack, choose a card, and pass the rest to your neighbor. The computer selects cards for the other seven players, and actually constructs their decks using the chosen cards, something that took way too much programming. You can then play your draft deck against the other seven players that drafted with you. After you have drafted all of your cards and saved them to a file, you have to open the Deck Editor, and then open the file that you just saved in order to actually make your deck.

MTG Forge doesn’t currently support sideboards, so just cram all of your good cards into your maindeck. This is a tidbit of inside info: when you are drafting instead of clicking the “Choose Button” card, you can just right click. By right clicking you are selecting the card that is currently highlighted.

Bonus Limited News:
You can edit which cards are classified as common, uncommon, and rare for Sealed and Draft! If that news isn’t great, what is? Chocolate covered deck protectors? The file “common.txt” contains all of the card names that are considered common, so if you are tired of playing against Wellwisher, just delete it. If you want to play with Kiki-Jiki, Mirror Breaker more, make him uncommon by adding him to the file “uncommon.txt” The files “common.txt,” “uncommon.txt,” and “rare.txt” have no blank lines, lines starting with “//” are ignored, and the card names must be valid. I suggest cutting and pasting card names from the file “cards.txt,” which holds all of the programmed cards, in order to avoid any messy errors.

Bad News:
Since this is the work of one programmer and freely distributed at no cost, the user interface (how stuff looks on the screen) is simple, but very usable. You can see a screenshot here.

The computer intelligence (AI) is simple. The computer only plays cards during its turn, and will play Giant Growth before declaring attackers much like a beginner. Even though the AI is basic, the computer can top deck some great cards, so I think it feels realistic. Honestly, I forget I’m playing a simple computer opponent sometimes since I am so into the game, and focused on winning. Because people enjoy winning, having a challenging yet beatable computer opponent works.

With the limited card pool and basic computer intelligence, you will not be able to test your deck for a tournament. I’m just saying this in case anyone has that idea. That was one of my ideas when starting with this project, but one man can only code so much. So features were cut, and although you can’t play your favorite deck, you can make new decks with all those banned cards like Ancestral Recall, Wheel of Time as well as other expensive rares like Adarkar Valkyrie and Visara the Dreadful. Here is a recipe for fun: mix in Ancestral Recall with a pinch of Eternal Witness for insane card drawing, but make sure you don’t deck yourself. One of my favorites is Kiki-Jiki, Mirror Breaker, which is fun to play and really silly to pronounce. And who can tell me what Fire Imp does? Well, he is Flametongue Kavu’s little brother, costs 2R, and he’s a 2/1 creature that deals 2 damage to target creature when he comes into play. Fire Imp is a fun Portal card that no one has heard of, but it’s a great casual card. And who out there really has 20-30 copies of Relentless Rats?

It all started when I found this cool 1996 Magic game by MicroProse called Duels of the Planeswalkers. It let you play against the computer, which lessened the humiliation of defeat. It featured about 640 cards from Alpha, Legends, Antiquities, The Dark, and 4th Edition. It was also way ahead of its time by letting you play against other people over the Internet, much like a free Magic Online. It had all the classic power cards, and I was in awe when I first saw them in action. Nevinyrral’s Disk, Ancestral Recall, Ali from Cairo, Time Vault, Berserk, and Black Lotus are all very broken. I could tell that these cards were overpowered, but also really fun. I played Constructed constantly for about a month or two straight.

I was getting bored, but I found an option to play Sealed deck. I randomly clicked on it to see how it was, but I wasn’t expecting anything too great. I loved it! I got to choose my cards from a random card pool and then face off in a 32-player tournament. It was brilliant. Those early card sets were not designed with Sealed in mind, so I had to use two tournaments packs and four boosters in order to construct a viable deck. Anything less was unplayable. The packs were skewed toward Red for some reason. Red always had the most creatures… go figure.

The MicroProse game was excellent. The computer acted intelligently enough, and would sometimes surprise me by combining the effects of two different cards. I enjoyed playing land destruction and other nasty decks, without actually annoying another person. Sealed deck was really fun, but I wish I could change the card set that it used. Some cards I just got tired of seeing and I wanted to delete them.

I started programming just to see how far I could get. I started by programming code that represented a card and then phase etc… MTG Forge just got bigger and bigger, and now it is around 700kb of source code. The source code is about the length of a 300 page novel. I programmed in Java because that is my best language. I am sort of surprised the whole project didn’t collapse, and it almost did a few times. When nothing worked, those were the hardest days. I programmed MTG Forge mainly for myself, and I am my own biggest fan. I play it almost every day.

AI (No not the awful movie):
The AI (artificial intelligence) is the most important aspect of MTG Forge. Yes, Magic is a fun game, but you need to have a challenging opponent.

I’ll let you in on a little secret. I don’t have the Internet at home. Are some of you shocked? I don’t have cable either, ha. Double shock! But don’t worry, I have used Magic Online, and at first glance I was very impressed with everything. The games played very. Unfortunately, after awhile I got irritated waiting on my opponents, and by the “random” disconnects when I was winning. The high card prices also frustrated me, so MTG Forge was born. My goal was to provide fast, fun games of Magic. I am very happy that MTG Forge is able to simulate drafting and Sealed games. Currently Sealed is my favorite, and I often make 2-3 decks with the same pool of cards in order to see which configuration works the best. Sometimes I play “speed Magic” to see how fast I can click and still win.

Okay, back to the nitty-gritty of the AI. The AI, of course, has many different parts. The main skeleton is named ComputerAI_General, and it calls the other parts of the AI depending on the phase. This part of the AI has code that handles playing a land, paying for a card, attacking, and blocking. Each of these separate parts has its own code, for instance ComputerUtil_Attack2 decides which creatures the computer will attack with.

The AI is roughly divided up into 2 parts. Code that is built into each specific card and code that attacks, blocks, plays a land, and pays for cards. Some AI is built into each card. For instance, the computer will target creatures with a defense of 2 or less when choosing targets for Shock. The AI code in Shock chooses the targets and decides when the computer should play it. All of the cards and their AI is crammed in CardFactory, which is roughly 10,000 lines long. Yes it is really, really long.

The AI is sub-optimal sometimes when playing cards like Wrath of God and Giant Growth. When playing Giant Growth, the computer will target a creature that will attack but won’t target a 2/2 if you have a 2/3 blocker. The computer will also not use regeneration effects or counterspells, unlike the old Magic game Duels of the Planeswalkers, also known as Shandalar. I find it impressive that Shandalar did do some things right and occasionally even pulls off some pretty good two-card combos. I am very pleased how MTG Forge’s AI worked out. It is smart enough to provide a good game, which was my goal. I have played MTG Forge more than probably anyone else, I’m guessing 100+ hours, but I still love it. Maybe next version I’ll add something that shows the “total time played” so you could see how much you really love Magic, and of course for bragging rights. Hehe.

Did you know that Sid Meier is credited as both a game designer and programmer in Shandalar?

Wild Wild Wild Draft:
Do you remember that old TV show that was named the “Wild Wild Wild West”? Okay, I only remember that it was a western and it had cool gadgets. I don’t know if the TV show had any giant robotic spiders like the movie did, but who knows? Now back on topic… what sort of draft makes you choose between a Mox and Meloku the Clouded Mirror? MTG Forge features these types of hard decisions. One of my draft decks featured 2 Moxes, 3 Serendib Efreets, Ancestral Recall, and Keiga, the Tide Star, which makes it the most expensive draft deck ever.

No, I wasn’t drafting Alpha, but I was drafting some of the best cards from Alpha and from all of Magic’s history. Someone suggested drafting all of the cards programmed with no rarity, so Juzam Djinn comes up as often as a common land. I thought it was a crazy idea, but I tried it. This sort of crazy drafting is the most fun ever. Deciding between Flametongue Kavu and Rorix Bladewing is just grueling. What is better, Wonder or Regrowth? Does Godless Shrine beat Terror or vice versa?

I open my first pack, and what do I see. The standout cards are Birds of Paradise; Helldozer; Jokulhaups; Keiga, the Tide Star; and Kiki-Jiki, Mirror Breaker. Man, I wish I could open a booster like this in real life.

Wrath of God:
People e-mailed me asking how I program cards so I’ll try to explain the process. I’m going to show you some Java code, and I hope your head doesn’t explode.

if(cardName.equals(“Wrath of God”) || cardName.equals(“Damnation”))

final SpellAbility spell = new Spell(card)

public void resolve()
CardList all = new CardList();

for(int i = 0; i < all.size(); i++)
Card c = all.get(i);

public boolean canPlayAI()
return 0 < CardFactoryUtil.AI_getHumanCreature().size();


All right, I’m sure the code looks like a mess, and everyone is confused… good, class is starting. The Card object gets its mana cost from the file “cards.txt” so the same code will work for Wrath of God and Damnation. (Objects are chunks of programming code.) A Card object holds one or more SpellAbility objects. Wrath of God’s SpellAbility object has a resolve method that destroys everything. (Methods are specific parts of an object. A Cat object would have a meow method.) Hopefully I haven’t put too many of my students to sleep yet. SpellAbility also has another method called canPlayAI that tells the AI if this card can be played. For Wrath of God, the canPlayAI method checks to see if you, the human player, have any creatures in play. If you don’t have any creatures, the computer won’t play Wrath of God. I know this is sort of a gunshot introduction to programming, but at least you got your feet wet. Congratulations because now you understand one of Magic’s most iconic cards.

Drafting with Data (from Star Trek)
Did you ever realize that Data was just Spock in a different form? Maybe I’ll stir up some controversy by posting that on some random Star Trek fansite. Anyway… I am very proud of the fact that you can draft in MTG Forge. Drafting is much faster than in real life, around 5 minutes. To begin with the AI chooses two colors and picks creatures first then spells. Don’t expect the AI to observe any sort of pick order, but thankfully the computer is still challenging, albeit a little bit random. Anytime the computer plays something like 2 Wrath of Gods and then Serra Angel you know you are going to be in trouble. And yes, I’ve had the computer play back-to-back Wraths, which is crazy but it completely decimated me. Those types of games are very memorable, and it is the very reason that I wrote MTG Forge.

Normally you would open and pass your 2nd booster pack to your left, but in MTG Forge everything is just passed to the right, it was easier to program and all that jazz. The computer does make his deck from his draft picks, which I find pretty impressive. The computer always plays 9 land of each of his two colors.

Extra Ramblings:
If you like Magic, and I bet you do, MTG Forge is really fun. Games are a quick 5-10 minutes and your opponent never gives up. Don’t you hate it when you are winning and your opponent has connection failure? Curse you, Magic Online! And you can play land destruction and other hate decks without annoying people.

I wrote MTG Forge because I wanted to play fast, quick games against the computer, using cool rare cards that I could never afford in this lifetime. I’m looking at you, Ancestral Recall and Juzam Djinn. Even though the AI is basic, the computer plays a challenging game. For more information, consult the user manual that is included when you install MTG Forge.

Download my program, and have some fun!

Download Me
Blog: Blog.

E-mail me any comments good or bad. I want to make MTG Forge the best I can, but please don’t write to me about any of the items below.

1. The user interface is very basic.
2. The computer doesn’t play perfectly.

3. You have to scroll to see all the cards in your hand.
4. No protection or morph yet, so shoot me… it’s hard.

mtgrares yahoo com

Notable Rares:

All Moxes
All Ravnica duel lands
Adarkar Valkyrie
Akroma, Angel of Fury
Akroma, Angel of Wrath
Ancestral Recall
Baru, Fist of Krosa
Beacon of Unrest
Birds of Paradise
Darksteel Colossus
Elvish Piper
Glorious Anthem
Jugan, the Rising Star
Juzam Djinn
Keiga, the Tide Star
Kiki-Jiki, Mirror Breaker
Kokusho, the Evening Star
Korlash, Heir to Blackblade
Library of Alexandria
Meloku the Clouded Mirror
Might of Oaks
Relentless Rats (Okay, he’s an uncommon but you can finally make that deck you always wanted to.)
Rorix Bladewing
Royal Assassin
Ryusei, the Falling Star
Sengir Vampire
Serendib Efreet
Serra Angel
Serra Avenger
Serra Sphinx
Stuffy Doll
Tarox Bladewing
Troll Ascetic
Visara the Dreadful
Wrath of God

All Cards:

Adarkar Valkyrie
Aggressive Urge
Air Elemental
Akki Drillmaster
Akroma, Angel of Fury
Akroma, Angel of Wrath
Allied Strategies
Ancestral Recall
Ancient Silverback
Angel of Mercy
Angelfire Crusader
Angelic Blessing
Animate Dead
Animate Land
Arashi, the Sky Asunder
Ashcoat Bear
Ashen-Skin Zubera
Ashes to Ashes
Assault Zeppelid
Aven Fisher
Azure Drake
Balduvian Barbarians
Ball Lightning
Barkhide Mauler
Baru, Fist of Krosa
Beacon of Destruction
Beacon of Unrest
Birds of Paradise
Blade of the Sixth Pride
Blind Phantasm
Blinding Light
Blinkmoth Nexus
Blistering Firecat
Blizzard Elemental
Blood Crypt
Bog Imp
Bonded Fetch
Bottle Gnomes
Breath of Life
Breeding Pool
Brute Force
Cackling Flames
Cackling Imp
Caller of the Claw
Cao Cao, Lord of Wei
Castle Raptors
Chittering Rats
Cloud of Faeries
Coastal Hornclaw
Commune with Nature
Coral Eel
Counsel of the Soratami
Courier Hawk
Craw Wurm
Crazed Skirge
Daggerclaw Imp
Dancing Scimitar
Dark Banishing
Darksteel Colossus
Darksteel Gargoyle
Defiant Elf
Delirium Skeins
Demonic Tutor
Devour in Shadow
Disciple of Kangee
Diving Griffin
Do or Die
Douse in Gloom
Dragon Roost
Dripping-Tongue Zubera
Dross Prowler
Drudge Skeletons
Dryad Arbor
Dusk Imp
Eager Cadet
Echoing Decay
Echoing Truth
Elvish Fury
Elvish Piper
Elvish Warrior
Ember-Fist Zubera
Enormous Baloth
Erratic Explosion
Essence Warden
Eternal Witness
Faceless Butcher
Fangren Hunter
Feral Lightning
Fighting Drake
Filthy Cur
Fire Imp
Flametongue Kavu
Fledgling Djinn
Floating-Dream Zubera
Fomori Nomad
Foot Soldiers
Foul Imp
Frost Ogre
Frostweb Spider
Funeral Charm
Furnace Spirit
Furnace Whelp
Gaea’s Anthem
Ghost Ship
Ghost Warden
Ghost-Lit Redeemer
Giant Cockroach
Giant Dustwasp
Giant Growth
Giant Octopus
Giant Warthog
Gift of Estates
Glorious Anthem
Glory Seeker
Gluttonous Zombie
Gnarled Mass
Goblin Balloon Brigade
Goblin Chariot
Goblin Piker
Goblin Ringleader
Goblin Sky Raider
Goblin Skycutter
Godless Shrine
Goldmeadow Lookout
Goretusk Firebeast
Greater Forgeling
Grizzly Bears
Hallowed Fountain
Hammerfist Giant
Hand of Cruelty
Haunted Angel
Hidetsugu’s Second Rite
Highway Robber
Hill Giant
Horned Turtle
Horseshoe Crab
Howling Mine
Hunted Troll
Hymn to Tourach
Ichor Slick
Ifh-Biff Efreet
Infernal Kirin
Intrepid Hero
Isamaru, Hound of Konda
Jackal Pup
Jugan, the Rising Star
Juzam Djinn
Kabuto Moth
Kami of Old Stone
Karplusan Strider
Kavu Climber
Keening Banshee
Keiga, the Tide Star
Kiki-Jiki, Mirror Breaker
Killer Whale
Kjeldoran War Cry
Kodama of the North Tree
Kodama’s Reach
Kokusho, the Evening Star
Korlash, Heir to Blackblade
Lantern Kami
Lava Spike
Lay Waste
Leonin Skyhunter
Library of Alexandria
Life Burst
Lightning Angel
Lightning Bolt
Lightning Elemental
Llanowar Behemoth
Llanowar Elves
Llanowar Mentor
Lucent Liminid
Lumengrid Warden
Magus of the Disk
Magus of the Library
Mahamoti Djinn
Malach of the Dawn
Marble Titan
March of Souls
Mass of Ghouls
Meloku the Clouded Mirror
Might of Oaks
Minions’ Murmurs
Minotaur Explorer
Mistral Charger
Mogg Fanatic
Molten Rain
Moorish Cavalry
Mox Emerald
Mox Jet
Mox Pearl
Mox Ruby
Mox Sapphire
Nantuko Shade
Needle Storm
Needlespeak Spider
Nessian Courser
Nevinyrral’s Disk
Night’s Whisper
Norwood Ranger
Orcish Artillery
Order of the Sacred Bell
Overgrown Tomb
Path of Anger’s Flame
Peel from Reality
Penumbra Bobcat
Penumbra Kavu
Peregrine Drake
Phantom Monster
Phantom Warrior
Phyrexian Gargantua
Phyrexian Hulk
Phyrexian Rager
Plague Wind
Primal Boost
Primal Clay
Primal Plasma
Prodigal Pyromancer
Prodigal Sorcerer
Psionic Blast
Pulse of the Tangle
Radiant, Archangel
Raging Goblin
Raging Minotaur
Raise Dead
Raise the Alarm
Reckless Wurm
Redwood Treefolk
Relentless Rats
Remove Soul
Renewed Faith
Revered Dead
Reviving Dose
Rootbreaker Wurm
Rorix Bladewing
Royal Assassin
Ryusei, the Falling Star
Sacred Foundry
Sakura-Tribe Elder
Sarcomite Myr
Savannah Lions
Scathe Zombies
Seizan, Perverter of Truth
Sengir Autocrat
Sengir Vampire
Serendib Efreet
Serpent Warrior
Serra Angel
Serra Avenger
Serra Sphinx
Shinka Gatekeeper
Shivan Dragon
Silent-Chant Zubera
Silvos, Rogue Elemental
Simic Sky Swallower
Skirk Shaman
Sky Swallower
Skyhunter Prowler
Skyknight Legionnaire
Slaughterhouse Bouncer
Sliver Legion
Snapping Drake
Sorceress Queen
Soul Warden
Spark Elemental
Spark Spray
Spined Wurm
Spitting Spider
Spotted Griffin
Sprout Swarm
Squall Drifter
Steam Vents
Steel Wall
Stern Judge
Stomping Ground
Storm Crow
Strangling Soot
Stuffy Doll
Suntail Hawk
Swords to Plowshares
Sylvan Messenger
Symbiotic Elf
Take Possession
Tarox Bladewing
Temple Garden
Tendrils of Corruption
That Which Was Taken
The Unspeakable
Thought Courier
Timberwatch Elf
Torii Watchward
Trained Armodon
Tribal Flames
Troll Ascetic
Tromp the Domains
Urborg Syphon-Mage
Utopia Tree
Vedalken Mastermind
Venerable Monk
Veteran Armorer
Veteran Cavalier
Villainous Ogre
Vine Trellis
Visara the Dreadful
Vodalian Merchant
Volcanic Hammer
Vulshok Sorcerer
Wall of Kelp
Wandering Stream
Watery Grave
Wayward Soul
Weathered Wayfarer
Wheel of Fortune
Whiptongue Frog
Whirlpool Rider
White Shield Crusader
Wild Elephant
Wild Mongrel
Wind Drake
Wirewood Elf
Wit’s End
Wojek Embermage
Words of Wisdom
Worldly Tutor
Wrap in Vigor
Wrath of God