Wednesday, October 29, 2008

Adding New Cards

MTG Forge and Magic both revolve around cards and more specifically, new cards. Magic is a great game but if the flow of new cards ever stops, most of Magic’s popularity would evaporate. Granted a small army of people would try to keep it alive but trading card games need new cards and so does MTG Forge.

I’m glad people are using these forums and creating new cards. The problem is that you can’t just download a card that someone else makes. A whole new version of MTG Forge has to be released in order to add a new card. (Granted you can add the card code and compile it yourself, but the average use can’t do this.) You can get the latest version of MTG Forge from here. Thanks for jpb for adding all the cards from the forums. It has around 90 new cards. There are still some errors, Will-o-wisp has two regenerate abilities, and not all of the new card pictures are downloaded.

Version 2 all cards should be just text files. So in order to add a new card, you just download the file and put it in the correct directory. Each card will has its own file and the card will be generated when the program first starts up. The cards will be created on the fly, at runtime which is better than hard coded Java cards. Programming Magic cards in Java is confusing and that is why other projects use other language, Firemox uses XML and Incantus uses Python. Next time I’ll show you the code for Royal Assassin from Firemox and Incantus.

Monday, October 27, 2008

The Mighty Rules Engine

One object to rule them all and in the darkness bind them. OK, enough of my Lord of the Rings paraphrase. In MTG Forge version 2 I have an object named “RulesEngine” that holds all rules of a Magic game. All game actions go through the Rules Engine like drawing a card, destroying a creature or advancing to the next phase.

Let me briefly explain what an object is to non-programmers. An object is a group of code that works on the same data. In Magic terms, a Card object would handle all card operations like changing the toughness, adding keywords and getting the card name. The term “class” is also thrown around and for our purposes “class” means the same as object. In Java object names are typically capitalized so that is why I wrote Card object, instead of card object.

Anyways, back to the Rules Engine. Unfortunately the Rules Engine object will be a very complicated and long, since it has to do everything. Currently MTG Forge tries to group many of the rules into GameAction but I did this mostly to save code. All of the rules should be put in one object. In case some rule needs to be fixed or modified, I know where to go, the Rule Engine object.

The cool thing about the rule engine is that it can be easily modified. Do you want to play type 4 with unlimited mana, done. Any rule can be modified. Complicated cards like Mana Flare (each land produces one extra mana) should be fairly simple to implement using the rules engine. I’m also hoping to be able to program one of Magic’s most powerful cards, Time Walk. (1U, Sorcery, take an extra turn after this one.)

I must complete my Lord of the Rings paraphrase. I find this terribly funny. And in case you didn’t get it, the one object to rule them all is the Rules Engine.

One object to rule them all, One object to find them,
One object to bring them all and in the darkness bind them

Wednesday, October 22, 2008

Phase Stops

Letting the user select which phases stop, so a card or ability can be played, is trickier than it seems. Programming phase stops is actually pretty hard because it is easy to get it wrong. I thought I was done with the phase stop code in version 2, but after testing it, the code didn’t quite work correctly. The good news is that I’ve written new code and version 2 has all the phases and the phase stops work.

The original phase stop code comes from a previous attempt at version 2 that I was working on a year ago and it had three buttons: OK, Cancel, and Reset. Each button is supposed to be very simple but they didn’t work correctly. The OK button saves your choices. The Cancel button doesn’t save your choices but it still has to reset graphic checkbox components that show you which checkboxes are selected. And the Reset button stops only during your two Main phases. (The program always lets you declare your attackers and blockers, you cannot accidentally skip those phases.)

So the phase stop code works and hopefully I won’t have to update it for a long awhile. Version 2 just cycles through the phases but this is an important step. This means that the Phase object is correctly going to the next phase, which seems minor but it is very important.

In MTG Forge, the reason that the computer can’t be the first player is because there is a problem with the phase cycle. I accidentally forgot to test if the computer could go first. In conclusion, phases and phase stops are hard to code but very important.

p.s. What are the default phase stops for Magic Online?

This is how the phase stop menu looks in version 2.

Monday, October 20, 2008

MTG Forge - Minor Update

