A Lightweight Rule-Based AI Engine for Mobile Games - CiteSeerX

6 downloads 5941 Views 214KB Size Report
development environment and the mimosa programming language for constructing ..... games currently being played on desktop computers over the internet.
A Lightweight Rule-Based AI Engine for Mobile Games Lynne Hall

Adrian Gordon, Russell James

Lynne Newall

University of Sunderland Mimosa Wireless Ltd. University of Northumbria, School of Computing and Technology 63 Galen House, Low Friar Street School of Informatics Sunderland, SR6 0DD, UK Newcastle Upon Tyne NE15UG, UK Newcastle Upon Tyne, NE1 8ST, UK +44(0)191 515 3249 +44(0)191 2303029 +44(0)191 227 3114

[email protected]

[email protected]

ABSTRACT The growth of the mobile gaming market offers considerable potential for the deployment of engaging and compelling games constructed using AI components and techniques. This paper discusses a rule-based approach for constructing lightweight Game AI systems for deployment on mobile devices. The development environment and the mimosa programming language for constructing Game AI components are outlined. A prototype game of Texas Hold’em Poker implemented using this environment is described. Ideas for future work, including the development of games mentors for deployment on mobile devices are briefly presented.

Categories and Subject Descriptors I.2.1 [Applications and Expert Systems]: Games, I.2.5 [Programming Languages and Software]: Expert system tools and techniques I.2.4 [Knowledge Representation Formalism and Methods]: Representations (procedural and rule-based).

Keywords Game AI, Mobile Gaming, Rule-Based Languages, Tools

1. INTRODUCTION The attraction of the mobile device market for software deployment is considerable, with penetration close to 80% for mobile phones in the UK [23] and expected to remain at this level [17]. Gartner reports that the mobile market is continuing to grow with expectations that between 450 and 460 million mobile phones will be sold globally in 2003 [24]. Handheld sales increased by 51% in Europe in 2002, with Palm, who lead the data-centric handheld segment experiencing a 45% growth [5]. Within the phone market, smart phones (e.g. Nokia 3650 and Sony Ericsson P800) continue to provide much of the growth showing the increasing popularity of integrated handheld devices [6]. The prediction is that application development for mobile devices will explode [25]. Industry expectations are that the market will Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. ACE 2004, June 3–5, 2004, Singapore. Copyright 2004 ACM 1-58113-882-2/04/0006 5.00.

[email protected]

be dominated by recreational software, particularly games, with significant growth anticipated in the near future [20]. The Wireless World Forum has issued a report claiming that the mobile games market, with its current value of EUR0.46bn will reach a value of EUR1.65bn by 2006, similar increases are also anticipated in the US and China [9]. The digital media consultancy, Machines That Go Ping [16] suggest that the growth in mobile gaming is largely due to improved hardware, particularly screen displays. In a survey reported in [27] 20% of respondents stated that the games

available on a platform affected their mobile phone selection. Although 78% of mobile game players are under 25, as [14] note on-line gaming is no longer the preserve of adolescent boys, but appeals to both genders [19]and increasingly to a wider age range [21]. The emerging consumer profile of the mobile gamer is of a young adult, having a few minutes spare and wanting to play something simple, but engaging. “Game AI” usually refers to the high-level control elements of computer-based entertainment applications, as opposed to the low level elements such as the rendering of graphical, audio or haptic components of the game. Game AI is receiving increased research attention [29], [18] and is recognized as a mechanism that could aid in the attempt to improve the game playing experience [26]. Game AI has been used in a range of games, from first person shooters [28] to traditional strategy games, such as Go [3]. Game AI essentially encodes behavioural rules that capture knowledge about a particular game domain, and the ‘agents’ that can inhabit it (e.g. game opponents). In all but the simplest of games, behavioural rules that govern the behaviour of entities within the virtual world of a game need to embody complex relationships between large numbers of rapidly changing aspects of the overall game state. Programming these behavioural rules is an acknowledged problem in computer game construction. One of the most significant problems in Game AI construction is that the procedural programming languages such as C, C++ and Java that are typically used in the implementation of computer games are not suitable for implementing large sets of complex behavioural rules. Attempting to construct complex behavioural rules in a language such as C++ tends to result in a raft of impenetrable code involving large numbers of if-then-else constructs, switch, case and loop statements. The programmer is responsible not only for defining the conditions under which a behavioural rule is to be applied, and the action to be taken when it does apply, but must also deal with deciding all of the

