Wezzle Collision Generator
I have a fascination with programming languages. I have been reading up on many different ones trying to get a feel for them all. I enjoy learning about the different syntaxes and what the advantages are of the different paradigms. I find most of the languages offer really interesting concepts and benefits.
Last night I was hacking around with Ruby and decided that to teach myself how to program better I would do something interesting for Wezzle. I had the idea of taking the XML markup for our achievements and making some sort of generator using our achievement pseudo-language.
Our achievement language basically amounts to what is known in computing as a Domain Specific Language (DSL). Luckily for me Ruby is a pretty good language for writing DSL’s.
I decided to start with the achievements that I find to be the hardest to write, COLLISION. A COLLISION occurs between 1 or many items. There are two seperate types of collisions which can be defined as either an AND or an INTO relationship. These can be seen in the following two examples:
Example 1:
<achievement name="A Tale of Two Rockets" difficulty="SILVER"> <description>Fire a rocket into another rocket.</description> <rule type="COLLISION" operation="BETWEEN"> <item type="ROCKET" /> <item type="ROCKET" /> </rule> </achievement>
Example 2:
<achievement name="A Tale of Two Rockets" difficulty="SILVER"> <description>Fire a rocket into another rocket.</description> <rule type="COLLISION" operation="BETWEEN"> <item type="ROCKET" > <item type="ROCKET" /> </item> </rule> </achievement>
While these two examples may look the same, they mean two different things. The first one can be written as COLLISION BETWEEN ROCKET AND ROCKET simply means that two rockets will be activated in a single turn. The second one however would be written like COLLISION BETWEEN ROCKET INTO ROCKET and means a rocket will be fired and activate another rocket by hitting it.
I have written a generator in ruby that takes an achievement (currently only collisions) in the following form:
BEGIN COLLISION
achievement:Rocketeer:BRONZE
description:Fire a rocket into a rocket and fire a rocket and a rocket.
rule:COLLISION BETWEEN ROCKET INTO ROCKET
rule:COLLISION BETWEEN ROCKET AND ROCKET
END
This is currently defined within the program and will output the properly formatted and tabbed XML which you can then paste into your achievements.xml file. The goal is to have it work for all achievements, and I will keep you updated as to the progress should I choose to continue. As it stands, you can find the current version here although it’s a little bit ugly. Please note, you must have ruby 1.9+ in order to run it.