Question.
I'm missing is a method to identify the dirty ladder
Taking into account that each of the suits is the same size and have the same displacement, you can transform any hand into spades and check if the difference between each hand card (ordered) is one unit.
Proposal.
Unfortunately, you do not contribute ANYTHING to your code, so it's all conjecture and the answer may not fit your needs; I assume that the cards are std::uint8_t
and that the player's hand is a std::vector
of those types:
using Carta = std::uint8_t;
using Mano = std::vector<Carta>;
bool escalera_sucia(const Mano &mano)
{
Mano temporal, palo;
// Transformamos toda la mano a Picas y a Palo
for (const auto &carta : mano)
{
temporal.push_back(carta % 13u);
palo.push_back(carta / 13);
}
// Comprobamos si la mano es sucia (tiene al menos dos palos)
if (std::all_of(palo.begin(), palo.end(), [i = palo[0]](Carta &c) { return c == i;} ))
return false;
// Ordenamos la mano resultante.
std::sort(temporal.begin(), temporal.end());
/* Nos aseguramnos que entre carta y carta de la
mano ordenada, haya solo una unidad de diferencia */
for (Mano::size_type indice = 1u; indice < temporal.size(); ++indice)
if ((temporal[indice] - temporal[indice - 1u]) != 1u)
/* Si llegamos aqui, significa que en algun momento la
diferencia entre una carta y la siguiente es mayor a 1 */
return false;
// Si llegamos aqui, la mano es una escalera sucia.
return true;
}
To transform into Picas (the base club) it is enough to make the module between the total of cards per suit ( 13
), to know which suit a card belongs to, just enough to divide between the cards of each suit ( 13
) being 0
picas, 1
diamonds, 2
hearts and 3
trefoils. A ladder will be dirty if there are at least two sticks in the hand and if the hand is ascending.
Warning.
I do not know the rules of Poker, so the previous algorithm may be wrong considering that the King (values 0
, 13
, 26
and 39
) goes before the Ace. This is could solve by placing the King at the end of the letters changing the order to 0
- 9
normal numbers, 10
Jack, 11
Reina, 12
Rey, etc ...