Ejemplo n.º 1
0
        private static void GenerateCharStats(CivilizationPivot civ)
        {
            if (CHARS_STATS.ContainsKey(civ) && FIRST_CHAR_STATS.ContainsKey(civ))
            {
                return;
            }

            var tempCharStats      = new Dictionary <char, Tuple <int, Dictionary <char, int> > >();
            var tempFirstCharStats = new Dictionary <char, int>();

            // TODO : files required for every civilizations !
            // string rName = $"{civ.Name.ToLowerInvariant()}_city_name";
            string rName = "french_city_name";

            var rows = Properties.Resources.ResourceManager.GetString(rName).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var row in rows)
            {
                int i = 0;
                foreach (var ch in row)
                {
                    if (i == 0)
                    {
                        if (!tempFirstCharStats.ContainsKey(ch))
                        {
                            tempFirstCharStats.Add(ch, 0);
                        }
                        tempFirstCharStats[ch]++;
                    }
                    else
                    {
                        if (!tempCharStats.ContainsKey(ch))
                        {
                            tempCharStats.Add(ch, new Tuple <int, Dictionary <char, int> >(1, new Dictionary <char, int>()));
                        }
                        else
                        {
                            tempCharStats[ch] = new Tuple <int, Dictionary <char, int> >(tempCharStats[ch].Item1 + 1, tempCharStats[ch].Item2);
                        }
                        var nextCh = i == row.Length - 1 ? END_OF_DATAS : row[i + 1];
                        if (!tempCharStats[ch].Item2.ContainsKey(nextCh))
                        {
                            tempCharStats[ch].Item2.Add(nextCh, 0);
                        }
                        tempCharStats[ch].Item2[nextCh]++;
                    }
                    i++;
                }
            }

            for (int i = 0; i <= 9; i++)
            {
                tempCharStats.Remove(i.ToString().First());
                tempFirstCharStats.Remove(i.ToString().First());
            }

            CHARS_STATS.Add(civ, tempCharStats);
            FIRST_CHAR_STATS.Add(civ, tempFirstCharStats);
        }
Ejemplo n.º 2
0
 private void SetDataSources()
 {
     ComboBoxSize.ItemsSource         = Enum.GetValues(typeof(SizePivot));
     ComboBoxLandShape.ItemsSource    = Enum.GetValues(typeof(LandShapePivot));
     ComboBoxLandCoverage.ItemsSource = Enum.GetValues(typeof(LandCoveragePivot));
     ComboBoxTemperature.ItemsSource  = Enum.GetValues(typeof(TemperaturePivot));
     ComboBoxAge.ItemsSource          = Enum.GetValues(typeof(AgePivot));
     ComboBoxHumidity.ItemsSource     = Enum.GetValues(typeof(HumidityPivot));
     ComboBoxCivilization.ItemsSource = CivilizationPivot.GetCivilizations(false);
 }