circumstances under which to check the game state against the behavioural rule’s pre-conditions. Many of the behavioural rules required for game play will interact with one another in ways which cannot easily be determined a-priori, or in ways which are amenable to static analysis. In general, the result of attempting to construct complex Game AI components using procedural programming techniques will be bloated code which is incomprehensible and virtually unmaintainable, leading to an inevitable increase in development time and requirements for product memory and processing power. The obvious approach to the development of complex intelligent games for deployment on mobile devices might appear to be to adopt a ‘thin client’ strategy, whereby a mobile device connects wirelessly to a remote, already existing Game AI system. However, there are several reasons why this is not the best approach, including cost (most wireless carriers charge for connection by the byte or by the minute), reliability (there are still problems of network coverage and performance on devices [8]), constant connection impact on battery life [6] and the increasing trend for downloadable mobile games, with 80% of the market anticipated to be of downloadable games by 2008 [1]. Creating downloadable games with AI components requires an approach that seeks to address the problems of the constrained nature of mobile devices. In this paper we present the approach of Mimosa Wireless Ltd. to mobile Game AI development. Using rule-based programming languages to implement the AI components of a game is one way of avoiding the pitfalls of procedural programming languages. Section 2 describes rulebased programming languages in general, pointing out their advantages for constructing Game AI systems, as compared with procedural programming languages. Section 3 introduces the mimosa language, which is targeted at producing lightweight game AI components for mobile devices, such as the latest generation of mobile phones. Section 4 describes a development environment for constructing Game AI components in the mimosa programming language, and Section 5 describes a prototype game implemented using this environment, which allows the user to play against expert level opponents in the game of Texas Hold’em Poker. Section 6 discusses the prototype game and presents some suggestions for future work.

2. RULE BASED PROGRAMMING FOR GAME AI Rule-Based programming is based on a simple model of computation in which knowledge is encoded in the form of sets of condition-action pairs known as production rules. The condition part of a production rule represents the pattern which must be matched in order for the rule to be applied, and the action part of the production rule represents the response that is to be made when the rule is applied. In a game application, the condition part of the production rule might involve interrogating the current state of the game, using virtual ‘sensors’; and the action part of the rule might involve some response to the game state, effected via virtual ‘actuators’. Rules might also embody intelligent behavioural knowledge at a much higher level, involving planning actions to enable a game agent to achieve high level strategic goals, for example.

Many rule-based programming languages have been implemented, such as OPS5 [10], CLIPS [13] and Jess [12], for use in a large number of intelligent systems applications, including Expert Systems and Intelligent Software Agents. [30] describes a language called RC++, a rule based extension to the C++ language, that is close in spirit to the work described in this paper, but which is aimed at games console hardware, rather than mobile devices. A program written in a rule based programming language is executed by using a working memory of ‘assertions’ about the state of the world within which the program is operating, and an interpreter, which matches rules to the working memory, and adds to and removes assertions in response to the actions undertaken by rules that have been executed. A program expressed as a set of production rules is entirely declarative; production rules embody no procedural knowledge. It is the responsibility of the interpreter to control the execution of the rules. This is one of the principal advantages of rule-based programming. The programmer can concentrate on producing a discrete body of rule logic, separated from other aspects of the system, by writing a set of modular rules that are easily understood, easily extended, and easily modified.

3. THE MIMOSA PROGRAMMING LANGUAGE The mimosa programming language is a rule-based programming language, aimed specifically at implementing intelligent applications, including Game AI applications, on mobile devices such as mobile phones, ‘smartphones’, and PDAs. Syntactically, the language borrows heavily from previous rule-based programming languages such as the OPS family of languages [4]. Working Memory assertions in this language are defined using the ‘literalize’ construct of the language (borrowed from OPS): (literalize player

:string name :string sex :integer age)

