Exemplo n.º 1
0
        public IFraction Divide(IFraction other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other is IFraction <int> )
            {
                return(Add((IFraction <int>)other));
            }

            if (other.Equals(0))
            {
                throw new DivideByZeroException();
            }

            if (_numerator == 0 && _wholeNumber == 0)
            {
                return(other);
            }

            if (other.GetMaxUnderlyingValue().CompareTo(int.MaxValue) <= 0 && other.GetMinUnderlyingValue().CompareTo(int.MinValue) >= 0)
            {
                return(Divide(Convert.ToInt32(other.WholeNumber), Convert.ToInt32(other.Numerator), Convert.ToInt32(other.Denominator)));
            }

            return((new Fraction64(this)).Divide(other));
        }
Exemplo n.º 2
0
        public IFraction Multiply(IFraction other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other is IFraction <long> )
            {
                return(Add((IFraction <long>)other));
            }

            if (_numerator == 0 && _wholeNumber == 0)
            {
                return(other);
            }

            if (other.Equals(0))
            {
                return(Fraction64.Zero);
            }

            if (other.GetMaxUnderlyingValue().CompareTo(long.MaxValue) <= 0 && other.GetMinUnderlyingValue().CompareTo(long.MinValue) >= 0)
            {
                return(Multiply(Convert.ToInt64(other.WholeNumber), Convert.ToInt64(other.Numerator), Convert.ToInt64(other.Denominator)));
            }

            return((new Fraction64(this)).Multiply(other));
        }
Exemplo n.º 3
0
    public void SelectFraction(IFraction fraction)
    {
        fractions.CurrentFraction = fraction;
        cards = collection.GetFractionCards(fractions.CurrentFraction.Name, true);

        FirstPages(cards.Count);
    }
Exemplo n.º 4
0
        /// <summary>
        /// Создаёт персонажа.
        /// </summary>
        /// <returns> Возвращает созданного персонажа. </returns>
        private static IPerson CreateStartPerson(string personSchemeSid, IPersonFactory personFactory,
                                                 IFraction fraction)
        {
            var startPerson = personFactory.Create(personSchemeSid, fraction);

            return(startPerson);
        }
Exemplo n.º 5
0
        public Fraction64(IFraction fraction)
        {
            long numerator, denominator;

            _wholeNumber = FractionUtil.GetNormalizedRational64(FractionUtil.ToInt64(fraction.WholeNumber), FractionUtil.ToInt64(fraction.Numerator), FractionUtil.ToInt64(fraction.Denominator, 1), out numerator, out denominator);
            _numerator   = numerator;
            _denominator = denominator;
        }
Exemplo n.º 6
0
        public Fraction16(IFraction fraction)
        {
            int numerator, denominator;

            _wholeNumber = (short)(FractionUtil.GetNormalizedRational(FractionUtil.ToInt32(fraction.WholeNumber), FractionUtil.ToInt32(fraction.Numerator), FractionUtil.ToInt32(fraction.Denominator, 1), out numerator, out denominator));
            _numerator   = (short)numerator;
            _denominator = (short)denominator;
        }
Exemplo n.º 7
0
 public FractionsButton Assing(Transform parent, IFraction fraction, Action <FractionsButton> click)
 {
     (Identifier, this.clickHandler) = (fraction, click);
     nameFraction.SetKey(fraction.Name);
     transform.SetParent(parent, false);
     fon.color = Color.gray;
     return(this);
 }
