map / wall generation

52
MAP / WALL GENERATION Automatic generation and maintenance of maps and walls

Upload: nuala

Post on 24-Feb-2016

48 views

Category:

Documents


0 download

DESCRIPTION

Automatic generation and maintenance of maps and walls. Map / Wall Generation. Content Overview. Generating maps What do we want in a map? Warcraft 3 map editor RTS maps for Empire Earth Wall Building Generating intelligent barriers Populating large worlds using limited resources - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Map / Wall Generation

MAP / WALL GENERATION

Automatic generation and maintenance of maps and walls

Page 2: Map / Wall Generation

Content Overview Generating maps

What do we want in a map? Warcraft 3 map editor

RTS maps for Empire Earth Wall Building

Generating intelligent barriers Populating large worlds using limited

resourcesThe Waterfall Algorithm

Page 3: Map / Wall Generation

Generating an RTS map

Page 4: Map / Wall Generation

RTS Map Generation: Overview Place players on the map first Grow land for each player Land that has not been allocated is

considered water Analyze terrain and add features Place resources around players fairly

Page 5: Map / Wall Generation

Scripting for variety Scripts are used to specify map parameters

such that they can be modified quickly without programmer intervention

For example: number of resources per playermaximum height of landplayer land allocationclimate

Page 6: Map / Wall Generation

Player placement - Step 1 Inscribe a large disk on the map

Inner and outer radii can be set in a script

Page 7: Map / Wall Generation

Player placement - Step 2 1 random point for each player is chosen

within the disk; closest points are pushed apart

Closest points are pushed apartiteratively untildistribution is satisfactory

Page 8: Map / Wall Generation

Player placement – Step 3 If the game has teams, they are

assigned to adjacent player locations

Page 9: Map / Wall Generation

Back it up - dummy players

Player locations will have allotted flat land and resources

We may want other areas of the map to also have these properties for player expansion

Page 10: Map / Wall Generation

Where to put land? This process is centered around the

positions of the players which have just been determined

Why? Land is a very important resource in RTS games: Exhibit A

Each player must receive an equal amount of buildable land

Page 11: Map / Wall Generation

Growing land: Clumps Land is grown in around players in “Clumps” Attributes of clumps can be set, such as:

clump size, number of clumps per player, chaos level

Clumps grow (consume tiles) until they reach the predetermined size

When a clump is completed, a new clump is created a random distance and angle away until the number of clumps required are generated

Page 12: Map / Wall Generation

Two methods for growing clumps Completion Method: One clump is grown to

completion before another is started Step Method: Grows clumps one tile per

iteration. This method is used to lay out each players’ land.

Page 13: Map / Wall Generation

Keeping track of clumps A 2-D array of all the tiles on the map is

initialized such that all tiles are water When a land clump is grown, it changes

the value for its tile in the array to indicate that the tile is part of a land clump

When a land clump is grown for a player, the player’s enumerated value is placed into the land-water array

Page 14: Map / Wall Generation

Different Map Types Island Map: Require a new land tile for a

player is not within some tile distance from another player’s land

Land Map: Allow players’ land to be adjacent to an enemy player’s land

Page 15: Map / Wall Generation

Flat Clumps While each player has been allocated an equal

amount of land, nothing has been set about the conditions on the land

To ensure that each player has the same amount of buildable land, a subset of their land clumps are “Flat Elevation Clumps”

Flat Clumps are grown using the completion method and can only grow in a player’s existing land

Page 16: Map / Wall Generation

Adding interesting terrain Terrain can be generated using Fractals

– “The Diamond-Square Algorithm”

Page 17: Map / Wall Generation

Resource Allocation Resources are placed on the map on a per-

player basis Placed within rings centered on a player’s

starting location (number of resources and size of ring are attributes which can be changed with scripts)

For a particular resource, random locations in the ring are tried until an acceptable location is found

Why might a location be unacceptable? Cannot be placed on a certain terrainMust have a minimum distance to other resourcesCannot be too close to the player’s start location

Page 18: Map / Wall Generation

What about the trees? Trees are placed last because they are

plentiful and restrict path finding. Forest size, number of forests per player can

be specified as attributes Forest growth is not restricted by the players’

land boundaries (unlike most other resources) Another type of clumps, “treeClumps” are

used to grow forests Forests cannot grow near other forests, and

some areas are marked as forest-free

Page 19: Map / Wall Generation

Flaws with this algorithm High processing times No ability to add specific terrain features Often resulted in maps in which players

had vastly different choke points, or even no access to other players

