scope creep

One great thing about writing code professionally is that the person who is paying you to do it also tells you when to stop. One great thing about writing code for yourself is that you can add all of the features! Well, one can try. But enough, the package is not finished, but it’s time I shared what I have created so far. Announcement: WMTools version 0.1 is today released as a toolkit for simulating activations in the game of Warmachine.

For this post I will simply show you how to download the R package. In the next few posts I will show some examples of how code for simulation can be used.

# install devtools for devtools::install_github
install.packages("devtools")
require(devtools)
# install visualTest
install_github("CSJCampbell/WMTools")

For those not familiar with the information sharing phenomenon that is GitHub, it’s an interesting thing. While designed for programming projects, it could be used for any type of collaborative project. The difference between something like this and, say, Wikipedia, is that everyone keeps a copy of the files, so you can revert changes you’ve made on your own machine, as well as contribute to the master repository.

The above code takes the package source from GitHub and installs it in your R installation’s package library. You can now use it.

> blueleader <- list(stats = c(SPD = 5, MAT = 7, RAT = 5),
+         range = list(),
+         melee = list('quake hammer' = list(stats = c(RNG = 2, PAS = 18),
+                 special = c("crit knockdown")),
+             'open fist' = list(stats = c(RNG = 0.5, PAS = 14), special = character(0))))
> # try to shoot with no gun
> activation(blueleader, target = list(stats = c(DEF = 13, ARM = 13, BASE = 30)),
+     strategy = "aim", boost_hit = TRUE, boost_damage = TRUE, foc = 3,
+     dice = c(1, 5, 4, 1, 1, 2))
[1] 0
> # charge in full tilt
> activation(blueleader, target = list(stats = c(DEF = 13, ARM = 13, BASE = 30)),
+     strategy = "charge", boost_hit = TRUE, boost_damage = TRUE, foc = 3,
+     dice = c(1, 5, 4, 1, 1, 2, 5, 5, 2, 6, 3))
[1] 19

The idea of the package is that models in the game are represented as data objects called lists. The functions then operate on them to represent the mechanics of the game. This modularization of the code means that code written to make predictions for the damage output of an Ironclad can also be used to make predictions for the damage output of a Scythean.

What makes this more interesting/fiddly is that most models in the game of Warmachine have special rules. These rules interact at different phases of the game turn, which means that they must manually be inserted into the code if they are going to trigger at the correct moment. I have currently included a small number of special abilities into the package, and will include more as they are needed for simulations.

I can now run all of my tests using a unit testing framework called testthat.

> require(testthat)
> test_package("WMTools")
activation : ....
make an attack : ..........
is attacker engaged : .....................
is scattering shot a hit : ...............
make a melee attack : ...........
make a ranged attack : ..........
take a shot : ...............
utilities : .......

This compact syntax means I can keep track of all components of the code, even if many months elapse! I still have lots to do – but do get in touch if you have any feedback.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s