Exemplo n.º 8
0
        public void Pow(IFraction frc)
        {
            var p = (double)frc.ToNumber();

            this.Numerator   = (decimal)Math.Pow((double)this.Numerator, p);
            this.Denominator = (decimal)Math.Pow((double)this.Denominator, p);
            SimplifyFloats();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Создаёт персонажа.
        /// </summary>
        /// <param name="serviceProvider"> Контейнер DI, откуда извлекаются сервисы для создания персонажа. </param>
        /// <returns> Возвращает созданного персонажа. </returns>
        public static IPerson CreateStartPerson(IServiceProvider serviceProvider, IFraction fraction)
        {
            var personFactory = serviceProvider.GetRequiredService <IPersonFactory>();

            var startPerson = personFactory.Create("human-person", fraction);

            return(startPerson);
        }
        public IPerson Create(string personSchemeSid, IFraction fraction)
        {
            var personScheme = _schemeService.GetScheme <IPersonScheme>(personSchemeSid);

            var person = new HumanPerson(personScheme, fraction);

            var attributes = new[]
            {
                new PersonAttribute(PersonAttributeType.PhysicalStrength, 10),
                new PersonAttribute(PersonAttributeType.Dexterity, 10),
                new PersonAttribute(PersonAttributeType.Perception, 10),
                new PersonAttribute(PersonAttributeType.Constitution, 10)
            };
            var attributesModule = new AttributesModule(attributes);

            person.AddModule(attributesModule);

            var inventoryModule = new InventoryModule();

            person.AddModule(inventoryModule);

            var equipmentModule = new EquipmentModule(personScheme.Slots);

            person.AddModule(equipmentModule);

            var сonditionModule = new ConditionsModule();

            person.AddModule(сonditionModule);

            var evolutionModule = new EvolutionModule(_schemeService);

            person.AddModule(evolutionModule);

            var survivalModule = new HumanSurvivalModule(personScheme, _survivalRandomSource, attributesModule,
                                                         сonditionModule, evolutionModule, equipmentModule);

            person.AddModule(survivalModule);

            var defaultActScheme  = _schemeService.GetScheme <ITacticalActScheme>(person.Scheme.DefaultActs.First());
            var defaultActSchemes = new[] { defaultActScheme };
            var combatActModule   = new CombatActModule(
                defaultActSchemes,
                equipmentModule,
                сonditionModule,
                evolutionModule);

            person.AddModule(combatActModule);

            var combatStatsModule = new CombatStatsModule(evolutionModule, equipmentModule);

            person.AddModule(combatStatsModule);

            var diseaseModule = new DiseaseModule(сonditionModule);

            person.AddModule(diseaseModule);

            return(person);
        }
Exemplo n.º 11
0
        IFraction <long> IFraction <long> .Subtract(IFraction <long> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            return(Subtract(other.WholeNumber, other.Numerator, other.Denominator));
        }
Exemplo n.º 12
0
        public Fraction8(IFraction other)
        {
            _hashCode = 0;
            sbyte numerator, denominator;

            _wholeNumber = FractionUtil.GetNormalizedRational8(FractionUtil.ToSByte(other.WholeNumber), FractionUtil.ToSByte(other.Numerator), FractionUtil.ToSByte(other.Denominator, 1), out numerator, out denominator);
            _numerator   = numerator;
            _denominator = denominator;
        }
Exemplo n.º 13
0
        public void Pow(IComplex z)
        {
            if (z.Im.Numerator == 0)
            {
                if (this.Im.Numerator == 0)
                {
                    this.Re.Pow(z.Re);
                }
                else
                {
                    var n = (double)z.Re.ToNumber();

                    if (n == 0)
                    {
                        this.Re = new Fraction();
                        this.Im = new Fraction(0, 1);
                    }
                    else if (n == 1)
                    {
                    }
                    if (z.Re.Numerator > 1 && z.Re.Denominator > 1)
                    {
                        //first power using numeratora and this function then root using this function and denominator
                        throw new NotImplementedException("Complex number to power of fraction is not implemnted");
                    }
                    else if (z.Re.Numerator > 1 && z.Re.Denominator == 1)
                    {
                        var r2 = (double)((Fraction)this.Re * this.Re + (Fraction)this.Im * this.Im).ToNumber();
                        var r  = Math.Pow(r2, 0.5);
                        var y  = (double)this.Im.ToNumber();
                        var rn = Math.Pow(r, n);

                        var phi = Math.Asin(y / r);

                        this.Re = new Fraction((decimal)(rn * Math.Cos(n * phi)), 1);
                        this.Im = new Fraction((decimal)(rn * Math.Sin(n * phi)), 1);
                    }
                    else if (z.Re.Numerator == 1 && z.Re.Denominator > 1)
                    {
                        var r2 = (double)((Fraction)this.Re * this.Re + (Fraction)this.Im * this.Im).ToNumber();
                        var r  = Math.Pow(r2, 0.5);
                        var y  = (double)this.Im.ToNumber();
                        var rn = Math.Pow(r, n);

                        var phi = Math.Asin(y / r);

                        this.Re = new Fraction((decimal)(rn * Math.Cos(n * phi)), 1);
                        this.Im = new Fraction((decimal)(rn * Math.Sin(n * phi)), 1);
                    }
                }
            }
            else
            {
                throw new NotImplementedException("Complex number to power of complex number is not implemented");
            }
        }
Exemplo n.º 14
0
Arquivo: Form1.cs Projeto: Gwee/csharp
        public Form1()
        {
            InitializeComponent();
            HttpChannel channel = new HttpChannel();

            ChannelServices.RegisterChannel(channel, false);

            myIFraction = (IFraction)Activator.GetObject(
                typeof(IFraction),
                "http://localhost:1234/_Server_");
        }
Exemplo n.º 15
0
 public void Multiply(string dim, decimal val)
 {
     if (this.Key == dim)
     {
         this.Value = (Fraction)this.Value * val;
     }
     else
     {
         throw new ArgumentException($"Couldn't find that key '{dim}' in expression dimensions");
     }
 }
Exemplo n.º 16
0
 public void SetSelecedButton(IFraction fraction)
 {
     foreach (var item in buttons)
     {
         if (item.Identifier == fraction)
         {
             currentButton?.SelectFraction(false);
             currentButton = null;
             Select(item);
         }
     }
 }
Exemplo n.º 17
0
        IFraction <int> IFraction <int> .Add(IFraction <int> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other is Fraction32)
            {
                return(Add((Fraction32)other));
            }

            return(Add(other.WholeNumber, other.Numerator, other.Denominator));
        }
