fuzzy logic in gaming

Upload: frisco-danconia

Post on 03-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Fuzzy Logic in gaming

    1/6

    Fuzzy Logic in Agent-Based Game DesignY ifanLi, Petr Musilek and Loren Wyard-Scott

    Department of Electrical and Computer EngineeringUniversity OfAlbertaEdmonton, AB T6G 2V4,Canadayifan, mnsilek, [email protected]

    Abstracf- The underlying artificial intelligenceo f computergames is constantly in need of improvement to meet the ever-increasing demands o f game players. This paper discusses bowintelligent agents and fuzzy logic can help increase the qualityand amonnt of a computer games most important element:interaction. The applicationsof fuzzy logic in behavior design areillustrated in detail through implementation of an arcade-stylegame.Keywordr -Agent, BDI, Fuzzy Control, Combs, Game

    I. INTRODUCTIONWhat is a computer game? In his influential book, TheArt of Computer Game Design [I], Crawford identifies four

    iimdamental elements of computer games: representation,interaction, conflict, and safety. A Game presents a virtualreality in which players enjoy interacting with the virtualbeings and taking challenges presented by the environmentwithout facing any physical risk. Of the four elements,interaction is considered the most important. The advent ofcomputers has brought forward an unprecedented interactivecapability, making computer games truly different fromconventional games.Intelligent agents [Z] and fuzzy logic [3] are twotechniques that can help increase the quality of interaction ingames. Agents provide a new architecture of gamedesignthatleadstomore flexible interaction, andfuzzycontrol affordsapractical method for generating subtle behavior.As defined in [Z], an agent is an autonomous softwareentity that has its own goals, sensory inputs, reasoning,reaction, and social ties. In the agent-oriented approach togame design, the game creatures are modeled as purposefulliving entities. This approach hears multiple benefits: 1) thedistributed natureof the architecture facilitates the creation ofcomplex system behaviors; 2) agents interact with each otherthrough high-level communication languages instead of rigidlow-level interfaces, makiig it simpler to manage largenumber of interactive behaviors; and, 3) when immersed inthe virtual environment, players tend to perceive the virtualcreatures as intelligent individuals; modeling them as suchfrom the beginning helpstomeet that expectation during laterdevelopment stages.In the domain of games,fuzzy control is not just anothercontrol method it is a quality behavior generator. Creatureswith subtle behaviors enhance the perceived complexity,enjoyableness and credibility of a virtual environment. While

    classical rule-based systems often fail to attain subtlety, fuzzyrule-based systems allow the nuances among inputs to becaptured and further reflected in the decisions at relatively IOWcomputational cost. Compared to some other intelligenttechniques, fuzzy rule-based systems are easy to design andimplement as well - they are very similar to the crisp rule-based systems, differing only in the approach usedtopartitionthe input space. As a natural extension of classical set logic,fuzzy logic is playing an increasingly importantrolein games.Thispaper provides an anatomyofbow agent technology,incorporated with fuzzy logic, canbeapplied to game design.A brief introduction to the Belief-Desire-Intention (BDI)agent theory and an overview of the BDLnet agent framework

    is provided in Section 11 Section 111 closely examnesBattleCity.net, a re-implementation of an old arcade game.SectionN outlines the extended framework and describeshow fuzzy rule-based computing can be used to improve theperceived quality of computer gomes. Finally, Section Vsummarizes the conclusions and indicates the direction offuture work.11. BACKGROUND

    A. Sofhvare AgentsAn agent theory defies the internals of agents. Amongthe many theories surveyedin [2], the BDI model [4][5][6] isthemost popular and influential.Duri ng the past decade, the BDI model bas been well-studied and formalizations have been developed [7][8]. Thestrong theoretical basis is supplemented by a number ofsuccessful industrial applications ranging from early NASAprojects[9]to more recent air-traffic management[101 and aircombat simulation [I ].The BDI model is rooted in the philosophical work ofBratman [12], which studies intention and its relation toothermental attitudes. As its name implies, BDI features threemajor mental attitudes as its building blocks - belief, desire,and intention:

    Beliefis the agents knowledge about its environment anditself.Desire describes the agents goal: a system state that theagent wants to achieve.Intention is the course of action that the agent has chosentoachieve that goal..

    7340-7803-8376-1/04/$20.00 Copyr i ght 2004 I EEE .

    http://battlecity.net/http://battlecity.net/
  • 7/29/2019 Fuzzy Logic in gaming

    2/6

    Plan is another important element of the BDI model. A actually carried out. During execution, one plan mayplan is a recipe of action for achieving a certain goal and is occasionally need to achieve a certain sub-goal that is beyondused to guide the deliberation process of the agents so they its capabilities to obtain. In such scenarios, the plan canneed not search through the entire space of possible solutions stimulate a new desire which the agent will try to fulfill in a~31. fashion simlar to that described earlier. For the originatingplan, the call is synchronous- t waits until the sub-goal isB. BDI..net achieved or believed unobtainable before devising further

    BDLnet [I41 is a Microsoft Visual C# [I51implementation of the Agentspeak [I61 BDI model. It isdesigned to be a lightweight framework for easy BDIimplementation by casual programmers. This designphilosophy leads to some favorable characteristics incomparison to the other existing BDI implementations, suchZEUS [20]. In particular, BDLnet offers the followingadvantages:

    Mainstream support and portability: BDLnet is written

    a~UM-PRS [17], JACK [18], J AM [19], dMARS [7], and

    using a popular programmng language and workseamessly with all programmng languages that supportthe .NET framework;Better alignment with standard programmng knowledge:models can be described using common programmngsyntaxrather than specialized symbolic logic;Testability: BDLnet is designed with testability in mnd,providing special facilities and considerations to aid thedebugging process;Explicit communication support: facilities for agentcommunication are built-in; andTool library: apart from basic infrastructure, theframework implements many intelligent algorithms(including fuzzy inference) ready for use by theapplication programmers.A~BDLnet agent operates through iterations of itsexecution cycle as depicted inFig. 1.

    Fig. 1BDl.net main execution cycleAt the beginning of each cycle, the agent senses itsenvironment and updates itsbelief. Consequently, desires mayarouse in response to the newly received stimulations. Theagent then matches its stock plans against the desires to findout the best applicable plan for each desire (based on theplans' fitness values) and initiates new intentions of execution.Upon the end of the cycle, the intention that serves the mosturgent desire is chosen from the intention library to be

    actions.Communication is of paramount importance in anyserious agent application: without communication, it is almostimpossible to exercise control over a multi-agent system, letalone collaborative problem-solving. Agent CommunicationLanguage (ACL) [21], along with content language andontology specifications, is an enabling technology of agentcommunication. BDLnet implements the Foundation forIntelligent Physical Agents (FIPA) [22] agent communicationlanguage standards for message encoding, semantics andpragmatics. FIPA ACL is chosen over the equally popularKnowledge Query and Manipulation Language(KQML) 1231due to its formal semantics, support for XM L (which isrelatively easy to parse), and other benefits such asspecifications of interaction protocols.

    C. F uzzyRule-basedSystemsFuzzy rule-based computing is the most widely used formof fuzzy logic. A fuzzy rule-based systems is generallycomposed of four components: 1) thefuzzifier converts thecrisp inputs into fuzzysets;2) therulebaseholds the relationsbetween the inputs and the desired output, expressed as acollection of IF-THEN rules; 3) thereasoning uni t applies theinputs to the rules; 4) the defizifer converts the result ofreasoning back to crisp output values.In the case of multiple inputs, the antecedents of a fuzzyrule are usually connected with the logical AND connective,and the rulebaseshould cover every possible combinationof

    all linguistic terms defined on each input variable. Thisrequirement of completeness leads to a combinatorialexplosion of the rules: for a systemof n inputs with m termseach, a total of m" rules are needed. Combinatorial ruleexplosion poses a severe problem for applying fuzzy controlin game designas it complicates the design process andtaxesprecious CPU resources.Combs has proposed the Union Rule Configuration (URC)[24](25] to alleviate the rule explosion problem. A typicalURC is expressedas follows:

    IFXlISAlLTHEN YISBIOR IFX ISA ,, THEN Y SBzOR IFX21SA2,THENYISB2 (1)OR ...OR IFX, ISAu THEN Y IS BkWhere X , denotes the input variables, Y denotes theoutput variable, and A, and Bk denote the linguistic termsdefined on the fuzzy variables. Instead of presenting the

    735

    http://bdi..net/http://bdi..net/
  • 7/29/2019 Fuzzy Logic in gaming

    3/6

    relationship between the connected antecedents and theconsequent, the URC relates each input variable directlyto theoutput variable, thus reducing the total number of rulesrequiredtom.n.Although the theoretical foundations of URC are stillunder debate [26][27], there is evidence of its applicability ina relatively large number of situations. It can serve as apractical and economc alternative to other approaches (suchas clustering and hierarchical systems) to solve the ruleexplosion problem.

    111 THEGAMEBattlecity is an old Nintendo Entertainment System NES)game released by Namco group in 1985. L i ke most earlyvideo games it employs a simple plot (cf. Fig. 2): 1 or 2players control their tanksand strive to protect their ownbase(presented as an eagle at the bottom of the map) and destroyall enemy tanks, then move on to the next stage. The gameprovides different terrain elements- ivers, bricks, stones, andtrees, each featuring unique properties. The enemies havevarious shapes, colors, speeds, and armor strengths. However,

    all enemies share the same stochastic behavior, making themrelatively easy targets. During game play, the humancontenders are to devise a terrain-relative strategy toeffectively clear the hostile tanks while remaining out ofharms way.

    Fig.2Original Battlecity Game (single player)BattleCity.net[28] is aremakeof the original Battlecitygame using the BDLnet framework andfuzzy logic. The rulesand graphic elements are transplanted as is, but for theconvenienceof research thenew game changes the plot to acomputer vs. computer battle. Whiletheenemy tanksremainstochastic, the player tanks are managed by intelligent agentsin ordertoelimnate the need for human intervention.

    A. DesignIn an agent-oriented approach the target system isdecomposed into autonomous entities and inanimate objects.

    The first step i s to decompose the system properly andidentify the agents. The nine types of entitiesare four terrainelements, three different enemy tanks, the base, and theplayers tanks. In theory, all entities can be agents, hut thatwould result in a wasteof computing resources. As with manyother design issues there is no straightforward answer as towhich entities should be designed as agents. However asimple rule of thumb is applied: if an entity is to performactions that change the environment, and the motivation forperformng these actions originates from the environment, it isa candidate to be made an agent.

    In BattleCity.net, the player-tank entity and the baseentity are designed as agents, leaving the restasplain objects.To generate a more realistic behavior, the player-tank agentshave limted sight, which in turn demands that the base (alsowith limted sight) monitor its own vicinity and alert theplayer-tank agents when enemes draw close. Additionally,the base constantly evaluatesits own situation and limts theplayer tanks distance to a level commensurate with thecurrently perceived threat. This strategy istoavoid a situationwhere the player tanks are too far awaytorescue a threatenedbase.....................................Game

    IPIwerAgent F0IIowRou1ePIa

    ChareEnewPlan

    Fig.3 BattleCity.netDesign ( SelectedComponents)From a design perspective, an agent-oriented solution is anatural extension of object-oriented programmng. Agent-based games can still take advantage of existing game

    736

    http://battlecity.net/http://battlecity.net/http://battlecity.net/http://battlecity.net/http://battlecity.net/http://battlecity.net/
  • 7/29/2019 Fuzzy Logic in gaming

    4/6

    development frameworks. BattleCity.netmakes use of a 2Dgrid game development framework that provides rendering,sound, collision detection, and basic object prototypes. BDIagents are embedded into the game objects to control theirbehaviors, hut the actual actions are still performed by theobjects, cf.Fig. 3.B. Implemenfafion

    The game framework provides a control loop driven byan extemal timer to handle animations and collisions, and togive the other game entities an opportunity to perform theirown processing. The enemytanks use this time slice to makerandom moves and occasionally open fre, while the playertanks and the base pass the control to their 'brains', i.e. theagents. The terrain elements are not active entities andtherefore do not require processing time.While the agent framework covers the mental operationsof an agent, plans have to be set up to inform the agent whatcanbedone and howtodo it. There aresi x major tasks for theplayer agent: to avoid bullets, to protect the base, to destroyenemies that can he fred at, to track the enemies down, to

    avoid collision with team-mates, and when no other task ispressing, explore the battlefield. Each of these situations hasto be completely handled by at least one plan. Taken that thegame is not complicated, one plan is conceived for eachrespective task. Simlarly, for the base agent, only two plansareneeded- calling for help and restricting the roamng rangeof the playertanks.Aside from the main control loop described earlier, eachBDI agent runs its own execution cycle in a separatethread.These loops are synchronized with the main control loop inorder to avoid undesirable results. In other words, consideringeach timer event as one step, the agents should only he able toperform one set of actions at any step. BDLnet providessupport for synchronization at two levels, both through

    semaphores: theagent execution cycle and the plans. At theagent execution cycle level, agents can he configured to waitfor a ready-to-go signal at the beginningof each cycle. Theplans can he interrupted and resumed at an execution cycle inthe future. This is useful when a plan, such as chasing theenemy, takes multiple steps to fmsh. Special care has to hetaken when implementing such plans by closely monitoringthe agent's statusto ensure that the plansarestill valid underthe current circumstances. This need arises since newsituations may develop while a plan is temporarily suspendedand other plansof higher importanceare executed, potentiallyinvalidating the original conditions.Without centralized control, the game agents coordinatestrategies among themselves. Calling for help is one situationthat requires such coordination.As illustrated below in Fig. 4,when the base senses enemy tanks around, it sets up acontract nef conversation with both player-tank agents bybroadcasting aCall or Proposal (CFP)message that indicatestheenemy's position and the deadline of proposal submssion.

    I f a player agent is not too busy it will reply with the cost of

    performng the rescue (the time it takes to reach the enemy'slocation). The base agent then chooses a winner from thesubmtted proposals. Once a contract is awardedto the playeragent, it initiates asubscribe conversation message with thebase agent so that it will be kept informed with up-to-dateinformation about the threat.

    I I

    I t I

    Fig. 4 Call for Help ContractNet ConversationAt the current stage the rule-based approach (in which aset of if-then-else statements define the stimuli and thecorresponding reactions) isused to generate the behaviors ofthe agents, and the standard A* search algorithm[29] isresponsible for path finding. The same configuration would heused without problem in a game that does not employ theagent-based design. However, since all the agents areplanning theirownpaths locally, thereis a possibility that theplayer-tank agents may run into each otherand, in the worst

    case, result in a deadlock. A solution to this problem is tohave the agents negotiate with each-other in caseof collision,but a simpler approach is taken here: both parties in collisionwill stop and wait for a random period of time before re-evaluating their situation. In this way, the fust agent torecover from the deadlock will haveto find a new path.IV. FUZZYLOGIC IN GAMEAGENTS

    As stated earlier, the base imposes dynamc constraints onthe player tanks' radius of roamng in accordance with itsperceived level of threats. A fuzzy rule-based system is usedhere to increase the level of details of the decision process.The base considersthreefactors when evaluating the threats: 1)the elapsed time since the last attack; 2 ) its shield level (i.e.the status of the walls surrounding the base); and 3) thecombined strength of the enemes in sight. The fuzzy rule-based systemtakes these three inputs and derives the desiredradius of the player tanks,which is then directed to the player-tank agents via a request conversation. The settings of the

    131

    http://battlecity.net/http://battlecity.net/
  • 7/29/2019 Fuzzy Logic in gaming

    5/6

    input and output variablesare showninFig. 5 (elapsed time isexpressed in unit of 30 mlliseconds, or one game executioncycle, and the desired radius is denotedinnumberofgrids).and @. The roamngradius limt of the player tanks is alsoshown on the pictures (denoted by 8 ) for visualizationpurposes.

    LASTASSAULT

    Fie. 6 Pamaitof thesame in action- beeinnhe0 2 4 6 8 10 12s m o

    0 2 4 6 8WSTRENGTH

    Fig. I Pomait of thegame in action- lightlyvulnerable

    5 10 15 20 25 30R4cilJ sFig. 5 F u ~ yariablesfor Player RadiusControl

    The traditional and the URC configuration wereevaluated and both met the expectations. However thetraditional configuration employs 27 rules, which is threetimesthe numberof rules used in theURC configuration, theCPU usage is considerably higher aswell. Obviously in thisparticular application the URC configuration is much morebeneficial.Below is a series of portraits of the game showing theeffects of the fuzzy rule-based system in various situations.The legends0 , 0 ,and0 indicate the two player tanks andthe base, with their respective sight limts denoted as0 ,a,

    Fig. 8 Portrait of thegame n action- mergency

    738

  • 7/29/2019 Fuzzy Logic in gaming

    6/6

    In Fig. 6, the game hasjust hegun and all conditions arefavorable- the shields of the base are intact, no enemy insight of the base, and there has never been any registeredattack. As a result, the player tanks are allowed to roamalmost freely. When the situation deterioratesin Fig. 7, theplayer tanksare informed to remain closer to the base. Finally,in Fig. 8 the base faces immnent threats- the shield on theright side is almost penetrated and an enemy is approaching,forcing one of the player tanks to engage the enemy and theother onetorush into the direct neighborhood of the base.V. CONCLUSIONS

    The Agent-oriented approach to game development offersmany benefits throughout the development cycle. It provides anatural way of modeling the game creatures and a softwarearchitecture of high flexibility and low coupling which allowsthe flourish of behaviors. In addition, developers can easilyintegrate their old game development frameworks with thenew design approach.Agents will certainly play a key role in gamedevelopment in the near future. However the agent-oriented

    approach is not without drawbacks. The most serious problemis the conflict between the need to maintainastoryline and theautonomous nature of the agents. The storylineoftendemandsprecise control over certain creatures properties, but theautonomous agents may exhibit undesirable emergentbehaviors due to the absence of centralized planning andcontrol. Such unwanted emergent behaviors can be elimnatedona per-problem basis, like the teammate avoidance problemdescribed earlier. While patch works can also be effective, thegeneral solution to this kind of problems will be a hybridarchitecture that features both centralized control andautonomous agents with back doors for external control.Fuvy logic is another intelligent technique that could beused to boost the performance of games. It handles complex

    control problems at low computational costs, withoutsacrificing the subtle details. While the paper discusses itsapplications withii the context of agent-oriented game design,fuvy control certainly applies tn games of any architecture.

    ACKNOWLEDGMENTSSupport provided by Alberta Science and ResearchAuthority is gratehlly acknowledged.

    REFERENCES[I ][2][3]141[5]

    C. Crawford, TheAll ofGmputer ComeDesign, Columbus: MeCraw-Hill, 1984.M. Wooldridge and N. R. J ennings, Intelligent agents: Theory andpractice, neK nowl edg=E ngi ~~in pReview,0(2), pp.115-152, 1995.W. Pedrycz and F. Gomide,An htmducrion lo Fuay& S, Cambridge:M l l Press, 1998.M. E. Brahnan, D. Israe, M. Pollack, Plans and Resource-Bounded&tical Reasoning,Compurorionalhfelligace,4:349-355, 1988M P. Georgeff and A. L. h s b , Reactive Reasoning and Planning,Proceedings of the Sixth National Conferenceon Artificial Intelligence,volumc 2,pp.677-682, Seattle, WA , 1987

    [a] A. S. RaoandM. P.Georgeff,M odeling Rational Agentswt hi n B BDI-archi teem, Pmeeedings of Knowledge Representation and Reasoning,pp.473484.1991[7] M. dlnvemo, D. K inny, M. Luck, and M. Wwldridge, A formalspecification of dMARS, Intelligent AgentsN, . P. Singh, A. S. Ran,andM. Wooldridge,e&, pp. 155-176. Springer Verlag, Berlin, 1998M dlnverno and M Luck, "Engineering AgentSpe&(L): A formalcomputational model, Joumal of L ogic and Computation, 8(3), pp.233-260, 1998M. P. Georgeff and F. F. Ingrand, Decision-Making in an EmbeddedReasoning System, Proc. Intl J oint Conf. on Anificial Intelligence,pp.972-978, August 1989[IO] M. L jungberg and A. Lucas, T he oasisair traffic management system,Praceedings of the Second Pacific Rim lntemational Conference onArtificial Intelligence, 1992[ I l l A . S. Rao, A. L ucas, D. Morley, M. Selvestrel, G. Murmy. Agent-oriented architecture for air-combat simulation: Technical ReportTechnical Note 42, The A ustralian Artif icial I ntelligence Institute, 1993[I21 M. E. BramLul, Inrenenfionr,Plom ond Procricol Reasoning, London:Harvard University Press, 1987[I31 A. S. Rao,A Unified View of Plansas Recipes, Contemporary ActionTheory, Editors Ghita Halmstrom-Hintikka and Raimo Tuomela, K ulverAcademic Publishers, The Netherlands, 1997[I41 Y . Li and P. Musilek, BDl.net: A L ightweight Framework,Proceedings of the Third ASERC Workshopon Quantitative and SoftComputing Based Sof twareEngineering, pp.49-53,2003

    1151 Microsoft Visual C# .net Home Page,hop://~dn.microsoR.com/vcsharp/,002[I61 AS . Rao, AgentSpeak(L) : BDI agents speak out in B logicalcomputable language, Proc. 7th European Workshop on ModelingAutonomous Agents in a Multi-Agent World, MAAMAW96, LNAI-1038, Springer Pub., 1996[I71 J. Lee, M. I. Huber, E. H. Durfee, and P. G. K enny, UM -PRS: AnImplementation of the Procedural Reasoning System far MultirobotApplications., Praccedings of the AlAA iNASA Conference onIntelligent Robotics in Field, Factory, Service, and Space, pp.842-849,1994[IS] P. Busena,R. Rannquist, A. Hodgsan, and A. Lucas,.JACK IntelligentAgents- Components for Intell igent Agents in lava, AOS TechnicalReport 1,1999[I91 M. Huber, Jam: a bdi-theoretic mobile agent architecture, Proc. Intl.Conf. A utonomous Agents, page 236243, 1999[20] H. Nwana, D. Ndumu, L. L ee, and J . Collis, ZEUS: A tool-kit forbuilding disbibuted multi-agent systems, AppliedArtificial ntelligenceJ oumal, 13(1):129-186, 1999[21] Y . Labrou, T. Finin, and Y . Peng, A gent Communication Languages:The Current Landscape, IEEElnIelligenf Ssfem, 14(2):45-52,1999[22] Foundation for Intelligent Physical Agents Home Page,htlp:l/www.fipa.orgl, 2W3[23] T. Finin et al, Specification of the KQML Agent CommunicationLanguage, Technical Report, DARPA Knowledge Sharing Initiative,External nterf aces Working Group, 1993[24] W. E. Combs, TheCombs Method for Rapid Inference, in TheFuuySsrem Hondbmk E. Cox, Ed., 2nd Edition, New York APProfessional, 1998, pp. 659--680[25] W. E. Combs and 1. E. Andrews, Combinatorial Rule ExplosionEliminated by a F uuy Rule Configuration, EEET r m.Fuay Sysrem,

    181

    [9]

    vol .6,pp. I-11,Feb. 19981261 1. M. Mendel and 0. Liang. Comments on Combinatorial Rule. .Explosion Eliminated by a Fuay Rule Configuration, EE ETransactionsanF uay Systems,vol. 7,no. 3.. June 1999.[27] S . Dick and A. K andel, Comment on CombinatorialRule ExplosionEliminated by a F w q Rule Configuration, E E E Transactions onF w q Systems,vol. 7,no. 4.. Aug. 1999.1281 Y . Li, P. M usllek and L. Kurgan, Battlecity Revived: G m esignwith BDl.net, Proceedings of the Fourth ASER C Worlwhop anQuantitative and Sof t Computing Based Sof tware Engineering, pp. 24-28,20(14[29] N. I. Nillson, Probl emSol vi ng M e l h d in Allificial Inlelligence,McGraw-Hill , 1971

    739

    http://bdl.net/http://bdl.net/