pub struct Api<'a> {
    mmap: MmapRaw,
    ipcdata: &'a mut IpcSharedMemory,
}
Expand description

Your bot’s interface to the game data.

This class provides a safe interface to the shared memory used for fast communication with the gameserver. Use the provided methods to obtain information about your snake’s surroundings or the server configuration, and to access persistent memory.

Please note that most methods return direct references to the shared memory structures. These are specified and documented in the ipc module.

Fields

mmap: MmapRawipcdata: &'a mut IpcSharedMemory

Implementations

Construct a new Api instance from the given shared memory file.

This function is used internally by the bot framework. Do not worry about it.

Get a reference to the server config data.

The returned structure contains information about the server configuration and static world information.

Get a pointer to the self information.

The returned structure contains information about your snake and parameters of the world.

Get a reference to the array of food items around your snake’s head.

The items are sorted by the distance from your snake’s head, so the first entry is the closest item.

Only the valid entries in the shared memory are returned.

Get a reference to the array of snake segments around your snake’s head.

The items are sorted by the distance from your snake’s head, so the first entry is the closest item.

Only the valid entries in the shared memory are returned.

Get a reference to the array of bot information structures.

Only the valid entries in the shared memory are returned.

Remove all color entries from the shared memory.

This must be called in your crate::usercode::init() function to remove the default color in case you want to set your own.

Add a color to your snake’s color sequence.

Call this multiple times from crate::usercode::init() to set up your snake’s colors. The provided sequence will be repeated along your snake if it has more sequence than colors were specified. You can set up to ipc::IPC_COLOR_MAX_COUNT colors.

Get a reference to the persistent memory.

You can use persistent memory to remember things across multiple lives of your snake. It is saved after your snake dies (even when your code crashes) and restored when it respawns.

Note that the size this memory is very limited (given by the ipc::IPC_PERSISTENT_MAX_BYTES constant). Use it wisely.

Send a log message.

These messages will appear on the web interface and in the World update stream when you provide your viewer key to the server.

Rate limiting is enforced by the gameserver, so messages are dropped when you send too many of them.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.