Wednesday, February 25, 2015

Lining up Octagons in Reassembly

Alright, I feel really, really dense now. I finally started playing Reassembly yesterday. Not sure why I waited this long, after all I had a beta key from the Kickstarter campaign. But that's not why I feel dense. (Well, a little maybe...)

For the first 10 hours or so, I could not for the life of me figure out how to design a ship that holds together well as soon as larger octagonal prefabs are involved. I just couldn't figure out how to line them up properly with the more square geometry of the other prefabs.

Oh how many things I tried. I actually thought I had tried everything in the game! As I was about to send the developer a bug report (well, since I know him, I was just going to whine at him on Facebook) I finally realized why there's one prefab that can be rescaled to odd dimensions like "square root of 2" and such:

Squares and Octagons: Check out the Little Rectangles!

Yep, you guessed it! Those are exactly the sizes you need to fit those darn octagons into a rectangular geometry. Oh how badly I beat up myself after I finally figured it out! I have a degree in Math and Computer Science mind you, and it's painful when you realize that instead of thinking about those dimensions in connection to my problem, I spent 10 hours just shrugging them off as "weird choices" by the developer. They're not weird, they're essential! Alright, but now back to playing the darn game!

Saturday, February 7, 2015

Installing LFS with QEMU

I traditionally start my Operating Systems course with an assignment that requires students to install Linux From Scratch. They need to hand in a disk image of a 32-bit x86 LFS that can be booted with QEMU, but how they go about making that image is up to them.

A common side-effect of this first assignment is that 20% of students drop the course in frustration. The complaint I hear most often is that they "learn nothing" because "it's just a long series of boring instructions and a tiny mistake in an early step can ruin the entire install 4 hours later". And they are correct (with the latter part anyway): That's exactly what this assignment is.

However, I vehemently disagree with the notion that there's no learning taking place here. Patience is a virtue. Persistence is as well. Working carefully should be one. And so on.

A few years ago I pretty much took the stance that if you're not able to do this, you're not going to be a good computer scientist: It's not just about coming up with new and shiny ideas and hacks, it's also about being able to do semi-boring detail-oriented work with lots and lots of care.

Nowadays I can appreciate that some students simply get too frustrated with this kind of work, especially if they also have to deal with unfamiliar tools and are not really sure how to start. So in an effort to help out a little bit, I've put together the following to show students how to get started (and finished!) with their LFS install using nothing but QEMU.

Note that the last time I actually tested these instructions was in February 2015 with QEMU 2.1.2 and LFS 7.6!

First install the current version of QEMU for your operating system, preferably through your package manager.

Then download and decompress the following disk image. It provides a basic install of Arch Linux that can be used to build LFS.

arch-based-lfs-install-i686.img.xz (483 MB)
(md5sum is 7ae93112f07d8662944a0d4ab0b1fa4d)

Note that this is a raw image that expands into a 4 GB file. You can check that everything is alright by starting QEMU and booting the image:

qemu-system-i386 -enable-kvm -m 256 -hda arch-based-lfs-install-i686.img -redir tcp:2222::22

If your host machine doesn't support KVM, things are going to be a lot slower for you; it's in your best interest to use on a host machine that supports KVM. The last option above instructs QEMU to forward port 2222 of the host machine to port 22 of the virtual machine. This is useful because it allows you to use SSH to do your work:

ssh -p 2222 root@localhost

That way you won't have to worry about QEMU's strange behavior when it comes to copying and pasting things, you can just use your regular terminal application.

Login as user root with password lfs and take a look around if you wish. The home directory of root will contain a bunch of LFS-related files from LFS 7.6. If you're working on a later version of LFS, you'll need to get updated copies of those files (as explained in the LFS book itself).

Finally you may want to run pacman -Syu to bring the system up-to-date before you continue. However, performing such an update is not without risks, especially if gcc gets updated to a version that can no longer compile some of the packages your LFS version depends on. So update with care!

Next run the scripts that check if all the required tools are installed and what versions you have compared to what's needed for LFS:

