public Play(Pile fromPile, Card fromCard, Pile toPile) { _fromPile = fromPile; _fromPileCardIndex = fromPile.IndexOf(fromCard); _fromCard = fromCard; _toPile = toPile; Logger.Write(GenerateToString()); }
private void ShufflePile(Pile pile) { for (int indexCard = _drawPile.Count - 1; indexCard >= 1; indexCard--) { int swapIndex = Utility.Random().Next(indexCard); Card tempCard = _drawPile[indexCard]; _drawPile[indexCard] = _drawPile[swapIndex]; _drawPile[swapIndex] = tempCard; } }
public void PrepGame() { for (int index = 0; index < _players.Count; index++) { Pile reservePile = _playerReservePile[index]; for (int cardIndex = 0; cardIndex < Board.ReservePileMax; cardIndex++) { reservePile.Add(_drawPile.Pop()); } } }
public List <Play> GetValidPlays() { List <Play> plays = new List <Play>(); Pile hand = GetHand(CurrentPlayer); foreach (Card handCard in hand) { foreach (Pile discardPile in _playerDiscardPiles[_currentPlayerIndex]) { Play play = new Play(hand, handCard, discardPile); plays.Add(play); } } return(plays); }
// void Shuffle() // void AppendPile(pile) public bool IsLegalPlay(Card card, Pile pile, out int playedValue) { switch (_pileType) { case PileType.Reserve: case PileType.Discard: case PileType.Draw: case PileType.Hand: default: playedValue = -1; return(false); case PileType.Build: if (card.IsSkipBo) { if (!pile.HasCards) { playedValue = 1; } else { playedValue = pile.Top.PlayedValue + 1; } return(true); } int requiredValue; if (pile.Count == 0) { requiredValue = 1; } else { requiredValue = pile.Top.PlayedValue + 1; } if (card.Value == requiredValue) { playedValue = requiredValue; return(true); } playedValue = -1; return(false); } }
private bool PlayCardFromHandToBuild(Board board) { foreach (Pile pile in board.BuildPiles) { Pile hand = board.GetHand(this); foreach (Card card in hand) { int playedValue; if (pile.IsLegalPlay(card, pile, out playedValue)) { card.PlayedValue = playedValue; board.DoPlay(new Play(hand, card, pile)); return(true); } } } return(false); }
private static Card PopCardFromPile(Pile fromPile, int index) { Card card = null; switch (fromPile.PileType) { case PileType.Build: throw (new ApplicationException("Can't pop cards from Build pile")); case PileType.Discard: case PileType.Reserve: case PileType.Hand: card = fromPile[index]; fromPile.Remove(card); return(card); default: throw new ApplicationException("Unhandled piletype " + fromPile.PileType); } }
public void FillCurrentPlayersHand() { Pile playerHand = GetHand(_currentPlayer); if (_hasBeenFilled && playerHand.Count != 0) { throw new ApplicationException("Over-dealing cards to the same player."); } while (playerHand.Count < Board.HandSize && _drawPile.Count > 0) { playerHand.Add(_drawPile.Pop()); } _hasBeenFilled = true; if (playerHand.Count == 0) { _isGameOver = true; } Logger.Write(string.Format("{0} Reserve({1}):{2}", playerHand.ToString("P"), GetReservePile(CurrentPlayer).Count, GetReservePile(CurrentPlayer).Top)); }
private void RecycleBuildPile(Pile pile) { ShufflePile(pile); _drawPile.AddRange(pile); pile.Clear(); }
public Play(Pile fromPile, Pile toPile) : this(fromPile, fromPile.Top, toPile) { }