Monday, February 14, 2011

Forge 2.0 - The Best Program Never Written

Forge 2 is vaporware. I've probably started it 5 times using Python and Java. I know what to do better (like fixing CardFactory) but it is just a lot of code to write.

CardFactory is the biggest thing I would change. Cutting and pasting code is a horrible practice and the card code could be much easier to read. Cards should be created from plain text like below. Shock and Prodigal Pyromancer could use the same target and resolve code.

Using the same code for instants/sorceries and activated abilities would be a huge leap forward. (Maybe the same code could be used for static abilities, who knows. It depends on the specific implementation.) In retrospect I think I could have used
Object.clone() to create new card objects.

Rules are the biggest challenge (of course). I would use a "big object" to implement all of Magic's rules in one place. While big objects should usually be avoided, in Magic anything can change anything else, so it is best to put everything into one large object.

The advantages I think would be huge. At first the Rules object could be simple. As more cards are added Rules could become more complicated. In order for Rules to work it has to be given all of the information about the game (which card produced which mana, did you play a red spell this turn, etc..) which would be challenging.

Putting all of the rules into one big object sounds bad until you consider the alternative: sticking the rules in a bunch of different, scattered objects which Forge currently does.

Even if Forge 2 only had these code improvements and the AI played the same, I think it could implement 95% of all Magic cards in existence. Also I think that Forge 2 should implement whole sets and not random cards. Implementing random cards is ok but whole sets would be more fun to use.

Theoretically if I got Forge 2 working with just a few cards, like the white cards from M11, I could release it and let other people do the rest. I just need to build Forge 2's skeleton which is easier said than done.

I'm not sure why working on Forge 2 feels so wrong. Maybe I'm happy with version 1 (and letting other people do all of the hard work). Maybe I'm afraid that I'll fail. Maybe I'm afraid that Forge 2 would not live up to my hype because at first, Forge 2 would only have 20 cards and it would not be very fun.

Like any questionable endeavor, I'm not sure that the work that I would put into Forge 2 would pay off.

--mtgares

p.s.

If Forge 2 used plaintext for the cards, people could easily add their own custom cards and even construct whole new sets. Below are just a few sample cards. I'm sure everybody would implement their version of "plaintext Magic cards" differently.

When I showed this before many people commented that the "Text:" field seemed unnecessary and could be generated from the other information. Maybe it could but since Magic is so complicated with more than 15,000 cards, I would rather not guess and just include an extra field. Personally I try to make the parsing code as simple as possible in order to reduce the possibility of bugs.

Shock
R
Instant

Spell
Text: Shock deals 2 damage to target creature or player.
Target: creature or player
Resolve: damage target creature or player: 2


Prodigal Pyromancer
2R
Creature Human Wizard
1/1

Activated Ability
Text: tap: Prodigal Pyromancer deals 1 damage to target creature or player.
Target: creature or player
Cost: tap
Resolve: damage target creature or player: 1


Venerable Monk
2W
Creature Monk
2/2

Triggered Ability
Text: When Venerable Monk comes into play, you gain 2 life.
Trigger: comes into play
Resolve: gain life – you: 2


Holy Strength
W
Enchant Creature
Static Ability
Text: Enchanted creature gets +1/+2.
Effect: enchanted creature gets: +1/+2


Glorious Anthem
1WW
Enchantment

Static Ability
Text: Creatures you control get +1/+1.
Effect: your creatures get: +1/+1

14 comments:

EOL (Eric O LEBIGOT) said...

Glad to see that you're using Python! In fact, I feel that Java is much more verbose and unnecessarily more complicated than Python… Hopefully this will lead to some productive work on Forge 2!

tehdiplomat said...

I feel like Forge is evolved into this system already. Chris H is working on converting as many cards as possible in the CardFactories to just a scriptable form. Easily a majority of the current (SVN) cards 6800+ cards are scripted only.

While I appreciate your effort to want to write Forge 2, I don't know if at this stage of the game with how much architecture has gone into Forge if it would be worth it. It would be hard to convince people to switch over, and splintering the userbase would only confuse people.

-friarsol

Forge said...

EOL - "Glad to see that you're using Python!"

I didn't make myself clear. In the past I've started Forge 2.0 using Python but abandoned it. Forge 2.0 has no working code in any language.

Forge said...

tehdiplomat,

If Forge 2.0 (F2) was ever released it would only have a few cards, 20 or so, to begin with. F2 would probably be confusing to users since it would represent a step backwards.

If F2 was ever released it would be a parallel project to Forge 1.0. Ideally F2 would only implement whole sets, be 100% rules compliment and have a better AI.

Forge said...

I just found this quote,

"It is important not to let the perfect become the enemy of the good." —Greg Hudson, Subversion developer

Which directly applies to my dilemma of Forge 2.

Urikkiru said...

So, I'm a c++ coder with some Qt experience. Recently at work I've done some things in relation to a very simple special purpose script language related to arbitrary in the wild HTML parsing.

Recently I discovered both Wagic and Forge, and got very excited up until the point where I realized that the rules and card implementations were extremely sporadic. Very frustrating to start building a deck from say, the Alara block, and not be able to use key cards.

After reading up and thinking about it, I believe that your desire to re-write Forge into something more rules compliant, and flexible is the right idea. I also like the idea of implementing 'sets' instead of individual cards. If for example you can start with something rather powerful that just implements say one of the more recent core sets, you probably have the tools needed to do more sets.(With the help of the community as you mentioned)