This states that a player will consist of “name”, “sex” and “age” data elements. Each of them is typed, name and age are strings, age is an integer. The other possible data type is “atom” (e.g. the default). An “atom” is just a unique symbolic value. Although “real” datatypes exist in the language, they are not as yet implemented in the development environment (many current mobile devices do not support floating point numbers). To actually create an instance of a predefined literal, the make construct is used: (make player ^name “jim” ^sex “male” ^age 55) The caret symbols proceed one of the attribute names of a predefined literal, such as “name” or “sex. The other essential component of programs written in this language is provided by a set of inference rules. These are expressed using the “p” construct (for “production rule”). The general syntax is as follows:

(p ... Æ ... )

Figure 1 shows the general architecture of this development environment.

Here is an example, taken from the famous “monkeys and bananas” planning problem: (p mb1 (goal ^g-status active ^g-type holds ^g-obj [w]) (object ^o-name [w] ^o-at [l] ^o-on ceiling) -->

Figure 1. The Development Environment

(make goal ^g-status active ^g-type move ^g-obj ladder ^g-to [l])) In this example the literal “goal” has attributes “g-status”, “gtype”, and “g-obj”, the literal “object” has attributes “o-name”, “o-at”, and “o-on”. The elements in square braces represent variables. To paraphrase this rule in English: “If you have a currently active goal which is to hold some object w, and if that object w is currently found on the ceiling at some location l, establish a new active goal to move the ladder to the location l”. Actions in this language are limited to make (create a new fact), modify (modify an existing fact), remove (remove an existing fact), and bind (establish a variable binding for later use). However, the language is extensible, by use of what are termed “external functions”. External functions allow a program written in mimosa to execute arbitrary pieces of code written in the underlying language of the rule interpreter. External functions can be used as actions in their own right, or can be embedded within make, modify or bind constructs. They are typically used for interacting with the GUI of a system, accessing network resources, interacting with external systems, or, in the case of Game AI, they can be used to interrogate or change the current game state, by operating as virtual sensors or actuators. An example of this use is shown in Section 5.

