Our Properties: Gamasutra GameCareerGuide IndieGames Indie Royale GDC IGF Game Developer Magazine GAO
My Message close
Contents
Sponsored Feature: Two Brains Are Better Than One -- How to Thread Game AI
 
 
Printer-Friendly VersionPrinter-Friendly Version
 


Part of:



Latest News
spacer View All spacer
 
February 9, 2012
 
What Nintendo's 2011 sales mean for Wii U, third parties [1]
 
DICE 2012: Culture, pride lead to success at Skyrim maker Bethesda [3]
 
DICE 2012: Is the publishing model broken? [15]
spacer
Latest Jobs
spacer View All     Post a Job     RSS spacer
 
February 9, 2012
 
Sony Computer Entertainment America LLC
Senior On-line Programmer
 
Radical Entertainment / Activision
AI Programmer (Senior)
 
Visual Concepts
Senior Producer, VC China (Shanghai)
 
Visual Concepts
Software Engineer, VC China (Shanghai)
 
2K Marin
FX Artist - XCOM
 
Visceral Games Redwood Shores
Sr. Gameplay Engineer-Visceral Games
spacer
Latest Features
spacer View All spacer
 
February 9, 2012
 
arrow Postmortem: CyberConnect 2's Solatorobo: Red the Hunter
 
arrow Jerked Around by the Magic Circle - Clearing the Air Ten Years Later [32]
 
arrow Building the World of Reckoning [4]
 
arrow SPONSORED FEATURE: TwitchTV - How to Build Community Around Your Game in 2012 [13]
 
arrow Happy Action, Happy Developer: Tim Schafer on Reimagining Double Fine [9]
 
arrow Building an iOS Hit: Phase 1 [11]
 
arrow Postmortem: Appy Entertainment's SpellCraft School of Magic [5]
 
arrow Talking Copycats with Zynga's Design Chief [82]
spacer
Latest Blogs
spacer View All     Post     RSS spacer
 
February 9, 2012
 
Did DoubleFine Just break the publishing model for good?
 
The Devil Is in the Details of Action RPGs - Part One: The Logistics of Loot [2]
 
Xbox LIVE Indie Games at it Again
 
Merging Waterfall and SCRUM [3]
 
Business Post Mortem: Wolf Toss: Pre-launch Planning & Blended CAC
spacer
About
spacer Editor-In-Chief/News Director:
Kris Graft
Features Director:
Christian Nutt
Senior Contributing Editor:
Brandon Sheffield
News Editors:
Frank Cifaldi, Tom Curtis, Mike Rose, Eric Caoili, Kris Graft
Editors-At-Large:
Leigh Alexander, Chris Morris
Advertising:
Jennifer Sulik
Recruitment:
Gina Gross
 
Feature Submissions
 
Comment Guidelines
Sponsor
Features
  Sponsored Feature: Two Brains Are Better Than One -- How to Thread Game AI
by Orion Granatir [Programming, Visual Computing]
Post A Comment Share on Twitter Share on Facebook RSS
 
 
July 10, 2009 Article Start Page 1 of 2 Next
 

[In this Intel-sponsored Gamasutra feature, game programming veteran Orion Granatir presents a practical look about how to use multi-core CPUs to thread game elements, in this case artificial intelligence (AI) for your game.] 

Artificial intelligence (AI) drives gameplay, whether you're talking about a complex system of AI or a simple scripting engine. To really maximize your AI's potential, it needs to utilize the entire CPU and this means threading. This article examines how to thread a simple AI and some of the challenges in writing an AI that truly scales with multi-core CPUs.

The concepts described in this article were used in the creation of the multithreaded AI of Intel's Smoke demo. This demo showcases functional and data decomposition with multiple game technologies, including physics, audio, and AI. The source code is free to download at Whatif.intel.com.

Why Thread?

Imagine you want to update a bunch of AI monsters. If you have only one core, all of those monsters must be processed in order. However, if you have multiple cores, you can process them at the same time.

More cores, and thereby more active threads, means you can have more monsters in your game!

A Simple AI

Let's start by defining a simple AI. Our AI is going to be an enemy that idles, waiting to spot the player. When it spots the player it runs at them and explodes when it gets close.

Many games use a state machine to define AI behavior. So, let's define our states...


The first state is AI_SPAWN. This is the initial state and sets up the AI. Once the setup is complete, the AI is put into the AI_IDLE state.


While in AI_IDLE, the enemy does a ray cast to determine if it can "see" the player. If the ray cast reaches (hits) the player, the state changes to AI_ATTACK.


While the AI is in the AI_ATTACK state it finds a path to the player. When it gets close it changes to AI_EXPLODE, hopefully causing damage to the player.


 
Article Start Page 1 of 2 Next
 
Comments


none
 
Comment:
 




UBM Techweb
Game Network
Game Developers Conference | GDC Europe | GDC Online | GDC China | Gamasutra | Game Developer Magazine | Game Advertising Online
Game Career Guide | Independent Games Festival | Indie Royale | IndieGames

Other UBM TechWeb Networks
Business Technology | Business Technology Events | Telecommunications & Communications Providers

Privacy Policy | Terms of Service | Contact Us | Copyright © UBM TechWeb, All Rights Reserved.