Monday, August 31, 2009

The Computer Doesn't Mulligan and Why It Doesn't Matter - Part 2

Basically the "Stack AI Land" option gives the AI a 5-10% improvement although this is just a guess. You can use this option to make the computer a little harder or easier. If I am playing MTG Forge's quest mode and the computer's decks are too easy I turn this option on and if I am losing more often, I turn it off. You can also do the same thing for sealed and draft.

Specifically the "Stack AI Land" option gives the computer 7 spells and 1 land. The computer then draws lands for the next 3 turns, then a spell, and then 3 more lands (I think). This improves the AI because it gives the computer 7 spells to choose from for the first couple of turns. A future improvement could stack the computer's deck with an optimal mana curve so the AI would always have something to play for each turn.

p.s. When the computer has to discard a card, I coded the AI to just discard a card at random. While this solution isn't perfect, it works "good enough".

Wednesday, August 26, 2009

The Computer Doesn't Mulligan and Why It Doesn't Matter - Part 1

The computer never mulligans. Truthfully I think I could program the computer to mulligan but I didn't think that it would greatly improve the AI.

When a player is deciding whether he should take a mulligan or not many factors flow through his head such as "Do I have the lands that I need to support this hand?", "Is this deck slow or fast?" and "Can I win the game with this hand?". I can't code any of that stuff so the computer would have to follow a few basic rules such as to mulligan if he had only one land.

MTG Forge has an option called "Stack AI Land" which can be turned on or off. When this option is on it stacks the AI's library so that he will draw a few lands to begin with and the rest of the lands are put on the bottom of the deck.

Theoretically this should give the AI a boost in longer games since you would occasionally draw a land while it will be drawing nothing but spells. The "Stack AI Land" option presumes a two color deck, so if the AI is playing a 3, 4, or 5 color deck you should turn this option off.

Monday, August 24, 2009

Incantus - Magic Online Clone

From time to time I try to talk about other Magic programs that you probably haven't heard of and Incantus is one of the best. Incantus is a computer program that lets you play against other people over the Internet and it enforces all of the rules like Magic Online. Incantus has a great user interface that is comparable to the new XBox game. Unlike Magic Online, Incantus does not have a central server so you have to find people to play against although it does have its own IRC Efnet channel #incantus.

Incantus is written in Python and works on Windows, Macintosh, and Linux. And if you really want to get involved you can program new cards or test cards to make sure that they are working correctly, just ask in the forums and they will help you. Incantus also features ALL of the phases and phase stops, unlike my own program MTG Forge. Incantus has more than 5,000 cards. Let me try to put this in perspective, 5,000 cards is INSANE since there are only 10,000 Magic cards ever printed.

Incantus doesn't have a deck editor but you can use Nate's Deck Editor to create decks. Nate's Deck Editor is intended to be used to create any type of deck (constructed, vintage, casual) and includes a listing of all Magic cards. It has a great search feature and can also be used to create decks for Magic Online, Apprentice, or Magic Workstation. Nate's Deck Editor is written in Java and will run on any platform.

And as a side note, Incantus doesn't let you play against the computer. If you want to play against the computer, you have to use MTG Forge.

Windows download
Mac/Linux download
The password to download Incantus is "rare".

Nate's Deck Builder

Here are some notes for using the deck builder to create decks for Incantus.

When using the deckbuilder you select "Custom" and any cards that are not implemented in Incantus will come up highlighted in red (i.e. they are "banned"). There are 5000+ cards supported by Incantus now and this just makes it easier to know which ones are implemented while using the deckbuilder. Also I recommend saving your decks in Apprentice format because that file format is supported by Incantus.

Saturday, August 22, 2009

AI Articles

Here are a few AI articles which could be applied to Magic. The Hoyle program has a set of advisors which help the program learn and act more like a human. Temporal difference is a type of re-enforced learning. The TD-Backgammon program learned to play backgammon just by playing itself over and over again. The program was good enough to compete against world class players.

These articles are very high level which means that are very dense and hard to read. There is some good info in them but you have to take your time.

PDF Articles

Friday, August 21, 2009

Jon Finkel Drafting Article

