Monday, September 27, 2010

Quest Mode: The Beginning

The quest mode is one of best parts of Forge. The idea of starting with a bunch of random cards and carefully building your deck until you become uber-powerful is every guys dream. (Or every girl’s dream. The best way for a beauty to meet a geek is through a card game like Magic.)

The “classic” quest mode was written by me (mtgrares) with comments from the forum. Everybody on the forum loves Forge and has many, many suggestions. The central idea in my mind was trying to code a menu based Shandalar. I can’t really program graphics very well so that restricted me to only using (boring) menus. The idea of choosing from 3 opponents came from one of the Yu-Gi-Oh games for Gameboy Advance. I liked the idea of being able to choose my opponent, even though I don’t usually care. (And yes I did play Yu-Gi-Oh videogames before Magic.)

One of the great things about the quest mode is that is it harder than your average match. Forge’s AI is very basic so the only way to “ramp up the difficulty” is to restrict the player’s cardpool while giving the AI more powerful cards.

While programming the quest mode I wanted to show a player’s progression by something other than the number of wins, so I came up with a “level” name like “Mana Mage”. The last level you can attain is “Serra Angel is your girlfriend” which is a little humorous. (The level names could be changed to something better/funnier, so feel free to make suggestions.)

The classic quest mode was fine but DennisBergkamp expanded on the idea by allowing players to purchase more life (you start with 15) or buy a pet (like a 1/1 wolf or a 0/3 plant). He added a variety of other things to buy such as a card shop, so you can buy individual cards, a free mulligan (you mulligan and get 7 cards but it costs a lot of money) and even “legendary” matches where you can to play against special opponents. Some legendary matches are restricted and you can only play them once. (I feel like a weenie but I haven’t played any legendary matches, I only play short quests for 10 or 15 matches.)

Technically you can choose from easy, medium, hard, or very hard quests but the difficulty only affects the overall length. Easy quests require 10 wins and very hard quests require 40 wins although you can keep playing if you want to (which appeals to some insane people that have 200 wins and 0 losses).

One of the improvements was to divide up the AI decks by difficulty. Currently there are 3 levels of difficulty. At the beginning of your quest, you only play against easy AI decks

Thanks to wololo for suggesting this topic. Be sure to check out his Magic project Wagic.


Friday, September 24, 2010

Scars of Mirrodin

