University Projects

Z Nation - Artificial Intelligence Project

Z Nation

Intro.

This is one of our project for Artificial Intelligence subject at the Jaume I University, in december 2018.

Summary of the game

Z Nation is a turn-based strategy video game, in which the player will face a second player managed by an AI. The goal of the game is to destroy your enemy's city. To do this, both must collect the different hidden resources scattered around the map in order to improve their cities and get units to attack and collect.

Requirements

The game should contain:

  • A behavior tree
  • Influence map
  • Different levels of AI

The team

This project was made with a group of 3 students from Jaume I University.

  • Verónica Martuscello
  • Alejandro Juan Peral

Design Description

The visual design of the game is based on the use of 3D low poly models, among which we can find the figures of resources, the city and the unity, as well as the scenery. Within the game, two types of units coexist: the explorer and the collector/attacker.

As for the conceptual design, the player must send many units as possible to attack the enemy city in order to defeat the opponent and win the game. To do this, you will have to explore the map in search of resources, amoung which we find two different types: food and materials. Material resources allow the construction of element called barracks, located within the city and capable of sheltering units. Food resources make it possible to capture and maintain (per turn) units, which will be limited in number by the number of existing barracks at a ratio 3/1, that is, 3 units per built barracks.

The limitations that the player has as are linked to the "fog of war", that is, the player does not know the map, does not know the position of the resources, so he must explore it, thanks to the help of the explorer unit character, in order to discover as mucha area as possible and thus be able to establish a winning tactic.

Finally, it is worth mentioning that victory will be granted to the player who has successfully assaulted the enemy city, and this will be when the number of attacking units that arrive in the city is greater than the number of units that remain inside it.

Artificial Intelligence techniques implemented

Representation of the terrain

The representation of the terrain in our game has been through a grid (or matrix) of square nodes. We have chosen this implementation since the hexagonal way seemed more complicated to us when traversing the matrix and since we needed several loops to do it, we preferred the "natural" way.

Each node stores all the necessary information of the terrain:

  • A boolean indicating if that node is visible to the enemy or not.
  • A boolean that indicates if that node is visible to the player or not.
  • A GameObject that will store if the node has an element above it or else it will be null. The objects that are on top of the node can be food, materials, group of survivors, enemy group or the city.
  • The resource cost(if any, otherwise this will be -1)
  • The grid is made up of nodes. The grid script has several functions that will help us iterate through it:

  • GetNeighbours(Node n) function: Go through the 8 neighbors of Node n and return them in a list.
  • GetNeighbourInLevel(Node n, int level): Go through all the neigbors of node n up to a certain level. This a breadth-first search taht starts at n and goes to a breadth level. It also returns a list of nodes.
  • Influence map

    The influence map in our game iterates through the nodes until it reaches a certain level to create the influence. In our game we have two types of objects that generates an influence: food and resources.

    The influence expands as follows:

  • In alert state is triggered when the enemy see the player, the enemy makes a pathfinding with the A* algorithm to the last known position of the player, then follows the path and also updates the position if he can see the player.
  • Patrol state is the enemy’s basic state in which he follows a route of points until he receives an alert, because the player has made a sound or because another enemy can see the player.
  • Attack state is the action of hitting the player in specific circumstances, when the enemy is a melee type, It should be in a closer range than X units to make the attack. If it is a shooter, it should be further away than X units and closer than Y to shoot (X and Y change between levels)
  • Searching state is the state in which the enemies have seen the player but they can’t see him right now so they look for him in an area around the last position where they saw him.
  • Alert is produced when an enemy hear a sound and it go to the position of the origin of the sound in a range of X units, they do this work with the A* algorithm and they can hear the sound even if they are behind a wall.
  • Follow the leader is the behavior that the hostage has when it is released by the player and consist of following the player with the A* in order to dodge obstacles.
  • Communication and coordination between enemies: Sounds and round up

    The enemies have got “walkies” to send warnings between them, we have represented this with a range in which the enemies detect the playero chen another enemy has detected him, they try to go through different paths to overthrow the player.

    Detection systems

  • Metallic griddle: It is a griddle on the floor that makes sound when the player walks over it, alerting nearby enemies of the player’s position.
  • Light switch: Is a switch on the wall that allows the player to turn off the light and disorient the enemies for a few seconds. If the player was being chased by an enemy, It stops the pursuit.
  • Door switch: Is a switch that open the door to the room that connects with the next level.
  • Vision cone: Is the graphic representation of the enemy vision in the game, when the player enters inside he is detected and the pursuit begins.
  • Hearing radios: Is the zone around the enemy where it can detect the player even if it isn’t looking at him. As with the vision cone, if the player enters the range, the enemy will detect him.
  • Fog of war (FOW)

    As said before, each node has two booleans indicating if that node was visited or not by the user, by the enemy or both. We use these booleans in order to create the FOW. The units can only move to the nodes they visited before. When making decisions, only the nodes that have been visited will be taken into account. The implementation is very easy, we go through all the neighbors of each node and we update the list of visible elements.

    Decision Tree (general, high level)

    The purpose that drives city AI in search of resources is the constant imposed need to create barracks, which in turn allow the creation of units.The decision tree implemented in the AI is more detailed bellow.

    Decision Tree (particular, low level)

    The city will send different groups to do different actions. But there may be situations along the way that they will have to deal with. We have decided that the AI will be agrassive, which means it won't considerer if the enemy group is bigger than it, it will attack it, so when they finished they will return to the decision that the city had sent them. If there are no enemies nearby, it will check to see if there are any nearby resources within its view range. If there is, it picks it up, if not, it will communicate with the explorer and ask if there is any resource nearby that it has seen, if so, it will go for that resource, otherwise the decision of the city will continue.

    Back to projects To main page
    Contact

    I'd Love To Hear From You.

    You can contact me by Twitter, LinkedIn or email.