Page 1 of 2

Adding cards...

PostPosted: 19 Sep 2008, 22:25
by DennisBergkamp
I've been looking at the source of CardFactory.java, tried adding a few cards.
Mostly just cards that already have already programmed game mechanics (such as "Exclude", I just blatantly copied Forge's original code for "Remove Soul" and added some "person that played this card draws a card" code).

Now, I want to add some more cards, I'm just getting my hands dirty and getting used to things...
I was thinking of adding some multicolored cards (recoil, undermine, absorb, ... should be easy right? ) ... but I couldn't find any multicolored cards in CardFactory.java. Are they located somewhere else ? Also, are there additional difficulties with programming multicolored cards?

Or are they so generic, that they can be completely generated from cards.txt?

Thanks :)

Re: Adding cards...

PostPosted: 20 Sep 2008, 03:37
by jpb
There may be something special about multi colored cards in that currently cards are determined to be black, blue, colorless, green, or red. You might need to change the logic of this to add more types to classify the different multi color cards. The cards you listed are not simple enough to just be contained in Cards.txt, so they will require an entry in CardFactory.java. I think Undermine and Absorb would be excellent cards to start on. They shouldn't be too difficult, however I wouldn't bother with the AI unless you are up to a challenge. Currently the AI does not know how to use counter spells. If you figure this out please add the AI to each of the counter spell cards out there. Recoil won't be too difficult besides again, the AI needs to determine which card to discard. There might be an example of this though, I am not sure of the top of my head.

Re: Adding cards...

PostPosted: 20 Sep 2008, 06:49
by DennisBergkamp
Thanks for the reply! Now I understand how it works, cards.txt allows very generic ("vanilla") cards to be added, more complicated cards also require CardFactory.
As for undermine, absorb, recoil, etc. I've already added them in CardFactory, just haven't compiled / tested anything yet so I have no idea if any of my additions work :)

And yes, I noticed there was no AI code implemented yet for any counterspells... maybe I'll take a look at it, but it sounds like it' could be way out of my league.

Re: Adding cards...

PostPosted: 20 Sep 2008, 07:11
by GandoTheBard
The main problem is that counterspells indicate several layers of thinking. 1) what mana to leave untapped if at all. 2) what cards are ok to let through. 3) do anything on opponents turn... the AI seems to be unable to do this even for the most simple of interactions except when it comes to blocks. If you solve all three problems you can implement AI Counterspell logic.

Re: Adding cards...

PostPosted: 20 Sep 2008, 19:23
by jpb
Absolute first step of implementing counterspells is to have MTG Forge iterate through the computers hand whenever the human plays a spell and check if canPlayAI returns true and if the card is an instant. After that is done then worry later about the saving mana and card management AI portions.

You can post your card additions here and I can test them out for you.

Re: Adding cards...

PostPosted: 20 Sep 2008, 23:08
by DennisBergkamp
Hmm, yeah I'm having problems compiling stuff... which version of the Java SDK do I have to use?

Alright, here's a really easy one: Exclude. (Hope I didn't mess up on this one :D )

in CardFactory.java:

//*************** START *********** START **************************
if(cardName.equals("Exclude"))
{
SpellAbility spell = new Spell(card)
{
public void resolve()
{
SpellAbility sa = AllZone.Stack.pop();
AllZone.GameAction.moveToGraveyard(sa.getSourceCard());
AllZone.GameAction.drawCard(card.getController());
}
public boolean canPlay()
{
if(AllZone.Stack.size() == 0)
return false;

//see if spell is on stack and that opponent played it
String opponent = AllZone.GameAction.getOpponent(card.getController());
SpellAbility sa = AllZone.Stack.peek();

//is spell?, did opponent play it?, is this a creature spell?
return sa.isSpell() &&
opponent.equals(sa.getSourceCard().getController()) &&
sa.getSourceCard().getType().contains("Creature");
}//canPlay()
};
card.clearSpellAbility();
card.addSpellAbility(spell);
}//*************** END ************ END **************************


in cards.txt:

Exclude
2 U
Instant
Counter target creature spell. Draw a Card.

in card-pictures.txt:
exclude.jpg http://resources.wizards.com/Magic/Card ... d22986.jpg

Re: Adding cards...

PostPosted: 21 Sep 2008, 02:39
by jpb
The card works, however the AI in this card is unused currently since this code is not evaluated when the human puts a spell on the stack. You will need to make MTG Forge able to do a counterspell before adding AI to this card will do any good.

One change before making this AI work would be to check for nulls. If MTG Forge would evaluate this code during the combat phase there might not be a spell on the stack and it would produce a NPE.

Re: Adding cards...

PostPosted: 21 Sep 2008, 04:35
by DennisBergkamp
Yeah I know there's no AI code for it yet...

Anyway, I'm still having trouble compiling, what version of Java are you using?

Re: Adding cards...

PostPosted: 21 Sep 2008, 04:58
by jpb
1.5

Re: Adding cards...

PostPosted: 21 Sep 2008, 17:54
by DennisBergkamp
Weird, it's giving me all sorts of errors using 1.5.0_16, and this is with the untouched source. Mostly, "cannot find symbol". #-o
I'll download eclipse and try it with that.

Re: Adding cards...

PostPosted: 21 Sep 2008, 20:06
by GandoTheBard
Sounds like you are missing a library...perhaps the fonts library for magic symbols?

Re: Adding cards...

PostPosted: 22 Sep 2008, 15:44
by Rob Cashwalker
Forge has a private version which he was able to allow the computer to play counterspell on your turn. There's a great fundamental difference in the two versions, and he told me that it's not stable. We'll just have to wait until v2 for that.

Compiling has also been a challenge for me - I found a copy of JBuilder 2006. Forge uses some older version of it. But my version complains about some GUI objects being depracated, but when I change them to the "current" objects, their screen dimensions don't work. I've coded a hundred cards and a couple hundred french-vanilla cards.txt ones, but I always have to submit them to Forge to be compiled.

Symbol errors are more likely that there's an object reference that the compiler can't figure out, either mis-spelled, mis-capitalized, the .java file for the object is missing, or one of the methods in it is missing.

Re: Adding cards...

PostPosted: 22 Sep 2008, 16:57
by DennisBergkamp
Very strange, I've tried Java 1.4, 1.5 and the latest one... still no luck #-o
It's too bad, I wanted to try and code some of the trickier cards... jpb, do you compile through a command line interface, or do you use a special program (such as Eclipse, JBuilder, etc.) ?

Re: Adding cards...

PostPosted: 22 Sep 2008, 18:17
by jpb
I use eclipse. Everything compiled fine under 1.5. When you do get everything to compile execute the Gui_NewGame class to start a game.

Re: Adding cards...

PostPosted: 22 Sep 2008, 18:50
by DennisBergkamp
Ahhhh!!! I FINALLY managed to compile!!! I got the previous (8/27) version of MTGForge instead, and this time, no problems. Eclipse does it just fine, also in 1.6 :D
The new source is definitely broken, unless I'm doing something wrong.