28.10.2014 Views

Game Design and Artificial Intelligence - Bournemouth University

Game Design and Artificial Intelligence - Bournemouth University

Game Design and Artificial Intelligence - Bournemouth University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

Contents<br />

<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong>..............................................................................................1<br />

Contents............................................................................................................................................1<br />

Abstract.............................................................................................................................................1<br />

Introduction......................................................................................................................................1<br />

<strong>Design</strong>...............................................................................................................................................2<br />

The Concept..................................................................................................................................2<br />

<strong>Design</strong> Research...........................................................................................................................3<br />

Background Story.........................................................................................................................4<br />

The C.O.M.P. (Corporation of Mineral Production)..............................................................5<br />

Hwetre ­..................................................................................................................................5<br />

The Hwetrese Space Fleet ­ ...................................................................................................5<br />

The Orains ­............................................................................................................................5<br />

The Silver Bullet ­ .................................................................................................................6<br />

<strong>Game</strong>play......................................................................................................................................6<br />

Character Statistics.......................................................................................................................7<br />

Primary...................................................................................................................................7<br />

Physical..................................................................................................................................7<br />

Mental ....................................................................................................................................8<br />

Social......................................................................................................................................8<br />

Special Skills..........................................................................................................................8<br />

Hidden Attributes...................................................................................................................8<br />

Spaceship Battles..........................................................................................................................9<br />

Implementation...............................................................................................................................12<br />

H<strong>and</strong>ling data..............................................................................................................................12<br />

<strong>Artificial</strong> <strong>Intelligence</strong> <strong>and</strong> Finite State Machines.......................................................................13<br />

Space Combat.............................................................................................................................16<br />

The Heads up Display.................................................................................................................17<br />

Learning QT.........................................................................................................................18<br />

Problems Encountered................................................................................................................18<br />

Conclusion..................................................................................................................................20<br />

Acknowledgements........................................................................................................................21<br />

References......................................................................................................................................21<br />

Bibliography...................................................................................................................................21<br />

Abstract<br />

The aim of this report is to research into game development, build the foundations for a solid game<br />

concept <strong>and</strong> to research into <strong>Artificial</strong> <strong>Intelligence</strong> involved in game development.<br />

Introduction<br />

There are a whole series of games developed over previous years that have attempted to simulate<br />

Page 1 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

human behaviour through artificial intelligence. Many of these games however never seem to be<br />

entirely believable due to a lack of memory in the AI characters of player events. Underst<strong>and</strong>ably,<br />

many recent games are designed to leave only a small amount of processor speed dedicated to the<br />

<strong>Artificial</strong> <strong>Intelligence</strong> due to high quality graphics, large scenes <strong>and</strong> the game engine physics. This<br />

in turn means that the AI is left to emulate human behaviour using as little processor time as<br />

possible. It is up to the programmer to develop effective <strong>and</strong> efficient ways of representing human<br />

decision making through the AI.<br />

Many strategic Roll Playing <strong>Game</strong>s often revolve around a central character aided by a small group<br />

of other chosen individuals, allowing the player to select a team that suits his methods <strong>and</strong> favoured<br />

strategies. This is a vital factor of the game design <strong>and</strong> if the player selects an unbalanced team, he<br />

will regret his actions later on. “Baldurs Gate” is the main reference here, although there are many<br />

others that use similar approaches (“final fantasy” , “ albion” etc.). Baldurs Gate uses a “ reputation”<br />

statistic which measures how famous/infamous the posse are. The non player characters (NPC)<br />

then use this number to build an opinion on the player. If there is a great difference between the<br />

teams reputation <strong>and</strong> the characters personality, the character will threaten to leave the group. This<br />

is a form of artificial emotion.<br />

<strong>Artificial</strong> Emotion is an intriguing feature which many games now use to assist the non player<br />

characters. It can be used for an NPC to keep track of specific player interaction, <strong>and</strong> thus allows<br />

some specific memory. It is an effective way of emulating some human emotions <strong>and</strong> therefore can<br />

be used to give effective <strong>and</strong> believable responses. The purpose of this project was to research<br />

computer game design <strong>and</strong> artificial intelligence as well as constructing a game design based on a<br />

concept I had been developing over the summer 2004. The concept for the game is based on<br />

working alongside a temperamental crew which reacts to the player actions, but through both small<br />

events <strong>and</strong> large alike. Through use of the artificial emotion rules, the non player characters will<br />

judge the player'sactions <strong>and</strong> will react accordingly based on its statistics. The final product will<br />

hopefully show some resemblance to the concept <strong>and</strong> provide a basis for much of the playability.<br />

<strong>Design</strong><br />

The Concept<br />

Team based Roll Playing <strong>Game</strong>s are often about selecting your squad <strong>and</strong> developing them through<br />

combat situations to give them experience allowing them to advance through levels <strong>and</strong> skills. It<br />

could be considered a form of man management in selecting your team <strong>and</strong> keeping the group<br />

balanced, but this project intends to take it a level further. The stories in these games tend to<br />

unravel based on the characters in the team through the pre­scripted story. This makes a game<br />

interesting the first time round, but once the player has seen the repercussions of having a specific<br />

character in his team, it is easy to adapt a second time round. For this game, although some stories<br />

are an inevitability, it would be a real innovation to have more unpredictable developments based<br />

on the characters. The best manner to address this would be through having the characters not only<br />

