* @brief Evaluate minimum possible tricks for a given position in double dummy analysis. * * This function estimates whether the minimum achievable tricks for the given position, * hand, depth, and target can satisfy the target, considering the trump suit and current state. * * @param tpos Position state * @param hand Current hand * @param depth Current search depth * @param target Target
| 28 | * @return true if target can be reached, false otherwise |
| 29 | */ |
| 30 | bool LaterTricksMIN( |
| 31 | Pos& tpos, |
| 32 | const int hand, |
| 33 | const int depth, |
| 34 | const int target, |
| 35 | const int trump, |
| 36 | SolverContext& ctx) |
| 37 | { |
| 38 | |
| 39 | const bool depth_ok = (depth >= 0 && depth < 50); |
| 40 | if ((trump == DDS_NOTRUMP) || (tpos.winner[trump].rank == 0)) |
| 41 | { |
| 42 | int sum = 0; |
| 43 | for (int ss = 0; ss < DDS_SUITS; ss++) |
| 44 | { |
| 45 | int hh = tpos.winner[ss].hand; |
| 46 | if (hh != -1) |
| 47 | { |
| 48 | if (static_cast<unsigned>(hh) < static_cast<unsigned>(DDS_HANDS) && |
| 49 | ctx.search().node_type_store(hh) == MAXNODE) |
| 50 | sum += std::max(tpos.length[hh][ss], |
| 51 | tpos.length[partner[hh]][ss]); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | if ((tpos.tricks_max + sum < target) && (sum > 0)) |
| 56 | { |
| 57 | if ((tpos.tricks_max + (depth >> 2) >= target)) |
| 58 | return true; |
| 59 | |
| 60 | for (int ss = 0; ss < DDS_SUITS; ss++) |
| 61 | { |
| 62 | int win_hand = tpos.winner[ss].hand; |
| 63 | |
| 64 | if (win_hand == -1) { |
| 65 | if (depth_ok) tpos.win_ranks[depth][ss] = 0; |
| 66 | } |
| 67 | else if (static_cast<unsigned>(win_hand) >= static_cast<unsigned>(DDS_HANDS)) { |
| 68 | // Invalid hand index; avoid using partner/lho/rho with OOB index. |
| 69 | if (depth_ok) tpos.win_ranks[depth][ss] = 0; |
| 70 | continue; |
| 71 | } |
| 72 | else if (ctx.search().node_type_store(win_hand) == MINNODE) |
| 73 | { |
| 74 | if ((tpos.rank_in_suit[partner[win_hand]][ss] == 0) && |
| 75 | (tpos.rank_in_suit[lho[win_hand]][ss] == 0) && |
| 76 | (tpos.rank_in_suit[rho[win_hand]][ss] == 0)) |
| 77 | { if (depth_ok) tpos.win_ranks[depth][ss] = 0; } |
| 78 | else |
| 79 | { if (depth_ok) tpos.win_ranks[depth][ss] = bit_map_rank[tpos.winner[ss].rank]; } |
| 80 | } |
| 81 | else { |
| 82 | if (depth_ok) tpos.win_ranks[depth][ss] = 0; |
| 83 | } |
| 84 | } |
| 85 | return false; |
| 86 | } |
| 87 | } |
no test coverage detected