Someone sent me this article about how Jon Finkel teaches a novice player how to draft in the Alara block. Jon Finkel is one of the best Magic player on the planet. Do you know Shadowmage Infiltrator, well thats his face and his card.

Wednesday, August 19, 2009

Errors Are a Fact of Life

At last count MTG Forge has a total 1,841 cards and a number of errors. I personally know that some cards are more buggy than others because I programmed them. I tried my best to get Empty the Warrens and Reach of Branches working correctly but they are still buggier than Auntie May's blueberry pie in summer (very buggy).

Those two cards should probably be removed from MTG Forge because they don't work well. Other buggy cards have "state effects" (now called state-based actions) like Glorious Anthem, sliver cards, and Wonder which really slow down the game.

MTG Forge has many bugs because we try to add as many new cards as possible. I was very happy to be able to add planeswalkers. Their only flaw is if the computer has two planeswalkers in play, you can only attack one of them. While this is technically a bug, I still think it is acceptable considering how planeswalkers are generally very powerful.

MTG Forge does not have any kind of error reporting mechanism. If you have an error, such as if the program just says, "The computer is thinking" it means that the AI has crashed and the program doesn't know what to do. Ideally it would be good to save this information to a file, so we would exactly know the problem without the person having to explain the whole situation.

Even though MTG Forge can only implement relatively simple Magic cards, I'm still glad that it supports Baneslayer Angel, Akroma Angel of Wrath, first and double strike, exalted, wither, persist, protection, shroud and morph.

Feel free to report any errors to the forums. We have over 80 pages of errors!!! (The 80 pages represents a considerable length of time and hopefully most of the bugs have been fixed.) I heard that someone pumped Chameleon Colossus so much that its power became negative, which happens when a Java variable "overflows".

