SPN C++ Bot Framework
|
A class providing a simplified API for the Bots. More...
#include <bot_api.h>
Public Member Functions | |
Api (IpcSharedMemory *shm) | |
Constructor for the API interface object. More... | |
const IpcServerConfig * | getServerConfig (void) |
Get a pointer to the server config data. More... | |
const IpcSelfInfo * | getSelfInfo (void) |
Get a pointer to the self information. More... | |
const IpcFoodInfo * | getFood (void) |
Get a pointer to the Food list. More... | |
size_t | getFoodCount (void) |
Get the length of the Food list. More... | |
const IpcSegmentInfo * | getSegments (void) |
Get a pointer to the Segment list. More... | |
size_t | getSegmentCount (void) |
Get the length of the Segment list. More... | |
const IpcBotInfo * | getBots (void) |
Get a pointer to the Bot list. More... | |
size_t | getBotCount (void) |
Get the length of the Bot list. More... | |
void | clearColors (void) |
Clear the color list. More... | |
bool | addColor (uint8_t r, uint8_t g, uint8_t b) |
Add a color to the color list. More... | |
void * | getPersistentMemory (void) |
Get a pointer to the persistent memory. More... | |
void | log (const char *msg) |
Send a log message. More... | |
Public Attributes | |
ipc_real_t | angle |
The direction into which the bot should move in the current frame. | |
bool | boost |
Set this to true to boost in this frame. | |
A class providing a simplified API for the Bots.
The main purpose of this class is to abstract away the layout details of the shared memory used to interface with the gameserver. Methods are provided to extract relevant data from the shared memory and the movement parameters for the current frame can be easily set using public member variables.
Most methods return pointers pointing into the shared memory to minimize the overhead. The returned structures are described in ipc_format.h .
|
inline |
Constructor for the API interface object.
Initialized the internal variables and stores the pointer to the shared memory. No need to call this from the bot code.
shm | Pointer to the (already set up) shared memory. |
|
inline |
Add a color to the color list.
You should do this during your bot's initialization. Colors cannot be changed afterwards.
r | The red channel (0-255). |
g | The green channel (0-255). |
b | The blue channel (0-255). |
|
inline |
Clear the color list.
You need to add new colors using addColor() or your snake will have lame default colors!
|
inline |
Get the length of the Bot list.
|
inline |
Get a pointer to the Bot list.
The length of the list can be determined using getBotCount().
|
inline |
Get a pointer to the Food list.
The Food list is sorted by distance from your snake's head.
The length of the list can be determined using getFoodCount().
|
inline |
Get the length of the Food list.
|
inline |
Get a pointer 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_PERSISTENT_MAX_BYTES constant). Use it wisely.
|
inline |
Get the length of the Segment list.
|
inline |
Get a pointer to the Segment list.
The Segment list is sorted by distance from your snake's head.
The length of the list can be determined using getSegmentCount().
|
inline |
Get a pointer to the self information.
This is not a list, but a pointer to a single structure containing information about your snake and parameters of the world.
|
inline |
Get a pointer to the server config data.
This is not a list, but a pointer to a single structure containing information about the server configuration and static world information.
It is only written once, so if you overwrite it by accident, it will only be reset when your bot restarts.
|
inline |
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.
msg | Pointer to the null-terminated message string. |