Saturday, November 28, 2015

Two kinds of equality: Thinking about Java's equals method

My planning document for this coming Monday's CS222 class read something like, "Do something with equals/hashcode/toString." I took some time this morning to flesh that out into a real lesson plan, and I came across some interesting tidbits along the way. This started as a Facebook post, but I realized I wanted something more archival, so I've upgraded to the blog.

StackOverflow led me to EqualsVerifier, a recent open-source project to automate testing of the contract between equals and hashcode in Java. It looks interesting, although I have not plumbed into its documented possible false-positives. The same post led me to EqualsTester, which has been part of Guava for quite some time, although I never came across it before. I use Guava in practically every Java project, and so it looks like EqualsTester is going to have to go into my back of tricks. Writing tests for equals is kind of a drag and—in retrospect—clearly automatable, although I never really thought about automating it before, so I never looked for library support.

The most fascinating thing I came across, however, is this 2009 article by Odersky et al., which I understand to be an updated extract from Programming in Scala. The article describes four common pitfalls when writing equality-testing methods in Java, and as they point out, three of the four are covered in Bloch's classic Effective Java. That fourth one, though, hit me hard, forcing me to recognize that I had been conflating two distinct concepts in my Java programs. The first I will call content equality, which is when two objects should be considered equal because they represent the same concept in the problem domain. The second I will awkwardly call JRE equality, because it's the kind of equality that the equals method contract really specifies.

It's easy to illustrate this with an example. Ignoring all other design considerations for a moment, we can create a class like this:

public class Achievement {

