public static Country GetCountryWithEnemyConnection(Game game, Player player, MapTemplate mapTemplate)
        {
            var enemyCountries = GetEnemyCountries(game, player);

            return player.Countries.First(
                    c => enemyCountries.Any(c2 => mapTemplate.AreConnected(c.CountryIdentifier, c2.CountryIdentifier)));
        }
Example #2
0
        public void PlayTurn()
        {
            this.ownTeam = game.CurrentPlayer.Team;
            this.ownPlayer = game.CurrentPlayer;;

            if (this.Place())
            {
                // Not first turn
                this.Attack();
                this.Move();
                this.EndTurn();
            }
        }
        public VictoryConditionResult Evaluate(Player player, Games.Map map)
        {
            if (!player.Countries.Any())
            {
                return VictoryConditionResult.Defeat;
            }

            if (player.Countries.Count() == map.Countries.Count())
            {
                return VictoryConditionResult.Victory;
            }

            return VictoryConditionResult.Inconclusive;
        }
 public static IEnumerable<Team> GetEnemyTeams(Game game, Player player)
 {
     return game.Teams.Where(x => !x.Players.Contains(player));
 }
        public static IEnumerable<Country> GetEnemyCountries(Game game, Player player)
        {
            var enemyTeams = GetEnemyTeams(game, player);

            return enemyTeams.SelectMany(x => x.Players).SelectMany(x => x.Countries);
        }
 public static Country GetCountryWithFriendlyConnection(Game game, Player player, MapTemplate mapTemplate)
 {
     return player.Countries.First(
             c => player.Countries.Any(c2 => mapTemplate.AreConnected(c.CountryIdentifier, c2.CountryIdentifier)));
 }
 public static Country GetConnectedFriendlyCountry(Game game, Player player, Country origin, MapTemplate mapTemplate)
 {
     return game.Teams.Where(x => x.Players.Contains(player))
             .SelectMany(t => t.Players)
             .SelectMany(p => p.Countries).First(c => mapTemplate.AreConnected(origin.CountryIdentifier, c.CountryIdentifier));
 }
Example #8
0
        public IEnumerable<Country> GetCountriesForPlayer(Player player)
        {
            if (this.PlayerToCountry.ContainsKey(player.Id))
            {
                return this.PlayerToCountry[player.Id];
            }

            return Enumerable.Empty<Country>();
        }
Example #9
0
 internal void UpdateOwnership(Player player, Country country)
 {
     this.UpdateOwnership(null, player, country);
 }
Example #10
0
        internal void UpdateOwnership(Player oldPlayer, Player newPlayer, Country country)
        {
            if (oldPlayer != null)
            {
                if (this.PlayerToCountry.ContainsKey(oldPlayer.Id))
                {
                    this.PlayerToCountry[oldPlayer.Id].Remove(country);
                }
            }

            if (newPlayer != null)
            {
                if (this.PlayerToCountry.ContainsKey(newPlayer.Id))
                {
                    this.PlayerToCountry[newPlayer.Id].Add(country);
                }
                else
                {
                    this.PlayerToCountry.Add(newPlayer.Id, new List<Country> { country });
                }

                country.PlayerId = newPlayer.Id;
                country.TeamId = newPlayer.TeamId;
            }
            else
            {
                country.PlayerId = Guid.Empty;
                country.TeamId = Guid.Empty;
            }
        }
 public VictoryConditionResult Evaluate(Player player, Games.Map map)
 {
     return VictoryConditionResult.Inconclusive;
 }
 public static Country GetConnectedEnemyCountry(Game game, Player player, Country origin, MapTemplate mapTemplate)
 {
     return GetEnemyTeams(game, player)
             .SelectMany(t => t.Players)
             .SelectMany(p => p.Countries).First(c => mapTemplate.AreConnected(origin.CountryIdentifier, c.CountryIdentifier));
 }
Example #13
0
        internal void CheckForVictory(Player active, Player passive = null)
        {
            foreach (var victoryCondition in this.Options.VictoryConditions)
            {
                var victoryConditionImpl = VictoryConditionFactory.Create(victoryCondition);

                // Check for passive player
                if (passive != null)
                {
                    if (victoryConditionImpl.Evaluate(passive, this.Map) == VictoryConditionResult.Defeat)
                    {
                        passive.Outcome = PlayerOutcome.Defeated;
                        passive.State = PlayerState.InActive;

                        this.GameHistory.RecordPlayerDefeated(passive);
                        // TODO: CS: Generate event
                    }
                }

                // Check for active player
                if (victoryConditionImpl.Evaluate(active, this.Map) == VictoryConditionResult.Victory)
                {
                    active.Outcome = PlayerOutcome.Won;
                    active.State = PlayerState.InActive;

                    this.GameHistory.RecordPlayerWon(active);
                    // TODO: CS: Generate event
                }
            }

            // Update team status
            var activeTeams = this.Teams.Where(x => x.Players.Any(p => !p.HasLost));
            if (activeTeams.Count() == 1)
            {
                // Only one team has survived, all players in this team have won
                foreach (var player in activeTeams.Single().Players)
                {
                    player.Outcome = PlayerOutcome.Won;
                    player.State = PlayerState.InActive;

                    this.GameHistory.RecordPlayerWon(player);
                    // TODO: CS: Generate event
                }

                this.End();
            }
        }
Example #14
0
        public int GetUnitsToPlace(MapTemplate mapTemplate, Player player)
        {
            // Base units as configured
            var unitsToPlace = this.Options.NewUnitsPerTurn;

            if (player.PlacedInitialUnits)
            {
                // Add units from number of occupied countries
                unitsToPlace += player.Countries.Count() / 3;

                // Bonus from continents
                unitsToPlace += mapTemplate.CalculateBonus(player.Countries.Select(x => x.CountryIdentifier));

                // Add any previous bonus
                unitsToPlace += player.Bonus;
            }

            return unitsToPlace;
        }
Example #15
0
        internal void RemovePlayer(Player player)
        {
            Require.NotNull(player, "player");

            this.Players.Remove(player);
        }
Example #16
0
        public Player AddPlayer(User user)
        {
            Require.NotNull(user, "user");

            if (this.Players.Count() >= this.Game.Options.NumberOfPlayersPerTeam)
            {
                throw new DomainException(ErrorCode.TeamAlreadyFull, "Team is already full");
            }

            var player = new Player(user, this);

            this.Players.Add(player);

            return player;
        }