4. A Development Environment for Game AI Conventionally, rule-based programming environments are thought to require powerful computing environments, with fast processors and lots of memory. However, most of this power is actually required in the process of constructing rule-based systems. Once they are constructed, they can actually operate in much more constrained environments, including those provided by the current generation of mobile devices, such as mobile phones. Mimosa Wireless Ltd. (http://www.mimosawireless.co.uk) has built a development environment in which intelligent systems, including Game AI components, can be constructed in a powerful workstation environment, and then easily ported to a range of mobile devices, of various categories.

MADE (Mimosa Application Development Environment) is an IDE which can be used for the rapid development of rule-based programs, written in the mimosa programming language, using a prototyping methodology. It is written entirely in Java. Once a system has been developed using this environment, the knowledge base, in the form of production rules and facts, can be extracted. This knowledge base can then be combined with one of a number of MEEs (Mimosa Execution Evironments), each of which is essentially a lightweight interpreter for the mimosa language, targeted at a particular class of mobile device. MEEs have been constructed in a variety of programming languages (in dialects of java and C++) for devices running various mobile device operating systems (including PalmOS, Symbian, and WinCE). As an illustrative example, the MEE written in J2ME (a language supported by many of today’s mobile phones) produces an unobfuscated .jar file of around 15k in size (without the knowledge base itself). Essentially, the MEE interpreters implement the well-known rete algorithm for interpreting rule-based programs [11]. This algorithm operates by turning the rule base of a program into a network, with rules which share patterns also sharing parts of this network. The algorithm efficiently matches rules by storing partial matches between match/execute cycles of the interpreter. The MADE system generates the rete network, and turns it into a small, efficient implementation by linearising it, and turning each node in the network into a 16 bit integer. The rule base therefore becomes a relatively small block of memory, suitable for a mobile device. The MEE interpreters essentially operate over this block of memory. MADE/MEE has been used to create a number of intelligent systems for mobile devices, including Expert Systems [22], Intelligent Software Agents [15], and Game AI components, as described in the next Section.

5. A MOBILE GAME: TEXAS HOLD’EM POKER Poker playing “is a game of imperfect information, where multiple competing agents must deal with probabilistic knowledge, risk assessment, and possible deception” [2]. Poki, a program for playing poker, has been developed by [2] with some success. However, its originators believe that a system based on

expert rules is unlikely to produce a world-class level of play, because covering every relevant situation in sufficient detail is not feasible. They believe that dynamic, adaptive, computer-oriented techniques will be essential to compete with the best human players. Others have concluded that human poker rules cannot be formalised, and so cannot easily be implemented using expert rules [7].

Figure 2 shows the game interface, running on a J2ME device emulator.

Texas Hold’em Poker is a variation of poker which is heavily reliant upon the player’s ability to reason using very little information (for example, the player playing first in the first round of betting has to make a decision based entirely on seeing only two cards – his or her own two ‘hole’ cards.). The subtleties and complexity of Texas Hold’em Poker strategy make it an ideal candidate for the implementation of Game AI using rule-based programming. A number of applications and games tutors for Texas Hold’em Poker have already been developed, but game players are currently restricted to their computer location. A version of this game targeted at mobile devices has been produced using the development environment described in the previous section. The MADE environment was used to generate a set of rules which embody poker stategy, and are used to provide intelligent opponents for the user playing the game of Texas Hold’em Poker on a mobile device. The poker strategy rules were developed and tested using MADE on a powerful workstation. The poker rules interacted with a ‘dummy’ game environment, implemented in java. Here is an example of a typical poker strategy rule:

Figure 2. The Texas Hold’em Poker Game Interface

(p getoutnopairnodraw (hand ^playersleft [nplayers]) (goal ^arg1 actpostflop ^arg2 [x] ^status done) (player ^seat [x] ^hasfolded false ^besthandpostflop < 2 ^card2rank < 13 ^flushdraw < 4 ^straightdrawcards < 4) Æ (modify 1 ^playersleft (minus [nplayers] 1)) (modify 3 ^actedpostflop yes ^hasfolded true) (modify 2 ^status done) (sendGameStatusMessage [x] fold))

What this rule is actually saying is that if a player has less than a pair after the ‘flop’ (where three community cards, which all players can incorporate into their hand, are revealed), they have no aces or kings, and they have no realistic prospect of drawing to a flush (seeing cards to give them five cards in the same suit) or a straight (five consecutively numbered cards) then they should fold their hand. The interesting part of this rule is the last of the actions, involving the function sendGameStatusMessage. This is an external function, which is not part of the mimosa language, but has been defined to be used within it for this particular application. External functions are used to extend the functionality of the language, allowing it to interact with arbitrary code outside of the rule based aspects of the system. In this case the sendGameStatusMessage function is used to send a message to the game interface, telling it to indicate that this particular player has folded their current hand.

The game interface and the mechanism for representing the game state were developed entirely separately from the Game AI component. In the final J2ME implementation of the system the J2ME version of the rule-base execution environment exists on a separate execution thread in the application, and communicates with the game state and the interface by means of external functions such as sendGameStatusMessage, as shown above. As well as external functions which inform the game engine about requested changes to the game state, there are also external functions which interrogate the current game state. For example, the AI engine interrogates the Game engine when it is the turn of the human player to play. This external function returns the play that the human player has made (e.g. check, bet, call, raise, fold, etc). Figure 2 shows the Poker Game AI engine running on an emulator for the J2ME platform. In order to port this game AI to other platforms, such as Symbian or PalmOS, all that is required is for the external functions to be re-written in the appropriate development language, since MEEs to handle the interpretation of the rule based aspects of the software, have already been implemented for these platforms. Typically, this has proven to require a fairly straightforward function-for-function re-write of the external functions. Because the AI component of the system is entirely separate from the Game engine itself, the AI can be modified, extended or completely replaced without this having any effect on the game engine code at all. This greatly assisted in the development of the game, since the AI could gradually be implemented and tested to

deal with successive stages of a typical Texas Hold’em Poker game (for example, there are separate, independent rules to deal with opening plays, post flop, post turn, post river, showdown etc.).

6. DISCUSSION The market for mobile games is expanding rapidly, with handset penetration approaching 100% in many markets in the developed world. There is a growing need for innovative, compelling game applications. Improving Game AI is an important way of improving the general game playing experience. Tools are required which will enable sophisticated, reliable, efficient AI engines to be rapidly developed for all genres of games. One approach to this problem is so-called rule-based AI, where a knowledge base in the form of facts and rules is developed alongside the game engine, but essentially separate from it. Tools such as that described in [30] can deliver rule based AI engines to powerful games consoles, but until now, mobile devices such as the latest generation of mobile phones, have not been considered powerful enough to run sophisticated AI engines. Conventionally, Rule-based programming environments are thought to require powerful computing environments, with fast processors and lots of memory. However, most of this power is actually required in the process of constructing rule-based systems. Once they are constructed, they can actually operate in much more constrained environments, including those provided by the current generation of mobile devices, such as mobile phones. In this paper we have shown that powerful workstation environments are only needed to develop rule-based AI engines. Once they are developed, they can run on much less powerful hardware, such as mobile phones and PDAs. Using the MADE and MEE tools with the mimosa language, intelligent applications, including lightweight Game AI engines, can be delivered to a range of mobile devices. An AI engine for a turnbased strategy game, Texas Hold’em Poker, has been developed using this approach. It is expected that many other such strategy games would be amenable to this same approach. It would also be relatively straightforward in future to produce arcade style games using this approach, in which each separate ‘enemy’ could be implemented as a separate thread, each of which would represent an intelligent agent existing autonomously within a game environment, and each of which could be developed entirely separately from each other, and from the game environment itself. Texas Hold’em Poker is one of the most popular interactive card games currently being played on desktop computers over the internet. However, many potential players are unclear of the rules and strategies that need to be employed to play this game successfully. It is hoped that the approach described in this paper could be used to construct intelligent agents which could play the role of ‘mentors’, offering advice and guidance to the player of strategy games. This could prove to be particularly important to improving the playability of mobile games, where in general the means by which the player can interact with the game environment are fairly impoverished. Towards this end, we are modifying the Poker application described in this paper to provide an intelligent tutoring

component, that will help a player to learn aspects of the strategy of poker while she is actually playing the game. The tutoring agent will observe the performance of the novice player, effectively ‘looking over her shoulder’, offering advice to her while she plays the game against expert opponents. Both tutor and expert components will have been constructed, separately, using the MADE/MEE toolset.

7. CONCLUSIONS The mobile gaming market offers considerable potential for the development of compelling and engaging games. Games AI has been seen to improve game play on consoles and PCs. However, few games incorporating AI components have been developed for mobile platforms due to their constraints of limited memory and processing power. In this paper, we have discussed the development of a rule-based system for playing poker on mobile devices. This was developed using a powerful workstation and then deployed on mobile devices using Mimosa’s rule-based intelligent system development environment, programming language and execution environment. Experimentation with this game shows the potential of AI for mobile devices for both playing and learning games.

8. ACKNOWLEDGMENTS Our thanks to Simon Oram, Digital Media Network, for providing the graphics for the Poker application.

9. REFERENCES [1] Analysys. Mobile games revenue to reach EUR3 billion in 2008, Analysys, 2004. [2] Billings, D., Davidson, D., Schaeffer, J. and Szafron, D. The challenge of poker. Artificial Intelligence, 134, 1-2 (Jan. 2002), 201-240. [3] Bouzy, B. and Cazenave, T. Computer Go: An AI oriented survey. Artificial Intelligence, 132, 1 (2001), 39-103. [4] Brownston, L., Farrell, R., Kant, E. and Martin, N. Programming Expert Systems in OPS5: An Introduction to Rule-Based Programming. Addison-Wesley, Reading, MA, 1985. [5] Canalys. Canalys research release 2003/71, Canalys, 2003. [6] Canalys. Mobile analysis: A choice of one or two devices, Canalys, 2001. [7] Dahl, F.A. Challenge to Formal Modeling of Poker and Bridge. Games and Economic Behavior, 40, 1 (2002), 147149. [8] Evans, B.G. and Baughan, B. Visions of 4G. IEE Electronics and Communication Engineering Journal, 12, 6 (2000), 293303. [9] Flannery, R. Web of Wealth, Forbes.com, 2003. [10] Forgy, C.L. OPS5 User's manual, Department of Computer Science Technical Report, Carnegie-Mellon University, 1981. [11] Forgy, C.L. Rete: A Fast Algorithm for the Many Pattern/Many Object Pattern Match Problem. Artificial Intelligence, 19 (1982), 17-37.

[12] Friedman-Hill, E.J. Jess, The Java Expert System Shell: Version 5.2, Sandia National Laboratories, Livermore, CA, 2001. [13] Giarratano, J.C. CLIPS User's Guide, Technical Report, NASA, Lyndon B. Johnson Space Center, Information Systems Directorate, Software Technology Branch, 1993. [14] Griffiths, M.D., Davies, M.N.O. and Chappell, D. Breaking the stereotype: the case of online gaming. Cyberpsychology & Behavior: The Impact Of The Internet, Multimedia And Virtual Reality On Behavior And Society, 6, 1 (Feb. 2003), 81-91. [15] Hall, L., Gordon, A., Newall, L. and James, R. A Development Environment for Intelligent Applications on Mobile Devices, Technical Report, Mimosa Wireless Ltd., Newcastle, UK, 2003. [16] Hermida, A. Mobile gaming 'set to explode', BBC News Online, 2003. [17] Kacker, A. New value drivers for the mobile business Analysys Resources: Industry Comment, 2002. [18] Laird, J.E. and van Lent, M. Human-level AI's Killer Application: Interactive Computer Games. AI Magazine, Summer (2001), 1171-1178. [19] Me, A. and Sicat, M. Statistics on Women and Men and ICT: The ECE Region, United Nations Economic Commission for Europe, 2003. [20] Metzler, J. 'Gamemaking God' Turns to the Small Screen But will his sports games make it in Japan, [email protected], 2003.

[21] MGAIN. Mobile Entertainment: Challenges and Possibilities - Consumer Demographics, 2003. [22] Newall, L., Hall, L., Paley, G., James, R. and Gordon, A., Mobile Mentoring for Diabetes in Proceedings of ICICTE 2004, (Samos, Greece, July 1-6, 2004). [23] Peters, S. Technology and adoption: Mobile services, The Teleconomy Newsletter, 2002. [24] Reuters. Mobile market heads for new high, ZDNet Uk, 2003. [25] Review, C.B. Applications on the move, Computer Business Review On-line, 2001. [26] Schaeffer, J. and van den Herik, H.J. Games, computers, and artificial intelligence. Artificial Intelligence, 134, 1-2 (Jan. 2002), 1-7. [27] Telecomworldwire. Mobile phone survey shows that games could affect choice of handset (In-Fusio and Orange survey), Telecomworldwire, 2002. [28] van Lent, M., Laird, J.E., Buckman, J., Hartford, J., Houchard, S., Steinkraus, K. and Tedrake, R., Intelligent Agents in Computer Games. in National Conference on Artificial Intelligence, (Orlando, FL, 1999), 929-940. [29] Woodcock, S. Game AI: The State of the Industry 2001-2 Game Developer Magazine, 2002. [30] Wright, I.P. and Marshall, J.A.R., RC++: a rule-based language for game AI. in First International Conference on Intelligent Games and Simulation (GAME-ON), (2000).