I uploaded a new version of MTG Forge but it is only a minor update. I think the only thing I added to the beta version were the 10 duel lands. Currently there is just a zip file but I will have the typical Windows installer uploaded by Tuesday. MTG Forge now has 870 cards.

This update has the complete source code and I updated the readme-compile.html file. I tested the source code twice and everything compiles like it should. MTG Forge will only compile with Java 1.4.

Remember to keep a copy of the file "all-decks2" because that holds all of the decks that you have created. If you still have the file “all-decks”, it is old and can be deleted.

MTG Forge comes with a “Quick Start” guide that answers common questions like how to target a player (click on the player’s life points) and how to download the card pictures (just look in the New Game menu). Just for fun I included an article written by Magic’s creator Richard Garfield that explains how he created the game and the early years in Magic History.html. You can read it here.

Download MTG Forge – includes Windows exe and Java jar for all operating systems as well as the source code

p.s. If somehow you are reading this article and you don’t know how to play Magic: The Gathering, download this demo and have some fun.

Windows Demo (85 MB)

Wednesday, October 15, 2008

More Plaintext Cards

Version 2 is progressing nicely and I although I haven’t gotten to the point of actually programming cards yet I have a set of 10 cards that I am refining on paper. I’m going to only show you 4 of those cards because I don’t want to bore you.

Writing cards in this format is easy and even nonprogrammers should be able to add a card or two. All the cards will be in one directory and each card will be in a separate file. So if someone else writes a card, all you have to do is download the file and put it in your card directory.

It seems like I could write a simple Card Maker application that would check your card text for errors and would allow you to choose the target and resolve from a list of all available choices, without making you cut-and-paste. The card format below won’t work for all Magic cards but it will work for most of them.

p.s. I put extra information at the end of the resolve text after the comma. You should notice that both Shock and Prodigal Pyromancer share the same targets and resolves, my heart jumps with happiness, code reuse is good.


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

Prodigal Pyromancer
2 R
Creature Human Wizard

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

Venerable Monk
2 W
Creature Monk

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

Holy Strength
Enchant Creature

Static Ability
Text: Enchanted creature gets +1/+2.
Effect: enchanted creature gets, +1/+2

Monday, October 13, 2008

AI and Limited Decks

While constructed decks are very focused, limited decks are not. Limited decks tend to be composed of good cards with a general theme. Limited decks tend to be more generalized because they rely on a mix of creatures and spells. The AI is very good at playing creatures since it just plays the biggest one and then attacks with it. I feel that the AI’s attacking and blocking strategy can be greatly improved in version 2.

So if MTG Forge is a limited simulator why does it matter? In case you forgot, the most important cards in limited are the commons, so I plan to program more commons in the future.

Commons are the least complicated cards, thus making them the easiest to program, and I plan to start with the commons of the Shards of Alara. (Everyone loves new cards, even programmers!!!) I’m not saying that I won’t program any uncommons or rares, I’m just saying that I will focus on the commons first.

And to tell you the truth, the effects on the common cards don’t give me nightmares like the rares. Programming one replacement effect is easy enough, but having multiple replacement effects is downright confusing. Most uncommons usually can be added with a little bit more effort. The fact of the matter is that it still takes loads of time and energy to program Magic cards, even the simple ones. If someone ever programs a whole block, bless his weary soul.

Friday, October 10, 2008

Computer Programming Comics

I love computer programming and comic books but those two passions don't usually intersect, but today they do. Recently, Google wrote an Internet browser called Chrome. Instead of using a boring press release to describe Chrome's features, Google decided to use an online comic book. The comic book is very funny, smart and easy to read. Programmers and non-programmers alike will laugh.

Chrome Comic Book

Wednesday, October 8, 2008

What is MTG Forge's Goal?

Recently I kept asking myself this question, “What is the real point of MTG Forge?” Is MTG Forge trying to help people learn more about the rules? (Originally I envisioned MTG Forge as more of an interactive rulebook than a videogame after reading a question someone submitted about Mirrodin’s new equipment subtype. The person totally misunderstood the idea of equipment.) Obviously, one of my goals was to simply play a game of Magic but to what end? Was MTG Forge trying to be a tournament simulator?