react to you, but with their fellow compatriots.<br />

The setting is science­fiction. The players objective is to build a reputation. A reputation of good<br />

Page 2 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

will <strong>and</strong> peace by becoming one of the greatest traders in the pirate l<strong>and</strong>s, or an egregious arrogant<br />

leader of a terrorist pirate organisation. The story is open ended <strong>and</strong> it is up to the player how he<br />

wishes to develop the narrative. The player acts as the leader of a small trading project <strong>and</strong> has the<br />

responsibility of rounding up a team of followers who can assist in the running of a starship. At the<br />

foremost stages of the game, the majority of the crew is chosen for him, so as to educate the basic<br />

functionality. However, the option then arises to restructure the team. The player then has to search<br />

for potential employees <strong>and</strong> it is here where the challenge begins.<br />

The main game elements involve:<br />

• Judging the non player characters;<br />

• Man management during missions;<br />

• Strategic space combat actions;<br />

• Earning money;<br />

• Developing a world reputation.<br />

Somewhere in between a historical naval battle <strong>and</strong> science fiction shows such as Star Trek is how<br />

the vision of the space combat sequence can best be described. The action should be viewed real<br />

time, although the damage is done sequentially. This is to allow the player to be able to react to any<br />

events that may occur in the ship. When events in the ship combat get tough, a poorly lead crew<br />

will exacerbate the situation. The more damage done to the ship, the less experienced characters<br />

become more likely to panic <strong>and</strong> the composure levels become of greater significance.<br />

<strong>Design</strong> Research<br />

“ This is just one of the as yet unsolved questions in games – if death is indeed trivial, if we can<br />

always have another chance, then how do we make a life a valuable commodity? We also never<br />

have any real consequences for our actions, so the lives of other in­game characters are likewise<br />

instantly devalued.”<br />

Lee Uren, [Uren00]<br />

This comment by Lee Uren provides a good foundation for the game idea. Many modern<br />

commercial games veer towards cinema in style of dramatics <strong>and</strong> these are expressed clearly<br />

through narrative stories <strong>and</strong> the characters. However with these overly emphasized situations the<br />

sense of believability can be degraded as most of these changes in plot may not be edited by a<br />

players actions. This is the same for many in game characters, no matter how the player interacts<br />

with them, they will always act the same way. The player often has little effect in changing the<br />

atmosphere within a game. This is something that this project wanted to explore.<br />

“ For every choice, a consequence” – Fable, Lionhead studios, box slogan.<br />

Peter Molyneux of Lionhead studios has attempted to fulfill this problem in “ fable” . The game<br />

promised more than it could deliver, but still ended up being a fun encounter. The main character<br />

carries two main “s ocial” attributes in the game which the NPCs react to, renown <strong>and</strong> alignment.<br />

The NPCs reaction do seem fairly believable in the game, although none of the characters have a<br />

Page 3 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

memory of previous events once you have moved into a different area <strong>and</strong> they solely react based<br />

on the players social attributes.<br />

“ The worst kind of game are those (usually adventure games) in which it'sobvious that the<br />

designer thought he he was writing a film or a novel. It'sthe frustrated author syndrome, <strong>and</strong> you<br />

know you're bearing the brunt of it when your choices in the game have shrunk to one linear path,<br />

or when you find yourself scrolling through never ending cutscene dialogues waiting to get to the<br />

action. These designers are entertaining nobody but themselves.”<br />

Dave Morris <strong>and</strong> Andrew Rollings [Rollings00]<br />

An engaging <strong>and</strong> believable story is one good way of drawing in the players attention, a good<br />

example of this is nintendo’ s “Z elda” series <strong>and</strong> all through the “final fantasy” series. The one<br />

setback to this is that the main story is often a linear event, <strong>and</strong> is not affected by the methods of<br />

how a player has gone through the story. Fable yet again has adhered to this, <strong>and</strong> has two potential<br />

endings , with both an ending for an evil <strong>and</strong> holy individual, although you are still forced to fight<br />

the inevitable final battle at the end. “Escap e Velocity: EV Nova” goes one better than this, <strong>and</strong> has<br />

a choice of six stories which support the main exploratory trading adventure.<br />

Many games now implement main stories with plenty of smaller stories <strong>and</strong> side quests. These help<br />

add a lot more detail to the game world <strong>and</strong> give the player options as to whether he wishes to fulfill<br />

these quests. “B aldurs Gate” utilizes this idea, <strong>and</strong> it certainly adds character to the world, but the<br />

main story is far too linear <strong>and</strong> there are many occasions where you are forced into encounters, or<br />

along specific routes.<br />

One of the main features of the concept is that man management will be key. One of the best<br />

current examples of this is the “championship manager” series by Eidos, or more recently<br />

“F ootball Manager 2005” by Sega. The main objective is to manage your football team through to<br />

league <strong>and</strong> cup success through shrewd market purchases <strong>and</strong> tactics. However this game also<br />

involves several interesting man management techniques. The players can be very temperamental<br />

at times, going through both good <strong>and</strong> bad patches of form regularly. Players that haven'tbeen<br />

selected for games recently may h<strong>and</strong> in transfer requests <strong>and</strong> become unhappy, affecting their<br />

overall performance in games. Other events similar to this can occur. All of them have been built<br />

around the player <strong>and</strong> could be avoided if the game was restarted. This is a terrific example of how<br />

