C#

Overview

The version of C# supported is C# Mono 6.6.0.161

Each turn your source code will be compiled within a new sandbox, by default no information is shared or persisted between turns, if you wish to persist data then you should use the User Data fields within the API.


Input - Standard Input (STDIN)

Within C# you can simply use Console.ReadLine() to capture the string input towards your bot.

// Read in the current Turn Data
string input = Console.ReadLine();

Ouput - Standard Outout (STDOUT)

Within C# you can simply use Console.WriteLine() to return your CSV based instructions to BotWars, however ensure you call this with Console.Out, as shown below, otherwise the output will not be read by the game engine.

// Return actions to BotWars
Console.WriteLine(string.Join(",", commands), Console.Out);

Example Bot

The below bot is very basic, it will simply try move closer to an enemy bot, and when close enough attempt an attack on that enemy bot.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ExampleBot
{
    class Program
    {
        static void Main(string[] args)
        {
            // Read in the current Turn Data
            string input = Console.ReadLine();

            // Created to hold each command
            List output = new List();

            // Split the game data
            var gameData = input.Split('#');

            // Split map state from the game data
            var bots = gameData[1].Split(',');

            // Find a victim
            string victimXY = null;
            foreach(var nextBot in bots)
            {
                if (nextBot.StartsWith("E"))
                {
                    var data = nextBot.Split('-');
                    victimXY = data[1];
                    break;
                }
            }

            foreach (var nextBot in bots)
            {
                if (nextBot.StartsWith("F"))
                {
                    var info = nextBot.Split('-');
                    output.Add(Result(info[1], victimXY));
                }
            }

            // Return actions to BotWars
            Console.WriteLine(string.Join(",", output), Console.Out);
        }

        static string Result(string thisBot, string destinationBot)
        {
            var thisBotCords = thisBot.Split(':');
            var destBotCords = destinationBot.Split(':');

            int.TryParse(thisBotCords[0], out int thisX);
            int.TryParse(thisBotCords[1], out int thisY);
            int.TryParse(destBotCords[0], out int destX);
            int.TryParse(destBotCords[1], out int destY);

            // Check if in attack range
            if(thisX == destX && thisY == destY - 1)  return thisBot + "-A-N";
            else if (thisX == destX && thisY == destY + 1) return thisBot + "-A-S";
            else if (thisX == destX - 1 && thisY == destY) return thisBot + "-A-E";
            else if (thisX == destX + 1 && thisY == destY) return thisBot + "-A-W";
            else
            {
                // Not in range, so move closer
                if(thisX < destX) return thisBot + "-M-E";
                if(thisX > destX) return thisBot + "-M-W";
                if(thisY > destY) return thisBot + "-M-S";
                if(thisY < destY) return thisBot + "-M-N";
            }

            return thisBot + "-D";
        }
    }
}
❤️ Feedback