상속: CollectionCards
예제 #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();
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #6
0
        public BagOfCards Clone()
        {
            var result = new BagOfCards(this.gameSubset);

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