the crew should be during the game.<br />

All of the games mentioned in this section have a lot that can be learned from, <strong>and</strong> hopefully much<br />

of this can be incorporated into the design <strong>and</strong> implementation. Though it is easy to get carried<br />

away at this point, it is best to try <strong>and</strong> keep things simple.<br />

Background Story<br />

The galaxy was once forged by a relationship between two races, the Orains <strong>and</strong> the<br />

Hwetrese. The Orains discovered the knowledge of the “ LightDrive” which allows spaceships to<br />

travel faster than the speed of light by converting a ship into molecules of light matter. Through<br />

this invention, the Orains become a race of discoverers <strong>and</strong> explorers <strong>and</strong> began setting up colonies<br />

Page 4 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

on other worlds. The Hwetre are a highly technological race which thrives on natural resources.<br />

However due to overwhelming dem<strong>and</strong>s from their spacecraft, The Hwetre have had to mine from<br />

other nearby planets for more fuel. To keep their homeworld habitable, they began researching into<br />

terror­forming environments, <strong>and</strong> after a few experiments have become successful. When the two<br />

races met, a new relationship was forged <strong>and</strong> a spacefleet designed to explore <strong>and</strong> keep order was<br />

created. This was known as the Trekan space fleet.<br />

Peace reigned throughout the galaxy for several decades. But the Hwetrese need for natural<br />

resources was proving too dem<strong>and</strong>ing as more citizens were being able to purchase more affordable<br />

space craft, <strong>and</strong> the need for fuel was highly extravagant. The Trekan space fleet issued dem<strong>and</strong>s<br />

that the Hwetrese should convert to natural energy. The C.O.M.P.are against this <strong>and</strong> force the<br />

Hwetrese government to stick with fuel but implore that they will begin researching effective<br />

manners of using solar or hydrogen based fuels. The tension between the two races mounted <strong>and</strong><br />

this evolved into a full scale war when the Hwetrese agency along with the C.O.M.P. had developed<br />

a super sized ship, known as the “ Doombringer” . This ship had the ability to terror­form planets<br />

rapidly into uninhabitable lifeless rocks.<br />

Orais is destroyed by the Hwetrese space fleet in the “Ba ttle for Orais”, a nd the remaining survivors<br />

are forced to flee to the “pi rate l<strong>and</strong>s” , unchartered areas which are ungoverned.<br />

The C.O.M.P. (Corporation of Mineral Production)<br />

The largest fuel producer of the known galaxy, <strong>and</strong> one of the biggest craft manufacturers. Began<br />

as a family business, <strong>and</strong> exp<strong>and</strong>ed greatly during the space age when it was selected as the<br />

manufacturer for the Hwetrese Space Research Company. Due to the status <strong>and</strong> supplements of the<br />

COMP, they own the highest position on the board for the Hwetrese Space Fleet.<br />

Hwetre ­<br />

This is the capital of the known galaxy, <strong>and</strong> home to the Hwetrese Space Fleet. This is heavily<br />

industrialized <strong>and</strong> the air is stale from fumes <strong>and</strong> the over pollution. The L<strong>and</strong>scapes vary from the<br />

architectural amazement of the great cities to the deserts <strong>and</strong> seas. There is little natural plant life<br />

left apart from several protected reserve areas.<br />

The Hwetrese Space Fleet ­<br />

Now Split into quadrants to help enforce their status within the galaxy. All quadrant overseers are<br />

part of the board, who share the responsibility of control. There are many patrols <strong>and</strong> spacedocks<br />

run by the Hwetrese fleet.<br />

The Orains ­<br />

Driven from their home planet by the Hwetrese, they now dwell in the unmapped territories. They<br />

are now a split race with few comm<strong>and</strong> ships to build an effective resistance. Despite this there are<br />

a few have sworn revenge on the Hwetre <strong>and</strong> formed pirate organizations to fight against the new<br />

Page 5 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

order.<br />

The Player ­<br />

The player is a halfbreed of Orain <strong>and</strong> Hwetrese <strong>and</strong> grew up living on Orais until the great war,<br />

during which he/she was separated from his/her parents. Brought up during the teen years in an<br />

orain refugee orphanage run by some ex­military personnel in the pirate l<strong>and</strong>s. He/she received a<br />

military education, disciplined in starship combat. It is now time to leave the orphanage <strong>and</strong> begin a<br />

new life.<br />

The Silver Bullet ­<br />

A modified armed transport craft. Runs on fuel. Solar Energy reserves. Not the fastest, but one of<br />

the most versatile. Modified for faster turning during combat situations.<br />

The ship has several hot spots. These are damageable zones in the craft, <strong>and</strong> if hit during combat<br />

when shields are down, will hinder the ship. If there is an engineer on board, these areas can be<br />

fixed. Some of these areas are vital to the game, if destroyed, the ship is destroyed. Some areas if<br />

damaged will cause severe problems.<br />

• Engines(left);<br />

• Engines(right); (if both of these are damaged then the ship cannot move)<br />

• Laser cannons (manual/auto)(top);<br />

• Laser cannons (manual/auto)(bottom);<br />

• Laser cannons front; (these are controlled by the pilot)<br />

• Shield generator;<br />

• Life support; (This is vital to the crew! They have a minute to get spacesuits on unless this is<br />

repaired)<br />

