| 58 | |
| 59 | |
| 60 | void example_with_context() |
| 61 | { |
| 62 | printf("\n=== Par Calculation WITH SolverContext ===\n\n"); |
| 63 | |
| 64 | // Create a single solver context for resource management |
| 65 | SolverContext context; |
| 66 | |
| 67 | printf("SolverContext provides:\n"); |
| 68 | printf(" - Reuse of allocated solver resources across calculations\n"); |
| 69 | printf(" - Persistent solver resources (no per-call allocation overhead)\n"); |
| 70 | printf(" - Consistent API with other context-aware DDS operations\n\n"); |
| 71 | |
| 72 | auto start_time = std::chrono::high_resolution_clock::now(); |
| 73 | |
| 74 | for (int handno = 0; handno < 3; handno++) |
| 75 | { |
| 76 | DdTableDeal table_deal{}; |
| 77 | for (int h = 0; h < DDS_HANDS; ++h) { |
| 78 | for (int s = 0; s < DDS_SUITS; ++s) { |
| 79 | table_deal.cards[h][s] = holdings_[handno][s][h]; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | DdTableResults ddtable; |
| 84 | ParResults pres; |
| 85 | // Use context-aware calc_par API |
| 86 | int res = calc_par( |
| 87 | context, |
| 88 | table_deal, |
| 89 | vulnerability_[handno], |
| 90 | &ddtable, |
| 91 | &pres); |
| 92 | |
| 93 | if (res == RETURN_NO_FAULT) |
| 94 | { |
| 95 | const char* suit_name = |
| 96 | (trump_suit_[handno] == 0 ? "♠" : |
| 97 | trump_suit_[handno] == 1 ? "♥" : |
| 98 | trump_suit_[handno] == 2 ? "♦" : |
| 99 | trump_suit_[handno] == 3 ? "♣" : "NT"); |
| 100 | |
| 101 | printf("Hand %d (%s): Par score = %s\n", |
| 102 | handno + 1, |
| 103 | suit_name, |
| 104 | pres.par_score[0]); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | auto end_time = std::chrono::high_resolution_clock::now(); |
| 109 | auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 110 | end_time - start_time).count(); |
| 111 | printf("\nTime (with context): %lld ms\n\n", static_cast<long long>(elapsed)); |
| 112 | } |
| 113 | |
| 114 | |
| 115 | void example_mixed_usage() |