Programming, game design, and faith

Sun halo

Author: james

The semantics of “do in order” and “do together”

Alice 2 and Alice 3 have code blocks called “do in order” and “do together.” They call these control structures, although usually programming languages have control structures like “if” and “while.” Instructions placed in a do in order block are executed one after the other. Each instruction has to wait until the one before it finishes before it can start. On the other hand, instructions placed in a do together block are executed simultaneously. All the instructions start at the same time, and the block itself is finished when the longest instruction inside finishes.

This is what I tell my students, but when asked to regurgitate this fact, some students instead say that “do in order” makes the animation choppy, while “do together” makes it smoother. For years I have marked this wrong, saying it has nothing to do with smoothness of animation. These are control structures; they are about how the instructions inside are executed. However, I think I figured out what they were thinking. Imagine you have to reach for something. Your elbow joint and shoulder joint both have to move to reach it, and you move them both together for a smooth movement. If you were to move your elbow joint by itself, and then your shoulder joint by itself, you may still reach your target, but the movement will look robotic and choppy. Therefore, “do together” allows for smoother animation.

Why does “do in order” look choppy and robotic? Robots are controlled by computer programs, and traditionally computer programs execute one instruction at a time. Doing one thing after the other is, in the imagination, exactly what computers do. It is what they do, except when they’re running in parallel.

But is “do together” really a great introduction to parallel programming? When programmers implement parallel algorithms, do they really think in a “do together” semantic? I’m not convinced.

Flipped classrooms

In the CS POGIL activity writing kickoff workshop, we did some activities to become more familiar with how to write good POGIL activities. One of the exercises had me thinking more about it even after the exercise was done. While thinking about the model, I even invented a different definition for the concept, better (in my opinion) than the one given by the model. This is a good feature for models in my own POGIL activities: a good model will keep students thinking about the new concept after the activity is over. The exercise was helpful to me because it focused on the invention part of a POGIL activity, which is something I’m not used to in activity designs.

We often talk about “flipped classrooms,” normally understood to mean the lecture is replaced by students reading at home and then working on homework during class. But a well-written POGIL activity is the real flip: Instead of an individual student observing a well-known concept discovered ages ago, students in a group context invent a concept themselves, maybe even in a new, productive way. Not only is the learning deeper, but the curriculum is decolonized.

New Monty Hall door variant

(The inspiration came from a student’s submission for Remake Candyland.)

Three people play a board game. The first to reach the end of the track wins. You each have a favorite candy, and there are three cards randomly shuffled, one for each candy. The player, on their turn, draws a card. If it is their card, they advance a space. If it is someone else’s card, the other player advances a space. The player can draw once more if they choose.

We can restate this as the Monty Hall game: The player chooses a card but does not reveal it. A neutral game master looks at the other two cards and reveals one that is not the player’s card. The player can choose to keep their choice or switch. Probability would dictate that it is always better to switch.

We can mix this up by having a biased party look at the other two cards and choose whether to allow the choice or not.

Sorcery in video games

I read a question and some responses on the Christian Game Developers Facebook group yesterday. The question was, “How do you guys feel about heroes in fantasy games using magic?” There was some discussion of the prohibitions of sorcery in the Bible and the example of the converts in the NT who burned their magical books.

In the video games I have played, magic is pretty much the same thing as superpowers. Being able to control the wind or throw a fireball is not different from what X-men or Avengers do. One commenter said he doesn’t participate in any of these forms of entertainment. I admire the consistency of this stance, but I think these things are fantasy and fun to imagine.

I had to think about the broader issue of evil in video games when I started playing Diablo and Diablo II. I decided that the stuff in that game (cemeteries, winged demons, pseudo-scriptural text) is almost completely unlike anything related to real Christianity, so it was OK to play.