This is a familiar concept to me from writing an engine to allow for scrips for parsing web sites. I truly believe that if I were to put in the work, I could eventually come up with a decent rules engine for Magic.

However, I'm aware that it will be harder than I think it is.(If for no other reason than I haven't ever *tried* to write it before) Also, I believe that you could do it better/faster simply because you have more experience with this area.

For selfish reasons, I encourage you to really embark on it. I'm highly tempted to try my hand at it myself, but would much rather not re-invent the wheel yet again if at all possible.

Also, my imagining is more a replacement for MTGO, with stand alone servers people can run for their friends to play on. AI is nice and all, but I tend to prefer playing against humans.

Michael said...

Instead of plain text for cards, consider using a simple symbolic language that can resolve to plain text, but which the compiler will read in symbolically.

It's easier for the computer to read that, and the simple semantic codes would be easier for a programmer to write/bugfix because they would be more precise than natural language.

Also, your core program could be written in a way that would avoid blatantly ripping off MTG's mechanics. For example, you could use new words to describe your semantics that are different from the words WOTC uses. You could leave it to someone else to write a semantic interpreter that would use WOTC's language to describe your semantic language in plain text.

You could deliver the Forge 2.0 code as one zip file/java archive, and someone else could deliver the code for the cards in a separate file. There could be 1 set of true official MTG cards using Forge 2.0, and someone else could make new cards that are not copies of MTG cards and therefore don't actually violate WOTC's copyright.

The mere existence of the second non-WOTC set of cards, even if few people played it, would likely be considered a "substantial non-infringing use" and therefore Forge 2.0 would not be a copyright violation against WOTC (although the exact copies of MTG cards would be a copyright violation).

I think you would have a much better chance of avoiding a copyright lawsuit, and avoiding WOTC being able to get an injunction against Forge, if you would re-write Forge from scratch in a way that did not include any copyrighted WOTC material, and could be used to play non-WOTC card games (albeit with rules similar to MTG), your actions are less likely to be considered illegal.

This is not legal advice, though--if you want that, you're going to have to pay a lawyer lots of money. I'm not giving that away for free.

Unknown said...

Hey. I've enjoyed forge for quite some time now and I've got to say, a completely new version would be awesome. I have one request though. It would be cool to be able to filter cards by their set. My experiences with magic have usually been more interesting when the decks are, or were, tournament legal. Just a thought.

Jeff said...

There is no reason to start Forge 2. The scripting language in the current version is simple and has incredible flexibility. Full sets will come in due time...nearly 7000 cards are done. I am amazed you don't approve of the abilityfactories being segmented. This makes things so much easier to find. You want to find out everything related to tokens? Head over to AbilityFactory_Token.java. The AI has been vastly improved over the last few weeks thanks to Sol's and others work in this vital area. It now casts spells and uses abilities on your turn. This is a very exciting time to be part of this project.

Forge said...

Forge 1.0 has turned out great and I can't imagine that 2.0 could be much better. A ton of people have improved 1.0 in all areas and having almost 7,000 cards is awesome.

Someday I may work on 2.0 but it will only feature Man vs Machine, no offense to people but sometimes they can be a jerk.

wololo said...

If I were to start a new game, I wouldn't go with Wagic 2, and I think you might have the same kind of feeling.
Forge and Wagic both have
- Big communities
- dedicated devs
- Huge card supports
- thousands of lines of code
- many limitations
- Legal grey-ness

The last one is my major concern. IF I were to spend 3 years of my life on a game, I wouldn't do it in a way that make it an easy target for a company to take down.

You've proven yourself that you could code a MTG engine. In my position, I would now either move on to something new, or keep improving/refactoring the exiting.

as tehdiplomat said, Forge is moving in the good direction, why even start something from scratch rather than leverage the existing code?

@Urikkiru: Both Wagic and Forge support close to 7000 cards, this is not "sporadic", this represents more than 50% of all cards ever created in MTG.
The only non official program that supports more cards than Wagic or Forge is Botarena, which currently has 8000+ cards.
Wagic is always looking for C++ programmers by the way.

Regarding "making something like MTGO", be warned that this is a very dangerous position to be in, from a legal point of view.

Zucan said...

I have toyed around with getting into programming something along MTG. However, the biggest issue I struggle with is doing something else that so many others are already doing. Should I start from scratch or should I jump in on one or more of these existing projects and help them out.

Maybe you should look at other things that can be done surrounding the game? How about separating the game engine from the rest of the program? Can we develop an API so that any GUI front-end can play any engine on the back-end? It would be cool to select player 1 as one game engine and player 2 as another game engine and see how they play against each other!

If you look at the many chess programs and chess engines out there, this is where I think Forge and others should go.

I believe MAGE is the closest to achieving this goal, as it has already broken its play into a client/server model. A game engine API is not quite like that, but close.

Forge said...

@wololo,

"Legal grey-ness

The last one is my major concern. IF I were to spend 3 years of my life on a game, I wouldn't do it in a way that make it an easy target for a company to take down."

Yeah, this is probably one of my biggest factors. Forge was great to work on but the potential take down is a big reason not to work on Forge 2.

"You've proven yourself that you could code a MTG engine. In my position, I would now either move on to something new, or keep improving/refactoring the exiting."

Yeah, I totally agree with this also.

туры в барселоне said...

I think every person ought to read it.