Terrain Analysis

DigiPen Institute of Technology 

December 2020 

For my final project of CS380, I was tasked with implementing several different techniques of terrain analysis. To test all the terrain analysis, I was required to use A* to have the agent move around the maze. I had to implement openness, visibility of the agent,  visibility of the map, and propagation. 


Openness is how close a space is to a wall. The closer the space is to a wall, the lower the openness value for that space is. The darker blue the space is the closer to a wall it is, thus the space is not that open. While the spaces that are in more of an open area of the map is closer to white or the openness value 0. To do this calculation, for each space in the grid you measure the distance of the closest wall and set one over the value to the alpha value of the openness layer. 

Agent Visibility

Visibility is all the spaces that the agent can see from their current space. In this part of the assignment, the map should show all the squares the agent can see from a given position. Dark green squares are visible to the agent and light green squares are partially visible to the agent. I did this by checking each space and if it is visible to the agent, meaning a line does not intersect any walls between the space and agent. This was very straight forward of calculating visible squares. However, the partially visible square were much tougher. To do the partially visible squares I needed to add many edge cases that checked all the neighboring spaces of seen spaces. If the neighboring space is a valid space then the agent should be able to see some part of the space, so it is marked as light green.

I also implemented what the agent can see in front of them. Any space that the agent can fully see will be marked in purple. This visibility is very similar to any stealth games where the player needs to avoid an enemy's field of view.

Map Visibility

Map visibility is very similar to agent visibility however its an O(n^2) operation to calculate the openness. When map visibility is active then the map will show the visibility of each space on the map. The value that is calculated for visibility is how many other spaces can see that space. The darker the color on the map, the more spaces can see that space. I implemented this part very similar to the agent visibility. For each of the spaces I check how many spaces can see that space by doing a vector check and seeing if it intersects a wall. If it does intersect a wall, I use the same edge cases to check if the space is partially visible. Visible and partially visible spaces both contribute to the calculation of visibility to the space.


One of the final things I had to do for this assignment was to implement propagation. This is when the user clicks on the map and pulses out in all directions from the space clicked. The pulse expands and decays over time going around walls throughout the map. This technique was not the easiest to implement. I had a lot of trouble with the pulse going around the walls of the map and going diagonally through walls. To implement this part of the assignment I looped through all the neighboring spaces and adding them to a list or container of some sort. Then I looped through the list of the spaces and continued to loop through their neighbors and setting their new decayed value. To prevent the pulse of spaces from going through the walls I had to add special edge cases to all the neighbor checks to see if it was a valid spot to advance the spread to. 

Hide and Seek

After implementing all these aspects of terrain analysis I put them all together to create a hide and seek mini game. The goal of the player is to hide from the seeker. The seeker will randomly roam around the map looking for the player. The player will be able to see the seeker's vision and and what spaces they see. If the seeker sees the player, it will chase them around the map. If the seeker loses vision of them it will propagate where the player was last seen and the seeker will search the area.