| 423 | } |
| 424 | |
| 425 | auto Moves::MakeNext(const int trick, const int relHand, |
| 426 | const unsigned short ourWinRanks[DDS_SUITS]) |
| 427 | -> MoveType const * { |
| 428 | // Find moves that are >= ourWinRanks[suit], but allow one |
| 429 | // "small" move per suit to explore losing options. |
| 430 | // |
| 431 | // The lowest_win array tracks the minimum rank to try next for each suit. |
| 432 | // After trying one card below the winning threshold, subsequent cards |
| 433 | // must meet the threshold. |
| 434 | |
| 435 | int *lwp = track[trick].lowest_win[relHand]; |
| 436 | MovePlyType &list = moveList[trick][relHand]; |
| 437 | trackp = &track[trick]; |
| 438 | |
| 439 | MoveType *currp = nullptr, *prevp; |
| 440 | |
| 441 | bool found = false; |
| 442 | if (list.last == -1) |
| 443 | return nullptr; |
| 444 | else if (list.current == 0) { |
| 445 | currp = &list.move[0]; |
| 446 | found = true; |
| 447 | } else { |
| 448 | prevp = &list.move[list.current - 1]; |
| 449 | if (lwp[prevp->suit] == 0) { |
| 450 | int low = lowest_rank[ourWinRanks[prevp->suit]]; |
| 451 | if (low == 0) |
| 452 | low = 15; |
| 453 | if (prevp->rank < low) |
| 454 | lwp[prevp->suit] = low; |
| 455 | } |
| 456 | |
| 457 | while (list.current <= list.last && !found) { |
| 458 | currp = &list.move[list.current]; |
| 459 | if (currp->rank >= lwp[currp->suit]) |
| 460 | found = true; |
| 461 | else |
| 462 | list.current++; |
| 463 | } |
| 464 | |
| 465 | if (!found) |
| 466 | return nullptr; |
| 467 | } |
| 468 | |
| 469 | if (relHand == 0) { |
| 470 | trackp->move[0].suit = currp->suit; |
| 471 | trackp->move[0].rank = currp->rank; |
| 472 | trackp->move[0].sequence = currp->sequence; |
| 473 | trackp->high[0] = 0; |
| 474 | |
| 475 | trackp->lead_suit = currp->suit; |
| 476 | } else if (currp->suit == trackp->move[relHand - 1].suit) { |
| 477 | if (currp->rank > trackp->move[relHand - 1].rank) { |
| 478 | trackp->move[relHand].suit = currp->suit; |
| 479 | trackp->move[relHand].rank = currp->rank; |
| 480 | trackp->move[relHand].sequence = currp->sequence; |
| 481 | trackp->high[relHand] = relHand; |
| 482 | } else { |