You can use the computer's activated abilities. I don't consider this a bug and I use it from time to time when the computer has an unfair advantage (aka when I'm losing).

The only "real" error reporting system is that I throw a RuntimeException if something shouldn't happen. Can this value be negative, if it can't, throw an exception. While this isn't perfect, it works "good enough" to allow me to fix the problem.

There is now a small team that works on maintaining MTG Forge, thanks to dennis, rob, and others who have helped.

Monday, August 17, 2009

How Do I Chose Which Cards To Add?

I get asked this question by e-mail and I'm sure many people think the same thing. I have two main criteria for adding new cards. One, can MTG Forge support the card and two, is the card fun and/or powerful?

MTG Forge can only implement straightforward Magic cards and until very recently didn't support creature enchantments or cards that produce more than one mana like Dark Ritual. MTG Forge has a number of cards that are complicated like planeswalkers, Thieving Magpie, and Hypnotic Specter but MTG Forge will probably never support a complicated card like Warp World, which is very powerful but also has some insane edge cases.

I know what kind of cards that MTG Forge can and cannot support but that information is very hard to explain to someone else because there are so many exceptions. MTG Forge can support Hex but cards are usually restricted to only one target. Time Walk cannot be supported because the phase code is very fragile.

I also try to only add cards that are fun or powerful. Maybe someone gets a kick using Eager Cadet but that card is very pathetic and weak. Royal Assassin is a simple card to program but it is extraordinarily powerful. Likewise the code for Wrath of God is very short but it is one of the most influential cards in Magic.

1. MTG Forge can only implement a small subset of all Magic cards.
2. The card needs to be fun and/or powerful.

On a side note, I was sad to see that Wrath of God wasn't included in the new Magic 2010 core set.

MTG Forge now has the all powerful Morphling!!!

Thursday, August 13, 2009

MTG Forge vs. Magic Online

Today I don’t have a hard-hitting, aka boring, programming topic to talk about so instead I’m just going to chat about MTG Forge versus Magic Online. Let me start out by saying that Magic Online is a great piece of software despite all of its flaws and in an odd way it was the inspiration for MTG Forge.

Magic Online is great. It enforces all of the rules and shows beginners what should really happen when you are playing a game of Magic. It never accidentally skips any steps and will only allow you to make legal moves, versus accidents that sometimes happen when playing with friends.

Much of my rules knowledge comes from watching Magic Online enforce every rule to the Nth degree. Back in the day when I was just learning the rules Magic Online taught me that lands were colorless because I couldn’t use them with Mourner’s Shield. (I’m sure many new players make the same mistake that I did.)

Magic Online is great but it has its flaws and personally most of those flaws are people. Yes playing against another person can be very challenging and fun but it can also be frustrating if they disconnect (on purpose) when you are winning. MTG Forge lets you use your most lethal, dangerous decks without annoying your opponent. Do you like land destruction, sure, go nuts. Are you a fan of discard control, go for it.

MTG Forge is not a replacement for Magic Online but is more of a solitaire version of Magic. Magic Online and MTG Forge cannot really be compared against each other because that they have different goals. Magic Online is trying to provide a fun atmosphere where you can spend money and MTG Forge provides hours of enjoyment by playing against the computer.

MTG Forge also lets player experience very powerful and very expensive cards like Land Tax, Wrath of God, Birds of Paradise, Black Lotus, Time Twister, and five of the planeswalkers.

Tuesday, August 11, 2009

Artificial Intelligence - Magic and Chess

Long before people were trying to program the computer to play a decent game of Magic, people were trying to teach it to play a decent game of chess. Computer chess programs are now very advanced and can crush the average player in the privacy of his home. I hope one day to develop a Magic AI capable of crushing most human players. (And then computers will naturally take over the Earth of course.)

According to Wikipedia the first chess program was written in 1958 but the first “credible” program didn’t appear until 1962. In 1967 was the first time that a computer beat a human player in a tournament.

Computer chess has advanced the field of artificial intelligence by producing the alpha-beta program which every chess program uses or a variation of it. Chess programs typically look very far into the future in order to make the correct move and also use a database for openings, plays at the beginning of the game, and endgames.

Even though checkers is relatively simple when compared to Magic and chess, it is still challenging to try to develop a good AI for it. In 2007 the computer program Chinook recently “solved” checkers. According to Chinook’s developers it will never lose a game and if no mistakes are made by either player, the game will always end in a draw.

Personally I’m not sure if Magic is more or less complicated than chess. In chess you seem to have more choices because you can move any of your 16 pieces and usually Magic doesn’t have that many choices. Although in my heart Magic will always be 100 times better than chess.

In 1997 the IBM chess computer Deep Blue did beat the reigning world champion Garry Kasparov but he “claimed that several factors weighed against him in this match. In particular, he was denied access to Deep Blue's recent games, in contrast to the computer's team that could study hundreds of Kasparov's.” “After the loss Kasparov said that he sometimes saw deep intelligence and creativity in the machine's moves, suggesting that during the second game, human chess players, in contravention of the rules, intervened.” [citation]

As I understand it Kasparov agreed to play Deep Blue if he was allowed to view Deep Blue’s game style, but the computer never played in any tournaments so Kasparov was denied and was forced to play against the computer in a shameless publicity stunt. So the IBM team deceitfully denied Kasparov a print out of Deep Blue’s games and might have cheated by allowing human intervention.

In 2003 Kasparov played the computer programs Deep Junior and X3D Fritz which both resulted in a draw. I consider this a victory for both Kasparov and computer chess.

Friday, August 7, 2009

Shandalar Update

Yes you can update your old 1997 PC game Shandalar. The update patch is called ManaLink 2.0 and there are close to 2000 new cards. You have to download a few files so I’ll point you to the installation guide. The forums that wrote the update can be found here.

This update includes Vanguard, Momir Basic, and type 4.

Vanguard is a like a normal duel, except both you and your opponent have one special card that gives extra abilties.

Momir Basic is a type of vanguard where your library has only land and you have a special card that reads: “X, Discard a card: Put a token of a random creature with converted mana cost X into play. Use this ability once per turn when you could play a sorcery.”

Type 4 infinite mana, also known as SPAT has special rules.
--Each player has unlimited mana available.
--Each player can only play 1 spell a turn.
--Before the game begins the deck is distributed between the 2 players.
--It is recommended that you use a singleton deck.

Both Momir Basic and type 4 can be very random but also very fun.

Wednesday, August 5, 2009

Adding ManaPool

I’m glad that MTG Forge now has a mana pool because I accidentally left it out. I know what your thinking, how could a guy forget one of the most important parts of Magic. OK, I still forgot it. Also from time to time I forget what are the 5 magic colors in Magic as well as the names of all 5 basic lands. Yes I remember them, but you wouldn’t believe the number of times that I need to know Plains, Mountain, Island, Forest, Swamp while programming MTG Forge. Even then I almost forgot Swamp.

Let me go back to the beginning. The truth is that MTG Forge had around 50 cards and was not released on the Internet. I was just adding good cards from the 9th Edition when I saw Early Harvest. I thought it would be cool so I easily coded it. The card untaps all of your land so it was very straightforward to program.

Then I put together a small test deck to make sure it worked. After I played Early Harvest reality hit me, THERE WAS NO MANAPOOL. Granted if you had 6 Forests, you could tap 3 to play a card and then the tap the other 3 to play Early Harvest but without a mana pool the card is severely crippled.

So from then on MTG Forge officially didn’t have a mana pool and I didn’t care. Which meant that my program couldn’t support Dark Ritual, Sol Ring, Seething Song or Magic’s most expensive card: Black Lotus. I shrugged a little and told myself that I could at it later if I really had to.

The truth is I didn’t write any of the mana pool code, it was all done by the nice guys on the forums: dennis, rob, and others. By the way I didn’t make a big deal about it but MTG Forge also supports protection, exalted, and shroud. Dennis had to update ALL of the targeting code, which was an enormous task. I didn’t think MTG Forge would ever have protection and shroud because it was such a difficult task.

p.s. Yes I created this card with the program Magic Set Editor.

Monday, August 3, 2009

Mana Pool

I forgot to say that MTG Forge now has a mana pool. Say hello to Black Lotus, Dark Ritual, Sol Ring, and Seething Song. Download this picture and put it in your pics directory.

New Version

I’m happy to announce that the new version of MTG Forge now has 150 new cards for a total of 1841 cards. All of the credit goes to DennisBergkamp, Rob Cashwalker and others from the forums. They have done a terrific job of updating MTG Forge with bug fixes and adding exciting new cards. (You should also note that the title bar has the incorrect date of 05/2009.)

There are a bunch of new M10 cards. The new cards include a bunch of “vanilla” creatures from Magic 2010 like Viashino Spearhunter (2R, 2/1 first strike), Kalonian Behemoth (5GG, 9/9 shroud), Deadly Recluse (1G, 1/2 reach deathtouch), Child of Night (2/1 lifelink). Other M10 cards include Holy Strength, Unholy Strength, Weakness, Brilliant Halo, (Enchanted Creature gets +1/+2, When Brilliant Halo is put into a graveyard from the battlefield, return Brilliant Halo to its owner's hand). Also added are the new M10 “lords” Goblin King, Lord of Atlantis, Elvish Champion, and Elvish Archdruid. More M10 cards include the new land Gargoyle Castle is also included, it can tap for 1 or for 5 be sacrificed for a 3/4 flying Gargoyle.

While new cards are super cool there are a number of Magic players that have some “old favorites” so Whirling Dervish, Putrefy, and the infinite token combo of Squirrel Nest and Earthcraft have all been added.

I can't believe that Serra Angel has been demoted to an uncommon in M10. Baneslayer Angel seems to take Serra’s place as the new flying, angel beatdown card. (Baneslayer Angel was also one of the cards that were added.)

I try to post an updated version of MTG Forge every month. If you want the cutting edge, newest version you can always check out the forums.

p.s. This is the 07/29 version that was posted on the forums.

p.s.s. In the Deck Editor you can move the new cards to the top by selecting "Sort By" then "Newer Cards First". Sometimes a card gets "remade" so it will appear at the top of the list even though a previous version of MTG Forge had that card.

p.s.s.s. AND I just fixed the picture download problem. This was only a problem if you didn't have MTG Forge previously installed. (The problem can be fixed by creating a directory named "pics" in the directory where you unzipped MTG Forge.)