Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 4
0
 public static IEnumerable<Team> GetEnemyTeams(Game game, Player player)
 {
     return game.Teams.Where(x => !x.Players.Contains(player));
 }
Ejemplo n.º 5
0
        public static IEnumerable<Country> GetEnemyCountries(Game game, Player player)
        {
            var enemyTeams = GetEnemyTeams(game, player);

            return enemyTeams.SelectMany(x => x.Players).SelectMany(x => x.Countries);
        }
Ejemplo n.º 6
0
 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)));
 }
Ejemplo n.º 7
0
 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));
 }
Ejemplo n.º 8
0
        public IEnumerable<Country> GetCountriesForPlayer(Player player)
        {
            if (this.PlayerToCountry.ContainsKey(player.Id))
            {
                return this.PlayerToCountry[player.Id];
            }

            return Enumerable.Empty<Country>();
        }
Ejemplo n.º 9
0
 internal void UpdateOwnership(Player player, Country country)
 {
     this.UpdateOwnership(null, player, country);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 12
0
 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));
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 15
0
        internal void RemovePlayer(Player player)
        {
            Require.NotNull(player, "player");

            this.Players.Remove(player);
        }
Ejemplo n.º 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;
        }