CodeCombat

Coding for loot

CodeCombat is a puzzle game by an identically-named company designed to teach players to write code. The game was released in 2013 for the web, and continues ongoing development. You can play the game here.

Players choose their language of choice (python, javscript, or coffeescript) and use object-oriented commands to navigate their hero through mazes of traps and monsters. Players start with abilities like hero.moveRight(), and gain progressively more complex commands like hero.attack(), and hero.findNearestEnemy() as they progress. In so doing, players learn the basics of programming, from calling functions, to using arguments, to defining variables and writing loops. Each level has a view of the dungeon on the left and a text-editor on the right where you write the code that tells your hero what to do. Players can write code and execute it to see how their hero behaves, and then edit and re-run a new version to try to keep themselves from running headfirst into a bone-crushing ax.

Watch out for ogres

Learning Objectives

The learning objectives are not listed in full in any particular list that I could find. Instead, levels are assigned keywords like “Arguments”, “Strings”, and “Reading the Docs” to describe the skills required to complete the level. This is further complicated by the fact that the game includes a number of worlds that cover a variety of domains including “Game Design” and “Web Development.”

Web and Game development are only available to paid subscribers, so I will limit my analysis to the first world, “Kithgard Dungeon”. Here is my take on the learning objectives involved:

  1. Skill: Given a list of available methods, students will be able to be able to make function calls in a correct sequence to move their character through a maze.
  2. Skill: Students will pass arguments to functions to move their character the correct distance, attack the correct enemies, and “say” (print) the correct words.
  3. Skill: Students will use infinite while loops to repeat sequences of actions concisely.
  4. Skill: Students will assign and reference variables to use as arguments in function calls.
  5. Disposition: Students will desire to write elegant code

Students can be expected to improve at objectives 1-4 if they are progressing in the game, because levels will require these skills to succeed. In contrast, playing the game is not guaranteed to foster interest in writing elegant code, but the game does incentivize writing elegant code by encouraging you to use “fewer than X” lines of code in each level and by awarding additional points based on your program’s concision.

It’s notable that as written, skills 1 and 2 are limited in scope to in-game skill. I struggled to write these two learning objectives in a satisfactory way and I think it speaks to a general concern about the level of transfer aspired to by this game. To what extent will playing this game empower students to write their own programs? To what extent should it aspire to do so? It’s difficult to judge this just by playing it. The game provides a large amount of scaffolding that does not appear to fade. This makes it hard to evaluate how much skill can transfer outside of the game. For that reason, I’ve limited those first two objectives manipulations entirely within the game, as this aligns more explicitly with what the game measures in its assessment of player competence.

Prior Knowledge

Players are expected to have significant digital literacy before playing the game. They must be able to read, type, and navigate menus with a mouse. Otherwise, they do not need to know much. The basics of programming syntax and semantics required to play are addressed in the tutorial levels, and each new concept and ability comes with tutorial content explaining how and why to use it.

Mechanics

The core mechanics of typing code into the text box, running it, and checking its output against the expected criteria aligns nicely with goals 1-4. Students are required to leverage function calls, arguments, variables and infinite while loops in an appropriate sequence to complete each level. In this regard, students cannot progress without doing these things. Each level includes opt-in hints, in addition to tutorial information, that elucidate how to use the relevant commands at your disposal.

Asking for a hint

Notably, the hints never “bottom out” into revealing a full solution to the problem. This may however result in struggling students getting frustrated that they don’t understand how to proceed. It does however require that students create their own solutions, and thereby progress in the level’s targeted learning objectives, in order to proceed. The game also provides conveniences like auto-completion and syntax and semantic error catching (e.g. missing quotes or referencing unassigned variables).

The ole’ rubber duck method

These scaffolds mirror the tools included in modern code-editors like VS Code and Sublime Text. Thus these features bring the core game loop closer to the idealized transfer tasks of writing one’s own program and at minimum, shouldn’t detract from the specified learning goals.

So what about goal 5? Do any of the mechanics support fostering interest in writing elegant code? Most levels include some restriction on the number of lines of code allowed to solve the problem. Additionally, many levels additionally offer extra rewards for writing concise code. While this does not guarantee influencing students’ dispositions, it does seem likely that these incentives might succeed in encouraging students to value concision in their code.

Gotta get those gems

Dynamics

