Thursday, March 27, 2008

Over Engineering

Starting a new software project is hard. First, you hope that your project gets to a finished state. Second, you have to decide on the technology. Java or Python? OpenGL or SDL? (Don’t worry if you don’t know what those acronyms mean, I don’t. All I know is that they are graphic libraries.) And finally, you have to make a ton of hard software design choices about the architecture that will haunt you throughout the development cycle.

The last choice is where I am struggling right now. I can’t see the whole project in my head. I’m trying to be agile and only program what I immediately need. MTG Forge 1.0 did help me see many aspects of the overall design that I did well and those that need improvement. MTG Forge was written before planeswalkers but it was flexible enough to incorporate them. (Although the program presumes your opponent will only have one planeswalker in play.) The file “cards.txt” was extremely useful for adding creatures with keywords like flying and haste. The “Generate Deck” option was a great success and I hardly ever use the deck editor any more. If I want to exercise my deck building skills I use the sealed deck option.

It is dangerous to talk about one’s weaknesses, since they usually outnumber the positive, but I’ll give it a shot anyways. People’s number one complaint about MTG Forge was the user interface and I understand where people are coming from. Personally MTG Forge’s biggest weakness was my cut-and-paste mentality when it came to programming cards. The amount of redundant card code is enormous. I plan to use the Factory pattern in order to centralize code like “choosing a target player” and “dealing damage to a creature.” In the back of my mind are hard cards like Searing Meditation (when you gain life you can pay 2 and deal 2 damage to a creature or player). Cards like that can only be programmed if all of the gain life code is in one place. (A better solution might be to observe a change in your life points instead of adding Searing Mediation to the life gain code.)

So what does all of this have to do with over engineering? Well you try to make really, really good design decisions in the beginning, so you don’t regret it later. I may never actually program Searing Meditation, but I want that level of flexibility. The best way to keep things flexible is to make each component only dependent on itself. The main parts of MTG Forge 2.0 will be Card (all card code will be handled here and could be used in other Magic projects), GUI (the user interface will be totally separate), Input (it handles all of the mouse actions like choosing targets), and the Engine (does things like lets a user draw a card, determines the winner or loser, and checks for creature damage).

I’m going to tell on myself, but my worst offense is probably global variables. They keep track of all player zones and life totals. (Everything that begins with AllZone is a global variable.) They are also cause MTG Forge to get slow after a few games since the stack of all the method calls keeps getting longer and longer. The Engine part of MTG Forge will replace the need for any global variables.

Hopefully I haven’t been too long. –Forge

8 comments:

Nanocore said...

Welcome to the life of a software developer. This is one of the things that I like the most. There is always an opportunity for improvement, learning and then refactoring. To use the cliche, "Experience is your best teacher". You are starting to see the importance of planning for a release, being reasonable for what to expect and be happy with attaining that goal. Then start the cycle over again, taking what you learned from previous cycles and rethink patterns and reach out for input . There is always someone out there that has more experience/knowledge in an area that might be able to be applied.

Silly Freak said...

Yeah, I also started a project. I try to hold all functionality compact so that the cards don't have to interact. I'm not very far. My goal is to play a land ;)
I also have started a blog (magicjavathoughts). Hope you'll like it.

Anonymous said...

While you are working on your new project, do you intend to release additional contents for your old one? If not, do you know a place where users could upload their? Sourceforge mtg forge seems to be still bugged...

Anonymous said...

Hey there!

I downloaded MTG Forge just a few days ago. I really like it.

Here's a situation you maybe haven't heard before: I'm an old man, never played Magic before, and am trying to learn. My wife bought be some cards, but I don't know anyone who plays. I read the rule book (which is actually a bit confusing, or at least intimidating) and such, but have had to read other material/watch YouTube videos/play your game in order to triangulate something like an understanding of the way to play this game. (Probably, it would just be easier to find someone to teach me, but I'm not terribly social, and I like a challenge).

Anyway, I sometimes find that I'm confused about what step of the game is currently unfolding. I read the little cues in the upper left hand corner of the screen, but they are sometimes ambiguous between whether I should be playing or whether the computer is playing (and sometimes they're not ambiguous, but specifically state whether it is the human or the computer that is taking a turn).

I'm sure that a seasoned Magic player gets what is happening. I'm not sure, however, that I get what is happening. Would it be possible to more clearly state those cues? Or even move the input box up and down from the computer's area to the player's area?

Anyway, as I said, I'm learning a lot from your program, and enjoying my time with it. Thanks for doing your work, and letting the rest of us benefit from it.

PsudoBuddha said...

dont feel bad about having trouble. if you knew how many hours, days, weeks i have dedicated to coding a efficient way to play magic, you would scream. in the past five years, ive probably started 8 different projects to implement any tcg (magic, yugioh ( yes, i am a looser;-) ) and quit before i had a single window of interface ( or button ). ive even reduced myself to vb2008 0.0

Forge said...

Thanks for all your comments. The more comments, the more that I know that I am "connecting" with my audience. :) :)

Hey Jeff, its ok to be old. I'm not a spring chicken any more. The best way to learn Magic is to download the offical Windows demo

"I read the little cues in the upper left hand corner of the screen, but they are sometimes ambiguous between whether I should be playing or whether the computer is playing (and sometimes they're not ambiguous, but specifically state whether it is the human or the computer that is taking a turn)."

Well you can only play a card when you are supposed to. Magic has a ton of phases but MTG Forge only has Main1, Attack, Block, after Block, Combat Damage, Main2.
Basically just play your land any cards during you Main1 or Main2 turns, and attack with your creatures (your creatures can attack on your NEXT turn). Later when you get better you will play Instants during "after Block" and the Combat Damage.

Forge said...

"Welcome to the life of a software developer"

Well I still love programming, I just hate making a bad decision in the beginning and having to live with it, or worse yet, starting over. I know how hard version 1 was, and version 2 seems too hard, lol.

Forge said...

"While you are working on your new project, do you intend to release additional contents for your old one?"

I add cards to MTG Forge very randomly. I probably won't add any, or just a few, since I am working on version 2.0 user interface code.

I never worked out a great place for users to upload code. You have to just e-mail to me, not very high tech I know.

My Sourceforge website CardWarrior2 changes all of the card names and is a little buggy. In case this blog gets shutdown by Wizards, my (buggy) code will live on at Sourceforge. I'm not sure if that makes much sense, but when you have put so much effort into something, you want it to sta around.