Exemplo n.º 18
0
        public void Divide(IFraction frc)
        {
            if (this.Denominator % 1 != 0 || frc.Denominator % 1 != 0 || this.Numerator % 1 != 0 || frc.Numerator % 1 != 0)
            {
                this.Numerator   = this.Numerator * frc.Denominator;
                this.Denominator = this.Denominator * frc.Numerator;

                SimplifyFloats();
            }
            else
            {
                this.Simplify(this.Numerator * frc.Denominator, this.Denominator * frc.Numerator);
            }
        }
Exemplo n.º 19
0
        IFraction <long> IFraction <long> .Multiply(IFraction <long> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other is Fraction64)
            {
                return(Multiply((Fraction64)other));
            }

            return(Multiply(other.WholeNumber, other.Numerator, other.Denominator));
        }
Exemplo n.º 20
0
    public FractionsData()
    {
        var temp = Resources.LoadAll <FractionScriptable>("Data/Fractions/").ToList();

        Fractions = temp.Where(x => x.Name != "neutral").ToList <IFraction>();
        Fractions.Add(temp.Where(x => x.Name == "neutral").First()); //Добавить нейтралов последними в список фракций

        if (Fractions.Count > 0)
        {
            CurrentFraction = Fractions[0];
        }
        else
        {
            Debug.LogError("Fractions not found!");
        }
    }
Exemplo n.º 21
0
 public void Set(string dim, decimal val)
 {
     //if (this.Key.ContainsKey(dim))
     //{
     //    this.Key[dim] += val;
     //    if (this.Key[dim] == 0)
     //    {
     //        this.Key.Remove(dim);
     //    }
     //}
     //else
     //{
     //    this.Key.Add(dim, val);
     //}
     this.Key   = dim;
     this.Value = new Fraction(val, 1);
 }
Exemplo n.º 22
0
        private int CompareTo(IFraction <int> other)
        {
            if (other == null)
            {
                return(1);
            }

            if (other is Fraction32)
            {
                return(CompareTo((Fraction32)other));
            }

            int n, d;
            int w = FractionUtil.GetNormalizedRational(other.WholeNumber, other.Numerator, other.Denominator, out n, out d);

            int i = _wholeNumber.CompareTo(w);

            if (i != 0)
            {
                return(i);
            }
            if (_wholeNumber == 0)
            {
                if (_numerator == 0 || n == 0 || _denominator == d)
                {
                    return(_numerator.CompareTo(n));
                }
            }
            else
            {
                if (_numerator == 0)
                {
                    return(n);
                }
                if (n == 0)
                {
                    return(_numerator);
                }
            }

            long n1 = _numerator, d1 = _denominator, n2 = n, d2 = d;

            FractionUtil.ToCommonDenominator64(ref n1, ref d1, ref n2, ref d2);
            return(n1.CompareTo(n2));
        }
Exemplo n.º 23
0
        private int CompareTo(IFraction <long> other)
        {
            if (other == null)
            {
                return(1);
            }

            if (other is Fraction64)
            {
                return(CompareTo((Fraction64)other));
            }

            long n, d;
            long w = FractionUtil.GetNormalizedRational64(other.WholeNumber, other.Numerator, other.Denominator, out n, out d);

            int i = _wholeNumber.CompareTo(w);

            if (i != 0)
            {
                return(i);
            }
            if (_wholeNumber == 0)
            {
                if (_numerator == 0 || n == 0 || _denominator == d)
                {
                    return(_numerator.CompareTo(n));
                }
            }
            else
            {
                if (_numerator == 0)
                {
                    return((n < (long)(int.MinValue)) ? -1 : ((n > 0L) ? 1 : 0));
                }
                if (n == 0)
                {
                    return((_numerator < (long)(int.MinValue)) ? -1 : ((_numerator > 0L) ? 1 : 0));
                }
            }

            long n1 = _numerator, d1 = _denominator, n2 = n, d2 = d;

            FractionUtil.ToCommonDenominator64(ref n1, ref d1, ref n2, ref d2);
            return(n1.CompareTo(n2));
        }