Resource placement system often created a resource advantage for certain players

Example of what these maps look like

Page 20: Map / Wall Generation

Building Walls Many RTS games allow the player to

build walls to impede enemy mobility, so AI players must be able to as well

A good wall building algorithm can make NPC opponents much more formidable

In games with a map editor, an automated wall building feature would make a level designer’s job easier

Page 21: Map / Wall Generation

Defining a Wall A wall segment is a passive defensive

structure which blocks movement over a single tile which it occupies

Wall segments are adjacent if they touch along the edges (not diagonals)

A wall is a set of wall segments whichEvery wall segment has two adjacent wall

segmentsThere is at least one interior tileAll interior tiles are connected through edges

Page 22: Map / Wall Generation

To be crystal clear…

Page 23: Map / Wall Generation

Greedy Algorithm A greedy algorithm is one that always takes

the best solution at the time Must define a heuristic to determine how

favorable a given action is Always choose the solution with the lowest /

highest value from the heuristic (depending on how your heuristic is defined)

Disadvantage: There is no guarantee that the overall solution will be optimal even if each step was optimal

Page 24: Map / Wall Generation

Approach #1- Build Wall Given a starting location which you would

like to protect with the wall Create a simple small rectangular wall

directly surrounding the starting point Using a series of moves, expand the wall

until it meets the desired properties Each “move” moves the interior space

outward such that exactly one more tile is walled off and the new wall still meets our wall definition

Page 25: Map / Wall Generation

Analyzing Permutations In order to decide which move is best, we

must consider all permutations Each 3x3 square generates 68

permutations. Once all permutations have been

determined, calculate their heuristic value (in this case, how many wall segments must be added to accommodate including the interior node)

Option with the lowest cost is chosen

Page 26: Map / Wall Generation
Page 27: Map / Wall Generation

What about natural barriers? Excellent question! Natural barriers would create many

more permutations, to the point where we are forced to ask the question, “Isn’t there a more efficient way to do this?”

The solution lies in realizing that there is a one-to-one relationship between a wall and the interior space protected by the wall

Page 28: Map / Wall Generation

Paradigm shift Instead of building the wall, we

concentrate on building the space within the wall

We still start with the starting node from before (the location we’d like to defend)

The “move” described before simply becomes adding another tile to the interior space (using the same greedy algorithm)

Page 29: Map / Wall Generation

Managing the nodes (tiles) Closed list – the list of nodes that have been

selected to be in the interior space Open list – the list of nodes that are candidates

for inclusion in the closed list (on the border) On each iteration, the nodes on the open list

are inspected, and the best candidate is moved to the closed list

This process is repeated until the desired size is achieved

Upon completion, the open list becomes the list of tiles on which to build the wall

Page 30: Map / Wall Generation

Pseudocode

Page 31: Map / Wall Generation

Keys to this algorithm Traversal Function: for a given node,

determine successor nodes (that become members of the open list)

