A whole Badger Brawl bot in one file, StarterBot.cs, small enough for a first
programming class. There's no project to set up: .NET 10 runs a single .cs file directly, and
downloads the one package it uses (CommandLineParser,
which reads the options below) the first time you run it.
-
Install the .NET 10 SDK.
-
Save
StarterBot.csinto an empty folder, or download it from a terminal:curl -O https://raw.githubusercontent.com/SnowSE/NetRTS/main/samples/csharp/StarterBot.cs
(In Windows PowerShell type
curl.exeinstead ofcurl.) -
In that folder, run it with a name of your own (3-32 letters, digits,
-or_):dotnet run StarterBot.cs --player-name Frank
-
Open the link it prints to watch your match at NetRTS.snowse.io.
The first run signs you up and saves your secret key in a file named after your bot, like
apikey-Frank.txt. Keep that file; it's how the server knows the bot is you.
| Option | What it does |
|---|---|
--player-name Frank |
Your bot's name. Without it the bot asks. |
--opponent rusher |
The house bot to play: sitter (default, easiest), economist, balanced or rusher (hardest). |
--tick-ms 250 |
Milliseconds per tick for a match you start (100-10000, default 1000). |
--create-match our-game |
Start a match for a classmate to join, instead of playing a house bot. |
--join-match our-game |
Join a waiting match by its name (or its id). League matches like season-week3 work the same way: claim your bot with Discord first, and play starts when the admin starts the heats. |
--server http://localhost:5080 |
Play on another server, like one running on your own computer. |
Every option, and its default, is a property of the Options class at the bottom of StarterBot.cs.
Change a Default there to change the setting, like your name, so you don't have to type it each
time.
To play a classmate, one of you runs --create-match our-game and the other --join-match our-game.
The first bot waits until the second one joins, then the match starts.
To see the options from the bot itself, put -- before --help (otherwise dotnet run shows its
own help):
dotnet run StarterBot.cs -- --helpTo add an option of your own, add a property with an [Option("my-option")] attribute to the
Options class.
The program runs six steps: read the options (one line, thanks to CommandLineParser), sign up, get
into a match, wait for it to start, play, and print the result. Each step after the first is its own
method. The strategy is in Decide, which calls one small method per idea:
GatherOre: idle workers dig the ore closest to the headquarters.TrainWorker: the headquarters trains workers until there are 8.BuildBarracks: one worker builds a Barracks.TrainSoldier: the Barracks trains soldiers.Attack: with 5 soldiers, they attack the enemy's starting corner.
It beats sitter, and sometimes economist; balanced and rusher are too strong for it. Use
--opponent to pick which house bot you play.
- Train more workers, or send some to a second ore deposit.
- Build a second Barracks.
- Mix in Archers (they shoot from 4 tiles away).
- Defend: when enemies come near your headquarters, attack them with everything.
- Research upgrades at a TechLab.
The bot guide lists every command, unit, building and rule.