sh version-check.sh
sh library-check.sh

Again, if you are using an LFS version greater than 7.6 you need to get yourself the updated versions of those files. Read through the output of the scripts and carefully compare against the versions listed in the LFS book. If a package is missing, you can (in most cases) install it as follows:

pacman -S whateverpackagename

Once you are sure that you have all the correct tools, use the following command to shut down the virtual machine:

shutdown -h now

You have now confirmed that you have a VM that can be used to install LFS. The next step is to make a separate disk image file for LFS:

qemu-img create lfs-target-disk.img 4G

This will create another 4 GB file that QEMU will use to simulate a second disk attached to the virtual machine. Restart QEMU as follows:

qemu-system-i386 -enable-kvm -m 256 -hda arch-based-lfs-install-i686.img -hdb lfs-target-disk.img -redir tcp:2222::22

Once again QEMU will boot into the Arch Linux installation we'll use to create the LFS system. Login again and then run the command

lsblk

to display the disks attached to QEMU. You should see /dev/sda with two partitions /dev/sda1 and /dev/sda2 as well as a new disk /dev/sdb. The former refers to the Arch Linux image, the latter to the LFS target image we just created. You now need to follow the instructions from the LFS book for creating partitions and filesystems on the LFS disk. I'd suggest that you create two partitions: First create a 3.5 GB partition for the root filesystem, then use the remaining space on /dev/sdb as a swap partition. Incidentily, that's exactly the partition layout I used for the Arch Linux image:

[root@arch4lfs ~]# fdisk -l /dev/sda

Disk /dev/sda: 4 GiB, 4294967296 bytes, 8388608 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x08659cdb

Device     Boot   Start     End Sectors  Size Id Type
/dev/sda1  *       2048 7317503 7315456  3.5G 83 Linux
/dev/sda2       7317504 8388607 1071104  523M 82 Linux swap / Solaris

Don't forget to mark /dev/sdb1 as bootable! Then create an EXT4 filesystem in /dev/sdb1 and a swap partition on /dev/sdb2 following the instructions from the LFS book.

Now you're set to perform the actual LFS install, so we'll skip ahead to the very end (hours later!) when you need to install the GRUB bootloader on /dev/sdb and create /etc/fstab in the LFS root filesystem.

The important thing to realize here is that when you boot your LFS disk image by itself, it will be considered /dev/sda by QEMU! Think about it, that's exactly what's been happening so far with the Arch Linux image. We handed it to QEMU using the -hda command line option, which told QEMU to consider it the first hard disk and boot from it. That's exactly what your LFS disk will be when it boots by itself.

Therefore, while you will install GRUB into the MBR of /dev/sdb as long as the Arch Linux image is /dev/sda, the configuration in /boot/grub.cfg as well as in /etc/fstab must be written with /dev/sda in mind. Proceed accordingly!

When you're done with all of that, follow the LFS book and leave the chroot, unmount all the LFS filesystems, and finally shut down the VM as before. Now you're ready to boot LFS:

qemu-system-i386 -enable-kvm -m 256 -hda lfs-target-disk.img

And there you go! Hopefully the boot process goes smoothly and you're looking at your brand-new LFS login prompt.

Credits: Thanks to Ruben Fiszel for taking Operating Systems as a graduate independent study course this semester, forcing me to double-check how all this LFS stuff really worked.

Sunday, December 21, 2014

Mixing and Matching Classes

I am a B/X D&D kind of guy: I like having four core classes and not much else. So officially that's Cleric, Fighter, Magic-User, and Thief — but actually I tend to call them Cleric, Fighter, Rogue, and Wizard instead. Never mind the details here, let's just say that I like those names better. Of course there are also demi-humans in B/X, but I treat them more like AD&D does: I separate race from class. I actually wrote a thing about that if you're interested. (Before you complain, I do understand why some people like race-as-class but for me it's just not the right fit, at least not for a campaign game.)

