Friday, November 30, 2007

AI – Curve my mana

My e-mail is on the fritz. Yahoo used to be so good but I might have to change to gmail. I'll try to send everyone a copy of my program on Monday.

I was thinking about how to make the AI a little better. I thought if the computer’s land was curved out, the computer would seem a little smarter. The computer’s opening hand is all spells and the computer will draw a land for the next 5 turns. This maximizes the possibility of the computer playing a timely 1 or 2 mana spell. After a few more turns the computer draws 2 more lands.

The rest of the computer’s land is artificially moved to the bottom of the computer’s deck, so the computer will always top-deck something useful. The long game will favor the computer, but the AI is still very beatable since it just plays a random spell. Currently the computer cannot evaluate the board position or anything complicated like that.

I could have gone a step further and guaranteed that the computer would be able to play a spell for the first 6 turns of the game. I might do this later. I had a hard time sorting and alternating the computer’s land so that it would look like this: Mountain, Plains, Mountain, Plains, etc… That way the computer will always be able to play a double costed card like WW as early as turn 3 and always on turn 4.

Other ways to make the computer stronger would be to have him draw 2 cards per turn. I have rested doing this since it would break the illusion that the computer was playing by the rules, but I might test it out to see if it really helps the computer.

Thursday, November 29, 2007

DCMA Counter-Notification

Hopefully I got a copy of MTG Forge to everyone that requested it. If you didn't get a copy, send me an e-mail or leave me a comment. I just laughed at everyones comments that had "Send me a copy of your awesome program" That was just really funny at the time.

The notice I was sent was covered under the DCMA and I was given an option of generating a counter-notification. This counter-notification would let me get the original copy of the DCMA letter sent to Sourceforge which would let me change the bits of my program that were copyrighter. The Firemox project, formerly the Magic-Project, is still up and seem to have only changed the ability name. For example they renamed Cycling to something else. They didn't change the card names, which I thought may be the problem.

I'm not sure if I have an ice cube's change is hades, but I at least tried. --Forge

Tuesday, November 27, 2007

Comments

Hi, I just wanted to reply to everyone's comments. The e-mail was sent to Sourceforge about copyright infringement. The DMCA Notice said that the acronym "MTG" infringed upon Wizard's copyright. (That would be easy to fix.) But that the program MTG Forge also infringed upon Magic Online.


I did notice recented that the Magic-Project became Firemox. I'm not sure what they changed in order to comply. I think I could change all the card names and that would be legal but I'm not sure. The pictures were not in the program MTG Forge but maybe just linking to the pictures was illegal. I'm hoping that by changing the card names and other things that the project will be hosted at a later time on sourceforge.

A couple of months in October I had a phone interview with Wizard's. They knew about my program but it didn't seem to concern them one way or another. They didn't comment about it at all.

Currently I have a new version that I'll e-mail to anyone that is interested. My e-mail is on the top-right of the screen, so just send me something short like "Send me your awesome program" and I'll send you the new version. If anyone knows of a site that wants to host my program (I just need somewhere that people can download it), let me know. Thanks for all your comments.


--Forge

Monday, November 26, 2007

Cease and Desist

I guess it was just a matter of time. I finally received a cease and desist letter from Wizards of the Coast legal counsel. They said I violated their copyright. I didn't know Wizards copyrighted all of their card names, but maybe they do. I presume they don't copyright the rules but I'm not clear on that point. Just wanted to tell everyone.
--Forge

Hello,

