Learning Combat in Nethack
Total Page:16
File Type:pdf, Size:1020Kb
Proceedings, The Thirteenth AAAI Conference on Artificial Intelligence and Interactive Digital Entertainment (AIIDE-17) Learning Combat in NetHack Jonathan Campbell, Clark Verbrugge School of Computer Science McGill University, Montreal´ [email protected] [email protected] Abstract We evaluate our learning-based results on two scenarios, one that isolates the weapon selection problem, and one that Combat in roguelikes involves careful strategy to best match is extended to consider a full inventory context. Our ap- a large variety of items and abilities to a given opponent, and proach shows improvement over a simple (scripted) baseline the significant scripting effort involved can be a major bar- rier to automation. This paper presents a machine learning combat strategy, and is able to learn to choose appropriate approach for a subset of combat in the game of NetHack.We weaponry and take advantage of inventory contents. describe a custom learning approach intended to deal with A learned model for combat eliminates the tedium and the large action space typical of this genre, and show that it is difficulty of hard-coding responses for each monster and able to develop and apply reasonable strategies, outperform- player inventory arrangement. For roguelikes in general, this ing a simpler baseline approach. These results point towards is a major source of complexity, and the ability to learn good better automation of such complex game environments, facil- responses opens up potential for AI bots to act as useful de- itating automated testing and design exploration. sign agents, enabling better game tuning and balance con- trol. Further automation of player actions also has advantage Introduction in allowing players to confidently delegate highly repetitive or routine tasks to game automation, and facilitates players In many game genres combat can require non-trivial plan- operating with reduced interfaces (Sutherland 2017). ning, selecting attack and defense strategies appropriate to Specific contributions of this work include: the situation, while also managing resources to ensure fu- • ture combat capability. This arrangement is particularly and We describe a deep learning approach to a subset of Net- notoriously true of roguelikes, which often feature a wide Hack combat. Our design abstracts higher-level actions to range of weaponry, items, and abilities that have to be well- accelerate learning in the face of an otherwise very large matched to an also widely varied range of opponents. For low-level action set and state space. game AI this becomes an interesting and complex problem, • We apply our design to two NetHack combat contexts, requiring the system to choose among an extremely large set considering both a basic weapon selection problem and an of actions, which likewise can be heavily dependent on con- extended context with a full inventory of combat-related text. As combat behaviours rest on basic movement control items. and state recognition, the combined problem poses a par- • Experimental work shows the learned result is effective, ticularly difficult challenge for learning approaches where generally improving over a simple, scripted baseline. De- learning costs are a factor. tailed examination of learned behaviour indicates appro- In this work we describe a machine learning approach priate strategies are selected. addressing one-on-one, player vs. monster combat in the paradigmatic roguelike NetHack. We focus on the core com- Related Work bat problem, applying a deep learning technique to the basic problem of best selecting weapons, armour, and items for There has been much recent interest in applying reinforce- optimizing combat success. To reduce the learning complex- ment learning to video games. Mnih et al. notably proposed ity and accelerate the learning process, we build on a novel, the Deep Q-Network (DQN) and showed better than human- abstracted representation of the action set and game state. level performance on a large set of Atari games, includ- This representation limits generality of the AI, but allows it ing Breakout, Pong, and Q*bert (2013; 2015). Their model to focus on learning relevant combat strategy, applying the uses raw pixels (frames) from the game screen for the state right behaviour in the right context, and relying on well- space, or in a formulation proposed by (Sygnowski and understood algorithmic solutions to lower-level behaviours Michalewski 2017), game RAM. We use the same DQN such as pathing. approach here, but with a hand-crafted game state and ac- tion set to speed up learning, given the much larger ba- Copyright c 2017, Association for the Advancement of Artificial sic action set and complex state space typical of rogue- Intelligence (www.aaai.org). All rights reserved. likes. Kempka et al. demonstrated the use of deep Q-learning 16 on the 3D video game Doom, similarly using visual in- 2017, with the vast majority of failures arising from monster put (2016), with applications by (Lample and Chaplot 2017). combat (NAO public NetHack server 2017). Narasimhan et al. use a deep learning approach to cap- Items are also randomly placed throughout the dungeon. ture game state semantics in text-based Multi-User Dungeon As mentioned above, there are many different item types: (MUD) games (2015). weapons (melee and ranged), armor (helms, gloves, etc.), Abstracted game states have been previously studied for scrolls, potions, wands, and more. Each item can be one RTS games (Uriarte and Ontan˜on´ 2014) as well as board of blessed, uncursed or cursed (referred to as BUC status); games like Dots-and-Boxes (Zhuang et al. 2015), in order to blessed items are more powerful than their uncursed coun- improve efficiency on otherwise intractable state spaces. We terparts while cursed items may cause deleterious effects. use an abstracted state space here for the same purpose. Further, each item is made of a certain material (iron, silver, RL approaches have also been applied to other, more tra- wood, etc.); materials interact with the properties of certain ditional types of games. The use of separate value and policy monsters (e.g., many demons are particularly susceptible to networks combined with Monte-Carlo simulation has been silver weapons). Weapons and armor can also have an en- shown to do very well on the game of Go (Silver et al. chantment level (positive or negative) which relates to their 2016), while using RL to learn Nash equilibriums in games damage output, as well as a condition based on their material like poker has also been studied (Heinrich and Silver 2016). (wood items can be burnt, iron items corroded, etc.). Competitions also exist for general game AI, such as the Another important mechanic of NetHack is resource man- General Video Game AI Competition (Liebana et al. 2016). agement. Player turns are limited by food availability, so ef- A small handful of heuristic-based automated players ex- ficient exploration and shorter combats are ideal; items are ist for NetHack. The ‘BotHack’ player was in 2015 the first also scarce, so their conservation for stronger monsters is bot (possibly only so far) to finish the entire game. This also advised. We do not deal with these issues in this paper. bot relies on hard-coded strategies for all NetHack mechan- ics. For combat, it uses movement-based strategies like lur- Modifications ing monsters into narrow corridors or keeping close to the We use a modified version of NetHack to allow for exper- exit staircase to have an option to retreat (Krajicek 2015a; iments that focus singularly on combat and item selection. 2015b). It also prefers to use ranged weapons against mon- Game features that might confound experiment results were sters with special close-range attacks and abilities. Although disabled, including starvation, weight restrictions, and item the BotHack player has beaten the entire game once (no identification; we leave these issues for future work. small feat), its average success rate is unclear. An auto- The ZMQ socket library is used as a basic interface be- mated player also exists for Rogue (a 1980 predecessor to tween our code and the NetHack game (Hintjens 2011). NetHack) called Rog-O-Matic. It uses an expert-system ap- Through ZMQ we send the keyboard character(s) corre- proach, although simple learning is enabled through a per- sponding to a chosen action, and NetHack sends back the sistent store (Mauldin et al. 1984). currently-visible game map and player attributes/statistics (i.e., all information that is otherwise visible to a player via Environment the typical NetHack console interface). After each action is taken, the player’s inventory is also queried to ensure an We use NetHack for our combat environment, an archetypal accurate state. Using ZMQ sockets allows for much faster roguelike made in the late ’80s that is still popular and get- gameplay than the typical approach of terminal emulation. ting updates to this day. A turn-based game, it takes place on a 2D ASCII-rendered grid, with a player avatar able to move Learning Approach around, pick up items, fight monsters, and travel deeper into the dungeon by issuing different keyboard commands. We use a Deep Q-Network for our learning algorithm, de- In every level of the dungeon lurk devious monsters – tailed below, as well as two trivial baseline algorithms that some having brute strength, others possessing nightmarish approximate a beginner player’s actions. abilities such as causing the player to turn to stone, split- ting in two every time the player tries to attack, or shoot- Baseline algorithms ing death rays. A player must develop strategies for each To compare our deep Q-network approach, we present two particular monster in order to survive. These strategies typi- simple algorithms for combat in our NetHack environment. cally involve the choice of a specific weapon to attack with, The first baseline equips a random weapon from its inven- armor to equip, and/or the use of special scrolls, potions, tory at the start of each combat episode, then moves towards wands, spells, and other miscellaneous items.