Now obviously there are many players with experience in other systems such as AD&D, and some of those players would really like to run a Paladin or a Druid or an Illusionist or whatnot. There are plenty of resources that provide those classes (and many more) as additions for B/X D&D or compatible systems such as Labyrinth Lord. But I still prefer the purity of just four core classes and so I usually negotiate with players like that, granting their characters a "small edge" that goes in the right direction but doesn't mess with the game too much. Dyson's random sub-classes are an excellent example of the kind of thing I tend to do.

Then along comes Zach H of Zenopus Archives fame with a G+ post that gets me thinking. Here's that post:

Idle thought on adding subclasses to whitebox OD&D or Holmes, but without adding any new rules.

Paladin = Fighter/Cleric
Ranger = Fighter/Thief
Monk = Cleric/Thief
Druid = Cleric/MU
Bard = Thief/MU

Subclasses are for humans only (Fighter/MU is still just elves). Use whatever multi-class rules you use for elves.

One can obviously debate whether the suggested "breakdown" for each of these is the best possible one, but the idea of "mixing and matching" the core classes to re-create approximations of other popular classes is genius! And although Zach's "idle thought" is not explicitly targetting B/X it can certainly work there as well, once we add some kind of multi-classing mechanic anyway.

As luck would have it, I already added such a mechanic in support of my take on demi-humans: I am using a variant of archetypal multi-classing! And one of the cool things about that approach is that Fighter/Thief and Thief/Fighter are not the same thing: The secondary class is always at half the level of the primary class, so those combinations feel very different in play.

Applied to Zach's idea this gives us a number of additional possibilities for "mixing" classes together. For example we can interpret Fighter/Thief as "Ranger" or maybe "Scout" whereas Thief/Fighter might be "Thug" or "Assassin" if we squint a little.

But I got my real Christmas present when I tried to figure out the difference between a Fighter/Cleric and a Cleric/Fighter. I agreed with Zach that a Fighter/Cleric should be a "Paladin", but what the heck is a Cleric/Fighter if not also a "Paladin", albeit of a slightly different bent? (Yes, I could make up another name for that combination, but it still seems too redundant.)

What hit me at that point was that the Cleric is already a multi-classed character: Clerics combine "divine spell-casting" with "decent combat-ability" after all! So if there was a class that only focused on the divine stuff, a Priest class say, then I would get a much more sensible result: The Fighter/Priest would be the "Paladin" but the Priest/Fighter would now be the "Cleric," reconstituted from salvaged parts.

Praise be to that glorious redemption from the interwebz!

This little insight fixes so much for me. I've always looked at Paladins with a critical eye, mostly because I felt like the Cleric was already some kind of Paladin to begin with. The "heavily armored guy bashing orcs with a mace while waving a cross" just never really worked for me as something a "run of the mill" religious person should be. So I found it necessary to cast the Cleric as a "militant fanatic" of sorts to make sense of it all and I assumed some "less militant" religious folks in the background as non-player characters: tending to the sick, writing history and philosophy tracts, celebrating "mass" of one sort or another, herding the undead pets of their EHP, etc.

Now I can finally remedy this situation in a framework that makes sense to me. I'll throw out the existing Cleric class and replace it with a Priest class that gets "divine spell-casting" and "turn undead" but nothing else. Priests are of a scholarly bent, sort of like Wizards (or Magic-Users or whatever). Priests get the Wizard's hit die, combat progression, weapon selection, and armor restrictions, but (just for kicks) they keep the old Cleric's saving throws. And of course Priests have to memorize spells from their "prayer books" just like Clerics had to already in my campaign. (This allows me to cut down on Dan's old complaint that Clerics have access to too many spells.) Now if players want to have a priestly character, one that's not also a slaughter-house, they finally can! And if they want to be something with more "oomph" in battle, well, just multi-class the right way and become either a Paladin or a Cleric.

Having said all that, the one thing I am not sure about is whether this added complexity is worth it in the end. Don't get me wrong, I really like this approach. But the old "just give them a special thing" worked as well and in the end it's more flexible since the referee is involved and can "grant" something that's very special and not in the "official" rules.