My name is Jacob Moorman; I am the Director of Operations for
SourceForge.net. You are receiving this mail because you are the
project administrator of the 'mtgforge' project, hosted by you on
SourceForge.net. We have recently received the following (forwarded)
DMCA request from the complainant (CC'd).

When cases like this arise, we always expeditiously forward the mail to
the project admin. Please review this message carefully and follow-up
as needed.

Following the DMCA requirements we have disabled public access to the
SourceForge.net-hosted space provided to your project.


You can read the specifics about our DMCA compliance in our Terms and
Conditions of Use page:
https://sourceforge.net/tos/tos.php#allegations_of_copyright_infringement_or_trademark_infringement



You can read our DMCA policy, including instructions for
counter-notification at:
https://sourceforge.net/docs/H10/


Thank you for your prompt attention to this serious matter.

Sincerely,

Jacob Moorman

CC: SourceForge legal
CC: Savvis (SourceForge.net datacenter provider)



Begin forwarded message:

> *From: *"Copyright@savvis.net "
> >
> *Date: *November 16, 2007 11:47:17 AM GMT-05:00
> *To: *>, > >, > >, >
> *Cc: *"Copyright@savvis.net "
> >
> *Subject: **Sourceforge - Savvis Case 1152152 - DMCA Notice -
> 66.35.250.203 - http://sourceforge.net/projects/mtgforge*
>
> Dear Administrator:
> SAVVIS has received notice that an IP address (see below) under your
> administrative control is distributing copyrighted works in violation

> of United States law, specifically, 17USC512 et seq., also known as
> the Digital Millennium Copyright Act ("DMCA").
> Please note that this activity is both illegal and in violation of
the
> SAVVIS Acceptable Use Policy ("AUP"), a copy of which may be reviewed

> at http://www.savvis.net/Customer/aup.html.
> Be advised that the DMCA places very stringent requirements on
SAVVIS,
> as the upstream provider, and that failure to resolve this issue in a

> timely manner could result in the termination of services to
offending
> IP's or sites. SAVVIS follows the DMCA time requirements very
> strictly: this issue must be resolved within 7 days of this notice to

> avoid active intervention under DMCA.
> If you require any assistance in resolving this, or any other SAVVIS
> security issue, please do not hesitate to contact me at any of the
> below points of contact.
> Sincerely,
> Jason R. Bradley GSEC
> Security/Abuse Engineer
> SAVVIS Security Services (S3)
> SAVVIS Communications
> 1 Savvis Parkway
> St. Louis, MO 63017
> 314-628-7821 - Desk
> 314.628.7050 - Fax
> **This message contains information which may be confidential and/or
> privileged. Unless you are the intended recipient (or authorized to
> receive for the intended recipient), you may not read, use, copy or
> disclose to anyone the message or any information contained in the
> message. If you have received the message in error, please advise the

> sender by reply e-mail at copyright@savvis.net
> and delete the message and any
> attachment(s) thereto without retaining any copies.**
>
> ************ORIGINAL COMPLAINT(S) BELOW*************
>
>
> *From:* Reynolds, Carin [mailto:cgreynolds@pbwt.com]
> *Sent:* Friday, November 16, 2007 10:01 AM
> *To:* Copyright@savvis.net
> *Subject:* DMCA Notice - http://sourceforge.net/projects/mtgforge
>
>
> November 16, 2007
>
> *_By Email_*
> copyright@savvis.net
>
> DMCA Designated Agent
> SAVVIS Communications Corporation
> One SAVVIS Parkway
> Town & Country, Missouri 63017
>
> *Re: DMCA Notice – **http://sourceforge.net/projects/mtgforge*
>
> *_Infringement of Wizards of the Coast, Inc. Copyrights and
Trademarks_*
>
> Dear Copyright Agent:
>
> We are counsel for Wizards of the Coast, Inc. (“Wizards”), the
owner
> of the copyrights and trademarks to the MAGIC: THE GATHERING®
trading
> card game. We recently became aware that you are the service
provider
> for www.sourceforge.net , which has
posted
> an online version of Wizards’ MAGIC: THE GATHERING® trading card
game
> at http://sourceforge.net/projects/mtgforgecalled “MTG Forge”
(“MTG”
> is a commonly used acronym for MAGIC: THE GATHERING®). The “MTG
> Forge” game is described as “a robust Java implementation of card
game
> Magic The Gathering that enforces the rules.” We have attempted
> repeatedly to contact the owner of this site, but have received no
> response and the infringing game has not yet been removed.
>
> This unauthorized copying of Wizards’ MAGIC: THE GATHERING®
trading
> card game constitutes copyright infringement in violation of 17
U.S.C.
> § 501. The unauthorized use of the MAGIC: THE GATHERING® name
> violates the federal trademark laws, including 15 U.S.C. §§ 1114(1)

> and 1125(a), by creating a likelihood of confusion with respect to
> Wizards’ authorization or sponsorship of or association with the
“MTG
> Forge” trading card game and the sourceforge.net website. This
> unauthorized use of the MAGIC: THE GATHERING® trademark is also
likely
> to dilute its distinctive quality in violation of 15 U.S.C. §
1125(c)
> and the anti-dilution laws of numerous states.
>
> Pursuant to the Digital Millennium Copyright Act (“DMCA”), we
have a
> good faith belief that the “MTG Forge” game identified above
infringes
> Wizard’s copyrights and other intellectual property rights, and is
not
> authorized by Wizards or its agents. We are authorized to act on
> Wizards’ behalf regarding these matters. The information provided
in
> this communication is accurate to the best of my knowledge and is
> provided under penalty of perjury.
>
> On behalf of Wizards, we therefore request that you act promptly to
> remove or disable access to the infringing “MTG Forge” game from
the
> sourceforge.net website*.*
>
> This letter does not purport to be a complete statement of the facts
> or the law and is without prejudice to Wizards’ legal and equitable

> rights.
>
> Sincerely yours,
>
> Carin G. Reynolds, Esq.
> *Patterson Belknap Webb & Tyler LLP*
> 1133 Avenue of the Americas
> New York, NY 10036-6710
>
> /tel/: 212.336.2104
> /fax/: 212.336.2277
> cgreynolds@pbwt.com
>
>
> ----------------------------------------------
> Privileged/Confidential Information may be contained in this message.
If you are not
> the addressee indicated in this message (or responsible for delivery
of the message to
> such person), you may not copy or deliver this message to anyone. In
such case, you
> should destroy this message and kindly notify the sender by reply
email. Please advise
> immediately if you or your employer do not consent to Internet email
for messages of this
> kind.
>
> ----------------------------------------------
>
> IRS Circular 230 disclosure: Any tax advice contained in this
communication (including
> any attachments or enclosures) was not intended or written to be
used, and cannot be
> used, for the purpose of (i) avoiding penalties under the Internal
Revenue Code or (ii)
> promoting, marketing or recommending to another party any transaction
or matter addressed
> in this communication. (The foregoing disclaimer has been affixed
pursuant to U.S.
> Treasury regulations governing tax practitioners.)
>
>
==============================================================================
>
>
> This message contains information which may be confidential and/or
> privileged. Unless you are the intended recipient (or authorized to
> receive for the intended recipient), you may not read, use, copy or
> disclose to anyone the message or any information contained in the
> message. If you have received the message in error, please advise the

> sender by reply e-mail and delete the message and any attachment(s)
> thereto without retaining any copies.

--
Jacob Moorman
Director of Operations, SourceForge.net
jmoorman@corp.sourceforge.com
moorman@sourceforge.net

**************************************************************************
This email may contain confidential and privileged material for the
sole
use of the intended recipient. Any review or distribution by others is
strictly prohibited. If you are not the intended recipient,
please contact the sender and delete all copies.
***************************************************************************

Wednesday, November 21, 2007

Rip Off Wizards

I suspect that some people think that I wrote MTG Forge to rip off Wizards, although no one has ever mentioned it. I wrote MTG Forge because it is a different, alternative way to play Magic. Speed chess and other variations don’t take away from regular chess, but they enhance it, and let people view the same game in a different way. Hopefully offshoots like speed chess and MTG Forge help people improve their skills.

I also doubt MTG Forge prevents people from buying cards. In a few of my e-mails people actually said that they went out and bought cards that were in my program because they were so fun to play with. Kiki-Jiki, Mirror Breaker was one such example. Personally I buy about one booster pack per set, I’m a big spender (cough, laughter). Although I do like reading Wizards daily articles and adding cards that stand out, like Thoughtseize.

MTG Forge was designed just to play a quick game of Magic against the computer. This was an unfilled niche and MTG Forge is still the “niche leader.” (I love the phrase “niche leader” and you will see that in future articles, lol.) Without waiting for a human opponent the game seems 100% faster. I really enjoy playing a 5 minute game of Magic.

I am very proud that MTG Forge lets users play sealed or draft. Constructing a powerful sealed deck is very fun and a personal favorite. You never know what crazy card pool you will have. I know sealed is considered the lesser, easier brother compared to drafting, but sealed can be very fun it its own right.

Drafting is similar to real life and lets the user encounter common problems such a bad mana curve, too few creatures, or weak color selection. I’ve stumbled upon all three of those problems and some of my draft decks play worse than my sealed ones. (I have probably included cards that are “too good,” like Ancestral Recall, so drafting is probably too easy compared with real card sets like Lorwyn.) My program does not try to compete with paper Magic or Magic Online, but instead lets the user have a different experience.

Friday, November 16, 2007

Programming Magic Cards is Easy

I am currently slowly working on MTG Forge 2.0 and it is difficult of course. I want to be able to program cards that I currently cannot do. With version 2.0 I am rebuilding everything from scratch which means that the old card code won’t work with the new code. Also, my progress is slow because real life gets in the way.

The really hard part about version 2.0 isn’t really just the cards. It already has such great cards like Iridescent Angel, Dark Ritual, Hypnotic Specter, Loxodon Warhammer, and enchantments like Spirit Link. The hard part is all of the other stuff that supports the cards like the user interface, combat, reading and writing files for the deck builder, and handling mouse input.

When adding cards to version 1.0, I only have to think about the card functionality. Does the card have a target? Does the card do something weird? Does it have an effect that ends at end of turn? I can conveniently forget about all the other code except the 100 or so lines that make up a specific card.

After not looking at MTG Forge’s source code for a week or two it is hard to understand everything that is going on. For truly bad source code see InputControl’s getInput method. It is 120 lines long and is hard to read and understand. It selects the next phase like Declare Attackers or the first Main phase.

Thankfully most of my other code isn’t so bad, but it is still hard to for other people to understand. I tried very hard making the Java code for each card readable. The code below is the Mirrodin card Tanglebloom and it is taken from the current version of MTG Forge. You can compare and contrast this article with my previous essay “Programming Magic Cards is Hard.”



//taken from CardFactory.getCard()

//Tanglebloom is an artifact that costs 1 and has an ability “1, tap: You gain 1 life.”
if(cardName.equals("Tanglebloom"))
{
//1 is the mana cost for the ability
final SpellAbility sp = new Ability_Tap(card, "1")
{

//the computer will only play the ability during his second main phase
public boolean canPlayAI()
{
return AllZone.Phase.getPhase().equals(Constant.Phase.Main2);
}

public void resolve()
{
AllZone.GameAction.getPlayerLife(card.getController()).addLife(1);
}

};//SpellAbility

card.addSpellAbility(sp);

//the text that is on the card
sp.setDescription("1, tap: You gain 1 life.");

//the text that is shown when on the stack
sp.setStackDescription("Tanglebloom - " +card.getController() +" gains 1 life.");

//the Input class handles all input
//Input_PayManaCost extends Input and lets the user pay the mana cost
sp.setBeforePayMana(new Input_PayManaCost(sp));

Tuesday, November 13, 2007

Pretty Card Pictures

You know how your friend likes to have all foil lands, well I sort of understand that now. I’ve become obsessed with the prettiest picture of each card. The default picture that Wizard’s provides for some of the old cards like Juzam Djinn and the moxes are pretty bad. They are faded and hard to read. So I fired up my old MicroProse Magic game and took screen captures of a few cards since it displays each card in a clear, large window. Now my virtual Mox Ruby looks better than its 1,000 dollar equivalent.

By default, all the lands are Unhinged, which are very pretty of course. The current pricing guide has them at $1 a piece, so MTG Forge is saving you money right off the bat. Now if I could only find a set of foil, Unhinged lands, I would be very happy.

Foil cards are nice to look at also. I know foil cards do the same thing but they look so darn cool. I used to have a foil Firebolt, until I accidentally erased it. I still have a foil Wonder that I am very proud of and you do to if MTG Forge downloaded your card pictures for you.

When choosing the card pictures that MTG downloads I tried to pick the “prettiest” version of each card. Take Counterspell for example, there are about six versions ranging from Alpha’s frilly 3 finger salute to Seventh’s edition “I can float in mid-air.” The version that MTG downloads is from Mercadian Masques. Most cards don’t have multiple card pictures to choose from but you could still track down a foil or a special rewards version. I’ve changed from being a card collector to an art dealer. Now if I could only track down a foil Serra Angel from 10th :) (I hate reminder text, don’t you?)

Thursday, November 8, 2007

CardFactory - Longest Method

I try to discuss both Magic and computer programming in my blog but sometimes I need to address just the boring, technical side of programming. I’ll try to make it as “user friendly” as possible but feel free to skip this if it gets too technical for you.

Cardfactory.java is one of the key objects in MTG Forge, it makes cards. CardFactory is a huge class weighing in at 423 kb and 14,000 lines (with many blank lines for readability). It is the largest class in MTG Forge and is 10 times bigger than the user interface Gui_Display2.

CardFactory’s intention is just to make cards. The longest method in CardFactory is getCard(String cardName, String owner) which returns a new Card object. This one method is 14,000 lines long, insane I know, but I have never had any trouble with it. Each card is subdivided with brackets, limiting the scope of all variables, much like a method of a class. Look at the code at the end of this article for an example of Wrath of God.

I needed some way of returning a variety of different card objects. I could have cloned objects or used another mechanism. In the new version of MTG Forge, each object is in its own separate class. So the file Wrath_of_God.java holds all of the code for Wrath of God.

I have tried to use many good software practices and design patterns. MTG Forge’s user interface just observes. SpellAbility’s resolve method is abstract, much like the command pattern. All of the mouse input uses the state pattern. The state pattern is crucial and without it I wouldn’t know how to handle the variety of user input that Magic requires. MTG Forge would not exist without the state pattern.

The two most common classes are Card and SpellAbility. The Card class is used like a physical card and exists in your hand, play, graveyard, or library. SpellAbility handles the effect that spells and abilities do when they resolve. SpellAbility has an abstract resolve method where the functionality of a card is programmed. For example the resolve method for Wrath of God would destroy everything. A Card object can hold one or more SpellAbility objects.

A Card object representing Elvish Piper which has an activated ability, will have two SpellAbilities. One will be the normal summon creature spell that puts it into play and the other SpellAbility will represent the activated ability. A Card object representing Wrath of God will only hold one SpellAbility object. Combining the classes for both spells and abilities into one class was a pivotal moment during the development of MTG Forge.

For more information about programming cards for MTG Forge, download the file 10-18-mtgforge-source.zip from sourceforge.net/projects/mtgforge and read compile.htm. To see how Magic cards can be encoded as XML files see sourceforge.net/projects/firemox
God or Damnation

//code snippet from CardFactory.java.getCard(String cardName, String owner)
//mana cost and card text is read from the file “cards.txt”
//a Card object name “card” is created earlier in the method

if(cardName.equals("Wrath of God") cardName.equals("Damnation"))
{
//the Spell class extends SpellAbility and ensures that sorceries
//and instants can only be played at the appropriate times

SpellAbility spell = new Spell(card)
{
public void resolve()
{
CardList all = new CardList();
//AllZone is a global, static class that holds all of the zones
//for each player: play, graveyard, hand, library
all.addAll(AllZone.Human_Play.getCards());
all.addAll(AllZone.Computer_Play.getCards());

for(int i = 0; i < all.size(); i++)
{
Card c = all.get(i);
if(c.isCreature())
AllZone.GameAction.destroyNoRegeneration(c);
//GameAction is a global, static class that does common game activities
//like drawing a card, shuffling library, destroying a creature, etc...
}
}//resolve()

//the computer will only play this card if canPlayAI() returns true
public boolean canPlayAI()
{
CardList human = new CardList(AllZone.Human_Play.getCards());
CardList computer = new CardList(AllZone.Computer_Play.getCards());

human = human.getType("Creature");
computer = computer.getType("Creature");

//the computer will at least destroy 2 more human creatures
return computer.size() < human.size()-1 AllZone.Computer_Life.getLife() < 7;
}//canPlayAI()
};//SpellAbility
card.addSpellAbility(spell);
return card;
}//if Wrath of God or Damnation

Monday, November 5, 2007

MTG Forge Memories

It is amazing how fun a game like Magic can be. I’m sure other trading card games must be a lot of fun, but Magic seems to beat them all. I wish you could play any card as a land, but hey, what’s Magic if you aren’t mana flooded/screwed?

I love some of the moments that happen while playing MTG Forge. Like tonight where the computer totally won the match using Liliana Vess. Usually Vess doesn’t really matter. I can generally hold her off by just discarding a spare land or something, but not this time. The computer kept making me discard and then raised a bunch of creatures from the grave. Thankfully I don’t have to admit defeat a human being. I was only beaten by software.

Sometimes MTG Forge’s AI is just brilliant or crazy or both. Picture this scenario. The computer just played Wrath of God and thankfully I still have a creature or two in my hand that I play. POW, another Wrath comes my way. I’m not sure if the computer is smart or dumb, but it won that game. The computer sometimes surprises me and that is probably as good as the AI gets right now.

I would love to make the computer able to win a tournament, but by that time we will all be living on Mars, well probably. Oh the pains of trying to program both long-term and short-term planning. I would like to make the computer have different personalities. Sometimes it might be really aggressive and other times just passive.

The computer needs to be a little unpredictable just like a real human opponent in order to make the game interesting. Maybe given the same situation the computer will sometimes block and sometimes not block, providing a little bit of tension. It does take a little bit of interest out of the game knowing when the computer will and won’t block. Keep playing MTG Forge and post any stories that you remember.