I started Forge, which is an open-source, free project that lets you play Magic: The Gathering against the computer. Currently other people are updating Forge and there will be no more posts to this blog.

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.

Ideally, a player should be able to have a chance to act/react 3 times during each phase.At the start, in response to cards or effects played by the opponent and at the end of a phase.Needed phases:-->Untap (no cards/effects can be played here)-->Upkeep (example: using the ability of a card in play to tap a land controled by opponent)-->Draw-->1st main phase-->Combat (as opponent declares attackers, you can react by turning a land like "Forbidding Watchtower" into a land and block with it. Which MTGForge does not allow right now)-->2nd main phase-->End of turn (all effects that last "until end of turn" end here)-->Clean up (No cards can be played here, usually only checks for the "no more than 7 cards in hand" rule I think)

Hi Gabriel, I'm glad that you like reading my blog and hopefully it inspires you and other people to start up their own project, even though it is a ton of work.

First strike is a pain to add since it requires extra phases. I know phases may not seem important, but phases are very crucial when programming Magic. Magic is all about moving carding and advancing to the next phase.

Mr Chaos,

Yes your 3 times per phase mean to me: in response to a spell or ability, or during that phase. But I understand what you are saying.