In any case, I still need to "interpret" all the possible class combinations in a useful way, and I am still having trouble with some of them. Maybe you can help by suggesting something I have not thought of? Here's what I have now:

Fighter / Priest = Paladin
Fighter / Rogue = Scout or Ranger
Fighter / Wizard = Warlock?
Priest / Fighter = Cleric
Priest / Rogue = Monk? Inquisitor?
Priest / Wizard = Druid? Shaman?
Rogue / Fighter = Thug or Assassin
Rogue / Priest = Charlatan? Agitator?
Rogue / Wizard = Bard?
Wizard / Fighter = ?
Wizard / Priest = Thaumaturgist? Theurge?
Wizard / Rogue = Illusionist? Mountebank? Trickster?

And with that I am putting my behind on a plane to Germany. Merry Christmas (or whatever it is you celebrate) and a Happy New Year!

Saturday, December 13, 2014

Geeky B/X D&D Love

I am a computer scientist by trade and I used to work a lot on programming languages. Specifically I worked on what (at least a certain community of researchers) calls "modular programming languages," a fancy way of saying "languages designed in the style of Niklaus Wirth" for the most part. Wirth and friends were very active in the 1960s when ALGOL 60 was "en vogue" as the "academically respectable" counterpoint to FORTRAN and COBOL, those drooling ogres that were even then teaching us how not to do it.

There's a famous 1973 keynote address entitled "Hints on Programming Language Design" given by Tony Hoare (who I'd consider to be one of those friends of Wirth) which was later published in various places including this technical report. In it, Tony finds a wonderful way of expressing just how much he respected ALGOL 60 and just how terrible he thought many of the more recent languages were. This is what he said:

The more I ponder the principles of language design, and the techniques which put them into practice, the more is my amazement and admiration of ALGOL 60. Here is a language so far ahead of its time, that it was not only an improvement on its predecessors, but also on nearly all its successors.

Now some may think that this is pure arrogance and venom and that it's no wonder that an "old fart" would say it. But it's also a very witty declaration of love for ALGOL 60. As I've been playing around with the various versions of D&D in recent years, I started feeling exactly the same way about B/X. So paraphrasing Tony Hoare, I would like to publicly state the following:

The more I ponder the principles of role-playing game design, and the mechanics which put them into practice, the more is my amazement and admiration of B/X D&D. Here is a role-playing game so clean, so concise, yet so complete, that it was not only an improvement on its predecessors, but also on nearly all its successors.

Of course I am now an "old fart" myself and I am sure many out there will find my (derivative) statement arrogant and venomous in the extreme. But it's also a (somewhat?) witty declaration of love for B/X D&D. One that I can only hope will inspire a few of you who have never looked at B/X before to actually take a peek. It's well worth it.

Thursday, December 11, 2014

Riffing on 2d6: Turning Undead

Alright, time to look at another classic application of 2d6, the "Turn Undead" mechanic. Unlike reaction rolls where the range a roll falls into matters, turning the undead requires beating a target number that depends on the level of the cleric as well as (the hit dice of) the undead creature to be turned. Traditionally the numbers 7, 9, and 11 have to be beat. Here's (part of) the relevant table from OD&D (Vol 1, page 22):

Cleric
Level
Skeleton
(1/2 HD)
Zombie
(1 HD)
Ghoul
(2 HD)
Wight
(3 HD)
17911N
2T7911
3TT79
4DTT7

Entries marked "N" cannot be turned at all, those marked "T" or "D" are automatically turned or destroyed. The chances of getting at least the required target number on a straight 2d6 roll are as follows:

2d6Percentage
758.33%
927.78%
118.33%

If we compare cleric level against undead hit dice, this means that clerics have a fairly small chance, less than a third in fact, for turning creatures of power equal to themselves. But at least that's a nice pattern: The entire table uses 9 for creatures equal to the cleric's level in hit dice. So we may not like the low chance of success, but at least the mechanic is consistent (for the most part anyway, vampires ruin it a bit with their variable hit dice).