In my head I have always thought of MTG Forge as a limited simulator. I believe MTG Forge could really shine in sealed and draft games. MTG Forge will always essentially be a little bit weaker in constructed games since they have very focused decks that execute a specific plan which require playtesting in order use correctly.

The computer AI will not have the luxury of playtesting like a human player and the computer will try to compensate by playing the deck as good as it can but the AI won’t follow deck’s overall game plan. Granted, specific AI’s could be written to play specific decks or types of decks which would improve the AI’s performance.

Join me next time as I continue my discussion of how MTG Forge’s uses limited decks, thank you and good night.

Monday, October 6, 2008

MTG Forge Forum

I’m glad that MTG Forge has its own forum thanks to Slightly Magic. And thanks to some fancy programming, they even have a feature that displays the card text when your mouse is hovering over the card name. For example if you move your mouse cursor over the text “Ancestral Recall” it will show you the text for that card, very cool indeed.

On MTG Forge’s forums you can discuss anything about the program. I have posted a master list of all known bugs and other people have posted bugs also. The deck sub-forum is getting quite popular. The beta version of MTG Forge lets you import or export a deck, so people are posting their decks.

I have posted 2 decks: a Black Vise and an Akroma, Angle of Wrath deck. Posting your own deck creation is pretty fun and I would encourage you to participate. I even asked for a 5 color, 60 card singleton deck and someone posted one for me, thanks Gando. So checkout MTG Forge’s forums and have some fun.

MTG Forge Forum
Slightly Magic Forum

(Slightly Magic holds all the forums and MTG Forge has its own sub-forum, got it?)

p.s. Slightly Magic’s forums also have many other Magic programs like Incantus if you want to read about them. There is also the HQ Project which aims to provide high quality picture scans of all Magic cards in existence, which is quite a task considering there are about 10,000 cards not including promos. It is fun to download all the token pictures and look through them.

Friday, October 3, 2008

OCTGN - Card Playing Software

There seems to be many trading card game projects floating around the Internet. I thought I would have heard about most of the major projects, and maybe I have, but here is another project called OCTGN which lets you play card games against other players over the Internet.

OCTGN supports Magic and major a few other cards games, although the documentation is nonexistent. I presume it does not enforce the rules but I could be wrong, again there is no documentation. It does support Two-Headed Giant would should be some fun, below is a screenshot. You can find more information by searching Google for OCTGN.

Main OCTGN Site

Wednesday, October 1, 2008

Random Thoughts About Version 2

I don’t have anything specific to write about today. I’ve done a lot of work on MTG Forge version 2, mostly “background code” that handles mouse clicks and stuff that is taken for granted. Thankfully the background code doesn’t usually have to be updated, so once it is written, it works.

The user interface for version 2 is working. It looks exactly like the current user interface but it uses abstract interfaces for the visual components (see the previous article). Some of the basic components like how I handle the mouse are the same as version 1, I still use the Input class.

I have all of the dialog boxes working. Dialog boxes are the popup boxes that ask you “Do you want to pay 2 life?” Yes or No. I have dialog boxes that show one card, many cards, just to show a message and one that shows a message with the yes/no button. The dialog boxes are a good example of background code.

I first started on working on MTG Forge version 2 over a year ago but I’ve only worked on it off and on. Over the last few days I’ve worked on it like a madman at 2am, 4am, and 6am. Currently version 2 is 131 KB of code, while version 1 weighs in at a hefty 1,000 KB. You have to keep in mind that version 1 probably should be 50% smaller if all of the redundant code was removed. (I would tell you the number of lines that version 2 has but I would have to write a small program and I’ve kind of burned out at the moment.)

Right now version 2 has working life points, mana pool, and board (the zones your hand and in play). Also the mouse click event works when you click on the life points, mana pool, or a card on the board. The “card detail” window on the right also works.

The next step is to get the user interface to cycle through all of the phases and to allow the user to select which phases to stop. Hopefully after I do that, I can actually program a card or two. I really want to just program cards, all of the background code is just laying the foundation. I’m going to lay a solid foundation so I don’t have to ever touch it again.

p.s. Version 2 will have ALL of Magic’s phases, so you can stop whenever you want to.

p.s. You can check out a visual spoiler of Shard of Alara here. We can all drool over the mega rares, lols.