I stopped playing Diablo II when I saw some of my friends playing the game for hours and hours, waiting for the rare loot drops. I wondered, is this game fun or addicting? Over the years I have come to the conclusion that the real evil of Diablo and other such games is the Skinner box—making players addicted to the game by activating pleasure centers in the brain at random times. Some game companies monetize this by making players pay for loot boxes.

Please think about if you’re playing a game because it’s fun and uplifting, or because your mind is being controlled by pleasure seeking. This goes for creating games, too.

Binocular depth perception in Alice

You can use Alice to make a 3D movie. The basic idea is to record the movie twice from slightly different camera locations. Viewers can see the depth in the movie by looking at each image with separate eyes. Try it on this image. You can use the Magic Eye trick, or look at it on a phone using Google Cardboard.

Binocular image of bunny in a scene

To make a 3D video in Alice, follow the steps below. I used Alice 2 on MacOS, but the instructions should be adaptable to other environments.

  1. First, the movie window size in Alice needs be an 8:9 ratio, rather than the default 4:3, because we will use iMovie to make the final product, and iMovie creates 16:9 ratio videos (widescreen). We need two images side-by-side, so an 8:9 ratio will work perfectly (a little taller than wide). You can set this in Alice 2 in the viewing angles in “seldom used properties” on the camera. The vertical viewing angle should be changed to 0.75; leave the horizontal viewing angle at 0.67.
  2. Next, create your Alice movie as usual.
  3. At the very beginning of your movie, create a duration 0 visible change (e.g. turn light brightness to 0 and then to 1). We will need this to align the timing of the left and right clips. It serves the same purpose as a clapperboard in a regular movie.
  4. Move the camera 0.05 m left for the viewer’s left eye.
  5. Play the movie, then start the video capture (command-shift-5 on Mac).
  6. Hit Restart on the Alice window. If you don’t see the light black out, hit restart again. Sometimes it’s not visible, so you have to keep restarting until you see the light blink.
  7. Stop the recording at the end of the movie.
  8. Move the camera 0.10 m right for the viewer’s right eye.
  9. Record the movie again. Make sure you see the light black out at the beginning. When you save the recording, make sure you know which clip is right and which one is left.
  10. Trim each clip so it begins right after the light turns on. (You can use QuickTime Player on Mac).
  11. Create a new project in iMovie, and add both clips. Add the right clip first so you know which is which. The one you add first is considered the main clip. Add the left clip so it overlaps with the first clip.
  12. Line up both clips on the left. Trim the longer clip to the length of the shorter.
  13. Select the upper clip and choose Split Screen.
  14. Share the video to a file or whatever you want.

You can watch the exported video in 3D using the “magic eye” trick if you make the window small. You can also watch the video using Google Cardboard or a similar device if you open the movie on your phone.

Example: Alice 2 file and Result video

The crown that will last forever

Presentation at ACMS 2019, Indiana Wesleyan University, 31 May 2019
James Vanderhyde, Saint Xavier University, Chicago

Smash Trophy

Paul, 1 Corinthians 9:24:

Do you not know that in a race all the runners run, but only one gets the prize?
Run in such a way as to get the prize.

David Sirlin, Playing to Win:

Winning at competitive games requires a results-oriented mindset that many players are simply not willing to adopt.

Introduction

David Sirlin, competitive video game tournament champion, wrote a book (2005) that explains how to win at games. Sirlin begins the book by describing a “mountain” of competitive gaming: a few gamers are already “on the journey” to the mountain peak, but most only think they are. “They got stuck at a chasm at the mountain’s base,” and “they are imprisoned in their own mental constructs of made-up game rules. … ‘Playing to win’ is largely the process of shedding the mental constructs that trap players in the chasm who would be happier at the mountain peak.”

