Inheritance: CollectionCards
Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        public BagOfCards Clone()
        {
            var result = new BagOfCards(this.gameSubset);

            result.CopyFrom(this);
            return(result);
        }
Exemplo n.º 7
0
        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;
            }
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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;
                }
            }
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
 public BagOfCards(CardGameSubset gameSubset, BagOfCards parent)
     : base(gameSubset, parent)
 {
 }
Exemplo n.º 12
0
 public BagOfCards Clone()
 {
     var result = new BagOfCards(this.gameSubset);
     result.CopyFrom(this);
     return result;
 }
Exemplo n.º 13
0
 public SingletonCardHolder(BagOfCards parent)
 {
     this.parent = parent;
 }
 public SingletonCardHolder(BagOfCards parent)
 {
     this.parent = parent;
 }
Exemplo n.º 15
0
        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;
        }
Exemplo n.º 16
0
 private void WriteAllCards(BagOfCards cards)
 {
     WriteAllCards((CollectionCards)cards);
 }
Exemplo n.º 17
0
 public void CopyFrom(BagOfCards other)
 {
     base.CopyFrom(other);
 }
Exemplo n.º 18
0
 public ListOfCards(CardGameSubset gameSubset, BagOfCards parent)
     : base(gameSubset, parent)
 {
 }
 private void WriteAllCards(BagOfCards cards)
 {
     WriteAllCards((CollectionCards)cards);
 }
Exemplo n.º 20
0
 public CollectionCards(CardGameSubset gameSubset, BagOfCards parent)
 {
     this.parent     = parent;
     this.gameSubset = gameSubset;
     this.mapGameCardIndexToCount = new int[this.gameSubset.CountOfCardTypesInGame];
 }
Exemplo n.º 21
0
 public void CopyFrom(BagOfCards other)
 {
     base.CopyFrom(other);
 }
Exemplo n.º 22
0
        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);
        }