/* @brief Moves a card from a tableau to a foundation. * @param SrcTableauIdx - Index of the source tableau. * @param DestFoundationIdx - Foundation to put the card into. * @return Boolean indicating if the move was valid or invalid. */ public bool MoveToFoundation(int SrcTableauIdx, int DestFoundationIdx) { bool validMove = false; Tableau SrcTableau = tableaus[SrcTableauIdx]; Card srcCard = SrcTableau.Cards[SrcTableau.Cards.Count - 1]; /* If this foundation is empty, check if the source card is an ace.*/ if (foundations[DestFoundationIdx].Count == 0 && srcCard.Value == 1) { foundations[DestFoundationIdx].Add(srcCard); validMove = true; } /* If the foundation is not empty, check if same suit and value is one higher*/ else { Card destCard = foundations[DestFoundationIdx][0]; if (CheckSuit(srcCard, destCard, false) && CheckCardValue(srcCard, destCard, false)) { AddToFoundation(srcCard, DestFoundationIdx); validMove = true; } } if (validMove) { if (SrcTableau.RemoveCards(1)) { points += 5; } points += 10; } return(validMove); }
/* @brief Performs the move of one or more cards from one tableau to another. * @param SrcTableau - Tableau where the cards are moving from. * @param Depth - How many cards are being moved. * @param DestTableau - Tableau where the cards are moving to. * */ private void MoveBetweenTableaus(Tableau SrcTableau, int Depth, Tableau DestTableau) { List <Card> cardsToMove = new List <Card>(); cardsToMove = SrcTableau.GetCards(Depth); foreach (Card card in cardsToMove) { DestTableau.InsertCard(card); } if (SrcTableau.RemoveCards(Depth)) { points += 5; } }