The book is very interesting and I recommend it. Sirlin covers many topics related to competitive gaming. Here are few highlights:

  • Shedding the “scrub” mentality (more on this later)
  • Doing whatever it takes: Being competitive requires dedication, training, and choosing the appropriate game. Sirlin gives plenty of advice.
  • The Art of War by Sun Tzu: This is a text written around 500 B.C. It is all about strategies for warfare, especially when not to fight. Sirlin applies this to competitive video games.
  • Champion play styles: Sirlin describes several play styles and then selects exemplars of each style—first one from the world of chess grandmasters, then one from the world of Street Fighter 2.

The scrub mentality

Common usage of the term “scrub” usually means the same thing as a newbie or “noob.” Sirlin means something more specific, however. He is referring to a player who loses but blames the loss on something external to the player: the game is broken, the opponent used a cheap move, the move should be banned, and so on.

Furthermore, the scrub is limited in game performance because of a set of self-imposed rules. They feel good about themselves because they never use “cheap” moves. This is the essence of the scrub mentality. They play by their own rules, rather than by the rules of the game, and if their opponents do not play by their rules, the opponents are labeled “cheap,” “boring,” “unfair,” “dirty players,” etc.

Conversely, players who play to win do whatever it takes to win, even if it means being labeled by scrubs. True competitors do not care about these negative labels. They prove they are the best by winning at tournaments.

For example, a popular competitive video game is Super Smash Bros., in which classic Nintendo characters are pitted against each other in hand-to-hand combat. The way this game works is that attacks do damage, and the more damage a character has sustained, the easier it is to throw them out of the ring. The first player thrown from the ring three times loses. In the first Smash game, a character named Kirby was considered more powerful than the rest of the characters and was even banned at some tournaments. Kirby has an undefeatable move where he sucks in an opponent and jumps off the edge with him. This is called “Kirbycide,” and it works when Kirby is ahead. In the second Smash game, the designers modified the Kirby character to make him much easier to defeat. At that point very few competitive players ever used Kirby. Many players consider Kirbycide to be a cheap move and are angered by it. Competitive players consider it a viable strategy. Watch this video for a competitive match including Kirby (Chu Dat vs. Chillin Dude). At 1:40 you can see the dreaded Kirbycide, and at 5:30 you can see another “cheap” move known as turtling. I don’t know why Chillin didn’t keep up the turtling; he would have won.

Perhaps you’ve played with scrubs. Have you read about them in the Bible?

Biblical scrubs

Jesus often faced the scrub mentality when teaching the Pharisees. “Why don’t your disciples wash their hands before they eat?” (Mark 7:1–23). “Your disciples are picking grain on the Sabbath!” (Matthew 12:1–14). The Pharisees played by their own rules, which they called the tradition of the elders, and expected everyone else to follow them, too. Jesus said to them, “Woe to you, teachers of the law and Pharisees, you hypocrites! You give a tenth of your spices—mint, dill and cumin. But you have neglected the more important matters of the law—justice, mercy and faithfulness,” and “You clean the outside of the cup and dish, but inside they are full of greed and self-indulgence.” (Matthew 23:23, 25).

Paul faced the scrub mentality when teaching the Gentile believers in Colossae: “Do not let anyone who delights in false humility … disqualify you. … [T]hey are puffed up with idle notions by their unspiritual mind.” (Col. 2:18). Whoever those teachers were that Paul was fighting against were again playing by their own rules and imposing their rules on others. “These rules … are based on merely human commands and teachings. Such regulations indeed have an appearance of wisdom, with their self-imposed worship, their false humility and their harsh treatment of the body, but they lack any value in restraining sensual indulgence.” (Col. 2:22–23). Like a scrub, the self-imposed rules are keeping you from succeeding at what you really want.

Have you seen the scrub mentality in your own life?

The game of life

Life is not a game, but let’s see how far the analogy takes us. A game has a system of rules and therefore an objective measure of progress. If you are playing by the rules, and winning more games, you are improving in your desired goal of playing to win.

