This C#-based WebSocket client was developed for the HackArena 2.5, organized by kn init. It serves as a api wrapper for participants to create AI bots that can play the game.
To fully test and run the game, you will also need the game server and GUI client, as the GUI provides a visual representation of gameplay. You can find more information about the server and GUI client in the following repository:
Clone this repo using git:
git clone https://github.com/INIT-SGGW/HackArena2.5-StereoTanks-CSharpThe bot logic you are going to implement is located in
Bot/Bot.cs:
Bot example can be found in Bot/Bot.cs file.
using StereoTanksBotLogic;
using StereoTanksBotLogic.Enums;
using StereoTanksBotLogic.Models;
namespace Bot;
public class Bot : IBot
{
public Bot(LobbyData lobbyData)
{
// Initialize your bot.
}
public void OnSubsequentLobbyData(LobbyData lobbyData)
{
// Define what should happen when lobby is changed.
// For example when somebody new joins or disconnects
// new LobbyData is sent and this method is run.
}
public BotResponse NextMove(GameState gameState)
{
// Define behaviour of your bot in this method.
// This method will be called every game tick with most recent game state.
// Use BotResponse to return your action for each game tick.
return BotResponse.Pass();
}
public void OnGameEnd(GameEnd gameEnd)
{
// Define what your program should do when game is finished.
}
public void OnGameStarting()
{
// Define what your program should do when game is starting.
}
public void OnWarningReceived(Warning warning, string? message)
{
// Define what your program should do when game is warning is recieved.
}
}The Bot class implements the IBot interface and defines the behavior of the bot.
- The constructor
Bot(LobbyData lobbyData)is called when the bot is created to initialize its state based on the initial lobby data. - The
OnSubsequentLobbyData(LobbyData lobbyData)method is triggered whenever there is an update to the lobby data, such as when players join or leave the game. - The
NextMove(GameState gameState)method is called every game tick to determine the bot's next action. This is where the bot’s behavior logic is implemented. It returns an BotResponse that defines what action the bot will take during the game tick. - The
OnGameEnd(GameEnd gameEnd)method is called when the game finishes, allowing the bot to handle any final actions or cleanup. - The
OnGameStarting()method is called when the game is about to start, letting the bot perform any preparations. - The
OnWarningReceived(Warning warning, string? message)method is invoked when the game issues a warning, allowing the bot to handle warnings appropriately.
The NextMove method returns an BotResponse object, which can be one of the following:
MoveResponse: Move the tank forward or backward. TheMoveDirectionenum defines the options:FORWARDorBACKWARD.RotationResponse: Rotate the tank or turret. TheRotationDirectionenum specifies the direction:LEFTorRIGHT.AbilityUseResponse: Use an ability such as firing a bullet or using a radar. TheAbilityTypeenum includes various options, such asFireBullet,UseLaser,FireDoubleBullet,UseRadar,DropMine,FireHealingBullet, andFireStunBullet.PassResponse: Do nothing for the current game tick.GoTo: Move the tank to specified coordinates on a board. You will need to send this response every tick until bot will reach specified destination. You can also useCostsandPenaltiesobjects in order to fine tune pathfinding to your needs!CaptureZone: Command the tank to attempt to capture the zone it is currently on. This is only effective if the tank is on a capturable zone tile. Use this method to increase your share in zone capture.
You can create these responses using static factory methods in the BotResponse class:
BotResponse.Move()BotResponse.Rotate()BotResponse.UseAbility()BotResponse.Pass()BotResponse.GoTo()BotResponse.CaptureZone()
You can modify the mentioned file and create more files in the
Bot directory. Do not
modify any other files, as this may prevent us from running your bot during
the competition.
If you need to include static files that your program should access during
testing or execution, place them in the data folder. This folder is copied
into the Docker image and will be accessible to your application at runtime.
For example, you could include configuration files, pre-trained models, or any
other data your bot might need.
You can run this bot in three different ways: locally, within a VS Code development container, or manually using Docker.
Simply open project in Visual Studio and use IDE interface to run and debug your bot!
To run the bot locally, you must have dotnet SDK 8.0 or later installed and dotnet runtime 8.0 or later.
Verify your dotnet SDK version by running:
dotnet --list-sdksVerify your dotnet SDK runtime by running:
dotnet --list-runtimesTo build your solution use in Debug configuration use:
dotnet build HackArena2.5-StereoTanks-CSharp.slnRemember we will test your bot in optimized Release configuration so make sure everything is correct. You can build Release version using command below:
dotnet build HackArena2.5-StereoTanks-CSharp.sln -c ReleaseAssuming the game server is running on localhost:5000 (refer to the server
repository's README for setup instructions), start the bot by running in build directory StereoTanksBot/bin/Debug/net8.0:
./StereoTanksBot -n CSharpBot -t heavyThe -n argument is required and must be unique. The -t specifies which type of tank will be hosted. Acceptable value are: heavy or light. For additional configuration options, run:
./StereoTanksBot --helpTo run the bot manually in a Docker container, ensure Docker is installed on your system.
Steps:
- Build the Docker image:
docker build -t bot . - Run the Docker container:
docker run --rm bot --host host.docker.internal -n TEAM_NAME -t heavy
If the server is running on your local machine, use the
--host host.docker.internal flag to connect the Docker container to your local
host.