• The bridge;<br />

• piloting controls;<br />

• Computer mainframe;<br />

• Power Generator; (if this is damaged, the ship can be destroyed)<br />

• Fuel Tanks; (again if this is ignited, the ship can be destroyed)<br />

Another problem that could occur is a hull breach, which could easily happen without shields. If<br />

this happens to a section of the ship, the area will be quarantined <strong>and</strong> not accessible to crew<br />

members without a space suit. For the purpose of the demo, the damage will probably be restricted<br />

somewhat.<br />

<strong>Game</strong>play<br />

Select your crew:<br />

Pick which characters you want for your crew, assign wages at values based on player skills with<br />

rates(minimum, st<strong>and</strong>ard, generous, extravagant). crew above st<strong>and</strong>ard wages will be more likely to<br />

be content with the opposite being true for those with minimum wage. *in the full game, it would<br />

be my intention for the player to start off on a planet where he has to find a selection of characters<br />

Page 6 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

that he feels could fill the position. This gives the player a chance to learn more about the world<br />

<strong>and</strong> the characters before setting off on the first mission. This is very much in a similar style to<br />

“B aldurs Gate” .<br />

Assign positions:<br />

There are potentially 4 positions to fill, although they are all optional. The player could choose to<br />

have no crew, but this would be foolish as no one single character could run an entire ship during<br />

combat!<br />

• The Gunner is responsible for all ship fire including control over laser turrets <strong>and</strong> missile<br />

launchers.<br />

• The Engineer takes the position of having to redirect power through out the ship during combat,<br />

<strong>and</strong> is a general dogsbody around the ship. He can undertake or lead with an assigned apprentice<br />

repair <strong>and</strong> upgrade operations on the ship out of combat.<br />

• The Pilot has the all important job of maneuvering the ship. He follows the orders straight from<br />

the captain <strong>and</strong> should always be under strict supervision.<br />

• The Navigator has the role of scanning for ships <strong>and</strong> reporting back to the captain. He analyses<br />

tactics of opposing enemies <strong>and</strong> should have a good background knowledge on the various space<br />

systems. A very useful route finder for long missions. Not always necessary, but useful to have,<br />

especially for new players.<br />

Once the player has chosen his crew with allocated positions <strong>and</strong> wages, the mission briefing<br />

begins. Here the player gets to set long­term shifts <strong>and</strong> work for the crew (i.e. For when they're not<br />

in combat, do battle station drills or upgrade or mend parts of the ships). The journey route is set by<br />