God has a system of rules, the nature of God. God’s nature is knowable by revelation. It is prescribed to us (partly) as a moral code. When a person has not come to terms with the sinful nature and accepted the grace of God and the saving work of Jesus, “they are imprisoned in their own mental constructs,” like a scrub, even if they are trying to live a moral life. All they have to work with are the moral codes they either come up with on their own or inherit from their parents and environment.

Games have an objective measure of improvement. How are you improving in your Christian walk? According to the rules I listed, you are winning if you are conforming more to the nature of God. This is difficult to determine, although Jesus and Paul listed a few in the passages already cited: justice, mercy, and faithfulness (Matthew 23:23); compassion, kindness, humility, gentleness, and patience (Col. 3:12). Sometimes it hardly seems objective at all. Are you more patient than you were 5 years ago? Can you even tell?

Sirlin (p. 1) wisely shies away from applying his principles outside the game: “games are sharply defined by rules; life is not. Exploring extreme corner cases of a game is what high-level play is all about. Exploring extreme situations in life can easily be socially unacceptable, morally wrong, and illegal.” Granted, some extreme lifestyle choices are all three of these. However, fully relying on God also allows you to reach extreme corner cases of life. How about pursuing a call to preach the gospel in an unreachable corner of the world? How about increasing your tithe by 1% every year until the day you die? How about choosing to live in a “rough” neighborhood? How about praying for every student who comes into your office, even at a state school where you could be in danger of job termination? How about praying for your spouse every single day? Or really and truly living to “rejoice always, pray continually, give thanks in all circumstances” (1 Th. 5)? I hope I someday have enough faith to do any and all of these.

Conclusion

As I study and teach computer science and video game design in particular, I am finding connections to truth and life beyond the technical skills we typically focus on. “Playing to win” is significant as an apologetics argument for the Christian life, which seems irrational to some people. As far as I can tell, Sirlin himself is an atheist. His recommended reading list says The God Delusion by Richard Dawkins is “Possibly the most important book in the world. Not a joke. It will be overlooked.” I presume he sees the scrub mentality in religious people. I think he does not realize that his own work points to faith.

Paul, 1 Corinthians 9:25:

Everyone who competes in the games goes into strict training. They do it to get a crown that will not last, but we do it to get a crown that will last forever.

Smash Trophy

World’s dumbest chatbot

Try it with emojis 😀

 

public class Test
{
  public static void main(String[] args)
  {
    System.out.println("Hello. How are you?");
    java.util.Scanner cin = new java.util.Scanner(System.in);
    String in = cin.nextLine();
    System.out.println("I feel "+in+" too.");
  }
}

Switching strategies

On the Ludology podcast this week, they said that game balance depends in one respect on how easy it is to switch strategies mid-game. If it is too hard to switch strategies, the endgame becomes meaningless, because there is no point in playing further once a strategy becomes dominant. But if it is too easy to switch strategies, the beginning of the game is meaningless, because you can switch at the end to win without regard for the rest of the game. So the key to making the whole game meaningful is to balance how easy or hard it is to switch strategies.

Entity-Component-System architecture

Recently I have been learning about the Entity-Component-System architecture for video game programming. I think it will help out with my “World’s Tiniest RTS” game. I learned about it here, in Robert Nystrom’s Game Programming Patterns. I also heard on the Exploding Rabbit podcast how Jay Pavlina (of Super Mario Bros. Crossover fame) uses the pattern. Here is my Clojure code for it, currently:

(defn create-game []
  {:entities {}})

(defn create-entity []
  [(java.util.UUID/randomUUID)
   {}])

(defn add-entity [game entity]
  (update-in game [:entities] conj entity))

(defn add-component [game entity com data]
  (assoc-in game [:entities (first entity) com] data))

;;example
(let [e1 (create-entity)]
  (->
    (create-game)
    (add-entity e1)
    (add-component e1 :position [3 4])
    (add-component e1 :name "ball")))

Powered by WordPress & Theme by Anders Norén