Bridge Calculator C API
C API for Bridge Calculator double dummy solver by Piotr Beling
|
Bridge Calculator API header file. More...
Go to the source code of this file.
Defines | |
#define | BCALC_VERSION 12070 |
Version of bcalc engine API. | |
#define | BCALC_PLAYER_NORTH 0 |
North player. | |
#define | BCALC_PLAYER_EAST 1 |
East player. | |
#define | BCALC_PLAYER_SOUTH 2 |
South player. | |
#define | BCALC_PLAYER_WEST 3 |
West player. | |
#define | bcalc_playerSymbol(player) ("NESW"[player]) |
Convert player number to player symbol. | |
#define | bcalc_declarerToLeader(declarer) (((declarer)+3)%4) |
Calculate leader hand using declarer hand. | |
#define | bcalc_nextHand(hand, delta) (((hand)+(delta)+4)%4) |
Calculate hand relative to given one. | |
#define | BCALC_SUIT_CLUBS 0 |
Club suit number. | |
#define | BCALC_SUIT_DIAMONDS 1 |
Diamond suit number. | |
#define | BCALC_SUIT_HEARTS 2 |
Hearts suit number. | |
#define | BCALC_SUIT_SPADES 3 |
Spades suit number. | |
#define | BCALC_NT 4 |
No trump. | |
#define | bcalc_suitSymbol(suit) ("CDHSN"[suit]) |
Convert suit number to symbol. | |
Typedefs | |
typedef struct BCalcDDS | BCalcDDS |
Handler to bcalc double dummy solver. | |
Functions | |
unsigned | bcalc_runtimeVersion () |
Get version of API used by runtime library. | |
BCalcDDS * | bcalcDDS_new (const char *format, const char *hands, int trump, int leader) |
Construct new solver. | |
void | bcalcDDS_delete (BCalcDDS *solver) |
Delete double dummy solver, free its memory. | |
const char * | bcalcDDS_getLastError (BCalcDDS *solver) |
Get last error string. | |
void | bcalcDDS_clearError (BCalcDDS *solver) |
Clear error message. | |
void | bcalcDDS_exec (BCalcDDS *solver, const char *cmds) |
Execute commands which can modify state of given solver (current situation in game represented by it). | |
int | bcalcDDS_getTricksToTake (BCalcDDS *solver) |
Calculate number of tricks possible to take. | |
int | bcalcDDS_getTrump (BCalcDDS *solver) |
Get trump suit. | |
void | bcalcDDS_setTrumpAndReset (BCalcDDS *solver, int new_trump) |
Set new trump suit and reset deal to initial state (undo all tricks). | |
void | bcalcDDS_setPlayerOnLeadAndReset (BCalcDDS *solver, int new_leader) |
Reset deal to initial state (undo all tricks) and change player on lead. | |
int * | bcalcDDS_getTricksTaken (BCalcDDS *solver, int *result) |
Get numbers of tricks which have been already taken by players in game connected with solver . | |
int | bcalcDDS_getCardsLeftCount (BCalcDDS *solver) |
Get number of cards which left to play in game connected with solver . | |
char * | bcalcDDS_getCards (BCalcDDS *solver, char *result, int player, int suit) |
Get cards owned by given player in given suit . | |
int | bcalcDDS_getPlayerToPlay (BCalcDDS *solver) |
Get player which should play now. | |
char * | bcalcDDS_getCardsToPlay (BCalcDDS *solver, char *result, int suit) |
Get cards possible to play in given suit by player who should play. | |
int | bcalcDDS_getPlayedCard (BCalcDDS *solver, unsigned whenIndex, int *suit, char *cardSymbol) |
Get card played as a whenIndex (when card played on first lead has index 0). | |
int | bcalcDDS_getPlayedCardsCount (BCalcDDS *solver) |
Get number of cards which have been already played. |
Bridge Calculator API header file.
#define bcalc_declarerToLeader | ( | declarer | ) | (((declarer)+3)%4) |
Calculate leader hand using declarer hand.
declarer |
declarer
is declarer #define bcalc_nextHand | ( | hand, | |
delta | |||
) | (((hand)+(delta)+4)%4) |
Calculate hand relative to given one.
hand | one of BCALC_PLAYER_* |
delta | clock-wise delta, +1 to next player (in clock-wise), from -3 to +3 |
#define BCALC_NT 4 |
No trump.
#define BCALC_PLAYER_EAST 1 |
East player.
#define BCALC_PLAYER_NORTH 0 |
North player.
#define BCALC_PLAYER_SOUTH 2 |
South player.
#define BCALC_PLAYER_WEST 3 |
West player.
#define bcalc_playerSymbol | ( | player | ) | ("NESW"[player]) |
Convert player number to player symbol.
player | player number, one of BCALC_PLAYER_* |
#define BCALC_SUIT_CLUBS 0 |
Club suit number.
#define BCALC_SUIT_DIAMONDS 1 |
Diamond suit number.
#define BCALC_SUIT_HEARTS 2 |
Hearts suit number.
#define BCALC_SUIT_SPADES 3 |
Spades suit number.
#define bcalc_suitSymbol | ( | suit | ) | ("CDHSN"[suit]) |
Convert suit number to symbol.
suit | suit, one of BCALC_SUIT_* |
#define BCALC_VERSION 12070 |
Version of bcalc engine API.
Bridge Calculator program version (unsigned integer in form YYMMN) on which base engine. Note that engine is released less often than program (in some program release engine is not changed).
Handler to bcalc double dummy solver.
Double dummy solver represents game with history of play. It also stores many values which was calculated for it.
Usualy you should only use pointer to this type.
unsigned bcalc_runtimeVersion | ( | ) |
Get version of API used by runtime library.
void bcalcDDS_clearError | ( | BCalcDDS * | solver | ) |
Clear error message.
solver | bcalc double dummy solver |
void bcalcDDS_delete | ( | BCalcDDS * | solver | ) |
Delete double dummy solver, free its memory.
solver | constructed by bcalcDDS_new, double dummy solver to delete, it is safe to pass NULL pointer (function do nothing in such case) |
void bcalcDDS_exec | ( | BCalcDDS * | solver, |
const char * | cmds | ||
) |
Execute commands which can modify state of given solver
(current situation in game represented by it).
solver | bcalc double dummy solver |
cmds | commands to execute |
Commands should be space separated and each can be one of:
char* bcalcDDS_getCards | ( | BCalcDDS * | solver, |
char * | result, | ||
int | player, | ||
int | suit | ||
) |
Get cards owned by given player
in given suit
.
solver | bcalc double dummy solver |
player | player, one of BCALC_PLAYER_* |
suit | suit, one of BCALC_SUIT_* |
result | buffer, place for results, safe length is 14 (13 cards and terminated zero) |
result
, zero-ended string, suits written using symbols from: AKQJT98765432, in case of error result
in unchanged form int bcalcDDS_getCardsLeftCount | ( | BCalcDDS * | solver | ) |
Get number of cards which left to play in game connected with solver
.
solver | bcalc double dummy solver |
char* bcalcDDS_getCardsToPlay | ( | BCalcDDS * | solver, |
char * | result, | ||
int | suit | ||
) |
Get cards possible to play in given suit
by player who should play.
solver | bcalc double dummy solver |
result | buffer, place for results, safe length is 14 (13 cards and terminated zero) |
suit | suit, one of BCALC_SUIT_* |
result
, zero-ended string, suits written using symbols from: AKQJT98765432, in case of error result
in unchanged form const char* bcalcDDS_getLastError | ( | BCalcDDS * | solver | ) |
Get last error string.
solver | bcalc double dummy solver |
int bcalcDDS_getPlayedCard | ( | BCalcDDS * | solver, |
unsigned | whenIndex, | ||
int * | suit, | ||
char * | cardSymbol | ||
) |
Get card played as a whenIndex
(when card played on first lead has index 0).
solver | bcalc double dummy solver |
whenIndex | card index, from 0 to bcalcDDS_getPlayedCardsCount(solver)-1 |
suit | place to save suit (if not NULL) |
cardSymbol | place to store card symbol (if not NULL) |
1
only if card with given index was played,0
if index is larger than bcalcDDS_getPlayedCardsCount(solver)-1 (error is not set in such situation and suit
and cardSymbol
are not changed). int bcalcDDS_getPlayedCardsCount | ( | BCalcDDS * | solver | ) |
Get number of cards which have been already played.
solver | bcalc double dummy solver |
int bcalcDDS_getPlayerToPlay | ( | BCalcDDS * | solver | ) |
Get player which should play now.
solver | bcalc double dummy solver |
solver
int* bcalcDDS_getTricksTaken | ( | BCalcDDS * | solver, |
int * | result | ||
) |
Get numbers of tricks which have been already taken by players in game connected with solver
.
solver | bcalc double dummy solver |
result | buffer, array of minimum length of 4, place to store calculated numbers of tricks |
result
array, number of tricks taken by players, use BCALC_PLAYER_* as this array indexes int bcalcDDS_getTricksToTake | ( | BCalcDDS * | solver | ) |
Calculate number of tricks possible to take.
solver | bcalc double dummy solver |
int bcalcDDS_getTrump | ( | BCalcDDS * | solver | ) |
Get trump suit.
solver | bcalc double dummy solver |
solver
BCalcDDS* bcalcDDS_new | ( | const char * | format, |
const char * | hands, | ||
int | trump, | ||
int | leader | ||
) |
Construct new solver.
Each solver has own memory and it is thread safety to operate on multiple solvers at the same time, but it is not safety to call more than one bcalcDDS_* function for one solver at the same time.
format | Format of hands , for example "NESW", "ESWN", ..., "PBN", "LIN":
|
hands | Players hands. Each player must have the same number of cards. To get situation inside trick, you should create tricks beginning situation and call bcalcDDS_exec to play tricks cards. |
trump | trump suit, one of BCALC_SUIT_* or BCALC_NT constant |
leader | player on lead, one of BCALC_PLAYER_* constant |
void bcalcDDS_setPlayerOnLeadAndReset | ( | BCalcDDS * | solver, |
int | new_leader | ||
) |
Reset deal to initial state (undo all tricks) and change player on lead.
Note that this doesn't clear transposition table, so calculation results which was colecting with an other player on lead will be still use. So if you need to iterate over all leader-trumps pairs, and calculate number of tricks to take for each, it is much more effective to iterate over trumps in outer loop and over leaders in inner loop.
solver | bcalc double dummy solver |
new_leader | player on lead, one of BCALC_PLAYER_* constant |
void bcalcDDS_setTrumpAndReset | ( | BCalcDDS * | solver, |
int | new_trump | ||
) |
Set new trump suit and reset deal to initial state (undo all tricks).
solver | bcalc double dummy solver |
new_trump | new trump suit to set for game connected with solver , one of BCALC_SUIT_* or BCALC_NT constant |