It is currently 23 Apr 2024, 23:20
   
Text Size

Adding cards...

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Adding cards...

Postby DennisBergkamp » 19 Sep 2008, 22:25

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 :)
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby jpb » 20 Sep 2008, 03:37

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.
jpb
 
Posts: 132
Joined: 05 Sep 2008, 13:12
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby DennisBergkamp » 20 Sep 2008, 06:49

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.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby GandoTheBard » 20 Sep 2008, 07:11

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.
visit my personal homepage here: http://outofthebrokensky.com

Listen to my podcast with famed AJ_Impy "Freed from the Real" on http://puremtgo.com
User avatar
GandoTheBard
Tester
 
Posts: 1043
Joined: 06 Sep 2008, 18:43
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby jpb » 20 Sep 2008, 19:23

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.
jpb
 
Posts: 132
Joined: 05 Sep 2008, 13:12
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby DennisBergkamp » 20 Sep 2008, 23:08

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
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby jpb » 21 Sep 2008, 02:39

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.
jpb
 
Posts: 132
Joined: 05 Sep 2008, 13:12
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby DennisBergkamp » 21 Sep 2008, 04:35

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?
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby jpb » 21 Sep 2008, 04:58

1.5
jpb
 
Posts: 132
Joined: 05 Sep 2008, 13:12
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby DennisBergkamp » 21 Sep 2008, 17:54

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.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby GandoTheBard » 21 Sep 2008, 20:06

Sounds like you are missing a library...perhaps the fonts library for magic symbols?
visit my personal homepage here: http://outofthebrokensky.com

Listen to my podcast with famed AJ_Impy "Freed from the Real" on http://puremtgo.com
User avatar
GandoTheBard
Tester
 
Posts: 1043
Joined: 06 Sep 2008, 18:43
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby Rob Cashwalker » 22 Sep 2008, 15:44

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.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Adding cards...

Postby DennisBergkamp » 22 Sep 2008, 16:57

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.) ?
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby jpb » 22 Sep 2008, 18:17

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.
jpb
 
Posts: 132
Joined: 05 Sep 2008, 13:12
Has thanked: 0 time
Been thanked: 0 time

Re: Adding cards...

Postby DennisBergkamp » 22 Sep 2008, 18:50

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.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Next

Return to Forge

Who is online

Users browsing this forum: No registered users and 54 guests


Who is online

In total there are 54 users online :: 0 registered, 0 hidden and 54 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 54 guests

Login Form