Testing real-time artificial intelligence: an experience with Starcraft c game Cristian Conde, Mariano Moreno, and Diego C. Martínez Laboratorio de Investigación y Desarrollo en Inteligencia Artificial Universidad Nacional del Sur, Bahia Blanca, Argentina mail@cristianconde.com.ar, marianomoreno3@hotmail.com, dcm@cs.uns.edu.ar, WWW home page: http://lidia.cs.uns.edu.ar/aigames Abstract. In this paper we describe the structure and behavior of an artificial intelligence bot capable of playing Starcraft. It was developed to participate in the AIIDE 2010 Starcraft Competition. Keywords: artificial intelligence, real time strategy games 1 Introduction Games are a subject of interest in Artificial Intelligence almost since the beginning of AI as a computer science discipline. Even more, complex game-related problems were solved by AI techniques before the popularization of videogames as an entertainment product [5]. Nowadays, a game genre that is very interesting in the AI field is simulation, and in particular real-time strategy (RTS) games. These games are more complex than traditional games, with several events occurring simultaneously within a dynamic environment. Basically, RTS games are simplified military simulations where the player must defeat the adversary by commanding virtual troops into a battlefield in real time. The production and improvement of troops is sustained by a simple self-contained economic model, usually based on the gathering of resources in the terrain, that can be exchanged by military units. In this game genre, player s reaction is supposed to be fast, and hence there is a limited time for reasoning [2]. There are several AI research areas that are very relevant to RTS games, such as reactive behavior, planning, collaboration and teamwork modeling, spatial and temporal reasoning, knowledge acquisition and learning, just to mention a few [4]. We are interested in artificial intelligence techniques suitable to be applied to real-time strategy games. Our line of research is mainly focused in the study of formalisms for knowledge representation and reasoning in order to achieve strategic thinking and planning in dynamic domains. 2 Real Time Strategy Testbeds As remarked in [2], most commercial RTS games lack of AI interfaces and then these systems cannot be used to conduct real-time AI research. Fortunately, there
are a few exceptions. In 2002, the University of Alberta launched a programming project called Open Real Time Strategy, or simply ORTS [1]. It is a programming environment for studying real-time AI problems such as pathfinding, dealing with imperfect information, scheduling and planning in the domain of RTS games. ORTS is a full game engine (licensed under GNU Public License), with a clientserver architecture where the server simulates the world and provides information to its clients. There is no predefined low-level behavior, so the client is responsible for every decision in the game, including basic pathfinding. In 2006, the first ORTS competition was held prior to Artificial Intelligence and Interactive Digital Entertainment - AIIDE 2006, with subsequent editions in 2007, 2008 1 and 2009. In 2010, Expressive Intelligence Studio at University of California (Santa Cruz), organized a real-time strategy AI competition using the commercial game Starcraft. The competition was hosted by AIIDE 2010. Bots for Starcraft can be developed using the Broodwar API, which provides hooks into the game. A C++ interface enable developers to query the current state of the world and issue orders to units. The competition consisted of four tournaments with different AI challenges. Basically the difference is about troops and terrain restrictions. The most challenging category is Tournament 4, a fully functional Starcraft match with fog of war. The bot must decide what to do in almost every aspect of the game: building locations, balance of troops according to their properties, technology research, group formations and general strategy. As expected, these decisions are supposed to be intelligent enough to seek the final victory. Our bot was built to play Tournament 4. It is a modest intelligent agent, focused in low-level artificial intelligence, setting the base for further research, as described in the following sections. 3 Our Starcraft bot The intelligent bot is developed using the BroodWar Application Programming Interface (BWAPI) 2, an open source C++ framework for creating AI modules for Starcraft Broodwar. Our particular bot for AIIDE 2010 was called Manolobot 3. BWAPI is used to sense the environment and to issue orders to individual units. It only reveals to AI modules the information that is normally visible to human players, which is considered a fair position to avoid cheating. Manolobot is formed by two main modules, Unit Manager and Strategy Manager. These modules are able to react to specific events on the game, for instance: onunitshow: triggered when a unit is visible on the map. onunitcreate: triggered when a new unit is created. onnukedetect: triggered when a nuclear launch was detected. These events (probably) require a process of decision making about the ongoing game. Hence, specific functions are invoked in response to these events. Modules are explained in the following sections. 1 We participated in that edition with an intelligent bot called LIDIABot. 2 http://code.google.com/p/bwapi 3 http://code.google.com/p/manolobot
3.1 Strategy Manager The Strategy Manager decides which are the next goals to pursuit, given the situation in the game. Goals are divided into several stages, according to the common way of playing. 1. Gathering: creation of workers to gather minerals at an acceptable rate. 2. Defense: enables the construction of basic military buildings. 3. Tech Upgrade: enables the construction of advanced buildings and the starting of research activities (siege mode in tanks, weapons upgrade, etc). 4. Draft: battle companies are defined, based on diversity of troops. 5. Conclusive: enables de construction of other buildings (as starports and science lab). The construction of an additional base is considered. Stages are sequential and the transition between stages is determined by certain gameplay parameters. However, the goals established in some stages may be still active in subsequent stages. For example, in every stage the gathering of resources continues as they are available. 3.2 Unit Manager The Unit Manager captures the required low-level intelligence. It decides the order in which goals must be completed and the selection and location of buildings, as explained below. Exploring the world. A special worker is selected to be assigned to exploration tasks. The Unit Manager issues order to this scout, who goes around the map searching for enemies and resources. The scout is an expendable unit, and it is expected to be killed at some point. Scouts are sent in a regular fashion. If vultures are available, one of them can be selected as a scout. Setting up the neighborhood. The location of buildings is a classic low-level problem of RTS games. It requires a terrain analysis to identify obstacles, such as mountains, mines and other buildings. The type of the new building must also be considered as it influences the general distribution. Some buildings will produce new units nearby and then enough space must be available. Other buildings are just required for city growing, as depots (houses or farms in other games). Bunkers and defense turrets are better situated in places where the enemy is likely to attack. Manolobot builds depots in the borders of the map, leaving free space in the center of the base area. For the rest of the buildings, Manolobot searches for available space using a spiral search algorithm starting from the central base. The terrain analysis is made using the Broodwar Terrain Analyzer (BWTA) Library 4. In Figure 1, the border of a region is marked with green lines. Red lines identify corridors, or hallways, in the terrain. This is later used to decide on bunker positions. 4 http://code.google.com/p/bwta
Fig. 1. Hallway areas identified in terrain analysis Logistic support. The Unit Manager organizes the gathering of resources, minerals and gas. It prioritizes minerals over gas, since the former is required more often than the latter. Workers are balanced according to this prioritization. Also, when a building or a combat unit requires repairs, the Unit Manager select workers for this task. Group formations. Group formation is one of the most important AI aspects in RTS games. The Unit Manager makes groups of troops, called here companies, and the group of bunkers. There are two kind of companies: Attack and Defense. A third company, the Airborne, was partially designed but not included in the final bot. Fig. 2. A line of defense
Group of Bunkers. The line of defense is formed by three bunkers, two missile turrets and three siege tanks. The location is selected according to some information provided by the BWTA Library. This library identifies chokepoints, a part of a region that is a possible connection to another region in the map. Hence, it is a potential enemy entry zone. The Unit Manager calculates the correct orientation of the line of bunkers and turrets. In Figure 2, a complete line of defense is shown. This line is facing to a hallway, as expected. Attack Company. It is initially formed by marines and medics, but as the game advances, tanks, science vessel and goliaths are added. Companies are commanded by one of its members, according to its inner composition. The commander choses a target and leads the way, and it is used as a pivot unit for group formation. The selection of the commander is made according to available troops nearby. It may be a tank or a marine and formations follows concentric arcs, with (from center to periphery) tanks, goliaths, marines and medics, if available. When no tanks or marines are nearby, the company goes back to a designated area close to the base. In Figure 3, an initial attack company is shown. Some decorations are added for debugging purposes: marines are marked with red rectangles, and the commander is marked with a white circle. Troops in the rear front are medics, ready to heal wounded marines. Companies are sent to attack buildings. There is a previously defined safe meeting-point, where the company may retreat in order to acquire reinforces. Manolobot sends new units to this point. Defensive Company. This unit is stationed in the base and it is formed by marines, medics and ghosts. Enemies are chosen as they enter inside the perimeter of the base. Fig. 3. An early attack company
4 Conclusions Manolobot is capable of winning games against the built-in Starcraft bot. We decided to apply a defensive, conservative strategy, and focus the work in an ordered process of growth. We know this strategy is not necessarily optimal in a regular competition, where opponents sometimes use excessive rush of troops, but we are most interested in intelligent behavior than in trophies. The development of a Starcraft bot is a very challenging task, since there are several AI problems to solve, of different nature. In contrast to ORTS platform, some low-level AI problems are already solved, such as pathfinding. This allows for deeper elaborations on the intelligence of the bot, by focusing in high-level strategy, which is desired in our line of research. Even then, there are different issues of varied complexity that must be addressed. For space reasons these issues cannot be technically described here, but some remarks can be done. 1. Micro-management requires specific AI techniques. We use an algorithm to manage workers and its goals (mineral and gas mining, building repairs). Troop formations uses an algorithm based on the proximity of troops and a pivot unit to define orientation and topology of formations. A lot of time is required to solve this problems before addressing macro-strategy. 2. High-level strategy must be adaptive. Although there is a general strategic plan, the intelligence of the opposing bot may vary and then some adjustments to the current strategy must be made. This is specially important in competitions, since several games are played with different bots. We choose to follow a general strategy as described before in the Strategy Manager, but some improvements must be made. As intended, most of the low-level AI problems were addressed and successfully solved in Manolobot. This was the first step in an extensive line of research. Our intention is to connect the Starcraft bot with a formalism of nonmonotonic reasoning for high-level planning. This allows a dynamic process of decision making. We are specially interested in DeLP-Defeasible Logic Programming [3]. A DeLP server is already available to infer decisions from a knowledge base. Unfortunately, the development of a bot is sometimes delayed by several bugs in the Broodwar API that leads to application crashes. References 1. Buro, M.: Orts: A hack-free rts game environment. In: Proceedings of the Third International Conference on Computers and Games. pp. 151 161 (2002) 2. Buro, M.: Real time strategy. new ai research. In: Proceedings of the International Joint Conference on AI 2003. pp. 1534 1535. Acapulco, Mexico (2003) 3. García, A.J., Simari, G.R.: Defeasible logic programming: An argumentative approach. Theory and Practice of Logic Programming 4(1-2), 95 138 (2004) 4. John Laird, M.v.L.: Human-level ai s killer application: Interactive computer games. In: Proceedings of the 17th. AAAI National Conference on AI 2000 and 12th Ann. Conf. Innov. Appl. AI. pp. 1171 1178. Texas, US (2000) 5. Shannon, C.: Programming a computer playing chess. Philosophical Magazine 41(314) (1950)