Exemplo n.º 24
0
        public void Add(IFraction frc)
        {
            if (this.Denominator % 1 != 0 || frc.Denominator % 1 != 0 || this.Numerator % 1 != 0 || frc.Numerator % 1 != 0)
            {
                this.Numerator    = this.Denominator * frc.Numerator + this.Numerator * frc.Denominator;
                this.Denominator *= frc.Denominator;

                SimplifyFloats();
            }
            else
            {
                var gcf = GCF((int)this.Denominator, (int)frc.Denominator);
                var den = this.Denominator * frc.Denominator / gcf;
                var num = this.Numerator * den / this.Denominator + frc.Numerator * den / frc.Denominator;

                this.Simplify(num, den);
            }
        }
Exemplo n.º 25
0
        public FractionRelation GetRelation(IFraction targetFraction)
        {
            if (this == Fractions.MonsterFraction && targetFraction != Fractions.MonsterFraction)
            {
                // Фракция монстров нападает на всех, кроме монстров.
                // У монстров нет друзей.
                return(FractionRelation.Enmity);
            }

            if (this != Fractions.MonsterFraction && targetFraction == Fractions.MonsterFraction)
            {
                // С монтсрами никто не дружит.
                // Все фракции считают их врагами.
                return(FractionRelation.Enmity);
            }

            // Все фракции, кроме монстров, друг к другу относятся нейтрально.
            return(FractionRelation.Neutral);
        }
Exemplo n.º 26
0
        public IFraction Subtract(IFraction other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other is IFraction <long> )
            {
                return(Subtract((IFraction <long>)other));
            }

            if (other.GetMaxUnderlyingValue().CompareTo(long.MaxValue) <= 0 && other.GetMinUnderlyingValue().CompareTo(long.MinValue) >= 0)
            {
                return(Subtract(Convert.ToInt64(other.WholeNumber), Convert.ToInt64(other.Numerator), Convert.ToInt64(other.Denominator)));
            }

            return((new Fraction64(this)).Subtract(other));
        }
Exemplo n.º 27
0
        public int CompareTo(IFraction other)
        {
            if (other == null)
            {
                return(1);
            }

            if (other is IFraction <int> )
            {
                return(CompareTo((IFraction <int>)other));
            }

            if (other.GetMaxUnderlyingValue().CompareTo(int.MaxValue) <= 0 && other.GetMinUnderlyingValue().CompareTo(int.MinValue) >= 0)
            {
                return(CompareTo(new Fraction32(Convert.ToInt32(other.WholeNumber), Convert.ToInt32(other.Numerator), Convert.ToInt32(other.Denominator))));
            }

            return((new Fraction64(this)).CompareTo(other));
        }
Exemplo n.º 28
0
        public bool Equals(IFraction other)
        {
            if (other == null)
            {
                return(false);
            }

            if (other is IFraction <long> )
            {
                return(Equals((IFraction <long>)other));
            }

            if (other.GetMaxUnderlyingValue().CompareTo(long.MaxValue) <= 0 && other.GetMinUnderlyingValue().CompareTo(long.MinValue) >= 0)
            {
                return(Equals(new Fraction64(Convert.ToInt64(other.WholeNumber), Convert.ToInt64(other.Numerator), Convert.ToInt64(other.Denominator))));
            }

            return((new Fraction64(this)).Equals(other));
        }
Exemplo n.º 29
0
        IFraction <long> IFraction <long> .Divide(IFraction <long> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other.Numerator == 0 && other.WholeNumber == 0)
            {
                throw new DivideByZeroException();
            }

            if ((other = other.AsInverted()) is Fraction64)
            {
                return(Multiply((Fraction64)other));
            }

            return(Multiply(other.WholeNumber, other.Numerator, other.Denominator));
        }
Exemplo n.º 30
0
        private static IPersonTemplateScheme[] GetPersonTemplateByFraction(IFraction fraction,
                                                                           ISchemeService schemeService)
        {
            if (fraction == Fractions.InterventionistFraction)
            {
                return(GetInterventionalistsPersonTemplates(schemeService));
            }

            if (fraction == Fractions.MilitiaFraction)
            {
                return(GetMilitiaPersonTemplates(schemeService));
            }

            if (fraction == Fractions.TroublemakerFraction)
            {
                return(GetTroublemakerPersonTemplates(schemeService));
            }

            return(GetPlayerPersonTemplates(schemeService));
        }