AMazeBot 2016 API: BotBrain
BotBrain
is the class that your class will
derive from. Therefore this is the primary API you need to
know to write your bot programs.
Constants
There are some constants available that describe some
parameters of the maze.
Signature |
Meaning |
int |
MAZE_SIZE |
The number of cells along either
side of the maze (which is always square). In this
year's version it is 29. |
int |
MAX_COORD |
The highest valid coordinate in the
maze. Since the cells are counted from 0, the maximum is
MAZE_SIZE - 1 = 28. |
int |
GOAL_SIZE |
The number of cells along either side of the goal room
(which is always square). In this year's version it is
3. |
Method Summary
The methods are divided into 2 categories: those that consume
energy, and those that do not.
Energy-free Methods
The following 8 methods are free—they do not use any of the
bot's energy. Some of them are required only once at the start
of a run, and others assist in AI heuristics or debugging.
Energy-consuming Methods
The following methods are the main "action" methods that
control the bot, and all use some energy. Each bot starts a
maze with 10,000 units of energy in its battery. If there is
insufficient energy remaining in the battery, a requested
action will not be completed and your bot will be exhausted.
Signature |
Valid Parameters |
Energy Cost |
boolean |
move(COMPASS
direction) |
Compass.NORTH
Compass.EAST
Compass.SOUTH
Compass.WEST |
8, or 12
if blocked |
boolean |
look(LOOK
direction) |
Compass.NORTH
Compass.EAST
Compass.SOUTH
Compass.WEST |
4 |
Point |
getPosition() |
|
1 |
Method Details
Each method is described in detail below.
getGoalCorner
Point getGoalCorner()
Returns the coordinates of the top-left cell in the goal
area, which is always 3 × 3 cells in size.
- Returns:
- A
Point
representing the goal area's
top-left cell.
- Energy cost:
- None.
getStartPosition
Point getStartPosition()
Returns the coordinates of the cell in which the bot will
start the current maze. Each maze may have a different
starting position.
- Returns:
- A
Point
representing the bot's starting
position.
- Energy cost:
- None.
getEnergy
int getEnergy()
Returns the amount of energy currently remaining in the
bot's battery. All bots will start a maze with 10,000 units
of energy (value exposed in the STARTING_ENERGY
constant). Useful actions consume some energy. This method
is not particularly useful for solving mazes, but may assist
in diagnostics.
- Returns:
- The bot's current reserve of energy.
- Energy cost:
- None.
println, print
void println(String message)
void print(String message)
void println()
These methods print the given String
(or just
a newline in the case of the last variant) to the console
(in the IDE or a CLI; no console is shown when invoking
directly from desktop) and also to the bot's log file. The
log file for all bots is
"./logs/<bot-package-name>.log". This log file records
any exceptions encountered by your bot. These methods are
intended to allow you to output your own diagnostic
information to assist in debugging.
The methods differ in whether they accept a string, and if
so whether they print a newline after the string. Together
they can be used to produce any format desired for output.
- Parameters:
message
- the message to be printed and
recorded in the log file. Can be any String
expression.
- Energy cost:
- None.
isInteractive
boolean isInteractive()
Determines whether the bot is running in an interactive
mode, i.e. the developer mode. This can be used, for
example, to create a GUI window for diagnostics when running
in developer mode, but avoid doing so in batch mode.
- Returns:
true
if the bot is running in developer
mode; false
otherwise.
- Energy cost:
- None.
printMazeType, printMazeSeed
void printMazeType()
void printMazeSeed()
These methods print to the log the type and seed
respectively of a randomly generated maze. This can be
useful in batch mode for identifying mazes that expose some
problem in your code. The batch log file for all bots is
"./logs/<bot-package-name>_batch.log". The batch log
won't record any maze information on its own, since doing so
during a batch will result in a flood of messages. These
methods allow you to do so if you desire.
- Energy cost:
- None.
clearLog
void clearLog()
Clears the contents of the bot's log file, but only if
invoked in the developer module. Has no effect in batch
mode.
The intention of this method is to allow developers to keep
the bot's log file open in a text editor capable of
reloading files on change, and have only the last run's log
shown (instead of having to repeatedly scroll to the bottom
of the file). Call this before your bot's main loop.
- Energy cost:
- None.
move
boolean move(COMPASS direction)
boolean move(String direction)
Attempts to move the bot in the given direction.
This method's cost is dependent on the outcome. If the
destination cell is a floor, then the move succeeds, the
bot's position is updated and 8 units of energy are
consumed. However if the destination cell is a wall, then
the move fails, the bot's position is unchanged, and 12
units of energy is consumed.
From the perspective of a physical robot it may seem odd
that bumping into a wall and returning to the middle of the
original cell should cost more energy than moving fully into
an adjacent cell. After all isn't the total distance
travelled in each case is very close to the same? Yes; but
it is generally a good idea to avoid bumping into walls for
other reasons; simply because it's a waste of time,
needlessly increases wear on both bot and wall, and can
negatively impact a bot's social status.
In our virtual environment we have set up the energy cost
to account for these other factors and provide an incentive
to look before moving.
- Parameters:
direction
- the direction in which to move,
either a COMPASS
direction or a String
("North","East"."South","West"). Case is not important.
- Returns:
true
if the move was successful, false
if it failed.
- Energy cost:
- 8 units if successful, 12 if failed.
look
boolean look(COMPASS direction)
boolean look(String direction)
Looks into the adjacent cell specified by the direction
parameter, and determines whether that cell is a floor or a
wall.
- Parameters:
direction
- the direction in which to look,
either a COMPASS
direction or a String
("North","East"."South","West"). Case is not important.
- Returns:
true
if the cell is clear (a floor), false
if it is blocked (a wall).
- Energy cost:
- Always 4 units.
getPosition
Point getPosition()
Returns the bot's current position. This is a convenience
method intended only to help beginners. Once you have
determined the bot's starting position (see getStartPosition
)
it is possible to thereafter continually track the position
of your bot as you move it. Such a technique costs no energy
at all, whereas this method costs 1 unit for each call. A
small cost but it adds up, and in the competition it can
make a difference.
- Returns:
- A
Point
representing the bot's current
position.
- Energy cost:
- 1 unit.