Programming some parts of Magic: The Gathering is simple while others are quite hard. First question, how many zones does Magic have? From the comprehensive rules 217.
“There are normally six zones: library, hand, graveyard, in play, stack, and removed from the game. Some older cards also use the ante and phased-out zones. Each player has his or her own library, hand, and graveyard. The other zones are shared by all players.”
Even though the answer is six, each player has his own library, hand, and graveyard, so the more correct answer is that Magic has a total of nine zones. MTG Forge uses a CardList, an ArrayList that only holds Card objects, for each zone. MTG Forge actually has more than 9 zones because it divides up zones into the stack, human hand, human graveyard, human removed from game, and corresponding computer hand, computer graveyard, computer removed from game. The zones are relatively straight forward to program because the only actions you can do is add a card, remove a card, and find a card.
Some complications occur when finding a card because multiple cards with the same name may be in play at the same time. How do you differentiate between different cards with the same name? The answer was in the old MicroProse game called Duels of the Planeswalkers, also known as just Shandalar, http://www.the-underdogs.info/game.php?id=1550 It had an option that allowed you to turn on the card’s number. So the answer is to give every card a unique number and to find cards based on that number, which is the method I use in MTG Forge. Magic Online most certainly uses the same method but it is transparent to the user since it is more user friendly and identifies the target with fancy arrows.
I know assigning cards different unique number isn’t exciting, but it is a critical part of programming Magic. Most programming is very, very boring, and it takes a great deal of time to get anything working. So I’m very happy with MTG Forge :)