Step debugging in Ruby


#1

If you’re using Rubymine

You can set up remote debugging.

Create a ruby remote debug configuration in Rubymine, setting the remote root and local root folder to your bot’s directory:

https://www.jetbrains.com/help/ruby/remote-debugging.html

Start your game with:

./halite --no-timeout "rdebug-ide -- host 0.0.0.0 --port 1234 -- MyBot.rb" "ruby whatever_opponent.rb"

Set your breakpoints, and run your remote debug configuration in Rubymine.

For me, rdebug-ide slows processing by a ton, so this was slow and tedious for issues that occurred late in the game on larger maps.

CLI alternative

I had no luck with pry-remote and similar, and also needed to monkey patch them to keep them from sending log and debugging messages back to halite.

Here’s a gist to send messages from halite to a unix socket and back, so that your terminal can be connected to your ruby process, and make use of pry / byebug etc. without fouling up your output to halite.

Update your game.rb (assuming you’re using the starter kit) to read/write to the socket instead of standard in / out (see gist).

Run with

./halite --no-timeout "ruby ProxyBot.rb" "some_other_opponent.rb"

Then launch your bot from another terminal:

ruby MyBot.rb