protected void MoveAllCardsFrom(CollectionCards other) { for (int index = 0; index < this.mapGameCardIndexToCount.Length; ++index) { this.mapGameCardIndexToCount[index] += other.mapGameCardIndexToCount[index]; var parent = this.parent; while (parent != null) { parent.mapGameCardIndexToCount[index] += other.mapGameCardIndexToCount[index]; parent = parent.parent; } } this.count += other.count; { var parent = this.parent; while (parent != null) { parent.count += other.count; parent = parent.parent; } } other.Clear(); }
protected Card Remove(Card card) { if (card == null) { return(null); } int indexForCard = this.gameSubset.GetIndexFor(card); if (indexForCard == -1) { return(null); } if (this.mapGameCardIndexToCount[indexForCard] == 0) { return(null); } this.mapGameCardIndexToCount[indexForCard] -= 1; this.count--; var parent = this.parent; while (parent != null) { parent.mapGameCardIndexToCount[indexForCard] -= 1; parent.count--; parent = parent.parent; } return(card); }
public GameState( IPlayerAction[] playerActions, int[] playerPositions, Game game, IEnumerable <CardCountPair>[] startingDeckPerPlayer = null) { this.game = game; GameConfig gameConfig = game.GameConfig; int playerCount = playerActions.Length; this.supplyPiles = gameConfig.GetSupplyPiles(playerCount, game.random); this.nonSupplyPiles = gameConfig.GetNonSupplyPiles(); this.mapCardToPile = new MapOfCardsForGameSubset <PileOfCards>(this.CardGameSubset); this.BuildMapOfCardToPile(); this.players = new PlayerCircle(playerCount, playerActions, playerPositions, game); this.hasPileEverBeenGained = new MapPileOfCards <bool>(this.supplyPiles); this.pileEmbargoTokenCount = new MapPileOfCards <int>(this.supplyPiles); this.trash = new BagOfCards(this.CardGameSubset); this.GainStartingCards(gameConfig); this.players.AllPlayersDrawInitialCards(gameConfig); foreach (PileOfCards cardPile in this.supplyPiles) { cardPile.ProtoTypeCard.DoSpecializedSetupIfInSupply(this); } }
internal PlayerState(IPlayerAction actions, int playerIndex, Game game) { this.game = game; CardGameSubset gameSubset = game.CardGameSubset; this.actions = new PlayerActionWithSelf(actions, this); this.EnterPhase(PlayPhase.NotMyTurn); this.playerIndex = playerIndex; // duplicates this.allOwnedCards = new BagOfCards(gameSubset); this.cardsInPlay = new BagOfCards(gameSubset, this.allOwnedCards); this.cardsInPlayAtBeginningOfCleanupPhase = new BagOfCards(gameSubset); // partition this.islandMat = new BagOfCards(gameSubset, this.allOwnedCards); this.nativeVillageMat = new BagOfCards(gameSubset, this.allOwnedCards); this.tavernMat = new BagOfCards(gameSubset, this.allOwnedCards); this.deck = new ListOfCards(gameSubset, this.allOwnedCards); this.discard = new BagOfCards(gameSubset, this.allOwnedCards); this.cardsBeingPlayed = new ListOfCards(gameSubset, this.allOwnedCards); // a stack for recursion this.cardsBeingRevealed = new BagOfCards(gameSubset, this.allOwnedCards); this.hand = new BagOfCards(gameSubset, this.allOwnedCards); this.cardsPlayed = new BagOfCards(gameSubset, this.cardsInPlay); this.durationCards = new BagOfCards(gameSubset, this.cardsInPlay); this.cardsToReturnToHandAtStartOfTurn = new BagOfCards(gameSubset, this.allOwnedCards); this.cardToPass = new SingletonCardHolder(this.allOwnedCards); this.cardBeingDiscarded = new ListOfCards(gameSubset, this.allOwnedCards); this.cardsSetAside = new BagOfCards(gameSubset, this.allOwnedCards); this.turnCounters = new PlayerTurnCounters(gameSubset); }
public GameState( IGameLog gameLog, IPlayerAction[] players, GameConfig gameConfig, Random random, IEnumerable<CardCountPair>[] startingDeckPerPlayer = null) { int playerCount = players.Length; this.gameLog = gameLog; this.cardGameSubset = gameConfig.cardGameSubset; this.supplyPiles = gameConfig.GetSupplyPiles(playerCount, random); this.nonSupplyPiles = gameConfig.GetNonSupplyPiles(); this.mapCardToPile = new MapOfCards<PileOfCards>(this.cardGameSubset); this.BuildMapOfCardToPile(); this.players = new PlayerCircle(playerCount, players, this.gameLog, random, this.cardGameSubset); this.hasPileEverBeenGained = new MapPileOfCardsToProperty<bool>(this.supplyPiles); this.pileEmbargoTokenCount = new MapPileOfCardsToProperty<int>(this.supplyPiles); this.trash = new BagOfCards(this.cardGameSubset); this.GainStartingCards(gameConfig); this.players.AllPlayersDrawInitialCards(gameConfig); foreach (PileOfCards cardPile in this.supplyPiles) { cardPile.ProtoTypeCard.DoSpecializedSetupIfInSupply(this); } }
public BagOfCards Clone() { var result = new BagOfCards(this.gameSubset); result.CopyFrom(this); return(result); }
protected void Add(Card card) { if (card == null) { return; } int indexForCard = this.gameSubset.GetIndexFor(card); if (indexForCard == -1) { throw new Exception("Tried to add card that wasn't in the game"); } this.mapGameCardIndexToCount[indexForCard] += 1; this.count++; var parent = this.parent; while (parent != null) { parent.mapGameCardIndexToCount[indexForCard] += 1; parent.count++; parent = parent.parent; } }
public GameState( IPlayerAction[] playerActions, int[] playerPositions, Game game) { if (playerActions.Length != playerPositions.Length) { throw new Exception(); } this.game = game; GameConfig gameConfig = game.GameConfig; this.emptyCardCollection = new CollectionCards(this.CardGameSubset, null); int playerCount = playerActions.Length; this.supplyPiles = gameConfig.GetSupplyPiles(playerCount, game.random); this.nonSupplyPiles = gameConfig.GetNonSupplyPiles(playerCount); this.mapCardToPile = new MapOfCardsForGameSubset <PileOfCards>(this.CardGameSubset); this.BuildMapOfCardToPile(); this.players = new PlayerCircle(playerCount, playerActions, playerPositions, game); this.hasPileEverBeenGained = new MapPileOfCards <bool>(this.supplyPiles); this.pileEmbargoTokenCount = new MapPileOfCards <int>(this.supplyPiles); this.trash = new BagOfCards(this.CardGameSubset); this.cardContextStack = new CardContextStack(); this.GainStartingCards(gameConfig); foreach (PileOfCards cardPile in this.supplyPiles) { cardPile.ProtoTypeCard.DoSpecializedSetupIfInSupply(this); } this.players.AllPlayersDrawInitialCards(gameConfig, this); }
protected void AddAllCardsFrom(CollectionCards other) { for (int index = 0; index < this.mapGameCardIndexToCount.Length; ++index) { int count = other.mapGameCardIndexToCount[index]; if (count == 0) { continue; } this.mapGameCardIndexToCount[index] += count; this.count += count; var parent = this.parent; while (parent != null) { parent.mapGameCardIndexToCount[index] += count; parent.count += count; parent = parent.parent; } } }
virtual public void Clear() { if (this.count == 0) { return; } var parent = this.parent; while (parent != null) { for (int index = 0; index < this.mapGameCardIndexToCount.Length; ++index) { parent.mapGameCardIndexToCount[index] -= this.mapGameCardIndexToCount[index]; } parent.count -= this.count; parent = parent.parent; } this.count = 0; Array.Clear(this.mapGameCardIndexToCount, 0, this.mapGameCardIndexToCount.Length); }
public BagOfCards(CardGameSubset gameSubset, BagOfCards parent) : base(gameSubset, parent) { }
public BagOfCards Clone() { var result = new BagOfCards(this.gameSubset); result.CopyFrom(this); return result; }
public SingletonCardHolder(BagOfCards parent) { this.parent = parent; }
internal CollectionCards RequestPlayerTrashCardsFromHand(GameState gameState, int cardCount, bool isOptional, bool allOrNone = false) { var trashedCards = new BagOfCards(gameState.CardGameSubset); CardPredicate acceptableCardsToTrash = card => true; while (trashedCards.Count < cardCount) { Card trashedCard = this.RequestPlayerTrashCardFromHandButDontTrash(gameState, acceptableCardsToTrash, isOptional); if (trashedCard == null) { break; } if (allOrNone == true) isOptional = false; trashedCards.AddCard(trashedCard); this.RemoveCardFromHand(trashedCard); } foreach (var trashedCard in trashedCards) this.MoveCardToTrash(trashedCard, gameState); return trashedCards; }
private void WriteAllCards(BagOfCards cards) { WriteAllCards((CollectionCards)cards); }
public void CopyFrom(BagOfCards other) { base.CopyFrom(other); }
public ListOfCards(CardGameSubset gameSubset, BagOfCards parent) : base(gameSubset, parent) { }
public CollectionCards(CardGameSubset gameSubset, BagOfCards parent) { this.parent = parent; this.gameSubset = gameSubset; this.mapGameCardIndexToCount = new int[this.gameSubset.CountOfCardTypesInGame]; }
public GameState( IPlayerAction[] playerActions, int[] playerPositions, Game game) { if (playerActions.Length != playerPositions.Length) throw new Exception(); this.game = game; GameConfig gameConfig = game.GameConfig; this.emptyCardCollection = new CollectionCards(this.CardGameSubset, null); int playerCount = playerActions.Length; this.supplyPiles = gameConfig.GetSupplyPiles(playerCount, game.random); this.nonSupplyPiles = gameConfig.GetNonSupplyPiles(playerCount); this.mapCardToPile = new MapOfCardsForGameSubset<PileOfCards>(this.CardGameSubset); this.BuildMapOfCardToPile(); this.players = new PlayerCircle(playerCount, playerActions, playerPositions, game); this.hasPileEverBeenGained = new MapPileOfCards<bool>(this.supplyPiles); this.pileEmbargoTokenCount = new MapPileOfCards<int>(this.supplyPiles); this.trash = new BagOfCards(this.CardGameSubset); this.cardContextStack = new CardContextStack(); this.GainStartingCards(gameConfig); foreach (PileOfCards cardPile in this.supplyPiles) { cardPile.ProtoTypeCard.DoSpecializedSetupIfInSupply(this); } this.players.AllPlayersDrawInitialCards(gameConfig, this); }