In Holmes D&D (page 12) and B/X D&D (page X5) we find the exact same table but with a small twist: Some undead creatures get different hit dice. Holmes keeps skeletons at 1/2 HD but changes zombies to 2 HD, B/X also changes skeletons to 1 HD. Curiously ghouls and wights remain at 2 HD and 3 HD respectively thus ruining the pattern that governed the table in OD&D.

Let's briefly look at AD&D in this regard (Dungeon Master's Guide, page 75). The hit dice are as in B/X D&D but the mechanic is now a d20 roll against a target number. Also clerics can affect undead creatures a lot more powerful than themselves:

Cleric
Level
Skeleton
(1 HD)
Zombie
(2 HD)
Ghoul
(2 HD)
Shadow
(3+3 HD)
Wight
(4+3 HD)
Ghast
(4 HD)
Wraith
(5+3 HD)
Mummy
(6+3 HD)
11013161920NNN
271013161920NN
3471013161920N
4TT4710131620

Obviously nothing of the formerly elegant mechanic is left at this point: We have ghasts, monsters with fewer hit dice than wights that are nevertheless harder to turn, we have target numbers missing (no 19 at level 4 for instance), we suddenly jump to "T" for two monsters at level 4 (presumably because shadows got inserted into the table), etc. Gary, what were you thinking? And what about the chances of success?

1d20Percentage
485%
770%
1055%
1340%
1625%
1910%
205%

So for level 1 clerics it got a little harder to turn skeletons, but turning zombies and ghouls actually became quite a bit easier. And now they even have a shot at turning shadows and wights! I guess the question is whether they should have a chance to turn undead creatures more than four times as powerful as they are? But that gets us too far off track, after all we want to study the 2d6 mechanic, not get bogged down in the thankless task of fixing AD&D.