Ejemplo n.º 3
0
        private void ComboBoxSize_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            var count = CivilizationPivot.GetCivilizations(false).Count;

            if (ComboBoxSize.SelectedItem != null)
            {
                count /= (6 - (int)ComboBoxSize.SelectedItem);
            }

            ComboBoxIaPlayersCount.ItemsSource   = Enumerable.Range(0, count);
            ComboBoxIaPlayersCount.SelectedValue = 0;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="mapSize">Map size.</param>
        /// <param name="mapShape">Map shape.</param>
        /// <param name="landCoverage">Map land coverage.</param>
        /// <param name="temperature">Map temperature.</param>
        /// <param name="age">Map age.</param>
        /// <param name="humidity">Map humidity.</param>
        /// <param name="playerCivilization">Human player civilization.</param>
        /// <param name="playerGender">The <see cref="PlayerPivot.Gender"/> value.</param>
        /// <param name="iaPlayersCount">Number of IA civilizations (except barbarians).</param>
        /// <param name="randomCityNames">Sets <c>True</c> to active random city names for the human player.</param>
        /// <exception cref="ArgumentNullException"><paramref name="playerCivilization"/> is <c>Null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="iaPlayersCount"/> invalid.</exception>
        public EnginePivot(SizePivot mapSize, LandShapePivot mapShape, LandCoveragePivot landCoverage, TemperaturePivot temperature,
                           AgePivot age, HumidityPivot humidity, CivilizationPivot playerCivilization,
                           bool playerGender, int iaPlayersCount, bool randomCityNames)
        {
            if (playerCivilization == null)
            {
                throw new ArgumentNullException(nameof(playerCivilization));
            }
            iaPlayersCount = iaPlayersCount < 0 ? 0 : iaPlayersCount;
            if (iaPlayersCount > CivilizationPivot.GetCivilizations(false).Count / (6 - (int)mapSize))
            {
                throw new ArgumentException("The IA players count is too high for this map size !", nameof(iaPlayersCount));
            }

            Map = new MapPivot(mapSize, mapShape, landCoverage, temperature, age, humidity);

            List <MapSquarePivot> excludedSpots = new List <MapSquarePivot>();

            HumanPlayer = new PlayerPivot(this, playerCivilization, false, GetRandomLocation(excludedSpots), playerGender, randomCityNames);

            var allCivs = CivilizationPivot.GetCivilizations(false);

            for (int i = 0; i < iaPlayersCount; i++)
            {
                CivilizationPivot iaCiv = null;
                do
                {
                    iaCiv = allCivs.ElementAt(Tools.Randomizer.Next(0, allCivs.Count));
                }while (HumanPlayer.Civilization == iaCiv || _opponentPlayers.Any(ia => ia.Civilization == iaCiv));
                _opponentPlayers.Add(new PlayerPivot(this, iaCiv, true, GetRandomLocation(excludedSpots), Tools.Randomizer.Next(0, 2) == 0, false));
            }

            BarbarianPlayer = new PlayerPivot(this, CivilizationPivot.Barbarian, true, null, false, true);

            // Sets war between every civilizations.
            for (int i = 0; i < Players.Count - 1; i++)
            {
                for (int j = i + 1; j < Players.Count; j++)
                {
                    Players.ElementAt(i).SwitchPeaceStatusWithOpponent(Players.ElementAt(j));
                }
            }

            CurrentTurn = 0;
        }
Ejemplo n.º 5
0
        private static char GetRandomFirstChar(CivilizationPivot civ)
        {
            var datas = FIRST_CHAR_STATS[civ];

            var rdm = Tools.Randomizer.Next(0, datas.Sum(kvp => kvp.Value));
            int i   = 0;

            do
            {
                rdm -= datas.ElementAt(i).Value;
                if (rdm <= 0)
                {
                    return(datas.ElementAt(i).Key);
                }
                i++;
            }while (rdm > 0);

            throw new InvalidOperationException("Should never occurs !");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Generates a city name for the specified <see cref="CivilizationPivot"/>.
        /// </summary>
        /// <param name="civilization">The civilization</param>
        /// <returns>The city name.</returns>
        internal static string GenerateCityName(CivilizationPivot civilization)
        {
            GenerateCharStats(civilization);

            var countChars = GetCityNameCharactersCount();
            var nameChars  = new char[countChars];

            for (int i = 0; i < countChars; i++)
            {
                if (i == 0 || nameChars[i - 1] == ' ')
                {
                    nameChars[i] = GetRandomFirstChar(civilization);
                }
                else
                {
                    nameChars[i] = GetRandomNextChar(civilization, nameChars[i - 1],
                                                     i - 2 >= 0 && nameChars[i - 2] == nameChars[i - 1],
                                                     (i - 2 >= 0 && nameChars[i - 2] == ' ') || (i == 1) || (i == countChars - 2));
                }
            }

            return(new string(nameChars));
        }
Ejemplo n.º 7
0
        private static char GetRandomNextChar(CivilizationPivot civ, char previousChar, bool alreadyTwice, bool forbidSpace)
        {
            var datas = CHARS_STATS[civ][previousChar].Item2;

            char?charTmp = null;

            do
            {
                var rdm = Tools.Randomizer.Next(0, datas.Sum(kvp => kvp.Value));
                int i   = 0;
                do
                {
                    rdm -= datas.ElementAt(i).Value;
                    if (rdm <= 0)
                    {
                        charTmp = datas.ElementAt(i).Key;
                        break;
                    }
                    i++;
                }while (rdm > 0);
            }while (charTmp.Value == END_OF_DATAS || (alreadyTwice && charTmp.Value == previousChar) || (forbidSpace && charTmp.Value == ' '));

            return(charTmp.Value);
        }