    private String name;
    public Achievement(String name) {;
    public void setName(String name) {;

It might be reasonable then to expect a test like this to pass:
    public void testEquals() {
        Achievement a1 = new Achievement("Blogging");
        Achievement a2 = new Achievement("Blogging");

If you've been doing Java for a while, you know this will fail with the default equals() implementation. Let's take the same approach that most of my students tend toward: let Eclipse generate the equals and hashcode methods for us!
public class Achievement {

    private String name;
    public Achievement(String name) {;
    public void setName(String name) {;

    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        return result;

    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Achievement other = (Achievement) obj;
        if (name == null) {
            if ( != null)
                return false;
        } else if (!name.equals(
            return false;
        return true;

OK, now the test passes, so we are happy, right? Well, maybe not. What if we add this test?
    public void testCollectionsIntegration() {
        Set<Achievement> set = new HashSet<>();
        Achievement a = new Achievement("Blogging");

This test fails, because we've hit what Odersky et al. list as Common Equality Pitfall #3: Define equals in terms of mutable fields. By changing the name of the achievement object, we alter its hash code, which means it "disappeared" from the set.

At the surface, it looks like there's no way out: you cannot make both tests pass. This makes it a beautiful error! The problem was never in the code, it's in how we think about the problem. The word "equals" is overloaded, as any student of programming languages knows, but that doesn't mean we can walk away from our fuzzy English understanding of the concept. The problem is that the seemingly innocuous unit test I introduced first assumes that Java's equals method should represent content equality, but that's not true. That is, the method is not about our tacit understanding of "equality": it's about making a complex runtime environment work in predictable ways.

It is fascinating that modern IDEs like Eclipse make it so incredibly easy to write these methods incorrectly. Indeed, the format of the equals method provided by Eclipse looks a lot like the template the Bloch himself provides in Effective Java. 

The solution suggested by Odersky et al. is simple and elegant: because there are distinct concepts for equals, have two implementations. The equals method inherited from Object will continue to do what it needs to do, and we introduce a new method to represent content equality. Following their example, we might introduce a method called equalContents, which we could test using code almost identical to our earlier misconceived test:

    public void testEqualContent() {
        Achievement a1 = new Achievement("Blogging");
        Achievement a2 = new Achievement("Blogging");

This leads to a simple implementation of our domain class:

public class Achievement {

    private String name;
    public Achievement(String name) {;
    public void setName(String name) {;
    public boolean equalsContent(Achievement other) {
        if (other==null) return false;
        if (other==this) return true;

Nice and clean, without all that crufty tool-generated code to boot, and both testEqualContent and testCollectionsIntegration pass.

I know I cannot bring a cohort of sophomores with me on this adventure on Monday, so they will only be dipping their toes into it.

Wednesday, November 11, 2015

Quoting myself through another's notebook

I had a student last year who recorded many choice quotations from my courses. Often these were silly or whimsical thoughts I shared with my students to keep the spirit light, although she also captured bits of wisdom. Today, she shared this one with me:
Make opportunities, not excuses. In the real world, no one cares why you're late, or why your part of the project isn't finished. All they know is that you didn't do what you were supposed to. So, what they want to know, is how you plan to make it right—how you plan to contribute despite your failure, and how will that contribution move the project along?
That's a nice quotation, but there's a story behind it that's even more interesting. This student took two courses with me last year—my colloquium on game design in the Fall and my game development studio in the Spring. As she was reviewing her notes in preparation for a presentation, she found similar quotations each semester. However, according to her, the one from Spring was much better articulated than the one from Fall.

The idea represented by this quotation is one that I fall back on regularly when dealing with student teams, but I do not rehearse any particular articulation of the idea: when the time is right to bring this up, I talk about it extemporaneously. I wonder, then, was the difference in articulation simply random, or was there something about the environment or context that inspired me more in the Spring? Both were among my favorite teaching experiences, although one was more like a conventional course than the other. The Fall meeting was late in the day, while the Spring meeting was early in the morning. In Fall, everyone had their own projects, whereas in Spring we were one team.

I realize that the difference may be inconsequential, but I cannot help but wonder, and so I am glad she shared this story with me.

Friday, October 30, 2015

Symposium on Games in Academia Redux

I wrote about planning the Symposium on Games in Academia about two weeks ago. The Symposium took place last week, and I would definitely call it a success. Approximately 50 attendees came to the symposium to hear fourteen speakers talk about the intersection of games and higher education.
The crowd before the afternoon coffee break
I had the opportunity to give the opening remarks, so I talked about some of the inherent problems of games in education: that we know that games can teach, but we don't really know what they teach, or how they teach, or in some cases, what they even are. It's a perfect storm for future research! I shared one of my favorite stories from my own work, how students playtesting a Morgan's Raid paper prototype concluded that George Ellsworth was a wizard: it wasn't the designer's intent that affected what they learned but the individual constructive and social play experience.

We had a variety of door prizes donated by Wizard's Keep, Game Stop at the Muncie Mall, and Aw Yeah Comics, as well as other local philanthropists. One of my favorite talks of the day was given by Joel Bozell, an acquaintance of mine who is immortalized as Brian van Hoose in Knights of the Dinner Table. He spoke about the Muncie and Ball State connections of the long-running comic.

Joel Bozell talks about Knights of the Dinner Table
Another personal highlight was Carisa Lovell's presentation about her experience as an English major on the Collaboration Station team. Most of our discussions have revolved around shared interests and experiences, but in this presentation, she eloquently tied the studio experience to her major.

Carisa Lovell demonstrates Collaboration Station
I took a leadership role in planning the event, and I am grateful for the assistance of Eva Grouling Snider, Jennifer Grouling, and Scott Reinke, who were instrumental in making it a success. My department also generously supported the event both with refreshments and the help of administrative staff. I should mention that Eva designed this clever little fellow, who I think needs to become a mascot for the Serious Games Knowledge Group.

Once we get the attendee list transcribed, I will be sending out a post-symposium survey to gather some assessment data. Some people expressed interest in running another event in Spring; while I am sure there are more people who would be willing to speak, I also worry about gathering too much low-hanging fruit too quickly. Others have mentioned a desire to have a bigger, more formal event next year, perhaps with outside speakers. That, of course, requires a budget, which we don't have. I am hoping that the post-symposium survey will get us a better picture of what our audience thinks, and we can use this to do some planning and perhaps some politicking.

Monday, October 19, 2015

Symposium on Games in Academia

I founded the Serious Games Knowledge Group at Ball State University about two years ago, I think it was October 2013. The premise of the group was to gather faculty from across campus who are interested in games as learning tools, defined quite broadly. From a small core, we grew to about a dozen faculty and staff. The university's concept of a knowledge group, as I understand it, is to bring faculty together to produce scholarship and, potentially, grant proposals. Our group has met roughly once a month over lunch, where we share our stories about games we are studying, games we are developing, conferences we have attended, and articles we are reading. There is great diversity in our group, but this diversity has meant that we have not collaborated with any shared purpose: while the sharing of our individual work is enriching and enlightening, it has not yielded any scholarly artifact that we can point to as our own. In some ways, we have operated more like special interest group than a knowledge group.

This came up in our first lunch, and we agreed to do something about it. This Friday, the Serious Games Knowledge Group is sponsoring a Symposium on Games in Academia, 2:00–5:00PM in BL104.

We put out a call for presentations at the end of September, and I was pleased to receive fifteen high-quality proposals—enough that we had to reserve a bigger space! The presentations represent an even wider variety of interests than the Knowledge Group itself, and presenters include tenure-track faculty, contract faculty, faculty who teach at the Indiana Academy, university staff, and undergraduate students. The event will truly be a celebration of our diversity of interests, a chance to share our stories in a more formal and thoughtful environment. Refreshments are being sponsored by my department, and there is a wide selection of door prizes that have been donated by area companies and individuals.

The event is free and open to the public, so if you're in Muncie this Friday, please feel free to come join us. Eva designed this flier to advertise the event, and you are welcome to post it and share it. I'll make some time to post a follow-up on my blog after the event.

Wednesday, October 7, 2015

Children of the Sun Redux: Visiting Angel Mounds

Back in Spring 2013, I mentored the team that developed Children of the Sun, an original educational iPad game about Middle Mississippian Native Americans. I wrote about the experience, and Steffan Byrne and I conducted a qualitative evaluation that is documented in our GLS 9.0 paper. The game was not widely disseminated, being developed specifically for the Indiana State Museum's summer program, so unfortunately there's no way for you to play it today.

Much of the game takes place in a village view, which shows some three hundred villagers within it. The depiction is taken from archaeological drawings of Angel Mounds.

The goal of the game is to build the largest central ceremonial mound while also surviving both natural and man-made challenges. The central brown rectangular area is where this mound is built. I don't have the winning screen on hand—and without an iPad or a current Unity3D license, I cannot generate one—but you can imagine that it looks like a large version of the smaller green mounds shown in the image.

When we made the game, the team made great use of the resources they had available. We talked with representatives from the Indiana State Museum, local experts in history and archaeology, informative Web sites, and several books from the Ball State library.

This past weekend, I visited the actual Angel Mounds for the first time. It's hard to get a sense of scale from this picture, but I can assert that after 500 years of erosion, that central mound is still big. In fact, the whole site was much bigger than I imagined.
This begs the question: why? Why is it that someone who spent a semester making a game about this very site would be surprised at the scale of it?

If you scroll up and take a look at the village map, and you compare it with the scale of actual site, the villagers are not to scale. We had a lot of discussion—some heated discussion, as I recall—about how to represent the villagers. We agreed that these villagers ought to be more iconic than realistic, but they needed to be distinguishable as people. As we worked on the game, though, the villagers were really the primary objects of interest. Even though our intention was for them to be iconic, they became the points of reference for everything else. Although we spent a lot of time on the village map's design, I don't remember anyone questioning the scale. I believe that, as a result, my memory of virtual Angel Mounds was that it was much smaller, so that the people would be the right size.

I'm sure this didn't come up in our formative evaluation, because at that point, we didn't realize it was a problem. I wonder, though, if players would draw the same conclusion, and be similarly surprised at the vastness of the actual Angel Mounds site?

Incidentally, I recommend visiting Angel Mounds. The interpretive museum area is excellent, and the site is well maintained and inspirational. My family has been talking quite a bit about what we saw here, using it as a touchpoint to explain world cultures and history.

Tuesday, September 29, 2015

Simple PlayN Tech Demo on GitHub

This weekend, I will be presenting a paper at the Consortium for Computing Sciences in Colleges Midwest 2015 Conference. My paper, "Teaching Undergraduate Game Programming with PlayN," is an experience report about using the PlayN game library in several different courses and student projects.

There are several aspects of game programming with PlayN that I find useful for teaching undergraduates, including:

  • using the main game loop to update game objects;
  • managing the build and dependencies using Maven;
  • incorporating cross-platform support via LWJGL, GWT, and Android;
  • building a TriplePlay UI;
  • fluent interface design; and
  • functional-reactive programming via React.
Rather than walk through a series of slides on these topics, I decided to build a tech demo to show these elements in action. Note that, as part of my current cybersecurity education game development project, I have been learning IntelliJ IDEA, git, and GitHub. I was inspired by Michael Bayne's Reversi tutorial, whose code he posted on GitHub, using branches to separate each step. I decided to take the same approach with my tech demo, Angry Cardinal PlayN Demo. Each branch name starts with a number, indicating the sequence I plan to show it during my talk. It would be an exaggeration to call this a game of any kind, but with a lot of imagination, one could see how it's the seed of an Angry Birds clone. Unlike Bayne's tutorial, which aims to show how all the features of PlayN can come together to make a working game, my tech demo is designed to only show a few features, using the least code I can. I believe I can mitigate the dangers of live coding by simply switching between branches during my talk.

I have never given a live demo in this way, and I'm eager to see how it is received. Configuring this demo required me to get some more experience with branching, merging across branches, and IDEA's copyright profiles.

Sunday, September 27, 2015

Painting: Shadows of Brimstone, City of the Ancients

I cannot remember where I first came across Shadows of Brimstone, but when I heard that it mixed the wild west with Lovecraftian horror, I was sold. There are two base sets, and a friend told me that City of the Ancients was one of the most fun cooperative dungeon crawls he had played. This one includes tentacle demons and night terrors, whereas Swamps of Death has endless zombies, so I placed my order for City of the Ancients.
Obligatory Box Art
This was my first time building models from the sprue, so I bought myself a pair of sprue cutters and got to work. Honestly, I thought it would be more fun, but mostly it was tedious. I was able to delicately balance the figures around assorted desk stuff in order for the limbs, tails, and tentacles to dry in place.

Workspace, Demons, and Heroes
Once the assembly was done, there was still a lot of patching up to do. I mixed up some Milliput and got to work.
The Milliput Plague affects us all
The next step was to attach the miniatures to their bases---another step I never had to do before, having been mostly painting pre-assembled board game miniatures. Most were no trouble, but the U.S. Marshal has a "lean" to his pose. A clever balancing act helped me to ensure he was affixed at the proper angle.
Cheaper than clamps
The first figures that I painted were the void spiders, all twelve of them. Some of my other sets included multiples of monsters, but I really think that twelve is too many. Brimstone comes with a metric ton of cardboard: it seems they could have had more variety in the monsters. These were kind of fun to paint except that there were so blasted many of them. I spray-primed them white and then used blue-purple washes and drybrushing. The mouth was done more conventionally, with a black ink wash to get the depths of the mouth and between the teeth.

A horde of void spiders
A horde of void spiders, but in a different pile
I should mention, either before or while working on the void spiders, I ran out of white paint—my second bottle to finish, following black a few months ago. Next time I was out, I picked up a new bottle at Hobby Lobby... or at least, I thought I did. I noticed that the texture seemed really strange, which at first I attributed to not having properly shaken the bottle. A few more spiders, and I was sure something was strange. Turns out, I had picked up “Foundation White,” which is really a primer and not the same as “White”.
White vs. Foundation White. Not interchangeable.
For basing, I used a mix of fine, medium, and large ballast, in approximately at 8:4:1 ratio. Although the game allows the characters to go to different worlds, I decided for simplicity's sake to try to make the bases match the Brimstone mines. Turns out Americana Spiced Pumpkin is almost a perfect match for the orange shade used on the game's tiles. I had primed the miniatures before doing the basing, using a Krylon black primer aerosol.

The primer is less rough than the base, but not as much as I would have liked.
You cannot see it so well from the picture, but I must have done something wrong with the priming. I suspect I was too far from the figures, because the texture that came out was really coarse, similar in feel to when I tried the Liquitex Basics Gesso on my grells. The primer absorbed thinned paints and washes like a sponge, leaving me very little control. I went ahead and finished the tentacles—which are not very interesting models anyway—but it was unpleasant enough that I did not want to continue this way.

Finished tentacles. Tabletop-quality, but not much more.
I threw the rest of the miniatures into a bath of Simple Green for a day or two, brushed them down, and re-primed (and re-based) them. This time, I was careful to do them in smaller batches, and on a table rather than the garage floor. The results were much better, although still not with the smoothness of the Vallejo surface primer I would normally brush on and which I used to touch up areas missed by the spray.

Undercoated on a much nicer layer of primer

The next batch I worked on were the stranglers. One of my goals for this set, which I could not meet appropriately on the tentacles, was to work on having higher contrast. I think I frequently make the mistake of thinking something looks great in my hand under my painting lamp, but when it's out on the table, it lacks the contrast to be interesting. I built up the stranglers from a dark undercoat, trying to keep shaded areas dark to make the muscles ripple. This was tricky in part because the models are not actually very detailed: some of what you see is "faked" with paint, not sculpted into the model. I was pretty happy with the flesh colors and then moved on to the mouth (sorry, no halfway photos here, though I wish I had some). I mixed a fleshy glaze and applied it in multiple layers around the "lips" area, matching the visual design of the box and rulebook art. At first, I was very unhappy with the appearance, and I was worried I had wrecked them. I took some more time to mix intermediate shades and try blending them in, and I tried to bring out more highlights at the edges and ridges. The result, I think, is one of the best blending jobs of any figure I've done.
Stranglers, amassing to form a target
Next up were the night terrors. The art on these figures is interesting, as they appear almost non-corporeal, which certainly matches the name. I built up in layers from almost black up to a mix of blue and white with a hint of green. I was pretty happy with these and took this picture thinking I would be done.
Night Terrors... but not quite yet complete
Looking at them the next day, I got to thinking about my goal to practice high contrast. These guys already have a lot of contrast... but is that my own delusion? What if I added even more contrast... what if I really turned it up to eleven? The card art certainly takes the highlights up closer to white than I had painted them. I decided to try it.
Super-contrast on the left, original on the right
I am sure I giggled with delight at the effect. I went through and touched them all up.
Night Terrors, actually complete
This brought me to the Goliath—a name which conjures up the notion that this creature was created only to be destroyed by so many Davids, but that's game design for you. I think I re-started this model twice before I got colors that really clicked. I believe I was trying to make it look muscular, similar to the stranglers, but in re-working it, I realized I needed more texture. Again, the model itself is kind of drab, devoid of detail, and I needed to use the paint to add texture, not just try to emphasize what was there.
Here are an undercoat and base color. Will it work this time?
After getting the two base layers down in a fairly straightforward approach, I started adding spots and bumps to the back, following the sculpted pattern but really trying to bring it out. For the “arms,” I put in thin parallel stripes, again to give more texture. After several layers of highlights, I had a flesh style that I was really happy with. The mouth tentacles are completely smooth, and I also decided to add some more textural interest there. The eyes are barely sculpted, and so I think this part is merely sufficient but nothing outstanding. The undersides of the arms were a little disappointing. Looking at it now, it doesn't look bad, but it's not quite what I wanted. I think I ran out of steam here. I tried using a bright yellow and then a sepia wash to bring out the shadows, but that just made the whole thing look dingy. I spent a lot of time just covering up areas where the wash had left unseemly spots. Despite this frustration, I think the overall model is quite good, having good contrast, interesting texture, and looking a bit frightening. Sorry that the images are a little overexposed.
*hack hack hack*
I happened to be working on this across the first weekend of the semester. I had already told my students in my course introduction that miniature painting is a hobby of mine. On the second Monday of the semester, I mentioned that they probably were involved in a range of activities: seeing old friends, making new friends, traveling home to spend time with family before big projects are assigned. I suggested that, perhaps, they wondered how their humble professor spent his weekend? Then I brought up this image and told them that I had spent it painting a demon's butt.

It's true, I spent hours staring at those cheeks.
This brings us to the heroes. The first one I painted was the Saloon Girl. I wonder, if she marries the U.S. Marshal, will she become Saloon Woman? Anyway, something interesting about this game is that each character card is reversible, with a different gender on each side. I first saw this in Legends of Andor, but that game used standees, so it was easy for them to include both male and female versions. Brimstone, on the other hand, only provides one gender of figure. I can't say I blame them, but I did wonder... what's a male Saloon Girl? Turns out it's a piano player. Hm. In digging up this picture, I came across an interesting theory that even this side is just a woman with a fake mustache, dressed up so she can come along monster-killing with the gents. It's hard to say without being able to tell what this character's skill is like with an actual piano.

Anyway, the figure was fun to paint. I used to fear reds, but now that I understand more about how to paint them, I see them as an exciting challenge. The Saloon Girl's outfit is highlighted up to orange, but it still reads as "red." Looking once again at contrast as a goal, I think this turned out well in several parts of this model, including the black trim that is highlighted up to grey. Her face is a bit flat, and I find faces hard to paint anyway. I tried to match the colors in the card art for all these characters, and I do wonder why the artist chose Christmas colors. I think I'll call her Merry.

Saloon Girl
Saloon Girl
Remember back when I said that I scrubbed these miniatures down after a bad priming job? Well, this was not entirely without casualties. The U.S. Marshal's rifle had a weak spot from the time I received it, and my old toothbrush was too much for it: the end of it broke off, never to be found.

Necessity, like Frank Zappa, is the mother of invention. I decided to try rebuilding the gun, making this my first real figure modification. I suppose if you split hairs, it's a repair job, but calling it a mod makes it sound more intentional. I found a straight pin that was the right diameter for the barrel...

and with a few snips of my wire cutters, some filing, superglue, and a touch of Milliput, my Marshal had a new weapon.

You may also remember that this guy leans backward. Many of the figures came off of their bases when I scrubbed them down, including him, which I took as an indication that he wasn't well on there in the first place. I decided that, after getting into the hobby about 1.5 years ago, it was time to start pinning. The first time I took my pin vise to a miniature, it was a bit daunting, but everything went smoothly. The first two I pinned were actually the Bandido and Gunslinger; the Marshal came afterward.

Compared to the Saloon Girl, the Marshal was a pretty dull miniature. I decided to put him in a matching vest and trousers, so there are not a lot of colors. The wooden handle to his rifle has some texture to it, and I used brown-red ink to try to make it look like stained wood. I built up the base with Milliput to make him standing on a slight slope, which helps correct his leaning pose as well.

I had moved on to the other heroes when I looked back at the Marshal and, as with the night terrors, wondered what would happen if I took up the contrast and highlights even more. I'm glad I did, as the final version is much more vibrant than before, when it was just too much brown. (Sorry, no comparison photos.)
U.S. Marshal
U.S. Marshal
The Bandido was much more fun to paint, with lots of accessories. I like how he has a very different look than the dull 19th-century men's fashion of the Marshal and Gunslinger. I'm happy with the contrast on his shirt, pants, and accessories. The green and white pattern on the hat is inspired by the card art and is mostly freehanded. It's not perfect, but it's sufficient. If anyone asks, it's not woven into the hat: the Bandido painted it himself. Also, once again, fun with reds, this time taking the highlights on the sash toward a mix of orange, yellow, and white. He's purposefully the hero around the most large stones, by the way, since he's the guy with the dynamite.
The last of the lot is the Gunslinger. I was going to refer to him as Gunhaver, but the trouble is that they all have guns. I mentioned 19th-century fashion above, and I was being serious. I looked around the Web a bit to see how others had painted their sets, and I am amazed at the number of people who have the Gunslinger in blue jeans and a black coat. I think this makes him look like a 1990s fashion reject rather than a stranger with no name. I ended up on the Wikipedia page about 1880s fashion and I thought, "There's a Wikipedia page about 1880s fashion?!" The Internet is an amazing place. Let me be... if not the first, then one of the few... to thank the community that maintains that page. As I suspected from my rigorous research (i.e. watching Deadwood), a gentleman certainly would have worn a matching jacket and trousers. As in the card art, I used a purple-pink waistcoat to add some color to what would otherwise be a dark model.
Here are all the heroes, standing together, ready to face evil.

Bring it on, evil.

Here they are, facing evil, and perhaps regretting that decision.
Don't look behind you...

Finally, to wrap things up, some happy family photographs.

Those tentacles are clearly less interesting than the rest.
Tall people... er, things... in the back

Some days, when I look at the variety of pictures I take during this projects, I think about building a lightbox, but where would I put it?

Thanks for reading!

Wait, what's that? How's the game, you ask?

I have no idea. We're still playing the Pathfinder Adventure Card Game.