Digital Media PhD Student
Kenneth is a doctoral student in the Digital Media PhD program. In his series “Kenneth on Games” he writes about his passion for games and game design.
Every few months, a new “learn to code” game hits the frontpage of Reddit. This time around, it’s CodinGame, which advertises itself as a system that’s not just for beginners, but also for more experienced programmers who can learn from each other. There are plenty of integrated social networks embedded in the game itself, such as rating systems for every coding puzzle. One of the lowest rated puzzles is called “Temperatures,” and I got stuck on this one for days. But what makes this puzzle bad, not from a programming perspective, but from a game design perspective?
Puzzles and Logic
Puzzles are arguably the most didactic form of gameplay in the field. If puzzles can teach you to think with portals, maybe they can teach you to think with fluid dynamics, or with physics, or with code.
Programming is a great field for nontraditional teaching methods, because traditional teaching methods don’t work well. Beginner students often spend their time stumbling over basic syntax before they even experience anything challenging. There are all sorts of ways for code to go wrong that a student can’t even comprehend what’s happening. Many people give up because it’s so difficult.
But this is the point where game design can distinguish between “good difficulty” and “bad difficulty.” Good difficulty inspires people to try again, whereas bad difficulty frustrates them and makes them want to quit. Game designers often use the term “flow” to describe a state of psychological immersion, and good difficulty keeps players in that state of flow.
What maintains flow? There are three factors: immediate feedback, the promise of success, and the “magic circle,” a term to describe the feeling that the situation is self-contained and has no connections to things outside of the circle. In Portal, the magic circle would be each individual test chamber. You don’t need anything outside of the test chamber to clear the puzzle. No hidden secrets, no items you needed to have in your inventory, just your brain and your portal gun.
Programming clearly violates at least two of these rules. There is no immediate feedback because you have to compile the code before you find errors. Even worse, only the most basic syntactical errors can be found this way: logic bugs will compile just fine, but it takes a long time to understand what went wrong. The magic circle does not exist because programmers often need to reach to outside sources like Google or Stack Overflow to find code snippets or documentation. When it comes to the promise of success, it’s arguable.
An experienced programmer can easily slip into a state of flow once they understand everything that is happening, and it feels great. But a beginner who has to trace through a web of conditional statements searching for a missing curly bracket is not having fun. This is where puzzle games can potentially come in: instead of forcing students to memorize syntax, a game can streamline the experience and focus on programming in terms of logic.
Temperatures and String Parsing
“Temperatures” is a puzzle where you are given a dataset of a variety of temperatures, and you need to write code that parses this dataset and gives the result closest to 0. For example, you might have five values that are -4, 12, 8, 9, and 2, and your code would be expected to identify 2 as the answer. There are other restrictions involving negative numbers or other edge cases, but the main point is about parsing numbers.
However, the puzzle gives you these numbers in the form of a string. It would make so much more sense to provide them as an array of integers, because that’s what they are. So the first thing you need to do is parse this string into an array of integers. Even though the computer already knows the array of integers and just gave it to you in the form of a string.
The puzzle itself is not about turning strings into integers. It’s about turning integers into an answer, and that’s the part that demands critical thinking. But turning strings into integers demands nothing except for rote menial copying. You go to Google, you find the answer, you paste it in, and you move on.
In Portal, this would be like if you had a puzzle where you stand in a corridor with the exit on the other side. The floor is covered in a dangerous substance and you’re obviously meant to use the portal gun to teleport across. But you don’t have a portal gun. You have go to to the Steam Workshop and download the portal gun mod.
Frictional Games, known as the developers of Amnesia, follow a rule for puzzles: “A puzzle should make players to do something in such a way that they feel they came up it themselves.” The answer should come organically by using the tools provided by the puzzle in an intelligent manner. It should not require anything outside of the magic circle.
There is a baseline level that needs to be met for a puzzle to maintain a magic circle. For Portal, this would be the controls: if you don’t know that you can look up, you would feel cheated if you faced a puzzle that is solved by looking up. For programming, this is a little harder, but I would say the baseline should be a general grasp of syntax, if statements, and variables.
But there are so many shortcuts that are like cheat codes. You would have no way of knowing about these shortcuts unless you already knew that they existed. Parsing a string into an array of integers is one such situation. If you didn’t know that there was a shortcut, there is absolutely no way to proceed. Alternatively, you could use the line “Array.ConvertAll(temps.Split(‘ ‘), int.Parse)” which automatically does everything that the puzzle should have done for you.
A puzzle should not be designed with the assumption that a player knows about these shortcuts. If the shortcuts are necessary, the puzzle designer has an obligation to integrate them in such a way that players can discover them without leaving the magic circle. Many games will use environmental clues to give subtle hints when players are stuck: if the player doesn’t know that they can swing on a rope to cross a forest chasm, the game might show monkeys swinging around in the background. Players in a learning situation should not be expected to already know the answer.
Better Programming Puzzles
“Temperatures” would be greatly improved if there was some way for players to code their own way to read the dataset, rather than automatically being given a string. If a player was so inclined, they could directly turn it into an integer array, or a string if they feel more comfortable that way. Instead, all players are funneled down a path that some of them might not even know has a solution.
I find “Fizzbuzz” to be a well-designed programming puzzle. Yes, there is a shortcut (the % operator, which some people may not know about), but it’s still easily solvable without it. A programmer only needs to know syntax, if statements, and variables to solve Fizzbuzz.
Puzzles are honestly one of the hardest parts of game design. They require a perfect balance between being too difficult and being too easy, while other genres can use external tools to pad the difference (such as an RPG placing a level restriction on a difficult dungeon). Whenever I try a new “learn to code” game, it always surprises me how much of the playerbase falls into one of two groups: professionals who want to show off how much they know, and bewildered beginners who have never typed a semicolon in their life. I fall closer to the latter category, and in the future I hope I can find a platform that helps me learn programming as seamlessly as Portal helps me learn about portals.