# Trainyard is NP-Hard

#### Abstract

Recently, due to the widespread diffusion of smart-phones, mobile puzzle games have experienced a huge increase in their popularity. A successful puzzle has to be both captivating and challenging , and it has been suggested that this features are somehow related to their computational complexity [5]. Indeed, many puzzle games – such as Mah-Jongg, Sokoban, Candy Crush, and 2048, to name a few – are known to be NP-hard [3, 4, 7, 10]. In this paper we consider Trainyard: a popular mobile puzzle game whose goal is to get colored trains from their initial stations to suitable destination stations. We prove that the problem of determining whether there exists a solution to a given Trainyard level is NP-hard. We also provide an implementation of our hardness reduction. 1 Introduction The tension between human beings and machines in railroad building dates back to over a century ago, as the famous tale of John Henry testifies. According to the story, John Henry was a steel-driving man who challenged the efficiency of steam drill machines in a competition. Eventually John prevailed, reportedly outperfoming the rival machine in a contest that lasted more than one day. He unfortunately died of exhaustion shortly after his feat and is now remembered by a statue and a plaque next to the entrance of the Big Bend railroad tunnel in West Virginia. Here, we once again consider a (virtual) challenge between humans and machines in railroad building, except that this time the human ingenuity is put to the test instead of their brute strength. We do so by studying the computational complexity of Trainyard, a smart-phone game where the player is responsible for suitably building railroad tracks. In the words of its author, Trainyard is " a grid-based logic puzzle game where the goal is to get each train from its initial station to a goal station. Every train starts out a certain colour, and most puzzles require the player to mix and merge trains together so that the correctly coloured trains end up at the right stations. " [13]. The game was conceived in 2009 and was first released for iPhones in 2010. In less than five months it climbed the Apple App Store charts becoming the most downloaded application in Italy and the United Kingdom, and the second most downloaded in the United

DOI: 10.4230/LIPIcs.FUN.2016.2

#### 12 Figures and Tables

Showing 1-10 of 15 references

## Sokoban is pspace-complete

• Joseph Culberson
• 1998