Beat My Bot: Team AI/Networking
This project was developed for one of my final year modules, which tasked me with designing and implementing an AI that would beat a simple AI developed by my university lecturer. My AI was used by six bots on the game’s red team, which had to capture domination points and eliminate the opposing team’s bots, as well as reload when necessary.
My AI is made up of three core concepts: A* Pathfinding, Reynold’s Steering behaviours and finite state machines.
A* pathfinding is used by the bot’s to find the best path (one that has the lowest cost) for the bot to reach whatever its target is set to. The map is analysed at the start of the game and a vector of nodes is stored to use to generate each bot’s path.
The behaviours system is used to allow the bots to actually move around the map – behaviours included actions such as avoiding walls; finding a path; and going to or from their targeted point in a number of ways (e.g. moving quickly to the target, slowing down as the bot approached the target or fleeing away from the target).
Lastly, the game uses finite state machines to manage tasks and set up the behaviours of each bot. There are currently 8 states, all of which inherit from one base state class. Each of the states is implemented as a singleton, so only one instance of the state exists at a time. The states include:
- Start – the state in which a bot starts. If the bot is alive, it moves to the Roam state.
- Roam – this state is the ‘tumbleweed state’, which evaluates if the bot is alive and has ammo. If it has no ammo, the state is changed to Reload. If it is not alive, the bot’s state is changed to the Start state.
- GoToDominationPoint – this state manages the bot’s ability to find a domination point to go to. The state sets the bot’s target domination point and finds a path to it, checking if an enemy is near to bot en-route, as well as if the bot’s domination point is in its line of sight and is owned by their team. If an enemy is nearby, the Attack state is switched to. If the domination point is in line of sight and not owned by the team, the bot switches to the Capture state, otherwise if it is owned, the bot switches to the Guard state.
- Capture – this state is switched to when the bot’s domination point is in its line of sight. It allows the bot to move to the domination point and capture it. While its this state, the bot gets a reference to all enemy bots and checks if they are near by. If they are, the bot attacks them by switching to the Attack state. If the bot loses line of sight, it switches to the GoToDominationPoint state.
- FindResupplyPoint – this state works a lot like the GoToDominationPoint state, as it finds a resupply point for the bot to go to when it has no ammo left.
- GetAmmo – this state works a lot like the Capture state, except for resupply points rather than domination points. However, there is no checking for nearby enemies, as the bot has no ammo to shoot with anyway.
- Attack – this state manages the bot’s ability to attack enemies, getting a reference to each bot and checking if it is alive and in range. If the bot’s accuracy is high enough, it will shoot the enemy and then go back to its assigned domination point.
- Guard – this state manages the defending of domination points, checking for nearby enemies when the point is in the team’s possession.
Additionally, the project also includes basic networking support for the game using Winsock2. This allows a server to host a game and for up to four clients to connect to watch the game. Each client operates its own instance of the camera, so each client can individually move around and zoom into/out of the map. Setting up the server or joining a game is done through the menu system before the game begins (pressing H starts a new game as a server; J brings up the IP address menu).
- DirectX 11
- Visual Studio 2013