private void Initialize() { DrawingStack.Shuffle(); for (var index = 0; index < CardsPerPlayer; index++) { for (var playerIndex = 0; playerIndex < Players.Count; playerIndex++) { var actualPlayerIndex = (playerIndex + CurrentDealerIndex + 1) % Players.Count; var card = DrawingStack.WithdrawTopCard(); Players[actualPlayerIndex].AppendCard(card); if (index == CardsPerPlayer - 1 && actualPlayerIndex == CurrentDealerIndex) { RequiredFirstCard = card; } } } if (ActiveStack.Cards.Count != 0) { throw new InvalidOperationException( $@"[Internal error] After initialization the active stack must be empty but it has { ActiveStack.Cards.Count} cards."); } }
private PlayingCard DrawCard() { if (DrawingStack.IsEmpty) { throw new InvalidOperationException(@"[Internal error] The drawing stack is empty."); } var result = DrawingStack.WithdrawTopCard(); if (DrawingStack.IsEmpty) { var refillCards = ActiveStack.WithdrawAllCardsExceptTopCardWithSameRank(); DrawingStack.Refill(refillCards); DrawingStack.Shuffle(); PointsRatio++; } return(result); }