Halite/Blockly: Create a Halite bot with Blocks!


#1

We’re excited to announce that you can now build a bot and submit it using Blockly! Check out our Blockly web editor here.

If you’ve used Blockly or Scratch before in school, now you can prototype a bot in our new editor. When you’re done, submit it directly to the competition, or download the JavaScript form of your bot and continue hacking.

We hope that newer programmers can experiment with building a Halite bot using this tool. Share our Blockly editor with the new programmers in your life and spread the fun of Halite!

00%20PM

Docs

Shipyard

  • “nothing on top of the shipyard” - Returns a boolean indicating if the shipyard has a ship on it or not.
    Useful to check if the coast is clear before constructing a new ship.
  • “spawn” - The shipyard builds a new ship for 1,000 halite. If there is already a ship on the shipyard, your new ship will collide with it, destroying both ships.
  • “current halite” - Returns the amount of halite you currently have stored. Your goal is to collect halite. Direct your ships to bring their halite cargo back to your shipyard to increase your current halite. Halite can be spent to build new ships.

Ship Actions

  • “move this ship toward” - Ships can move one square in a cardinal direction per turn toward a given target. Each move costs 10% of the halite available in the sea at the ship’s starting location, debited from the ships’ cargo.

  • “move this ship” - Ships can move one square in a cardinal direction per turn. Each move costs 10% of the halite available in the sea at the ship’s starting location, debited from the ships’ cargo.

  • “Collect halite” - Ships can collect 25% of the halite from the sea at their present location, rounded up to the nearest integer.

  • “Convert into dropoff” - Ships can be converted into dropoff sites at their present location. The conversion costs 4,000 halite, deducted from total current stored halite. Ships can store halite at a dropoff point just as they would at the shipyard.

Ship Status

  • “Current status” - Returns your ship’s current status.

  • “Set status to ‘’” - Set a ship’s status to control what it does from turn to turn. This makes your ship stateful so that it can save knowledge and complete tasks over multiple turns.

  • “this ship’s cargo” - Returns how much halite this ship is carrying. Ships have a capacity of 1,000 halite.

  • “Halite under this ship” - Returns the halite concentration in the sea beneath the ship’s current location.

  • “this ship is at home” - Checks if the ship is currently at a shipyard.

Distance and Directions

  • “distance to” - The Manhattan distance between two locations, accounting for the wraparound of the game map.

  • “the nearest shipyard or dropoff” - The position of the closest shipyard or dropoff.

  • “nearby patch of halite” - The position of a nearby rich location of halite.

  • “random direction” - Returns a random cardinal direction.

Game Constants

  • “price of a ship” - The price of building a new ship at your shipyard is 1,000 halite.

  • “price of a dropoff” - The price of converting a ship to a new dropoff is 4,000 halite, deducted from total current stored halite. The converted ship’s halite cargo and the halite in the sea under the new dropoff is credited to the player. These credits resolve first, and can be used toward the cost of the dropoff.

Logging

  • “print ‘’” - Logging is how your bot communicates with you. Read logs in the panel under the visualizer - scroll all the way down to see your logging statements.

#2

#3

Pretty cool…

2 quick things:

  1. Variables do not seem to work… anytime I try to use one, it crashes and won’t “compile”.
  2. We really need a value for current turn number or total number of ships that can be used with the shipyard (especially without variables), so that we don’t just building ships constantly.

#4

@msa_webmaster thanks for the feedback!

We’ll be tracking the issue here:

If you’re interested in digging into Blockly, we’d welcome contributions for more blocks.