One thing the AD&D version points to is that there probably should be more levels of difficulty. In the original 2d6 version we go from a 58% chance for turning directly to a 100% chance, a level of progress unheard of in other areas (combat or thieves' skills for example). And of course there are plenty of possible target numbers:

2d6Percentage
2100%
397.22%
491.67%
583.33%
672.22%
758.33%
841.67%
927.78%
1016.67%
118.33%
122.78%

What sticks out, because they fit with the existing "7, 9, 11" pattern, are the target numbers "5" and "3" that could precede a "T" result thus extending the table. And that's exactly what Labyrinth Lord does (page 9):

Cleric
Level
1 HD2 HD3 HD4 HD5 HD
17911NN
257911N
3357911
4T3579

Note also that the table no longer lists specific undead creatures, probably just as much of an improvement as the wider range of target numbers. We now get the following chances for successfully turning undead:

2d6Percentage
397.22%
583.33%
758.33%
927.78%
118.33%

Some may complain that the additional target numbers "nerf" the cleric too much, but I disagree. Modifying the table this way brings it closer to the more gradual progressions exhibited by other mechanics such as combat and thieves' skills. It's also fun to roll knowing that one is 97% likely to succeed, dare I say more fun than being 100% likely without a roll? What it doesn't do, however, is usefully approximate the AD&D chances for turning:

2d6Percentaged20Percentage
397.22%--
583.33%485%
758.33%1055%
927.78%1625%
118.33%205%

There are lots of gaps (for 2, 7, 13, and 19 on d20) that make mapping the AD&D table back to the 2d6 table too much of a hassle. Of course I am not even sure why we'd want to do that, but I had to point it out anyway because it was possible after all to get a decent approximation in the case of reaction rolls.

Yet another wonderful variation on the 2d6 table comes from Dyson Logos. He uses the notation "x/y" to indicate that on "x" or higher the undead are turned but on "y" or higher they are destroyed instead:

Cleric
Level
1 HD2 HD3 HD4 HD5 HD
1911NNN
27911NN
35/117911N
43/95/117911
5T/73/95/1179

In this way, not only are the chances for turning "smoothed out" compared to B/X, but the same is true for the chances of destroying the undead. Note that unlike Labyrinth Lord itself, Dyson consistently assigns 9 as a target number for undead creatures with the same number of hit dice as the cleric has levels. This is actually what OD&D did (see above) but the "B/X shift" for skeletons and zombies makes it seem like clerics in his campaign have it harder than clerics in regular Labyrinth Lord or B/X games. Fixing the table to bring it in line with those percentages is easy enough though:

Cleric
Level
1 HD2 HD3 HD4 HD5 HD
17911NN
25/117911N
33/95/117911
4T/73/95/1179
5T/5T/73/95/117

And there you have it, the 2d6-driven table for turning or destroying undead creatures that I would most likely use in the future. But now it seems like I spent a whole lot of time specifically on turning undead and not on 2d6. Or did I? What do we have "encoded" in that last table? It's a task that depending on the level of a character has different chances of succeeding. And actually, it can succeed "normally" and "perfectly" if we include turning and destroying undead creatures. Does that smell a little bit like a possible skill mechanic? :-)

Monday, December 8, 2014

Read Dyson! Now what about other blogs?

I spent the last three days reading the entirety of Dyson's Dodecahedron and I have to say it was worth it. I was about to load one of his maps into GIMP, slap "I read all of Dyson but I didn't even get a cookie!" over it and include it with this post, but frankly I am too tired now.

What got me started initially was simply trying to get my grubby little fingers on every single map he has posted, but then I found so many other fun things to read. Take, for example, his extended play report for The Temple of Illhan. I really wish he had been able to actually write the module with his then-DM, it sounds like so much fun! Or check out his design notes on the various levels of Dyson's Delve, quite inspirational for the dungeon stocker in me. Then there are the random tables covering everything from polearms to lost cities, all thoroughly enjoyable and most even useful.

So aside from singing Dyson's praises, why make a post about this? Well, now I wonder what I've been missing on other "famous" D&D-type blogs. Should I go ahead and schedule a few weeks to read all of Joe Bloch, Robert Conley, and Wayne Rossi? I probably won't get cookies from them either, will I? But what if I don't read them now and they disappear next month? If we're lucky the WayBack Machine has them archived forever in the way we got lucky with philotomy.com. But who's to say? I guess I am getting old and weird, worrying about preserving the collective genius out there. Does anyone else worry about the same thing?

Anyway, I am off to buy myself a cookie now...

Sunday, December 7, 2014

Hit points over time in B/X

I read a claim somewhere that high-level thieves are formidable warriors in B/X and I almost back-stabbed myself for not noticing this before. Then again I rarely play at high levels so at least I have that excuse. At level 3, thieves are still just as wimpy as magic-users of course (details):

Average hit points at level 3.

An average of 7.5 versus the fighter's 13.5 hit points? Hardly a threat to anything but a lone kobold... Things get a bit more interesting at level 14 as the differences between the various classes become more pronounced (details):

Average hit points at level 14.

The thief has now moved past the halfling and the magic-user and is closing in on the elf. Of course an average of 32.5 versus the fighter's 50.5 is still not going to promote the thief into the front ranks. By the time we reach level 25, however, all of that changes (details):

Average hit points at level 25.

Now the thief is second only to the fighter having passed all the other characters on average. Only lucky dwarves could conceivably have more hit points than the thief now. This situation only solidifies by the time we get to level 36 of course (details):

Average hit points at level 36.

At this point the role of the "backup fighter" has clearly shifted from the cleric to the thief, as long as we ignore armor class anyway. So thieves, while starting out at the bottom of the hit point food chain end up close to the top of it. I found that surprising enough to put together a post with lots of nice graphs for you.

Addendum: Just for kicks, how does B/X compare to AD&D for the core classes? Not surprisingly, AD&D characters at level 20 are quite a bit more hardy than B/X characters (details):

Average hit points at level 20 in B/X and AD&D.

The B/X fighter lines up perfectly with the AD&D cleric and the B/X thief is way behind the AD&D thief. Even the AD&D magic-user, getting to roll until level 11, is slightly more beefy than the B/X magic-user.