Bridge Calculator C API
C API for Bridge Calculator double dummy solver by Piotr Beling
bcalcdds.h File Reference

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.
BCalcDDSbcalcDDS_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.

Detailed Description

Bridge Calculator API header file.


Define Documentation

#define bcalc_declarerToLeader (   declarer)    (((declarer)+3)%4)

Calculate leader hand using declarer hand.

Parameters:
declarer
Returns:
player on lead in deal where declarer is declarer
#define bcalc_nextHand (   hand,
  delta 
)    (((hand)+(delta)+4)%4)

Calculate hand relative to given one.

Parameters:
handone of BCALC_PLAYER_*
deltaclock-wise delta, +1 to next player (in clock-wise), from -3 to +3
Returns:
calculated hand, one of BCALC_PLAYER_* value
#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.

Parameters:
playerplayer number, one of BCALC_PLAYER_*
Returns:
player symbol, one of 'N', 'E', 'S', 'W'
#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.

Parameters:
suitsuit, one of BCALC_SUIT_*
Returns:
suit symbol, one of 'C', 'D', 'H', 'S', 'N' (for NT)
#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).

See also:
bcalc_runtimeVersion

Typedef Documentation

typedef struct BCalcDDS BCalcDDS

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.


Function Documentation

unsigned bcalc_runtimeVersion ( )

Get version of API used by runtime library.

Returns:
version of API used by (typically: dynamic) runtime library
See also:
BCALC_VERSION
void bcalcDDS_clearError ( BCalcDDS solver)

Clear error message.

Parameters:
solverbcalc double dummy solver
void bcalcDDS_delete ( BCalcDDS solver)

Delete double dummy solver, free its memory.

Parameters:
solverconstructed 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).

Parameters:
solverbcalc double dummy solver
cmdscommands to execute

Commands should be space separated and each can be one of:

  • <C><S> - where <C> is card symbol (like: A, Q, T, 6), <S> is suit symbol (one of: C, D, H, S), play choosen card
  • x - play smallest possible card following played suit
  • u - unplay one card
  • ut - unplay last trick
  • ua - unplay all tricks
char* bcalcDDS_getCards ( BCalcDDS solver,
char *  result,
int  player,
int  suit 
)

Get cards owned by given player in given suit.

Parameters:
solverbcalc double dummy solver
playerplayer, one of BCALC_PLAYER_*
suitsuit, one of BCALC_SUIT_*
resultbuffer, place for results, safe length is 14 (13 cards and terminated zero)
Returns:
result, zero-ended string, suits written using symbols from: AKQJT98765432, in case of error result in unchanged form

Get number of cards which left to play in game connected with solver.

Parameters:
solverbcalc double dummy solver
Returns:
how many cards left to play to deal end, integer from 0 to 52
char* bcalcDDS_getCardsToPlay ( BCalcDDS solver,
char *  result,
int  suit 
)

Get cards possible to play in given suit by player who should play.

Parameters:
solverbcalc double dummy solver
resultbuffer, place for results, safe length is 14 (13 cards and terminated zero)
suitsuit, one of BCALC_SUIT_*
Returns:
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.

Parameters:
solverbcalc double dummy solver
Returns:
last error message or NULL if no error, pointer to internal solver buffer (valid up to next bcalcDDS_* call for solver passed as argument)
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).

Parameters:
solverbcalc double dummy solver
whenIndexcard index, from 0 to bcalcDDS_getPlayedCardsCount(solver)-1
suitplace to save suit (if not NULL)
cardSymbolplace to store card symbol (if not NULL)
Returns:
  • 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).

Get number of cards which have been already played.

Parameters:
solverbcalc double dummy solver
Returns:
number of cards which have been already played

Get player which should play now.

Parameters:
solverbcalc double dummy solver
Returns:
player which should play now in game connected with given solver
int* bcalcDDS_getTricksTaken ( BCalcDDS solver,
int *  result 
)

Get numbers of tricks which have been already taken by players in game connected with solver.

Parameters:
solverbcalc double dummy solver
resultbuffer, array of minimum length of 4, place to store calculated numbers of tricks
Returns:
result array, number of tricks taken by players, use BCALC_PLAYER_* as this array indexes

Calculate number of tricks possible to take.

Parameters:
solverbcalc double dummy solver
Returns:
number of tricks possible to take (in future) by line which plays in current situation
int bcalcDDS_getTrump ( BCalcDDS solver)

Get trump suit.

Parameters:
solverbcalc double dummy solver
Returns:
trump suit of game connected with 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.

Parameters:
formatFormat of hands, for example "NESW", "ESWN", ..., "PBN", "LIN":
  • "PBN" is Portable Bridge Notation like format,
  • "lin" is BBO .lin like format,
  • rest show order of hands.
handsPlayers 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.
trumptrump suit, one of BCALC_SUIT_* or BCALC_NT constant
leaderplayer on lead, one of BCALC_PLAYER_* constant
Returns:
Constructed solver or NULL in case of out of memory. Returned solver can have error set in case of deal parser error, invalidate trump or leader (see bcalcDDS_getLastError) and in such case you should not use that solver. In all cases constructed solver should be freed, after use, by bcalcDDS_delete.
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.

Parameters:
solverbcalc double dummy solver
new_leaderplayer 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).

Parameters:
solverbcalc double dummy solver
new_trumpnew trump suit to set for game connected with solver, one of BCALC_SUIT_* or BCALC_NT constant
 All Files Functions Typedefs Defines