### DealerParBin and SidesParBin Output Examples Source: https://github.com/afwas/python-dds/blob/master/dds.md Shows example output formats for DealerParBin and SidesParBin functions, which provide results in binary using the parResultsMaster structure, and how these can be converted to text formats. ```text “Par 110: NS 2S NS 2H” ``` ```text “NS Par 130: NS 2D+2 NS 2C+2” when it does not matter who starts the bidding. ``` ```text ”NS Par -120: W 2NT
EW Par 120: W 1NT+1” when it matters who starts the bidding. ``` -------------------------------- ### Play Trace Example Source: https://github.com/afwas/python-dds/blob/master/dds.md Illustrates a play trace example showing the number of tricks from the declarer's viewpoint after each card is played, including the initial double-dummy value before any cards are played. ```text 9 10 10 10 10 9 9 ``` -------------------------------- ### Setup and Initialization Source: https://context7.com/afwas/python-dds/llms.txt Load the shared library and configure the thread pool before calling any solver function. SetMaxThreads(0) auto-configures threads based on available CPU cores and memory. ```APIDOC ## Setup and Initialization Load the shared library and configure the thread pool before calling any solver function. `SetMaxThreads(0)` auto-configures the number of threads based on available CPU cores and memory. ```python import dds import ctypes # Load library (edit path in dds.py if needed — default: "libdds.so") # dds = cdll.LoadLibrary("libdds.so") # Auto-configure threads (mandatory on Linux/Mac, recommended on Windows) dds.SetMaxThreads(0) # Optionally request a specific number of threads (here: 4) actual_threads = dds.SetMaxThreads(4) print(f"Threads allocated: {actual_threads}") # Release all DDS-allocated memory when done dds.FreeMemory() ``` ``` -------------------------------- ### Analyze Play with PBN Deal Source: https://github.com/afwas/python-dds/blob/master/examples/readme.md Analyzes a deal and card plays to evaluate the leader's trick-making potential. Shows shifts in expectation when mistakes are made. This example uses a PBN deal format. ```text AnalysePlayPBNBin, hand 2: OK ----------------------------- AK96 KQ8 A98 K63 87 QJT5432 A62 T QJT4 6 AT75 QJ82 J97543 K7532 94 Number : 49 Play 0: -- 9 Play 1: SQ 10 Play 2: D2 10 Play 3: S8 10 Play 4: SA 10 Play 5: HK 10 Play 6: HT 10 Play 7: H3 10 Play 8: H2 10 Play 9: HQ 10 Play 10: S2 10 Play 11: H4 10 Play 12: H6 10 Play 13: H8 10 Play 14: D6 10 Play 15: HJ 10 Play 16: HA 10 Play 17: S7 10 Play 18: SK 10 Play 19: S4 10 Play 20: C4 10 Play 21: D8 10 Play 22: C2 10 Play 23: DK 10 Play 24: D4 10 Play 25: H9 10 Play 26: C5 10 Play 27: S6 10 Play 28: S3 10 Play 29: H7 10 Play 30: C7 10 Play 31: C3 10 Play 32: S5 10 Play 33: H5 10 Play 34: CT 10 Play 35: D9 10 Play 36: ST 10 Play 37: D3 9 Play 38: DQ 9 Play 39: DA 9 Play 40: C8 9 Play 41: S9 9 Play 42: SJ 9 Play 43: C9 9 Play 44: DT 9 Play 45: CQ 9 Play 46: D5 9 Play 47: CA 9 Play 48: C6 9 ``` -------------------------------- ### Calculate Double Dummy Table Source: https://github.com/afwas/python-dds/blob/master/examples/readme.md Analyzes a deal from all players' perspectives in all nominations to determine trick outcomes. Useful when the declarer can impact the final result. This example uses a PBN deal format. ```text CalcDDtable, hand 2: OK ----------------------- AK96 KQ8 A98 K63 87 QJT5432 A62 T QJT4 6 AT75 QJ82 J97543 K7532 94 North South East West NT 9 9 3 3 S 4 4 9 9 H 10 10 2 2 D 8 8 3 3 C 6 6 7 7 ``` -------------------------------- ### Par Contract Calculation Examples Source: https://github.com/afwas/python-dds/blob/master/dds.md Illustrates the notation used for par contracts, indicating outcomes for different player pairs (EW, NS, W) and contract results (e.g., doubled, going down, making exactly, making overtricks). ```text "4S*-EW-1" means that E and W can both sacrifice in four spades doubled, going down one trick. ``` ```text "3N-EW" means that E and W can both make exactly 3NT. ``` ```text "4N-W+1" means that only West can make 4NT +1. In the last example, 5NT just making can also be considered a par contract, but North-South don’t have a profitable sacrifice against 4NT, so the par contract is shown in this way. If North-South did indeed have a profitable sacrifice, perhaps 5C*_NS-2, then par contract would have been shown as “5N-W”. Par() would show “4N-W+1” as “W 45N”. ``` -------------------------------- ### ConvertToSidesTextFormat Source: https://github.com/afwas/python-dds/blob/master/dds.md Example of text output from SidesParBin. ```APIDOC ## ConvertToSidesTextFormat ### Description Example of text output from SidesParBin. ### Parameters - **pres** (struct parResultsMaster *) - Description - **resp** (char *) - Description ``` -------------------------------- ### SetMaxThreads Source: https://github.com/afwas/python-dds/blob/master/dds.md Used at initial start and can also be called with a request for allocating memory for a specified number of threads. Mandatory on Linux and Mac (optional on Windows). ```APIDOC ## SetMaxThreads ### Description Used at initial start and can also be called with a request for allocating memory for a specified number of threads. Is apparently¸mandatory on Linux and Mac (optional on Windows) ### Parameters - **userThreads** (int) - Description ``` -------------------------------- ### SolveBoard Function Calls Source: https://github.com/afwas/python-dds/blob/master/dds.md Demonstrates sequential calls to SolveBoard with varying 'deal.first' values for different player leads. Ensure table reusability is safe when mode is 2. ```c SolveBoard(deal, -1, 1, 1, &fut, 0), deal.first=1 ``` ```c SolveBoard(deal, -1, 1, 2, &fut, 0), deal.first=2 ``` ```c SolveBoard(deal, -1, 1, 2, &fut, 0), deal.first=3 ``` ```c SolveBoard(deal, -1, 1, 2, &fut, 0), deal.first=0 ``` -------------------------------- ### SolveoardPBN Source: https://github.com/afwas/python-dds/blob/master/dds.md Similar to SolveBoard, but accepts input in PBN (Portable Bridge Notation) format. It also directly exposes the thread index to the user. ```APIDOC ## SolveoardPBN ### Description Solves a single bridge deal using PBN format and returns the result. This function is similar to `SolveBoard` but differs in its input format. ### Parameters - **dl** (struct dealPBN) - The bridge deal to solve in PBN format. - **target** (int) - Controls the search behavior. See `SolveBoard` documentation for details. - **solutions** (int) - Controls the number of solutions to return. See `SolveBoard` documentation for details. - **mode** (int) - Controls the search behavior and transposition table reuse. See `SolveBoard` documentation for details. - **futp** (struct futureTricks *) - A pointer to a structure where the results will be stored. - **threadIndex** (int) - The index of the thread calling the function. Must be between 0 and 15. ``` -------------------------------- ### AnalysePlayBin and AnalysePlayPBN Input Structures Source: https://github.com/afwas/python-dds/blob/master/dds.md Defines the input structures for AnalysePlayBin and AnalysePlayPBN functions, highlighting the differences in data types for deal and play trace information between binary and PBN formats. ```c struct deal dl ``` ```c struct playTraceBin play ``` ```c struct solvedPlay *solvedp ``` ```c int thrId ``` -------------------------------- ### Solve Multiple Hands in Parallel (PBN Format) Source: https://context7.com/afwas/python-dds/llms.txt Use SolveAllBoards to solve multiple bridge hands simultaneously, optimizing performance by using all available threads and reusing transposition tables. This is preferred over looping SolveBoardPBN. ```python import dds, hands, functions, ctypes dds.SetMaxThreads(0) bo = dds.boardsPBN() solved = dds.solvedBoards() line = ctypes.create_string_buffer(80) bo.noOfBoards = 3 PBN_deals = [ b"N:QJ6.K652.J85.T98 873.J97.AT764.Q4 K5.T83.KQ9.A7652 AT942.AQ4.32.KJ3", b"E:QJT5432.T.6.QJ82 .J97543.K7532.94 87.A62.QJT4.AT75 AK96.KQ8.A98.K63", b"N:73.QJT.AQ54.T752 QT6.876.KJ9.AQ84 5.A95432.7632.K6 AKJ9842.K.T8.J93", ] trumps = [0, 1, 0] # Spades, Hearts, Spades leaders = [0, 1, 2] # North, East, South for i in range(3): bo.deals[i].trump = trumps[i] bo.deals[i].first = leaders[i] for j in range(3): bo.deals[i].currentTrickSuit[j] = 0 bo.deals[i].currentTrickRank[j] = 0 bo.deals[i].remainCards = PBN_deals[i] bo.target[i] = -1 # Maximum tricks bo.solutions[i] = 3 # All cards bo.mode[i] = 0 res = dds.SolveAllBoards(ctypes.pointer(bo), ctypes.pointer(solved)) if res != dds.RETURN_NO_FAULT: dds.ErrorMessage(res, line) print(f"DDS error: {line.value.decode('utf-8')}") else: for i in range(3): print(f"\n--- Hand {i+1} ---") functions.PrintFut("All cards", ctypes.pointer(solved.solvedBoards[i])) # Example output (hand 2): # card suit rank equals score # 0 C 2 4 # 1 C 8 4 # 2 C Q J 4 ``` -------------------------------- ### AnalysePlayPBN Source: https://github.com/afwas/python-dds/blob/master/dds.md As AnalysePlayBin, but with PBN deal format. ```APIDOC ## AnalysePlayPBN ### Description As AnalysePlayBin, but with PBN deal format. ### Parameters - **dlPBN** (struct dealPBN) - Description - **playPBN** (struct playTracePBN) - Description - **solvedp** (struct solvedPlay *) - Description - **thrId** (int) - Description ``` -------------------------------- ### SolveAllBoards Source: https://github.com/afwas/python-dds/blob/master/dds.md Solves all boards provided in PBN format. Consider using this instead of the next 3 “Chunk” functions. ```APIDOC ## SolveAllBoards ### Description Solves all boards provided in PBN format. Consider using this instead of the next 3 “Chunk” functions. ### Method (Not specified, likely a function call) ### Parameters - **bop** (struct boardsPBN *) - Description not specified - **solvedp** (struct solvedBoards *) - Description not specified ### Format PBN ``` -------------------------------- ### Define Deal with PBN String Representation Source: https://context7.com/afwas/python-dds/llms.txt Create a 'dealPBN' object using a standard PBN string for deal representation. This format is preferred for readability and interoperability. Configure trump, lead hand, and remaining cards. ```python import dds dlPBN = dds.dealPBN() dlPBN.trump = 4 # NoTrump dlPBN.first = 0 # North leads dlPBN.currentTrickSuit[0] = 0 dlPBN.currentTrickSuit[1] = 0 dlPBN.currentTrickSuit[2] = 0 dlPBN.currentTrickRank[0] = 0 dlPBN.currentTrickRank[1] = 0 dlPBN.currentTrickRank[2] = 0 # PBN format: : # Each holding: Spades.Hearts.Diamonds.Clubs dlPBN.remainCards = b"N:QJ6.K652.J85.T98 873.J97.AT764.Q4 K5.T83.KQ9.A7652 AT942.AQ4.32.KJ3" ``` -------------------------------- ### AnalyseAllPlaysPBN Source: https://github.com/afwas/python-dds/blob/master/dds.md As AnalyseAllPlaysBin, but with PBN deal format. ```APIDOC ## AnalyseAllPlaysPBN ### Description As AnalyseAllPlaysBin, but with PBN deal format. ### Parameters - **bopPBN** (struct boardsPBN *) - Description - **plpPBN** (struct playTracesPBN *) - Description - **solvedp** (struct solvedPlays *) - Description - **chunkSize** (int) - Description ``` -------------------------------- ### AnalyseAllPlaysPBN: Analyze multiple play sequences in parallel (PBN) Source: https://context7.com/afwas/python-dds/llms.txt Analyzes up to 20 boards with play traces simultaneously using multiple threads. Useful for batch processing of multiple hands. ```python import dds, hands, functions, ctypes dds.SetMaxThreads(0) boPBN = dds.boardsPBN() playsPBN = dds.playTracesPBN() solvedPs = dds.solvedPlays() line = ctypes.create_string_buffer(80) PBN_deals = [ b"N:QJ6.K652.J85.T98 873.J97.AT764.Q4 K5.T83.KQ9.A7652 AT942.AQ4.32.KJ3", b"E:QJT5432.T.6.QJ82 .J97543.K7532.94 87.A62.QJT4.AT75 AK96.KQ8.A98.K63", b"N:73.QJT.AQ54.T752 QT6.876.KJ9.AQ84 5.A95432.7632.K6 AKJ9842.K.T8.J93", ] play_strings = [ b"CTC4CACJH8H4HKH9D5DAD9D2S7S5S2SQD8D4DQD3H3HAH6H7C3C8CQC2S3SKSAS6HQH5HJHTCKC9D6C5S4SJS8C6DJ", b"SQD2S8SAHKHTH3H2HQS2H4H6H8D6HJHAS7SKS4C4D8C2DKD4H9C5S6S3H7C7C3S5H5CTD9STD3DQDAC8S9SJC9DTCQD5CAC6DJCKCJD7", b"HAHKHQH7D7D8DAD9C5CAC6C3", ] play_counts = [45, 52, 12] trumps = [0, 1, 0] leaders = [0, 1, 2] boPBN.noOfBoards = 3 playsPBN.noOfBoards = 3 for i in range(3): boPBN.deals[i].trump = trumps[i] boPBN.deals[i].first = leaders[i] for j in range(3): boPBN.deals[i].currentTrickSuit[j] = 0 boPBN.deals[i].currentTrickRank[j] = 0 boPBN.deals[i].remainCards = PBN_deals[i] boPBN.target[i] = -1 boPBN.solutions[i] = 3 boPBN.mode[i] = 0 playsPBN.plays[i].number = play_counts[i] playsPBN.plays[i].cards = play_strings[i] res = dds.AnalyseAllPlaysPBN( ctypes.pointer(boPBN), ctypes.pointer(playsPBN), ctypes.pointer(solvedPs), 1) # chunkSize if res != dds.RETURN_NO_FAULT: dds.ErrorMessage(res, line) print(f"DDS error: {line.value.decode('utf-8')}") else: for i in range(3): print(f"\n--- Hand {i+1} ---") functions.PrintPBNPlay( ctypes.pointer(playsPBN.plays[i]), ctypes.pointer(solvedPs.solved[i])) ``` -------------------------------- ### ConvertPBN / PrintHand Source: https://context7.com/afwas/python-dds/llms.txt Utility functions for PBN parsing and hand display. These helpers are found in `examples/functions.py` and assist in converting PBN strings to binary holdings and printing board layouts. ```APIDOC ## ConvertPBN / PrintHand — PBN parsing and hand display utilities (`functions.py`) Helper functions in `examples/functions.py` for converting PBN strings to binary holdings and printing board layouts. ```python import dds, functions, ctypes # Print a deal from its PBN string in compass layout pbn = b"N:QJ6.K652.J85.T98 873.J97.AT764.Q4 K5.T83.KQ9.A7652 AT942.AQ4.32.KJ3" functions.PrintPBNHand("Example hand", pbn) # Output: # QJ6 # K652 # J85 # T98 # AT942 873 # AQ4 J97 # 32 AT764 # KJ3 Q4 # K5 # T83 # KQ9 # A7652 # Convert PBN string to binary remainCards array remainCards = [[0 for _ in range(dds.DDS_SUITS)] for _ in range(dds.DDS_HANDS)] functions.ConvertPBN(bytearray(pbn), remainCards) # Print a DD results table table = dds.ddTableResults() # ... (populate via CalcDDtablePBN) ... # functions.PrintTable(ctypes.pointer(table)) # Output: ``` ``` -------------------------------- ### Calculate Binary Dealer Par and Convert to Text (North Dealer, Not Vulnerable) Source: https://context7.com/afwas/python-dds/llms.txt Calculates par results in binary format using DealerParBin and then converts it to a human-readable string with ConvertToDealerTextFormat for custom output. Requires table results, dealer, and vulnerability. ```python import dds, hands, functions, ctypes dds.SetMaxThreads(0) DDtable = dds.ddTableResults() pres = dds.parResultsMaster() line = ctypes.create_string_buffer(80) output = ctypes.create_string_buffer(200) functions.SetTable(ctypes.pointer(DDtable), 0) # hand index 0 res = dds.DealerParBin( ctypes.pointer(DDtable), ctypes.pointer(pres), hands.dealer[0], # North hands.vul[0]) # Not vulnerable if res != dds.RETURN_NO_FAULT: dds.ErrorMessage(res, line) print(f"DDS error: {line.value.decode('utf-8')}") else: dds.ConvertToDealerTextFormat(ctypes.pointer(pres), output) print(output.value.decode('utf-8')) ``` -------------------------------- ### AnalyseAllPlaysPBN Input Structures Source: https://github.com/afwas/python-dds/blob/master/dds.md Defines the input structures for the AnalyseAllPlaysPBN function, which is the PBN-formatted equivalent of AnalyseAllPlaysBin. It uses PBN-specific structures for boards and play traces. ```c struct boardsPBN *bopPBN ``` ```c struct playTracesPBN *plpPBN ``` ```c struct solvedPlays *solvedp ``` ```c int chunkSize ``` -------------------------------- ### AnalysePlayPBN Input Structures Source: https://github.com/afwas/python-dds/blob/master/dds.md Defines the input structures for AnalysePlayPBN functions, which are similar to AnalysePlayBin but use PBN-specific data types for deal and play trace information. ```c struct dealPBN dlPBN ``` ```c struct playTracePBN playPBN ``` ```c struct solvedPlay *solvedp ``` ```c int thrId ``` -------------------------------- ### Calculate Double-Dummy Table (PBN Format) Source: https://context7.com/afwas/python-dds/llms.txt Use CalcDDtablePBN to compute the full double-dummy table for a single deal provided in PBN format. This calculates maximum tricks for all 20 strain/declarer combinations. ```python import dds, hands, functions, ctypes dds.SetMaxThreads(0) tableDealPBN = dds.ddTableDealPBN() table = dds.ddTableResults() myTable = ctypes.pointer(table) line = ctypes.create_string_buffer(80) tableDealPBN.cards = b"E:QJT5432.T.6.QJ82 .J97543.K7532.94 87.A62.QJT4.AT75 AK96.KQ8.A98.K63" res = dds.CalcDDtablePBN(tableDealPBN, myTable) if res != dds.RETURN_NO_FAULT: dds.ErrorMessage(res, line) print(f"DDS error: {line.value.decode('utf-8')}") else: functions.PrintTable(myTable) # Example output: # North South East West # NT 9 9 3 3 # S 4 4 9 9 # H 10 10 2 2 # D 8 8 3 3 # C 6 6 7 7 ``` -------------------------------- ### AnalysePlayPBN: Analyze a single play sequence (PBN format) Source: https://context7.com/afwas/python-dds/llms.txt Analyzes a single deal and play sequence in PBN notation to determine the double-dummy trick count after each card. Use this to detect suboptimal plays. ```python import dds, hands, functions, ctypes dds.SetMaxThreads(0) dlPBN = dds.dealPBN() playPBN = dds.playTracePBN() solved = dds.solvedPlay() line = ctypes.create_string_buffer(80) dlPBN.trump = 4 # NoTrump dlPBN.first = 1 # East leads for i in range(3): dlPBN.currentTrickSuit[i] = 0 dlPBN.currentTrickRank[i] = 0 dlPBN.remainCards = b"E:QJT5432.T.6.QJ82 .J97543.K7532.94 87.A62.QJT4.AT75 AK96.KQ8.A98.K63" # PBN play string: pairs of suit+rank characters, no spaces # e.g. "SQ" = Spade Queen, "D2" = Diamond Two playPBN.number = 49 # number of cards in the trace playPBN.cards = b"SQD2S8SAHKHTH3H2HQS2H4H6H8D6HJHAS7SKS4C4D8C2DKD4H9C5S6S3H7C7C3S5H5CTD9STD3DQDAC8S9SJC9DTCQD5CAC6DJCKCJD7" res = dds.AnalysePlayPBN(dlPBN, playPBN, ctypes.pointer(solved), 0) if res != dds.RETURN_NO_FAULT: dds.ErrorMessage(res, line) print(f"DDS error: {line.value.decode('utf-8')}") else: functions.PrintPBNPlay(ctypes.pointer(playPBN), ctypes.pointer(solved)) ``` -------------------------------- ### Initialize DDS Library and Thread Pool Source: https://context7.com/afwas/python-dds/llms.txt Load the DDS shared library and configure the thread pool. SetMaxThreads(0) auto-configures threads based on system resources. Ensure FreeMemory() is called when done. ```python import dds import ctypes # Load library (edit path in dds.py if needed — default: "libdds.so") # dds = cdll.LoadLibrary("libdds.so") # Auto-configure threads (mandatory on Linux/Mac, recommended on Windows) dds.SetMaxThreads(0) # Optionally request a specific number of threads (here: 4) actual_threads = dds.SetMaxThreads(4) print(f"Threads allocated: {actual_threads}") # Release all DDS-allocated memory when done dds.FreeMemory() ``` -------------------------------- ### SidesParBin Source: https://github.com/afwas/python-dds/blob/master/dds.md Similar to SidesPar, but with binary output. ```APIDOC ## SidesParBin ### Description Similar to SidesPar, but with binary output. ### Parameters - **tablep** (struct ddTableResults *) - Description - **sidesRes** (struct parResultsMaster[2]) - Description - **vulnerable** (int) - Description ``` -------------------------------- ### SolveAllBoards Source: https://context7.com/afwas/python-dds/llms.txt Solves multiple bridge hands in parallel using PBN format. It can solve up to 200 boards simultaneously and reuses transposition tables for efficiency. ```APIDOC ## SolveAllBoards — Solve multiple hands in parallel (PBN format) Solves multiple hands simultaneously using all available threads. Automatically detects and reuses transposition tables for repeated or near-identical deals. ### Method `dds.SolveAllBoards(bo, solved) ### Parameters - **bo** (`ctypes.pointer(dds.boardsPBN)`): Pointer to a structure containing the deals to be solved. - **solved** (`ctypes.pointer(dds.solvedBoards)`): Pointer to a structure where the results will be stored. ### Request Example ```python import dds, hands, functions, ctypes dds.SetMaxThreads(0) bo = dds.boardsPBN() solved = dds.solvedBoards() line = ctypes.create_string_buffer(80) bo.noOfBoards = 3 PBN_deals = [ b"N:QJ6.K652.J85.T98 873.J97.AT764.Q4 K5.T83.KQ9.A7652 AT942.AQ4.32.KJ3", b"E:QJT5432.T.6.QJ82 .J97543.K7532.94 87.A62.QJT4.AT75 AK96.KQ8.A98.K63", b"N:73.QJT.AQ54.T752 QT6.876.KJ9.AQ84 5.A95432.7632.K6 AKJ9842.K.T8.J93", ] trumps = [0, 1, 0] # Spades, Hearts, Spades leaders = [0, 1, 2] # North, East, South for i in range(3): bo.deals[i].trump = trumps[i] bo.deals[i].first = leaders[i] for j in range(3): bo.deals[i].currentTrickSuit[j] = 0 bo.deals[i].currentTrickRank[j] = 0 bo.deals[i].remainCards = PBN_deals[i] bo.target[i] = -1 # Maximum tricks bo.solutions[i] = 3 # All cards bo.mode[i] = 0 res = dds.SolveAllBoards(ctypes.pointer(bo), ctypes.pointer(solved)) if res != dds.RETURN_NO_FAULT: dds.ErrorMessage(res, line) print(f"DDS error: {line.value.decode('utf-8')}") else: for i in range(3): print(f"\n--- Hand {i+1} ---") functions.PrintFut("All cards", ctypes.pointer(solved.solvedBoards[i])) ``` ### Response Example ``` --- Hand 2 --- card suit rank equals score 0 C 2 4 1 C 8 4 2 C Q J 4 ``` ``` -------------------------------- ### AnalyseAllPlaysPBN Source: https://context7.com/afwas/python-dds/llms.txt Analyzes multiple play sequences in parallel using PBN format. It can solve up to 20 boards simultaneously in multiple threads. ```APIDOC ## AnalyseAllPlaysPBN — Analyse multiple play sequences in parallel (PBN) Solves up to 20 boards with play traces simultaneously in multiple threads. ```python import dds, hands, functions, ctypes dds.SetMaxThreads(0) boPBN = dds.boardsPBN() playsPBN = dds.playTracesPBN() solvedPs = dds.solvedPlays() line = ctypes.create_string_buffer(80) PBN_deals = [ b"N:QJ6.K652.J85.T98 873.J97.AT764.Q4 K5.T83.KQ9.A7652 AT942.AQ4.32.KJ3", b"E:QJT5432.T.6.QJ82 .J97543.K7532.94 87.A62.QJT4.AT75 AK96.KQ8.A98.K63", b"N:73.QJT.AQ54.T752 QT6.876.KJ9.AQ84 5.A95432.7632.K6 AKJ9842.K.T8.J93", ] play_strings = [ b"CTC4CACJH8H4HKH9D5DAD9D2S7S5S2SQD8D4DQD3H3HAH6H7C3C8CQC2S3SKSAS6HQH5HJHTCKC9D6C5S4SJS8C6DJ", b"SQD2S8SAHKHTH3H2HQS2H4H6H8D6HJHAS7SKS4C4D8C2DKD4H9C5S6S3H7C7C3S5H5CTD9STD3DQDAC8S9SJC9DTCQD5CAC6DJCKCJD7", b"HAHKHQH7D7D8DAD9C5CAC6C3", ] play_counts = [45, 52, 12] trumps = [0, 1, 0] leaders = [0, 1, 2] boPBN.noOfBoards = 3 playsPBN.noOfBoards = 3 for i in range(3): boPBN.deals[i].trump = trumps[i] boPBN.deals[i].first = leaders[i] for j in range(3): boPBN.deals[i].currentTrickSuit[j] = 0 boPBN.deals[i].currentTrickRank[j] = 0 boPBN.deals[i].remainCards = PBN_deals[i] boPBN.target[i] = -1 boPBN.solutions[i] = 3 boPBN.mode[i] = 0 playsPBN.plays[i].number = play_counts[i] playsPBN.plays[i].cards = play_strings[i] res = dds.AnalyseAllPlaysPBN( ctypes.pointer(boPBN), ctypes.pointer(playsPBN), ctypes.pointer(solvedPs), 1) # chunkSize if res != dds.RETURN_NO_FAULT: dds.ErrorMessage(res, line) print(f"DDS error: {line.value.decode('utf-8')}") else: for i in range(3): print(f"\n--- Hand {i+1} ---") functions.PrintPBNPlay( ctypes.pointer(playsPBN.plays[i]), ctypes.pointer(solvedPs.solved[i])) ``` ``` -------------------------------- ### SolveAllBoards Function Signature Source: https://github.com/afwas/python-dds/blob/master/dds.md Defines the parameters for SolveAllBoards, which invokes SolveBoard multiple times in parallel using threads. Up to 200 boards are permitted per call. ```c struct boards *bop ``` ```c struct solvedBoards * solvedp ``` ```c int chunkSize ``` -------------------------------- ### AnalyseAllPlaysBin Input Structures Source: https://github.com/afwas/python-dds/blob/master/dds.md Specifies the input structures for the AnalyseAllPlaysBin function, which processes multiple boards in parallel. It includes structures for boards, play traces, and solved plays. ```c struct boards *bop ``` ```c struct playTracesBin *plp ``` ```c struct solvedPlays *solvedp ``` ```c int chunkSize ``` -------------------------------- ### SolveBoard Source: https://github.com/afwas/python-dds/blob/master/dds.md Solves a single hand from the beginning or from later play. Supports binary deal format. ```APIDOC ## SolveBoard ### Description Solves a single hand from the beginning or from later play. ### Method (Not specified, likely a function call) ### Parameters - **dl** (struct deal dl) - Description not specified - **target** (int) - Description not specified - **solutions** (int) - Description not specified - **mode** (int) - Description not specified - **futp** (struct futureTricks *) - Description not specified - **threadIndex** (int) - Description not specified ### Format Binary ``` -------------------------------- ### Define Deal with Binary Representation Source: https://context7.com/afwas/python-dds/llms.txt Create a 'deal' object to represent a board using the DDS binary holding format. Suits are encoded as bitmasks. Configure trump, lead hand, and remaining cards. ```python import dds, hands, ctypes dl = dds.deal() # trump: 0=Spades, 1=Hearts, 2=Diamonds, 3=Clubs, 4=NoTrump dl.trump = 4 # No Trump # first: 0=North, 1=East, 2=South, 3=West dl.first = 0 # North leads # No cards already played to current trick dl.currentTrickSuit[0] = 0 dl.currentTrickSuit[1] = 0 dl.currentTrickSuit[2] = 0 dl.currentTrickRank[0] = 0 dl.currentTrickRank[1] = 0 dl.currentTrickRank[2] = 0 # holdings[hand][suit][hand_index] — bitmask encoding # hands.holdings is a 3×4×4 array of precomputed bitmasks for h in range(dds.DDS_HANDS): for s in range(dds.DDS_SUITS): dl.remainCards[h][s] = hands.holdings[0][s][h] ``` -------------------------------- ### Calculate Sides Par (Not Vulnerable) and Convert to Text Source: https://context7.com/afwas/python-dds/llms.txt Calculates separate par results for NS and EW sides using SidesParBin, then converts these binary results to a human-readable text format using ConvertToSidesTextFormat. Useful when outcomes differ based on who bids first. Requires table results and vulnerability. ```python import dds, hands, functions, ctypes dds.SetMaxThreads(0) DDtable = dds.ddTableResults() sidesRes = (dds.parResultsMaster * 2)() textRes = dds.parTextResults() line = ctypes.create_string_buffer(80) functions.SetTable(ctypes.pointer(DDtable), 2) # hand index 2 res = dds.SidesParBin( ctypes.pointer(DDtable), sidesRes, hands.vul[2]) # Not vulnerable if res != dds.RETURN_NO_FAULT: dds.ErrorMessage(res, line) print(f"DDS error: {line.value.decode('utf-8')}") else: dds.ConvertToSidesTextFormat(sidesRes, ctypes.pointer(textRes)) for side in range(2): label = "NS" if side == 0 else "EW" print(f"{label}: {textRes.parTextResults[side].decode('utf-8')}") ``` -------------------------------- ### Solve Single Hand (PBN Format) Source: https://context7.com/afwas/python-dds/llms.txt Use SolveBoardPBN to solve a single bridge hand provided in PBN format. It can return all legal cards or only optimal cards. ```python import dds, hands, functions, ctypes dds.SetMaxThreads(0) dlPBN = dds.dealPBN() fut3 = dds.futureTricks() fut2 = dds.futureTricks() line = ctypes.create_string_buffer(80) dlPBN.trump = 1 # Hearts dlPBN.first = 1 # East leads for i in range(3): dlPBN.currentTrickSuit[i] = 0 dlPBN.currentTrickRank[i] = 0 dlPBN.remainCards = b"E:QJT5432.T.6.QJ82 .J97543.K7532.94 87.A62.QJT4.AT75 AK96.KQ8.A98.K63" # solutions=3: all legal cards res = dds.SolveBoardPBN(dlPBN, -1, 3, 0, ctypes.pointer(fut3), 0) if res != dds.RETURN_NO_FAULT: dds.ErrorMessage(res, line) print(f"Error: {line.value.decode('utf-8')}") functions.PrintFut("solutions == 3", ctypes.pointer(fut3)) # Example output: # card suit rank equals score # 0 C 2 4 # 1 C 8 4 # 2 C Q J 4 # 3 H T 3 # 4 D 6 3 # solutions=2: only optimal cards res = dds.SolveBoardPBN(dlPBN, -1, 2, 0, ctypes.pointer(fut2), 0) functions.PrintFut("solutions == 2", ctypes.pointer(fut2)) ``` -------------------------------- ### CalcDDtablePBN Source: https://github.com/afwas/python-dds/blob/master/dds.md Solves an initial hand for all possible declarers and denominations using PBN deal format. Similar to CalcDDtable. ```APIDOC ## CalcDDtablePBN ### Description Solves an initial hand for all possible declarers and denominations using PBN deal format. Similar to CalcDDtable. ### Method (Not specified, likely a function call) ### Parameters - **tableDealPBN** (struct ddTableDealPBN tableDealPBN) - Description not specified - **tablep** (struct ddTableResults *) - Description not specified ### Format PBN ``` -------------------------------- ### Calculate All DD Tables in Parallel (PBN Format) Source: https://context7.com/afwas/python-dds/llms.txt Use CalcAllTablesPBN to calculate double-dummy tables for a batch of deals simultaneously. This is significantly faster than calling CalcDDtablePBN repeatedly and can optionally compute par scores. ```python import dds, hands, functions, ctypes dds.SetMaxThreads(0) DDdealsPBN = dds.ddTableDealsPBN() tableRes = dds.ddTablesRes() pres = dds.allParResults() line = ctypes.create_string_buffer(80) # mode=-1: no par calculation; set to vulnerability code to include par mode = -1 tFilter = ctypes.c_int * dds.DDS_STRAINS # trumpFilter: set True to EXCLUDE that strain ``` -------------------------------- ### ConvertToDealerTextFormat Source: https://github.com/afwas/python-dds/blob/master/dds.md Converts binary output from DealerParBin to text format. ```APIDOC ## ConvertToDealerTextFormat ### Description Converts binary output from DealerParBin to text format. Example of text output from DealerParBin. ### Method (Not specified, likely a function call) ### Parameters - **pres** (struct parResultsMaster *) - Description not specified - **resp** (char *) - Description not specified ### Format Text ``` -------------------------------- ### Calculate All Tables PBN Source: https://context7.com/afwas/python-dds/llms.txt Calculates results for all tables using PBN deal format. Handles potential DDS errors and prints messages. ```python trumpFilter = tFilter(0, 0, 0, 0, 0) DDdealsPBN.noOfTables = 3 PBN_deals = [ b"N:QJ6.K652.J85.T98 873.J97.AT764.Q4 K5.T83.KQ9.A7652 AT942.AQ4.32.KJ3", b"E:QJT5432.T.6.QJ82 .J97543.K7532.94 87.A62.QJT4.AT75 AK96.KQ8.A98.K63", b"N:73.QJT.AQ54.T752 QT6.876.KJ9.AQ84 5.A95432.7632.K6 AKJ9842.K.T8.J93", ] for i in range(3): DDdealsPBN.deals[i].cards = PBN_deals[i] res = dds.CalcAllTablesPBN( ctypes.pointer(DDdealsPBN), mode, trumpFilter, ctypes.pointer(tableRes), ctypes.pointer(pres)) if res != dds.RETURN_NO_FAULT: dds.ErrorMessage(res, line) print(f"DDS error: {line.value.decode('utf-8')}") else: for i in range(3): print(f"Hand {i+1}:") functions.PrintTable(ctypes.pointer(tableRes.results[i])) ``` -------------------------------- ### SolveAllChunksPBN Function Signature Source: https://github.com/afwas/python-dds/blob/master/dds.md Defines the parameters for SolveAllChunksPBN, used for solving chunks of boards in parallel with PBN format. It is recommended to use SolveAllBoards instead. ```c struct boardsPBN *bop ``` ```c struct solvedBoards *solvedp ``` ```c int chunkSize ``` -------------------------------- ### Solve Bridge Board and List Solutions Source: https://github.com/afwas/python-dds/blob/master/examples/readme.md Solves a bridge board and lists the number of solutions found, along with detailed card-by-card analysis for each solution. Displays the board layout and card rankings. ```text SolveBoard, hand 2: solutions 3 OK, solutions 2 OK -------------------------------------------------- AK96 KQ8 A98 K63 87 QJT5432 A62 T QJT4 6 AT75 QJ82 J97543 K7532 94 solutions == 3 card suit rank equals score 0 C 2 4 1 C 8 4 2 C Q J 4 3 H T 3 4 D 6 3 5 S Q JT 3 6 S 5 432 2 solutions == 2 card suit rank equals score 0 C 2 4 1 C 8 4 2 C Q J 4 ``` -------------------------------- ### CalcDDtable Source: https://github.com/afwas/python-dds/blob/master/dds.md Solves an initial hand for all possible declarers and denominations (up to 20 combinations). Supports binary deal format. ```APIDOC ## CalcDDtable ### Description Solves an initial hand for all possible declarers and denominations (up to 20 combinations). ### Method (Not specified, likely a function call) ### Parameters - **tableDeal** (struct ddTableDeal tableDeal) - Description not specified - **tablep** (struct ddTableResults *) - Description not specified ### Format Binary ```