Intelligent Wall Placement Locations to protect Use natural barriers Wall cost Distance from a given location Size of protected area
Possible Solutions Build rectangular wall Add walls to level via map editor Wall-building algorithm
Problem Definition Protect a given location by blocking the movement of enemy units Implies: –Block all access routes –No breaks
Preliminaries Restricted to tile-based maps Obstruction footprints confined to tiles Wall segment –Passive defensive structure –Blocks unit movement over a single tile Two wall segments are adjacent when they touch along the edges (not diagonals) Four adjacent wall segments (neighbors) for each free standing wall segment Each wall segment of a wall has two neighbors
Definitions A wall is a set of wall segments connected together in such a way that –Every wall segments has exactly two unique neighbors ( wall segments linked in circular fashion) –At least one interior tile (tile inside the walled- off area) –All interior tiles (interior area) are connected through edges (not diagonally).
Acceptance Criteria Minimum / maximum distance from location to protect Minimum / maximum number of interior tiles Maximum number of wall segments (cost of building wall)
Definition of Problem On a given tile map, build a wall that fits the definition, protects the given location, and meets the given acceptance criteria.
Wall-building algorithm Starting location (given) that needs to be protected Apply an initial wall around this location Move wall outwards greedily: remove an existing wall segment and place it in a different location, so that –Net gain of exactly one interior tile –Resulting wall still meets the wall definition Some moves might require addition of extra wall segments Stop when acceptance criteria are met
Does this work? Every group allows 17 possible moves = 68 possible moves Common patterns can be used to reduce number of cases Natural barriers act similarly to wall segments Natural barriers will greatly increase the number of possible moves Large number of moves
Is there a better way? Instead of expanding wall, expand interior area Once expansion is done, generate wall around interior area
Definitions Node = representation of the smallest area, e.g. a tile or a waypoint, that can be obstructed by the placement of game objects Graph with every edge connecting two nodes Edge defines path units can take Nodes sharing same edge are called adjacent
Definitions (cont.) A node can have any number of adjacent nodes A wall segment that is part of a wall still only has two neighbors Interior tile interior node Interior area set of interior nodes Starting location starting node Move process of adding new nodes to the interior area
New wall-building algorithm Start with starting node Expand interior area by adding one node per step Select the node to add using a greedy methodology ( heuristic function) Stop when acceptance criteria are met
Data structures Closed list –Nodes in the interior area Open list –Nodes bordering the interior area –Ranked by heuristic function –After node was moved to closed list, add new neighboring nodes
Traversal Function Get all successor nodes for a particular node Power to block individual node to prevent the interior area from spreading into undesirable areas Frequently used by heuristic function to get list of successor nodes for cost calculation
Heuristic Function f(n) is cost function representing the cost of adding node n to interior area c is a constant larger than the maximum possible distance from the starting node w(n) is the cost of walling off node n d(n) is the distance from node n to the starting node
w(n) Number of wall segments needed to keep the new node walled off from the outside area Only w(n) generates asymmetric walls stretching in only one direction –Why? –List of successor nodes tends to be arranged in a certain order. –Beginning of list gets preference over nodes with same cost further down the list –Leads to expansion in general direction of successor node at the top of the list
d(n) Add distance from starting node Maximize the minimum wall distance from the starting node for same wall cost good for defensive purposes Distance-related part has to be less significant than portion related to walling-off Achieve this by multiplying cost of walling off with the maximum distance (c)
Minimum distance Gives priority (0) to the nodes closer than the required minimum distance Need to adjust acceptance function to require that all nodes have reached minimum distance Used to protected important location, e.g. building, from enemy fire
What about natural barriers? Traversal has to ignore natural barriers Heuristic function needs to treat barriers as free wall segments and ignore them in the calculation of w(n) Efficient implementation: Change node traversal to ignore barriers
Map Edges? Inaccessible, maybe even permanent fog of war –Requires impassable terrain around them –Treated as natural barriers Embraced as part of game play –Traversal cannot find nodes past the map edges –Heuristic function has no cost for those nodes –Area past the edges treated as invisible natural barrier
Maximum Distance? Do not let open nodes at maximum distance become interior nodes Undermines functionality of open list! Introduce maximum distance list –Holds nodes located at max distance –Before adding a node to open list, check its distance –If equal to max distance, add it to max distance list –Upon completion, merge open and max distance list to get final solution Used to place wall within manageable distance, or ensure protective cover of tower fire
Doors and Gates? A wall without doors and gates is not that useful! Simply place gates at evenly spaced locations in the wall –Dumb solution –Might place a gate right in front of a natural barrier –Might not get us to all interesting locations Smart solution: Create paths from starting location to interesting outside locations. Where path and wall intersect, place a gate.
Diagonal Walls? Walls might be connectable diagonally Cost function needs to ignore cost of walling off a diagonal direction Diagonal successor nodes may not be added to open list