The official visual spoiler for Scars of Mirrodin is here. (I have a special place in my heart for Mirrodin because I started learning Magic during Darksteel, Mirrodin's 3rd set.)

Scars of Mirrodin - Visual Spoiler

Monday, September 20, 2010

Can this creature block that creature?

Combat is essential to Magic (and most card games) and blocking is part of combat.

Forge uses the method CombatUtil.canBlock(Card attacker, Card blocker) to determine if a creature can block. The canBlock() method returns true if the blocker can block and false if it can’t. (All classes ending in “Util” are composed of global, public, static methods and “Util” stands for “utility”.)

In the beginning canBlock() only checked for flying and fear but now the method has grown to 250 lines (including whitespace). You can view the canBlock() method here. Landwalk was one of the first code snippets that was submitted. (Probably by Rob Cashwalker or DennisBergkamp.) I was impressed that landwalk could be implemented and that canBlock() was able to be modified by an outside coder.

While canBlock() is long it isn’t too hard to understand because each code segment does its test and returns false if the blocker cannot block. Each of the “if” code segments are separate and do not interact.

Here are some of the conditions that canBlock() tests for:


Legendary landwalk
Nonbasic landwalk

CARD can block only creatures with flying
CARD can't be blocked by creatures with flying
CARD can't be blocked except by creatures with flying

CARD can't be blocked by white creatures
CARD can't be blocked by Walls

CARD can block creatures with shadow as though they didn't have shadow

CARD can't block creatures with power X or greater
CARD can't block creatures with power X or less

Each of the above conditions is a string (characters that you can see) and each card holds any number of strings (which internally are called keywords). The great thing is that Forge uses the text file cards.txt to create basic creatures that have one or more of the above keywords. Forge can even create instants and activated abilities by using special “scripting” keywords. I plan to talk more about scripting in a week or two. (For more info you can view cards.txt here.)

Here are two examples that don't require any extra Java coding.

no text

Avian Changeling
2 W
Creature Shapeshifter
no text

Live long and prosper,

I wasn't aware of the proliferate keyword. The card picture above is from the set "Duel Decks: Elspeth vs. Tezzeret".

Proliferate means "You choose any number of permanents and/or players with counters on them, then give each another counter of a kind already there."

Thursday, September 16, 2010

What subjects do you want me to write about?

The hardest thing is coming up with the topic which is why I sometimes have the "top 10 cards" because I have no idea what to write about.

Please tell me what kind of things you want to read.


Monday, September 13, 2010

Forge is customizable but poorly documented

The power of Forge is that you can change many things but only if you know the "secret inner workings" that aren't documented very well. Which leads to the next logical question is, "Why don't you write better documentation?" And truthfully I have spent a few hours writing docs but it is hard to understand the changes because Forge is constantly changing.

Someone posted a question on the forum and said that he was tired of always drafting the same cards and wanted to know how to change the draft cardpool (the cards that Forge uses to create the booster packs). Awhile ago I wrote a "set editor" that allows you do that but the problem is that the set editor was created before there was a separate set of files for draft. Yes the set editor can edit the draft cardpool but you have to move the files yourself.

In the lastest version of Forge, each card now has its rarity set in the "cards.txt" file. (Thanks to whoever added the rarity and http picture link for each card.) The good news is that the new rarity includes mythic rares. The bad news is that I don't know how Forge uses this new information.

So while Forge is moving in the right direction beware of the occasional blind turn. (Extending a metaphor is hard work.) Forge is always improving even though it is a work-in-progress.


If you want to change your draft files, unzip this file in your /res/draft/ directory. This way each card has an equal chance of showing up, since all three files have the same cards: common.txt, uncommon.txt, rare.txt.

Forge uses the files common.txt, uncommon.txt and rare.txt to create booster packs. Forge has 3 sets of these files for: sealed deck, quest, and draft. The sealed deck files are in /res/ directory. The quest files are in the /res/quest/ directory and the draft files are in /res/draft/ directory.

When you run the set editor it asks, "Do you want to edit the quest booster files?" which edits the files for quest. If you select no, you are editing the files for sealed deck. So you cannot directly edit the draft cardpool but you can move the files: common.txt, uncommon.txt, and rare.txt to the /res/draft/ directory. (For fun, cut and paste all of the cards into one big file and make 2 copies of that file. Then name all three files: common.txt, uncommon.txt, and rare.txt.)

You can download the set editor here.

Monday, September 6, 2010

Musings on Forge 2 - Less is More

I've been thinking a little about Forge 2. One of the problems when designing the "2nd version" is that you have a tendency to add every little feature that you thought of while doing version 1. This tendency is completely wrong. Less is more. Programming takes time, so you should try to maximize the final result, which means cutting features.

At first I wanted version 2 to have a better user interface (UI). The UI is what every person sees and uses. The UI affects the user's "happiness index", how hard is it to use this program? My decision is that version 2 will have the same UI, so I can work on other features. (Of course the user interface will be separate from the rules engine and could be improved later.)

After saying "no" to the UI, I decided the single most important feature of version 2 would be a smarter, nastier computer opponent. The current AI is basically a knee-jerk reaction and the computer doesn't think ahead. Hopefully in version 2 the computer will think ahead and it will be awesome.

At first the AI will only attack, block, and play cards/abilities during his main phases. This restriction is here because it is realistic. I will encounter many unforeseeable problems while coding an improved but scaled-back AI. After I have the AI working, I can make it more complete and able to respond to spells/abilities on the stack and play abilities/instants during combat.

Programming a Magic AI is hard and for proof here is an excerpt from the Moxdev blog which aims to implement Magic in C#.

[Begin Quote]

!Health Warning!

Attempting to program AIs for MTG can be dangerous to your health. If you suffer from any symptom, stop reading immediately. Symptoms may include

--Extreme fatigue, with insomnia
--Seeing min-max trees in your cereals
--Sudden urge to stop programming forever
--Starting to talk to your AI
--AI programming is not recommended for pregnant women and children under 5.

[End Quote]

That post really made me laugh because coding a good AI can be very frustrating. If you set you expectations too high, you will never get your program up and running (because you will be too exasperated and just quit). The only perfect computer program, is one that never gets written.

The good news is that even if the AI only does basic actions like attacking/blocking/playing cards during his main phases, the AI will be better because it will be thinking ahead. Hopefully the AI should be able to make good decisions like using two Shocks to kill a flying 4/4, something the current AI cannot do.

And don't worry, if I get a few cards working in Forge 2, I will post it (and probably brag on myself). My goal isn't to develop the greatest Magic program in the universe and then keep it a secret.

On a side note, people seem to want the convenience of playing Forge in the browser because you don't have download anything, so I'm keeping that in mind. Forge 2.0 will come in two flavors: browser version and a downloadable, offline version.

See you next Monday,
Same Bat-Time,
Same Bat-Channel