I call this function in order to get a List<List<Card>>
:
List<List<Card>> comboCards = GetComboCards(new List<Card>(), board, new List<List<Card>>());
private List<List<Card>> GetComboCards(List<Card> previous, List<Card> board, List<List<Card>> combos)
{
for (int i = 0; i < board.Count; i++)
{
Card card = board[i];
List<Card> newPrevious = previous.Skip(i).ToList(); // FIXME: Not right
newPrevious.Add(card);
combos.Add(newPrevious);
List<Card> newBoard = board.Skip(i + 1).ToList();
GetComboCards(newPrevious, newBoard, combos);
}
return combos;
}
There's a problem with previous.Skip(i).ToList()
which I'm unsure of how to correct.
Example:
Board contains 4 cards. When run through GetComboCards, the List will return the appropriate number of List<Card>
's (15). However the List will have duplicates of the same combination in [5] and [12] for the 3rd card and again in [7], [11], and [14] for the 4th card.
Can anyone tell me what I'm doing wrong here? I know it has to do with the line where I've added FIXME, but I can't seem to figure it out. Any help would be greatly appreciated, thank you!