In the game of Scopa, at the player's turn, there could be anywhere from 0 to 39 cards on the table (although 10+ is an extreme). I'm trying to figure out the best way to figure out possibilities for the player to pick up cards off the table. Also, in Scopa, you can only pickup cards off the table if there's 1+ cards on the table that add to equal the value of the card in your hand.
Currently, I've got something close to:
for (Card card : cardsOnTable) {
for (Card card2 : cardsOnTable) {
if (card2 != card) {
if (card.getValue() + card2.getValue() == cardInHandValue) {
//Add to list of possibilities.
}
}
}
}
But that only works out while checking the table for possibilities of two cards. The problem is that there could be possibilities of 3, 4, etc. cards, and that detecting how many cards it needs to check (how many nested loops) doesn't seem possible. What method could I go about using to check for card possibilities?