Next: , Previous: , Up: C API   [Contents][Index]

5.2 libbot

5.2.1 Overview

View lcov test coverage results on

5.2.2 API

Function: int lw6bot_init (lw6bot_backend_t * backend, lw6bot_seed_t * seed)

backend: backend to use

seed: parameters required to build bot (game state, among other things)

Initializes a bot object. Must be performed before any other call. The seed is absolutely required, for a bot really needs to know what map/context it’s working on, including at creation time

Return value: 1 on success, 0 on failure.

Function: void lw6bot_quit (lw6bot_backend_t * backend)

backend: unitialize a bot backend

Closes a bot, but does not free all ressources.

Function: int lw6bot_next_move (lw6bot_backend_t * backend, int * x, int * y)

backend: bot to work on

x: next x position (out param)

y: next y position (out param)

Queries the bot for its next move, this is actually the one interesting function in the whole bot API.

Return value: 1 on success, 0 on failure.

Function: char * lw6bot_repr (const lw6bot_backend_t * backend)

backend: bot to represent

Gives a human readable representation of bot

Return value: dynamically allocated string.

Function: lw6sys_assoc_t * lw6bot_get_backends (int argc, const char * [] argv)

argc: argc, as passed to main

argv: argv, as passed to main

List available bot backends. The hash contains pairs with id and name for each backend. The id is the technical key you can use to load the backend, the name is something more readable you can display in an interface. The backend objects themselves are not instanciated by this (in fact, they are, but released on the fly) you need to load and initialize them afterwards.

Return value: hash containing id/name pairs.

Function: lw6bot_backend_t * lw6bot_create_backend (int argc, const char * [] argv, const char * name)

argc: argc, as passed to main

argv: argv, as passed to main

name: string containing bot key, typically got from lw6bot_get_backends

Creates a bot backend, this is just about loading the dynamic library if needed, and/or check bot engine is available, and connect to it. It does not perform initialization.

Return value: bot backend.

Function: void lw6bot_destroy_backend (lw6bot_backend_t * backend)

backend: bot backend to destroy

Frees the ressources associated to a bot, which must have been properly uninitialized before.

Return value: none.

Function: int lw6bot_test_register (int mode)

mode: test mode (bitmask)

Registers all tests for the libbot module.

Return value: 1 if test is successfull, 0 on error.

Function: int lw6bot_test_run (int mode)

mode: test mode (bitmask)

Runs the bot module test suite, testing most (if not all...) functions.

Return value: 1 if test is successfull, 0 on error.

Struct: lw6bot_backend_s

The bot backend is the first argument passed to any bot function, it contains reference to all the functions which can be used as well as a pointer on associated data. In OO, this would just be an object, with members and methods, using polymorphism through opaque pointers.

Member of lw6bot_backend_s: dl_handle

Type: lw6dyn_dl_handle_t *

Definition: lw6dyn_dl_handle_t* lw6bot_backend_s::dl_handle

Handle on dynamic library (if it makes sense).

Member of lw6bot_backend_s: bot_context

Type: void *

Definition: void* lw6bot_backend_s::bot_context

Bot specific data, what is behind this pointer really depends on the bot engine.

Member of lw6bot_backend_s: argc

Type: int

Definition: int lw6bot_backend_s::argc

The argc value passed to main.

Member of lw6bot_backend_s: argv

Type: const char **

Definition: const char** lw6bot_backend_s::argv

The argv value passed to main.

Member of lw6bot_backend_s: id

Type: u_int32_t

Definition: u_int32_t lw6bot_backend_s::id

The id of the object, this is non-zero and unique within one run session, incremented at each object creation.

Member of lw6bot_backend_s: seed

Type: lw6bot_seed_t

Definition: lw6bot_seed_t lw6bot_backend_s::seed

Parameters passed at initialization.

Member of lw6bot_backend_s: init

Type: void *(*

Definition: void*(* lw6bot_backend_s::init)(int argc, const char *argv[], lw6bot_data_t *data)

Pointer on lw6bot_init callback code.

Member of lw6bot_backend_s: quit

Type: void(*

Definition: void(* lw6bot_backend_s::quit)(void *bot_context)

Pointer on lw6bot_context callback code.

Member of lw6bot_backend_s: next_move

Type: int(*

Definition: int(* lw6bot_backend_s::next_move)(void *bot_context, int *x, int *y, lw6bot_data_t *data)

Pointer on lw6bot_next_move callback code.

Member of lw6bot_backend_s: repr

Type: char *(*

Definition: char*(* lw6bot_backend_s::repr)(void *bot_context, u_int32_t id)

Pointer on lw6bot_repr callback code.

Struct: lw6bot_data_s

Data used by a bot, those are essentially stable data passed as an argument plus changing data, that is, the game state.

Member of lw6bot_data_s: game_state

Type: const lw6ker_game_state_t *

Definition: const lw6ker_game_state_t* lw6bot_data_s::game_state

Game state the bot will have to base its reflexion upon. This not need be always the same game state, the pointer might change, but it should always refer to the same logical game, that is, at least, same struct.

Member of lw6bot_data_s: param

Type: lw6bot_param_t

Definition: lw6bot_param_t lw6bot_data_s::param

Constant parameters passed to the bot at creation.

Struct: lw6bot_param_s

Parameters usable by a bot engine. Those are the stable, fixed parameters passed at bot creation, they don’t change during the bot life.

Member of lw6bot_param_s: speed

Type: float

Definition: float lw6bot_param_s::speed

Speed of the bot, this is a value between 0.0f and 1.0f, 1 means normal speed, 0 is as slow as possible. Values over 1 will make the bot act/move faster than usual.

Member of lw6bot_param_s: iq

Type: int

Definition: int lw6bot_param_s::iq

IQ is supposed to reflect the cleverness of the bot. The default is 100 (this value is basically a percentage), 0 means just so stupid, and a high value, for instance 200, means very clever.

Member of lw6bot_param_s: cursor_id

Type: u_int16_t

Definition: u_int16_t lw6bot_param_s::cursor_id

The cursor ID, which is a 16-bit non-null integer.

Struct: lw6bot_seed_s

Parameters passed at bot creation, the only use for this is to simplify the protoype of the init function.

Member of lw6bot_seed_s: game_state

Type: const lw6ker_game_state_t *

Definition: const lw6ker_game_state_t* lw6bot_seed_s::game_state

Game state, that is, the level used, the fighters on it, the other cursors positions, and so on.

Member of lw6bot_seed_s: pilot

Type: lw6pil_pilot_t *

Definition: lw6pil_pilot_t* lw6bot_seed_s::pilot

This can be NULL, it’s a pilot object which can be used in some case, when, for instance, in dirty read mode, we want to read the level on the fly without syncing.

Member of lw6bot_seed_s: dirty_read

Type: int

Definition: int lw6bot_seed_s::dirty_read

The dirty read mode (between 0 and 2).

Member of lw6bot_seed_s: param

Type: lw6bot_param_t

Definition: lw6bot_param_t lw6bot_seed_s::param

Parameters given to the bot at creation.

Next: , Previous: , Up: C API   [Contents][Index]