Debugging of Bots

Hi Hennie,
Any suggestions on whats the best way to debug a bot in visual studio.
My current solution is to add a Debugger.Launch(); inside the bot code, and set my bot’s to execute the battleship app with all the relevant arguments.

Then VS prompts me which debugger to use

Attach to process method won’t suffice because battleship launches and ends the bot so fast each round.


Put the state.json file somewhere, then you can set the command line arguments for your bot using these kinds of instructions and then run your bot using F5 (possibly with breakpoints set).

You can have a look in the log.txt file that is written every round to see what the command line arguments tend to look like.

One hassle at the moment is that the state.json file is currently deleted for all the rounds except the last one, so what I do is simply to log the content of the state.json file just as my bot starts up, so I can paste it back into a file if I want to do some debugging, or run the round again after some changes to my bot.

Hi Mr_C,

Gustav has a good suggestion and that is what I usually do. In cases where I really want to get debug across multiple rounds or train a machine learning algorithm however I usually modify the game engine code.

Because you are using .Net you can run your bot directly from the game engine. My suggestion would be to download the source code for the game engine and then extend the player class, you can then start the game with your bot as one of the players, that way you are in the same process as the game engine and can debug fairly easily.

Alternatively modify the BotRunner class to load your main method directly by importing your project/bot into the class and then run it directly instead of starting a new process.

Hope this helps

Thanks guys. Both suggestions are great. I like the idea of cracking open the game engine. Ill give that a try

Hmmm, any advice for debugging a match for a Java bot?
also using a state.json file that you have harvested.

Hi mvariyawa,

As gustav suggested you can save a state.json file and start your bot manually with that as the argument.

Another alternative would be to change the game engine slightly so it starts the java bot with remote debugging parameters. That way for every round the java program will start and will wait for the remote debugger to connect before continuing with execution. Just remember to run the game engine with the -nolimit parameter so that it doesn’t kill your bot for going over time.

Thanks @gustav. That works well for debugging a single round.

Thanks @Wackymax. I was trying to get away with not meddling in C#. I have zero C# knowledge, a few days left, and an incomplete Bot :stuck_out_tongue:

I went with unit tests instead. It’s not perfect, but it’s not completely useless. They should bring me some value-for-money in the long term…I hope!

I’m still a bit lost. I know how to add the cmd line arg for the battleships to play with my bot…but I don’t know how to be able to debug the bot itself…I’ve been using the Log function built-in but I need to access it live…There’s a flaw in my logic but I can’t see it :pensive:

I gave up on trying to debug live. I wrote some unit tests, and I debug those instead.

@Wackymax seems to have a good answer though.

To debug live, I added a while loop in the beginning to wait until a debugger connected before continuing.

1 Like

@unss that is genius. Thanks