the player, with assistance from the navigator (who can set the route automatically). (in the full<br />

version, supplies (eg. Missiles, ship upgrades, food)<br />

Character Statistics<br />

Any good game tries to keep things as simple as possible yet attempt to do something complex in<br />

nature. This game requires several base level stats which will be used throughout. These stats are<br />

billed into four main categories primary, physical, mental <strong>and</strong> social. All attributes are measured<br />

from 0 to 100.<br />

Primary<br />

• Age: This affects mainly physical attributes, the older the more degradation may occur.<br />

Learning is also affected.<br />

• Race: Different races often lead to discrimination due to the history of the world.<br />

• Reputation: Unknown to Legend. All characters will have some form of fame.<br />

Physical<br />

• Dexterity: This attribute is prime for many special skills, including engineering, piloting,<br />

gunning <strong>and</strong> weapon combat. Also key for additional skills like gambling.<br />

• Stamina: This judges how much physical labour a character can undertake. This judges<br />

how much a character recuperates during rest periods.<br />

Page 7 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

Mental<br />

• Wisdom: This is obviously key in many special skills <strong>and</strong> affects learning rates as well. This<br />

also key to decision making.<br />

• Composure: This is key in extreme situations, such as combat situations or when decision<br />

making.<br />

Social<br />

• Character: This describes the characters personality, ie good or evil. 50 is neutral, 0 is<br />

chaotic <strong>and</strong> 100 is angelic.<br />

• Influence: An important attribute that determines how much a character can persuade others,<br />

<strong>and</strong> is vital to a leader or captain.<br />

Special Skills<br />

On top of these basic skills, the characters also have traits <strong>and</strong> special skills. No character will have<br />

each trait, but they can learn new traits as the game progresses. If they don't posses a trait that is<br />

required during the game, a basic level will be created at level 0. All these attributes accumulate<br />

with experience <strong>and</strong> through learning.<br />

• Captaincy: A captaincy skill helps a captain gain respect from crew mates<br />

• Gunning: For the use of craft or vehicle laser cannons.<br />

• Engineering: This is important for repairing <strong>and</strong> modifying spacecrafts, vehicles <strong>and</strong><br />

weapons.<br />

• Medicine: For doctors or medics,<br />

• Piloting: useful for being able to pilot ships<br />

• Navigating: This is important for discovering safer <strong>and</strong> faster routes through the galaxy<br />

• Shooting: this is shooting accuracy with pistols <strong>and</strong> rifles.<br />

• Electronics: For computing <strong>and</strong> rewiring circuitry.<br />

Additional Skills Traits<br />

These are mainly non academic skills <strong>and</strong> are just tend to add additional personality to the<br />

characters. For example, gambling, alcoholic, lechery, sport, politics ... etc.<br />

Hidden Attributes<br />

All the statistics listed above can be viewed within game by the player to help judge whether they<br />

are the character to hire for their ship. However there are also a list of temperamental attributes<br />

which can change dramatically based on specific events.<br />

• Opinion on the player: (between 100 to 0) This judges whether an AI character likes you or<br />

not.<br />

• Opinion on other AI character: (between 10 to ­10) This can lead to friction between the<br />

Page 8 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

crew.<br />

• Longterm Happiness: A happy worker is a better worker! Keep your crew happy to avoid<br />

problems.<br />

• Stamina (cumulative): This is a r<strong>and</strong>om counter which decreases during heavy labour<br />

events, <strong>and</strong> recuperates during rest periods based on the characters non­hidden stamina<br />

attribute.<br />

Spaceship Battles<br />

The idea is that the player would have minimal control over what happens to his ship, <strong>and</strong> it is down<br />

to the rest of his crew to carry out his comm<strong>and</strong>s. This then makes it imperative to choose the<br />

correct crew <strong>and</strong> treat them in the right manner. The enemy is not outside, but inside. It is the crew<br />

that must be kept happy to keep them working well.<br />

As captain, the player can order the pilot to fly to any object (ideally he could point to a position on<br />

a map). This would mainly be flying to ships or navigation points (which allow the ship to leave<br />

the territory). A list of comm<strong>and</strong>s for combat should also be listed.<br />

Below are a couple of game references for the visuals that this space Combat simulation should<br />

look like.<br />

Page 9 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

Fig 1.1 – Operation : Inner Space<br />

Page 10 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

Fig 1.2 – Escape Velocity: EV Nova<br />

Page 11 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

Implementation<br />

When starting development of the game, a lot of time was spent designing the character <strong>and</strong> crew<br />

AI side of the program but most of the coding time was involved with the space combat system, as<br />

this was pivotal to getting a functioning <strong>and</strong> fun product. It required these visuals for underst<strong>and</strong>ing<br />

what the player is attempting to achieve. The main factor proved to be time <strong>and</strong> learning. At the<br />

end of this project, there was an emphasis on producing something that was fun to play <strong>and</strong><br />

interactive with the player but could still carry across much of the concept work. Once the space<br />

combat system was developed, there was little time left to spend on the crew FSM system, however<br />

some items have been implemented to indicate what could have been if more time was available.<br />

H<strong>and</strong>ling data<br />

When designing a skeleton structure of the game engine, the file system was split into three main<br />

sections. One of the sections would be dedicated to the interior of the ship, checking on the<br />

conditions of each of the crew members <strong>and</strong> working out the respective work rates. The second<br />

section consists of the ship fighting, updating <strong>and</strong> drawing all objects in the world space. The final<br />

section is the main section where everything must be h<strong>and</strong>led including the opengl setup <strong>and</strong> calls<br />

to the other two sections.<br />

This was the first time I had attempted to do a programming project using multiple files, <strong>and</strong><br />

therefore it was key that I passed the correct data around for the game engine to operate. The main<br />

pivotal point for this was between the ship combat <strong>and</strong> the ship interior. The player ship<br />

information needs to be passed to the heads up display, the crew work rates need to be sent to the<br />

combat system <strong>and</strong> both sections need to be able to h<strong>and</strong>le key presses. The first attempts at<br />

producing the space combat system were flawed due to a lack of cohesion when attempting to pass<br />

data to <strong>and</strong> from the space combat file. After learning the uses of object orientation, this problem<br />

was simplified. Object orientation allows information that previously couldn’ t be shared from<br />

specific modular files (eg. shipCombat.cpp does not know of objects in crew.cpp) to be accessible<br />

by the use of placing the data in sets of interacting objects [macey00]. Using classes to contain the<br />

data, through inheritance <strong>and</strong> the use of the STL(st<strong>and</strong>ard template library) [bateman00] I was able<br />

to format a much neater <strong>and</strong> more accessible system.<br />

Page 12 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

Fig 2.1 – Overview of the data h<strong>and</strong>ling in the game<br />

During this project, it was imperative to try <strong>and</strong> keep the number of global variables to a minimum<br />

if possible as this would be more liable to errors due to repeating names. This was problem was<br />

solved by keeping most of the data rapped up in variables in lists with object orientation. The use<br />

of Object Factories [rollings01] could also have made a large difference in keeping the code tidy,<br />

but a lack of time for the implementation prevented this.<br />

<strong>Artificial</strong> <strong>Intelligence</strong> <strong>and</strong> Finite State Machines<br />

For this project, the <strong>Artificial</strong> <strong>Intelligence</strong> didn’t need to be overly complex, though at one point<br />

further research into genetic algorithms <strong>and</strong> neural networks [ai­junkie01] looked a distinct<br />

possibility. Neural networks, based on genetic algorithms, try to simulate the way the human brain<br />

works by taking a number of inputs into a “ neuron” which effectively calculates a result <strong>and</strong> returns<br />

an output. As impressive as this method of AI is, it seemed needlessly awkward considering what<br />

the program required.<br />

During the first attempt at the space combat situation, I had already stumbled on the functionality of<br />

the FSM (finite state machine). I was working on a system that used a switch statement based on a<br />

state which was one of either, fly towards, stop or drift. This is an example of a very simple FSM.<br />

Page 13 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

Fig 2.2 – The layout for the crew AI working state.<br />

“ Because game character behaviour can be modeled (in most cases) as a sequence of different<br />

character “ mental states” – where change in state is driven by the actions of the player or other<br />

characters, or possibly some features of the game world – game programmers often find that finitestate<br />

machines are a natural choice for defining character AI.” – p284 AI wisdom [Houlette00]<br />

For the Crew AI, there are two FSMs. One that isn't fully implemented in the game which is the<br />

basic FSM for working state (see fig 2.2), the second is the emotion state machine. The working<br />

FSM is designed to find out whether an NPC is working on a job (eg. Gunning, piloting etc.) or is<br />

idle due to refusing orders or finishing a current one or if it is moving to a new location based on a<br />

new order. The emotion state machine works slightly differently but uses the same theories.<br />

<strong>Artificial</strong> Emotion.<br />

As previously mentioned in the design, the artificial emotion is a method for the NPCs to judge the<br />

player through the decisions made based on his statistics. Each NPC carries an OPINION statistic<br />

on each character in the crew, including the player. This counter, between 0 <strong>and</strong> 100, changes as<br />

the game progresses based on the input from the player <strong>and</strong> events happening through the ship. The<br />

emotion state machine then uses this counter as part of the calculations to figure if there any<br />

changes in emotional states. The class for the AI is defined below:<br />

class crewAI : public crewMember<br />

{<br />

public:<br />

std::string getType(void);<br />

int state;<br />

int emotion_state;<br />

int wages;//WAGES is 1­4, 1 being minimum, 4 being max<br />

int aggression;// use this to judge orders.<br />

int discipline;// <strong>and</strong> this!<br />

bool refuse_order;<br />

int ORDER;<br />

double OPINION_player;<br />

double OPINION_crewAI;<br />

Page 14 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

double HAPPINESS_general;<br />

double HAPPINESS_daily;<br />

double FSM_TIMER;<br />

int FSM();<br />

int emote_FSM();<br />

void update(double);<br />

};<br />

crewAI(int);<br />

~crewAI();<br />

The key to the NPC’s judgm ent is based on the aggression value in the demo game, although ideally<br />

more statistics would be considered. Both the pilot <strong>and</strong> gunner can be given the comm<strong>and</strong>s based<br />

on their aggression, <strong>and</strong> both have their preferred aggression factors. If the gunner is an aggressive<br />

character, he will not appreciate being told to fire slowly <strong>and</strong> accurately. If this occurs during the<br />

game, the NPC’s OPINION_player will decrease by one. This is only a minimal amount, but if the<br />

player continuously issues this order the NPC will become more likely to refuse new orders <strong>and</strong> will<br />

switch to doing what he would rather do. However, good performance will counter this, every time<br />

experienced is gained, the OPINION_player will be increased based on the amount.<br />

The emotion state FSM often uses the OPINION_player to help with calculations to see if the state<br />

needs to be changed. Every five seconds the function will be called:<br />

If(refusing_order false)<br />

Test if orders to be refused();<br />

If(refusing_order true)<br />

Test if Opinion has increased;<br />

Test if orders to be refused();<br />

If true, refusing_order false;<br />

If(state is normal)<br />

{<br />

if(FEAR function() returns true)<br />

return new_state;<br />

if(LUCK function() returns true}<br />

return new_state;<br />

}<br />

If(state is not normal)<br />

Check to see if state returns to normal;<br />

The above pseudo code will find out what emotion_state the NPC is in <strong>and</strong> if it is taking new<br />

orders. The program uses this information elsewhere in the program to change the NPCs attributes<br />

if needed<br />

Page 15 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

fig 2.3 – The bridge of the ship with the player character <strong>and</strong> the AI pilot<br />

Space Combat<br />

The space Combat was where most effort was based during the production of this project. For the<br />

demo, all though there was not enough time to implement a three dimensional version, it was<br />

possible to work on a two dimensional approach, with an x <strong>and</strong> y axis. Three attempts were made at<br />

producing the AI for the ships. The first experiment was creating a ship that would follow a target<br />

around. This was done by calculating the distance between the ship <strong>and</strong> the target in both x <strong>and</strong> y<br />

axis, calculating the angle between them <strong>and</strong> adding a velocity based on the angle. Much of this<br />

was taken from my previous programming project from last year, as this used the same theory to<br />

have an object always look towards a target. However there was a drawback with this. The ships<br />

could only rotate 360 degrees. Once the angle reached over 360 degrees, the object would have to<br />

rotate all the way round the other way as the object believes the angle to be a small value (as the<br />

value over 360 would then switch to 0). This method required some tweaking which would allow<br />

the object to follow an object by rotating around the quickest way. The way this was solved, was<br />

through working out the difference between the current ship rotation <strong>and</strong> the desired angle. If this<br />

difference is less than <strong>and</strong> absolute value of 180 degrees, the ship can rotate based on whether angle<br />

is smaller or larger. However if the difference is bigger than 180, then we have to reverse this<br />

situation as the target has gone full circle. This took a while to discover, but it is fairly effective.<br />

if((rotation­angle)>180)<br />

{<br />

if((rotation­angle)>0)<br />

rotation+=(70.0*TIMER);<br />

}<br />

if((rotation­angle)


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

}<br />

Fig 2.4 – Both ships will always be aiming to look at each other.<br />

The ships can carry different speeds, <strong>and</strong> potentially different rotational speeds aswell. I have tried<br />

to demonstrate this in the demo by having two types of enemy ships, fighters <strong>and</strong> scouts. The<br />

scouts are three times faster, but do less damage.<br />

Using the STL this allowed a better organization of the objects in the scene. All the objects the<br />

player can target (ships, navpoints <strong>and</strong> planets) are in one list. Each one of these objects are<br />

inherited from the base class c_spaceObject, <strong>and</strong> by using the method of casting down, all the<br />

objects could easily be pushed into a st<strong>and</strong>ard list (which is effectively a linked list for c++).<br />

This list is then accessed several times through the program. Once for drawing the objects,<br />

updating them <strong>and</strong> filtering for a target. The Player defines the target to aim towards through<br />

filtering through this list.<br />

The damage to the ship is calculated through a r<strong>and</strong>om number roll(between 0­100) against the pilot<br />

workrate statistic(calculated in the crewAI). Damage against other ships uses the gunner rating<br />

verses a roll.<br />

The Heads up Display<br />

“ I find the interface is one of the hardest aspects of game design. It should be intuitive <strong>and</strong> icons<br />

should be kept to a minimum. I have never got an interface right (the) first time. It'sone of those<br />

things that should be tested <strong>and</strong> tested until everyone is happy with it.” ­ Peter Molyneux. P47<br />

[Molyneux00]<br />

Page 17 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

Fig 2.5 – an experiment with Qt working with OpenGL.<br />

Learning QT<br />

The game required quite a complex HUD, originally the method for this was going to be through<br />

creating textures for each ASCII character. However, further research into the QT software<br />

revealed another potential solution. QT offers a host of functions for creating some simple looking<br />

but effective HUD tools, including push buttons, radio buttons <strong>and</strong> tick boxes. It works quite<br />

simply through a slot <strong>and</strong> signal algorithm [macey01]. Whenever a message needs to be sent from<br />

an item, like a push button, it calls its signal function which is sent to one or more slots of other<br />

objects. The most useful element is that it can display opengl scenes in a window, with a frame of<br />

buttons on the outside. The only setback is that it does slow down the opengl program, but it would<br />

be a useful for small programs so would have worked quite nicely with the demo.<br />

In the end I decided to use the glText to display the information, though it is still my intention to<br />

use qt for a HUD which the player can interact with.<br />

Problems Encountered<br />

I originally setup the game to be able to switch between levels easily based on a selected global<br />

levelNumber using the following code:<br />

Switch(levelNumber)<br />

{<br />

case (1):<br />

{<br />

draw all objects level_1;<br />

}<br />

break;<br />

}<br />

The program had a strange bug when I attempted to start on a different level number <strong>and</strong> attempted<br />

to switch to the current level. The enemy ship speed seem to rocket for some unknown reason. I<br />

originally thought it could be to do with the timer, but as I disabled this at the beginning of the level<br />

Page 18 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

loading, this was ruled out.<br />

When I switched machine I realized that all the starships were moving at a much faster speed. I<br />

realized later on that this was due to the ship update function not incorporating a timer amount when<br />

calculating the velocity. This was easily fixed by editing the speed values <strong>and</strong> multiplying the<br />

velocity by the timer to get the new ship position.<br />

Once I had discovered about casting down inherited objects into a global list of the base class, I had<br />

an issue with occasionally needing to be able to access items only in the inherited classes. By<br />

including a function called getType, which returns the name of the object type, I could cast a new<br />

pointer of the inherited type to the same data as the base class pointer. I have Leigh Mcloughlin to<br />

thank for this!<br />

if(gunman­>getType() == "crewAI")<br />

{<br />

crewAI *NPC = (crewAI*) gunman;<br />

...<br />

}<br />

The main problem involved with this project was purely the time limit. I ended up being so<br />

distracted by the space combat side of the program, <strong>and</strong> left only a small amount of time on the<br />

crew AI. This is a huge shame as I had done a lot of research into this, but have little to show for it.<br />

Further Development<br />

On a personal note on this project, there is so much more that I would like to achieve with this<br />

game, as the current demo does not do the concept justice <strong>and</strong> I intend to continue this work at a<br />

later stage. I have already mentioned that I would like to take this game into the third dimension at<br />

some point (properly! not just pseudo 3d), but for the moment I'mlooking to continue developing<br />

the two­dimensional version.<br />

Space Combat ­<br />

• Develop FSM for ships, give the enemy better AI. Have different styles of attack runs for the<br />

enemy ships <strong>and</strong> evasion manoeuvres (eg. 3 point turn, barrel rolls, ship banking)<br />

• Have specific areas to target, allowing ships to be disabled through damaging specific areas,<br />

rather than simply being destroyed. Shields could also be implemented<br />

• Capital ships. Having giant sized ships would be quite an interesting feature, although this is<br />

more of a chrome feature at the moment (ie. It would be nice, but not necessary)<br />

• Group AI tactics for enemies <strong>and</strong> allies alike. This would involve having formations, <strong>and</strong><br />

enemies can judge on attacking <strong>and</strong> retreating based on a group strength.<br />

• Radar. Either having a small radar on the screen, or an option to switch to an overview of all the<br />

ships in the area (similar to “ Homeworld” )<br />

The Crew­<br />

• Allow movement for the crew, using the A* path finding system. They would then be able to<br />

move <strong>and</strong> switch between jobs <strong>and</strong> in the case of the engineer, he would be able to move to<br />

repair the damage around the ship.<br />

• Create more emotions for the characters. Currently only a few are implemented, more emotional<br />

Page 19 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

states leads to a less predictable game <strong>and</strong> it would be far more interesting.<br />

• Develop more orders to interact with the characters. The player should have more freedom in<br />

the gameplay <strong>and</strong> not feel too restrained.<br />

• Look into the psychology behind human emotions to allow more realistic reasoning behind<br />

changes in character states.<br />

Story <strong>and</strong> Missions ­<br />

• The first part of the game needs a little work, I hope to have a good background story for the<br />

main character <strong>and</strong> subsidiary characters.<br />

Conclusion<br />

This project has been ideal as a revision for programming, <strong>and</strong> I have learned several useful<br />

techniques for developing games through the use of object orientation. The final piece however was<br />

a disappointment, as I did not achieve what I set out to reach. The hope was that there would have<br />

been a playable game at the end of the project. Restarting the project on no more than three<br />

occasions certainly did not help the situation, although i did learn from my mistakes on the previous<br />

attempts.<br />

In the end though, I really only ended up with a combat system that had only a few small features.<br />

The combat lacks the interactive element due to a lack of controls. With more time to exp<strong>and</strong> on<br />

this project, there is a lot more that could easily be done <strong>and</strong> I am convinced that this could blossom<br />

into an innovative game.<br />

Page 20 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

Acknowledgements<br />

Phil Allen – for encouraging me to concentrate on story <strong>and</strong> design issues.<br />

Stephen Bell – for all his advice during tutorials.<br />

Eike Anderson – help with researching AI.<br />

Leigh Mcloughlin – general programming advice.<br />

References<br />

[Uren00] ­ UREN, L., 2003. Computer <strong>and</strong> Video <strong>Game</strong> <strong>Design</strong> Issue.<br />

[macey00] ­ MACEY, J. 2004. BA computer visualization <strong>and</strong> animation, computer programming 3<br />

lecture notes<br />

[macey01] ­ MACEY, J. 2003. QT <strong>and</strong> OpenGL.<br />

[bateman00] ­ BATEMAN, R. 2004. Programming with the St<strong>and</strong>ard Template Library.<br />

[Rollings00] – p13 ROLLINGS, A. AND MORRIS, D., 2004. <strong>Game</strong> Architecture <strong>and</strong> <strong>Design</strong>: A<br />

New Edition<br />

[Rollings01] – p561­563 ROLLINGS, A. AND MORRIS, D., 2004. <strong>Game</strong> Architecture <strong>and</strong><br />

<strong>Design</strong>: A New Edition<br />

[Houlette00] – p284 FU, D. AND HOULETTE, R.2003. The Ultimate Guide to FSMs in <strong>Game</strong>s<br />

[Molyneux00] – quoted in p47 ROLLINGS, A. AND MORRIS, D., 2004. <strong>Game</strong> Architecture <strong>and</strong><br />

<strong>Design</strong>: A New Edition<br />

Bibliography<br />

CRAWFORD, C. 1982 The Art of Computer <strong>Game</strong> <strong>Design</strong><br />

PEABODY, S. 1997. The Art of Computer <strong>Game</strong> <strong>Design</strong> [online], Washington State <strong>University</strong>.<br />

Available from:<br />

http://www.vancouver.wsu.edu/fac/peabody/game­book/Coverpage.html<br />

[accessed 26 th February]<br />

UREN, L., 2003. Computer <strong>and</strong> Video <strong>Game</strong> <strong>Design</strong> Issues<br />

J. VINCE. ed. H<strong>and</strong>book of Computer Animation<br />

Cromwell Press, Trowbridge, Wiltshire: Springer, p1­27<br />

ROLLINGS, A. AND MORRIS, D., 2004. <strong>Game</strong> Architecture <strong>and</strong> <strong>Design</strong>: A New Edition<br />

United States of America: New Riders Publishing<br />

BATEMAN, R. 2004. Programming with the St<strong>and</strong>ard Template Library, <strong>Bournemouth</strong>.<br />

Available from:<br />

http://www.robthebloke.org<br />

[accessed 26 th February]<br />

MACEY, J. 2004. BA computer visualization <strong>and</strong> animation, computer programming 3 lecture<br />

notes<br />

<strong>Bournemouth</strong> <strong>University</strong>, Poole.<br />

Page 21 of 22


<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

MACEY, J. 2003. QT <strong>and</strong> OpenGL, <strong>Bournemouth</strong> <strong>University</strong>, Poole. Available from:<br />

http://dec.bournemouth.ac.uk/staff/jmacey/QT/index.html<br />

[accessed 16 th February]<br />

UNKNOWN AUTHOR & DATE. Genetic Algorithms in Plain English <strong>and</strong> Neural Networks in<br />

Plain English<br />

www.ai­junkie.com<br />

[accessed 3 rd March]<br />

FU, D. AND HOULETTE, R.2003. The Ultimate Guide to FSMs in <strong>Game</strong>s<br />

S. RABIN. ed. AI <strong>Game</strong> Programming Wisdom 2<br />

p283­301<br />

http://www.worldvillage.com/wv/gamezone/html/reviews/inspace.htm<br />

image of Operation Inner Space<br />

http://www.captainz.net/evn_omega/sol1.jpg<br />

image of EV Nova<br />

Page 22 of 22

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!