Games, programming, and Magic: the Gathering. What more could you want?

Better Late Than Never


Well, I was slammed with a flurry of events this last weekend that lingered through Monday that led to me being unable to post. I’ll have to use the autopress feature more often, so that an article will be up whether or not I’m available, especially since this is the second or third time I’ve had this happen to me.
Anyhow, I’ve sort of decided to bite the bullet and started the search for a decent server (just for project hosting). SourceForge + customization is always a possibility, and so is a leased or subleased portion of a server. Aside from that, I haven’t invested much time into it, so I’m not too sure.
Recently, however, I’ve begun learning Java more aggressively and have finished a couple of small projects in it and am nearly done with a mid-sized one. My personal opinion of the language (having learned C# as my first “real” programming language) is that, while far better than C++, it lacks some of the functionality that is innate to C#. Moreover, it’s lack of operator overloading and peculiarities of equality are unintuitive – e.g., it compares addresses in memory rather than the contents thereof. I do think it’s worth knowing, however, especially for cross-platform support – and there is less animosity towards the JRE than towards the .NET Framework.
I do want to do some sort of “graduation” project before I return to Crystal Lotus… maybe I’ll write a mid-sized game with Open GL or make a significant contribution to an existing project. I’m personally inclined towards the latter, because I believe that creating a game architecture from scratch would be unreasonable given my other activities and responsibilities.

Is This the End?


Well, this past week has been rather productive for me, to say the least (The week before that, I just relaxed and had fun). Beyond work, I spent a goodly amount of time researching AI techniques and algorithms, XNA, and generally speaking, anything and everything that I found remotely interesting about game programming.
But… I also did a bit of research on the legality of MtG rules enforcement programs. Medium-length story short, I can’t legally release/advertise/etc one if I live in the US. Were I in Europe, Australia, or Asia, on the other hand, it would be fine, assuming I avoided Wizards of the Coast’s obvious IP like mana symbols or card frames/images. As it is, they could come after me (though it is highly unlikely they would spend the money for lawyers and the like for a mere freeware program as undeveloped as mine). I wish to find a server hosted in a country other than the US before I continue active development, and I’m not sure how long that would take. I am aware that Forge, specifically, took 2 years and a certain degree of notoriety before it received a relatively mild CAD (cease-and-desist), and Magic Set Editor has never been touched with so much as that, but I don’t feel the risk is worth taking.

But… have a link to another WordPress blog. I know the guy who’s writing it; he rather likes talking about AI and theories. He’s promised me he’ll do an article soon on Negamax, Minimax, Aspiration and the like by next week. Check his blog out!

Oops


As many of you well know, it’s ostensibly Winter Break in America – really, it’s a glorified Christmas break. Nonetheless, this holiday time is rather busy, so no updates until the weekend after the next one (in January…). Enjoy your vacations!

It’s Quiet… Too Quiet


’tis true, though, my life’s been rather quiet of late. No worldshaking calamities (besides WikiLeaks, and that’s US shaking… and MineCraft going Beta soon. o_O), but only a bit of quiet coding.

I did promise to show you my experiments with WPF, and so lo and behold!

This has Windows Aero style glass in the background, and a large InkPad over it so that I can scribble freely with my mouse. I would’ve drawn something, but my digital art is, well, programmer art. By the way, all you .NET programmers reading this – don’t make the mistake of trying to have inheritance with WPF forms… it hates them. I forced mine to obey me, but at the cost of precious tens of minutes of my life I’ll never get back.
On that note, winter break is coming here in Washington, and so is more dedicated coding on Crystal Lotus! Until next week…

Snippetz


Well, this weekend has sorta been my relaxation weekend – lots of fiddling with code, experimenting with other programs’ source code, and relaxing… especially since my uncle and cousins were at my place for all of yesterday (read: no work done).
But… I have started planning some of the cool UI design features, and I’m definitely working with WPF. Hopefully by next weekend I’ll have a screenshot or two to post that shows of some of the feature’s I’m trying to implement.

Omniscient Onions


Well, thankfully, all-knowing leeks don’t exist.
But guess what onions have? That’s right – layers! And guess what cards have – layers! But by corollary, aren’t cards omniscient? Technically, no… but yes.

Leaving aside my CardLayer mention, each card has to know about every other card’s state, as well the condition/life totals of players, library, graveyard, exile, and so on. You could say each card has to know the GameState. But since a GameState can change quickly, the GameState is rather one of many GameStates – there is a GameState for each potential future action you could do, such as drawing a card, casting a spell, attacking, or activating a creature’s ability. Essentially, this means that the GameState has to be easily copied and modified, especially so that the AI can use it to predict the results of casting a card or declaring a certain creature as a blocker.

Interesting, right? But not relevant to our knowledgeable vegetables and their thrice-accursed layers! Well, think back to the comprehensive rules… and remember the card Diminish. And its mother, Godhead of Awe. What these two little cards do is override a creature’s power and toughness, making it a 1/1.
But what of Lignify? Well, beyond P/T changing effects, Lignify also deprives creatures of abilities, such as haste or morph.
Now, let’s kick it up a notch. What happens when Lignify enchants a creature – say, Prodigal Pyromancer – and then you cast Godhead of Awe? Well, Pinging Timmy there is a 1/1 just like always… but can’t ping. And it’s all thanks to the magic (pun intended) of layers.
Now, why does this matter for programmers? We can always hack it in! But, really, creating a CardLayer class that does such things as allowing for replacement or modification of stats is VITAL. It makes your code cleaner, easier to read/write, and more compliant with the comprehensive rules.
So, over the past couple of days, I’ve been coding that class.
Each of those accessors – the brunt of the class interface – are two-way get/set, meaning that they are used to both access and modify the layer’s attributes. Aside from that, a simply “Copy” method and a additive operator do the grunt work of the class. The additive operator makes code easy when stacking multiple layered effects, and the Copy operator allows for a card like Lignify to internally store a CardLayer and simple copy it onto each creature it enchants.

Deep breath! You’re done with the article now! Comments, criticism, etc?

Turkeys, Code and Cards


Well, today’s blog entry is all programmer content. Huzzah!

The deck editor, as you’ll recall, has a search function on it that lets you use card names, costs, colors, types, rules text and creator information to find the exact card you were thinking of. With each press of the “Go” button the list of cards grows progressively shorter until you press the “Clear” button. Simple enough, right?

Actually, it was fairly easy. It turns out that since I plan to let users search through any part of a card’s text, I don’t need to implement any algorithms like ShellSort. Instead, I used RegEx – regular expressions – and checked for matches with the pertinent info. However, since MtGColor is an enumeration, I preformed a brute-force query on it to allow the user to search through colors.

The chief other feature differentiating my deck editor from those in Forge or Wagic is the format enforcement. Formats are completely data-driven, so you can go ahead and create your own custom format or block format as you wish. Checking if a deck is format-legal is also rather simple. First, I ensure that the maindeck and sideboard meet the format’s criterion, and then I go through each card in the deck and ensure that it fits within that cards format limit – e.g., banned and restricted cards are supported as easily as Relentless Rats and basic lands.

One minor quirk in my Deck Editor is that the images for cards are downloaded off the internet and then cached onto the hard drive, but it uses the same thread as the actual deck editor GUI. This pause is generally unnoticeable on my laptop, but on occasion takes as long as a second and a half. I did go in and tweak my code to multithread image downloading, but it caused a handful of other bugs. So, unfortunately, you’ll have to bear with a pause or two when first viewing cards.

The final item of note is that I’ve begun working on the rules-enforcement code. I haven’t added in a scripting engine yet; I’m considering Lua at the moment. I also haven’t implemented a GUI, but have plans to develop one in WPF. On a side note, since I’m a Rules Advisor (having passed the test), I’m hoping to make my engine 100% rules compliant for cards after 4th edition (that means no ante or such… or Shahrazad! – which, BTW, means “luck” or “fate” in Hindi). Technically, I should reread the comprehensive rules day by day as I code my engine, but no one has that much time! However, I’ve had a breakthrough about how to code cards that no other engine whose source code I’ve read has effected.

But I’ll be back Sunday night to post about that!

Tag Cloud