Robot Game comes with a library to make your life easier. It's packaged inside the
rg module which you can import like any other, by writing
import rg at the top of your file. Things to note:
Returns the mathematical distance between two locations.
Returns the walking difference between two locations. Since robots can't move diagonally, this is
dx + dy.
Returns a list of the types of locations that
loc is. Possible values are:
invalid— out of bounds (e.g. (-1, -5) or (23, 66))
normal— on the grid
spawn— spawn point
obstacle— somewhere you can't walk (all the gray squares)
This method has no contextual information about the game—
obstacle, for example, doesn't know if there's an enemy robot standing on a square, for example. All it knows is whether a square is a map obstacle.
The returned list may contain a combination of these, like
Returns a list of adjacent locations to
loc. You can supply a list of location types to filter out as
filter_out. For example,
rg.locs_around(self.location, filter_out=('invalid', 'obstacle'))
would give you a list of all locations you can move into.
Returns the next point on the way from
dest_loc. For example, the following code
import rg class Robot: def act(self, game): if self.location == rg.CENTER_POINT: return ['suicide'] return ['move', rg.toward(self.location, rg.CENTER_POINT)]
would make your robot move to the center, then commit suicide.
The location of the center of the board.
A special type of dict that can be accessed via attributes that holds game settings.
game.robots is a dictionary of robots with locations as keys and robots as values, you can use:
(x, y) in game.robots
True if there's a robot at
(x, y) and