Exemplo n.º 1
0
        public void Add(DominionBase.Game game, DominionBase.Players.Player player)
        {
            if (game.Players.Count != _NumberOfPlayers)
            {
                throw new Exception("Incorrect number of players in game!");
            }

            if (player != null)
            {
                if (!game.Players.Contains(player))
                {
                    throw new Exception("Player not found in game!");
                }

                // One more game played!
                this.GamesPlayed++;

                // If the game actually finished properly, instead of being aborted
                if (game.State == DominionBase.GameState.Ended)
                {
                    // Player won (or at least tied in winning)
                    if (game.Winners.Contains(player))
                    {
                        this.GamesWon++;
                    }

                    if (player.VictoryPoints < this.LowestScore)
                    {
                        this.LowestScore = player.VictoryPoints;
                    }
                    if (player.VictoryPoints > this.HighestScore)
                    {
                        this.HighestScore = player.VictoryPoints;
                    }

                    _TotalScore += player.VictoryPoints;
                }
            }

            if (game.State == DominionBase.GameState.Ended)
            {
                foreach (DominionBase.Players.Player winner in game.Winners)
                {
                    // Since properly-used cards like Feast, Mining Village, & Embargo never end up in a player's hand,
                    // we need to count how many of the cards were played during the game and add them to the player's
                    // total as well as the total number of cards in the player's hand
                    IEnumerable <DominionBase.Cards.Card> trashedCards = game.TurnsTaken.Where(t => t.Player == winner).
                                                                         SelectMany <DominionBase.Turn, DominionBase.Cards.Card>(
                        t =>
                        t.CardsPlayed.Where(c =>
                                            c.CardType == DominionBase.Cards.Base.TypeClass.Feast ||
                                            c.CardType == DominionBase.Cards.Seaside.TypeClass.Embargo ||
                                            (c.CardType == DominionBase.Cards.Intrigue.TypeClass.MiningVillage && t.CardsTrashed.Contains(c)) ||
                                            (c.CardType == DominionBase.Cards.Cornucopia.TypeClass.HornOfPlenty && t.CardsTrashed.Contains(c))
                                            )
                        );

                    int handCount = winner.Hand.Count + trashedCards.Count();

                    foreach (DominionBase.Piles.Supply supply in game.Table.Supplies.Values)
                    {
                        Type   cardType    = supply.CardType;
                        String cardTypeKey = cardType.AssemblyQualifiedName;

                        int cardTypeCount = winner.Hand.Count(c => c.CardType == cardType) + trashedCards.Count(c => c.CardType == cardType);

                        if (!_WinningCardCounts.ContainsKey(cardTypeKey))
                        {
                            _WinningCardCounts[cardTypeKey] = new CardStatistics(cardType);
                        }
                        _WinningCardCounts[cardTypeKey].Add(cardTypeCount, handCount);

                        if (winner.PlayerType == DominionBase.Players.PlayerType.Human)
                        {
                            if (!_WinningHumanCardCounts.ContainsKey(cardTypeKey))
                            {
                                _WinningHumanCardCounts[cardTypeKey] = new CardStatistics(cardType);
                            }
                            _WinningHumanCardCounts[cardTypeKey].Add(cardTypeCount, handCount);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
		public void Add(DominionBase.Game game, DominionBase.Players.Player player)
		{
			if (game.Players.Count != _NumberOfPlayers)
				throw new Exception("Incorrect number of players in game!");

			if (player != null)
			{
				if (!game.Players.Contains(player))
					throw new Exception("Player not found in game!");

				// One more game played!
				this.GamesPlayed++;

				// If the game actually finished properly, instead of being aborted
				if (game.State == DominionBase.GameState.Ended)
				{
					// Player won (or at least tied in winning)
					if (game.Winners.Contains(player))
						this.GamesWon++;

					if (player.VictoryPoints < this.LowestScore)
						this.LowestScore = player.VictoryPoints;
					if (player.VictoryPoints > this.HighestScore)
						this.HighestScore = player.VictoryPoints;

					_TotalScore += player.VictoryPoints;
				}
			}

			if (game.State == DominionBase.GameState.Ended)
			{
				foreach (DominionBase.Players.Player winner in game.Winners)
				{

					// Since properly-used cards like Feast, Mining Village, & Embargo never end up in a player's hand, 
					// we need to count how many of the cards were played during the game and add them to the player's
					// total as well as the total number of cards in the player's hand
					IEnumerable<DominionBase.Cards.Card> trashedCards = game.TurnsTaken.Where(t => t.Player == winner).
						SelectMany<DominionBase.Turn, DominionBase.Cards.Card>(
						t => 
							t.CardsPlayed.Where(c => 
								c.CardType == DominionBase.Cards.Base.TypeClass.Feast || 
								c.CardType == DominionBase.Cards.Seaside.TypeClass.Embargo ||
								(c.CardType == DominionBase.Cards.Intrigue.TypeClass.MiningVillage && t.CardsTrashed.Contains(c)) ||
								(c.CardType == DominionBase.Cards.Cornucopia.TypeClass.HornOfPlenty && t.CardsTrashed.Contains(c))
								)
							);

					int handCount = winner.Hand.Count + trashedCards.Count();

					foreach (DominionBase.Piles.Supply supply in game.Table.Supplies.Values)
					{
						Type cardType = supply.CardType;
						String cardTypeKey = cardType.AssemblyQualifiedName;

						int cardTypeCount = winner.Hand.Count(c => c.CardType == cardType) + trashedCards.Count(c => c.CardType == cardType);

						if (!_WinningCardCounts.ContainsKey(cardTypeKey))
							_WinningCardCounts[cardTypeKey] = new CardStatistics(cardType);
						_WinningCardCounts[cardTypeKey].Add(cardTypeCount, handCount);

						if (winner.PlayerType == DominionBase.Players.PlayerType.Human)
						{
							if (!_WinningHumanCardCounts.ContainsKey(cardTypeKey))
								_WinningHumanCardCounts[cardTypeKey] = new CardStatistics(cardType);
							_WinningHumanCardCounts[cardTypeKey].Add(cardTypeCount, handCount);
						}
					}
				}
			}
		}