Acceptance Function: determines whether or not the current wall is acceptable (# of nodes on the closed list, etc)

Heuristic Function: ranks open nodes, and thusly controls the shape of expansion. Must attempt to maximize area walled off while minimizing cost to do so

Page 32: Map / Wall Generation

More on the Heuristic Simply using the cost to include a node tends

to result in asymmetric walls which stretch in one direction.

To correct this behavior, we add a term to the heuristic equation which increases the cost of nodes proportionally to their distance from the start node.

However, we must ensure that the distance does not out-weigh the cost of building

This results in a formula of this formf(n) = c * w(n) + d(n)

Page 33: Map / Wall Generation

What about natural barriers? This algorithm allows us to easily incorporate the

possibility of natural barriers with some modifications

Traversal Function: must be changed to ignore natural barriers when looking for nodes to include

Heuristic Function: must consider natural barrier nodes to have no cost when considering including the bordering nodes in the open set

With these modifications, the algorithm takes advantage of natural barriers and tries to use them as free walls

Page 34: Map / Wall Generation

Min/Max Distance Requirements Minimum Distance: We may want to ensure that

no wall segments are within a certain distance from the starting node. To accommodate for this, set the heuristic value (cost) of all nodes within the minimum distance to 0.

Maximum Distance: This can be done by monitoring the inclusion of nodes on the open list. If the node is at the maximum distance, add the node to a maximum distance list instead of the open list. Upon completion, we must merge the open list with the maximum distance list to get the full wall

Page 35: Map / Wall Generation

Doors and Gates We may want to have the ability to move

friendly units in and out of the walled area Brute force method: place openings

randomly or at fixed intervals More sophisticated: create paths (using

A*) from starting node to all locations of interest outside the walls. Intersections between these paths and the wall are logical locations for doors

Page 36: Map / Wall Generation

Diagonal Walls With a few modifications, this algorithm

can be adapted to games which do not allow diagonal movement

Heuristic: Cost function must ignore cost of walling off diagonally

Traversal: Ensure diagonal successor nodes are not added to the open list

Page 37: Map / Wall Generation

Populating Large Worlds Many actors in a large world map can

consume an inordinate amount of resources

“Waterfall concept” helps to alleviate pressure on system resources

General idea is to devote the most system resources to units closest to the player, and limit actions of those far away.

Page 38: Map / Wall Generation

Five Functional Components1. The Context2. The Character3. The Personality4. The Director5. The Manager

Each of these is represented as a class in the architecture’s implementation

Page 39: Map / Wall Generation

The Context The “soul” of the AI Set of all essential variables and data

required to represent the state of an agentIs the agent currently active?Visual representation being usedState of thought process

Information is used by the Character class to affect agent behavior

Page 40: Map / Wall Generation

The Character Takes an instance of Context and uses

the data contained therein to generate input for the agent- causes it to behave in a certain manner

Can be thought of as a script for the role the agent is playing

Will be sub-classed to generate a range of behaviors

Page 41: Map / Wall Generation

The Personality Allows multiple agents with the same

Character to act in slightly different waysExample: if an agent drives a vehicle

○ Character: Agent drives fast○ Personality: provides a range from which the

Character provides a range of minimum speed values

Ensures that agents are unique

Page 42: Map / Wall Generation

The Director Responsible for determining when

agents fall in and out of the waterfall based on a complex set of rulesThis helps maintain the illusion of a world

teeming with active agents Also chooses which Character an agent

should use when it falls back into the “waterfall”

Page 43: Map / Wall Generation

The Manager Holds, instantiates, updates, renders,

and destroys all AI agents These functions could be absorbed into

the Director if desired, but separating them eases management and encapsulates functionality

Deals with the physical aspect of AI: instantiates visual and functional piece of the game the user sees

Page 44: Map / Wall Generation
Page 45: Map / Wall Generation

Mechanics Director determines if the Context needs to

exit the waterfallIf yes, a new location is chosen for the Context,

and agent is placed thereIf not, a Character is chosen for the Context

and the Context is assigned to a Character

Page 46: Map / Wall Generation

Mechanics cont… Next, the Character is allowed to operate

on the ContextPath informationCollision informationFriend / foe information

Character never directly moves the agent; it leaves ‘suggestions’ the agent can use to affect its physical representation

The Director then determines if the agent has left the waterfall

Page 47: Map / Wall Generation

Flow of the Waterfall Purpose is to focus on the most interesting

AI activity close to the player Agents that have “exited” the waterfall may

be recycled into a visible position or replaced with other agents

Most effective in a game where the player moves at a steady predictable rate

There must be a well-defined set of rules for when agents will enter and exit the waterfall

Page 48: Map / Wall Generation

Exit Rules Dependant on the type of game and visibility

/ line-of-sight distances (the shorter these distances, the better the system will work)

Examples of exit rulesThe agent is farther than a certain distance awayThe agent is behind the camera for a certain

amount of timeThe agent is outside the view cone for a certain

amount of time

Page 49: Map / Wall Generation

Entry Rules Where to spawn the agent?

Very specific to the player’s location, movement, viewing direction

Some example rules○ Enter agents behind the player, speed them up so they pass

the player○ Enter agents just out of player’s view distance○ Enter agents into predetermined locations in anticipation of

player’s arrival What type of Character to spawn?

Are there too few agents with this Character in the Waterfall?

Are agents of this Character relevant to the game in the player’s current situation? E.g. more cops if the player is doing something illegal

Page 50: Map / Wall Generation

Optimization Just don’t do it

If an agent too far away or occluded, turn off unnecessary functions (animation, collision checks)

Do it, but only so oftenSome things can be done just once in a

while (update pathfinding, searching for downhill direction, other long searches)

Page 51: Map / Wall Generation

Summary Map Generation: Algorithm described can

create some good maps, but still has its flaws Wall Generation: good walls can make an AI

opponent more formidable; the algorithm described here adapts to natural barriers and makes player-like walls

Resource management: On a large map, you can’t afford to have all AI agents perform all of their actions all the time. The Waterfall algorithm can help alleviate pressure on processing time

Page 52: Map / Wall Generation

Questions?