Context
Artificial Intelligence has been implemented in games for a long time. In my second year at the AUAS, we followed a class regarding this topic. This provided an intro to the broad subject of Artificial Intelligence, but dove deeper in the implementation in games. We learned about various elements, such as flocking, trees, graphs, agents and pathfinding. To test our understanding of the subjects, projects were available to experiment with and to expand.
Most projects were playable and functional, meaning that there already was a running game. Students’ main job was to either improve the code or finish certain methods. In this post I will showcase the three projects, because the projects didn’t require a lot of my own written code. Code snippets that I do showcase however, are self written (either finished the function(s) or I made it). All projects were made in Unity with C#.
Projects showcase
The Flocking Dead

This project focusses on Flocking. In the program, zombie seagulls (green) chase normal seagulls (white) to try and turn them into zombies. My job was to execute certain behaviors from Flocking, such as separation, alignment and cohesion. To do this, I would have to finish code inside behavior classes and adjust values in the inspector to increase the weight of certain behaviors.

Adjusting these weights would make the agents behave differently. Some scenarios I created were: Normal seagulls grouping together and fleeing together, a lot of zombies chasing a single seagull, zombie seagulls splitting up and normal seagulls grouping together when being chased. Executing the behaviors and tweaking the weights made me learn a lot about the individual behaviors and what they do. I also learned about the code architecture behind this project and how artificial intelligence can be implemented for agents in games.
An example of the code I wrote in this project from the EvadeBehavior class:

Treespire

‘Treespire’ focusses on implementation of trees as AI in games. In this game, the user operates a computer which can play multiple programs. The two programs above, each implement trees in some way. For ’20 Questions’, the program tries to guess what the user is thinking about by asking questions. In the other program, ‘Noughts ‘nd Crosses’ , the program tries to outsmart the player and win the famous game.
To make these programs work as intended, I had to work and experiment with a few classes regarding trees. My main input for this project was the implementation of a minimax function for the ‘Noughts ‘nd Crosses’ program. In this function, the program needs to calculate and store the best moves to play himself. This is what the function looks like:

I learned a bunch by looking at the code present in the project. I saw how trees were implemented and how traversing through them in code works. Additionally, I experimented more with concepts like Minimax and AB-pruning, which increased my understanding of the subject.
Tiles of Chicks Island

The final project for this topic is all about path finding. In this game, one of three maps can be loaded to display an island with a player character and goal. The player can activate one of three algorithms to operate. The algorithms will find a path from the player character to the goal. The algorithms used are A*, BreadthFirstSearch and Dijkstra.
My job was finishing the algorithms so they perform correctly. By adding heuristics (weights) to the mix, the algorithms could behave differently. My implementation of the A* algorithm is as follows:

While I didn’t implement a lot of my own code in the project, I did learn a lot about pathfinding. Playing around a lot with the content of the project made me acquainted with how the three algorithms work. I experimented with tweaking weights to see how the algorithms would behave, and implementing the algorithms themselves made me more aware of how they work individually.