There are no penalties for running incorrect code. It can be difficult to determine exactly what your character will do in advance of running the code, in large part because there are minimal visual cues representing how far apart different places on the map are. You can tell your character to .moveRight() twice in a row, but how far will she go each time? This can be frustrating, but this frustration is somewhat mitigated by the ability to edit and re-run your program without penalty. Thus the game encourages a trial-and-error or guess-and-check approach. If you are not sure what will work, try running a partial solution, and seeing what goes right and what doesn’t. Then you can adjust your program and try again. While it may not be a programming best-practice to start writing code without premeditating your plan with some diagrams and/or psuedo code, this dynamic does encourage students to iterate in the face of failure.

Aesthetics

The gap between what you predict your commands to do and what they will actually do creates a feeling of separation between yourself and the character. Thus the game feels like rather than directly moving your character, you instructing the character on how to navigate the dungeon, and hoping that your instructions are enough. Despite your best intentions, the hapless hero has an affinity for walking blindly into danger. Thus the overall feel is one of protecting a helpless idiot from danger by giving them extremely thorough directions. The lack of penalty for executing incorrect solution makes running an incomplete program (which dooms our poor hero to certain death) an inexpensive way to check how close your answer is to a correct solution. This makes the hero’s life heavily expendable. I would describe the resultant aesthetic as refining grist for the mill. You iteratively develop the instructions you provide your hero/lemming while continuously sending them headlong into peril, until finally arriving at a program that naviagates the hero safely through the gauntlet.

This aesthetic encourages students to engage in trial-and-error, and to perservere in the face of failure, which seem to serve all 5 of the above learning objectives. The aesthetic does somewhat undervalue planning in advance, which may not be optimal. Still, the game heavily encourages learners to revise and seamlessly retry their solutions, which faciliates growth towards all the game’s learning objectives.

Learning Science

Timely Feedback: Players receive three key kinds of feedback to help them navigate each level: explicit syntax corrections, explicit semantic corrections, and the hero’s performance. The first two mimic a text editor to alert the player of certain specific kinds of errors (like missing quotes or referencing unassigned variables). The hero’s performance offers implcit feedback: the player can observe whether the hero moved in the right path, attacked the right enemies, spoke the right password, etc. All of this information collectively empowers learners to debug incorrect solutions and arrive at a program that meets the level’s requirements.

Segmentation: The sequence of levels is designed to introduce concepts gradually, starting with the basics of syntax and growing progressively more complex as players move through the game. When a new concept is introduced, it is done explicitly and in relative isolation. Players are given a new item to equip that gives them a new method to use and are put in a level that will require use of the new technique and little else. Then players build up to using the technique in combination with previously learned techniques in later levels. This segmentation and sequencing of the content helps to reduce the cognitive load and thereby make the learning easier.

Modality: None of the key information is presented auditorily. All the sound is background music, sound effects, or silly sound bytes like, “For the win!”. This may mean that an undue burden is placed on learners’ visual systems, wasting their auditory cognitive capacity. The value of the visual presentation of information is that it mimicks the authentic experience of using documentation and your text editor to figure out what to write, and that the visuals can stay constantly present on-screen for checking and re-checking against your code. It might be better to present some hints and scaffolding in auditorily, as this might be useful for highlighting sailient details acutely without requiring students’ continued attention.

Transfer: It is an open and critical question how well this game prepares learners to write programs outside of the game context. All the function calls used in the game are entirely specific to the game context and have no meaning outside it. But calling pre-defined functions, and giving them the correct arguments to achieve your desired end, are indeed skills that programmers must be able to do. Likewise, while loops and variables serve similar purposes in and out of the game. This suggests that the skills learned in the game will likely transfer to outside of the game, but those skills may be insufficient to empower learners to write programs on their own, without learning more about what functions are natively available in their chosen programming language, and perhaps additionally without some coaching on what kinds of problems programming can be used to solve. We might for example expect that a learner playing this game would be able to call the print() function in python to print a variable of interest in their console, but only after being told that the print function exists and that it works similarly to the hero.say() method they have already used.

Synthesis

Overall, CodeCombat appears to foster learning of its desired objectives. The skill goals (labeled 1-4 above) are explicitly required of the player to proceed through the game, and the dispositional goal of desiring to write elegant code is implicitly encouraged by rewarding players for writing concise code. The mechanics provide rich feedback and segment and sequence the content into manageable chunks. The dynamics and aesthetics work together to encourage players to iterate again and again until they arrive at an acceptable solution.

The biggest open question remains, “What can successful players now go out and do?” Since the game never involves writing code to achieve a purpose that directly aligns with a typical programming task, it is unreasonable to assume that learners will thus learn to write rich programs just by playing the game. But the skills they learn by playing will be directly applicable in authentic programming contexts. So perhaps the reasonable conclusion is that playing this game will prepare learners to learn to code more quickly by giving them core skills that they will need when they try to write programs of their own.

Leave a comment