예제 #1
0
        protected BaseCharacterModel()
        {
            // ICharacter
            _armors     = new List <IArmor>();
            _weapons    = new List <IWeapon>();
            _perception = 0;
            _class      = null;
            _race       = null;
            _crrentExp  = 0;
            _deathTrows = new bool[, ] {
                { false, false, false }, { false, false, false }
            };
            _hitPointDice       = null;
            _hitPoints          = 0;
            _inspiration        = 0;
            _level              = 1;
            _name               = "New Player";
            _proficiencyBonus   = 0;
            _speed              = 0;
            _temporaryHitPoints = 0;

            // IStats
            _charisma     = 0;
            _constitution = 0;
            _dexterity    = 0;
            _intelligence = 0;
            _strenght     = 0;
            _wisdom       = 0;

            // ISkills
            _selectedSkills = new List <Skill>();
        }
예제 #2
0
    private void NormalAttack(ICube cube)
    {
        _config.CallAttackCubeEvent(cube, 1);

        GizmoCenter = cube.GetPosition();
        GizmoSize   = Vector3.one;
    }
예제 #3
0
        public static ICube Sort(this ICube cube, List <string> fieldsToSortOn)
        {
            foreach (var fieldToSortOn in fieldsToSortOn)
            {
                if (!cube.DataTypes.ContainsKey(fieldToSortOn))
                {
                    throw new Exception($"Cannot sort on field {fieldToSortOn} as it is not present");
                }
            }

            var outCube = new ResultCube();

            outCube.Initialize(cube.DataTypes);

            var fieldNames = cube.DataTypes.Keys.ToList();
            var indexes    = fieldsToSortOn.Select(x => fieldNames.IndexOf(x)).Reverse();

            var rows = new List <ResultCubeRow>(cube.GetAllRows());

            foreach (var ix in indexes)
            {
                rows = rows.OrderBy(x => x.MetaData[ix]).ToList();
            }

            foreach (var row in rows)
            {
                outCube.AddRow(row.MetaData, row.Value);
            }

            return(outCube);
        }
예제 #4
0
        /// <summary>
        /// Rend un axe au format CSV.
        /// </summary>
        /// <param name="hyperCube">HyperCube.</param>
        /// <param name="context">Contexte.</param>
        /// <param name="writer">Writer CSV.</param>
        /// <param name="activeCounters">Compteur actifs.</param>
        /// <param name="axis">Axe.</param>
        private static void CreateCsvAxis(IHyperCube hyperCube, Context context, TextWriter writer, Dictionary <string, string> activeCounters, string axis)
        {
            CounterCubeCriteria criteria = new CounterCubeCriteria(axis, TimeLevel.Hour);
            CubeKey             key      = criteria.CreateCubeKey(context.EndDate);
            ICube cube = hyperCube.GetCube(key);

            if (cube != null && IsShown(context.EndDate, context.Filtre, hyperCube, criteria))
            {
                writer.Write(axis);
                writer.Write(";");

                double total = cube.GetCounter(Analytics.ElapsedTime).GetValue(CounterStatType.Total);
                writer.Write(Convert.ToString(total, CultureInfo.CurrentCulture));
                writer.Write(";");

                double hits = cube.GetCounter(Analytics.ElapsedTime).GetValue(CounterStatType.Hits);
                writer.Write(Convert.ToString(hits, CultureInfo.CurrentCulture));
                writer.Write(";");

                double avg;
                foreach (ICounterDefinition definition in hyperCube.AllDefinitions)
                {
                    if (activeCounters.ContainsKey(definition.Code))
                    {
                        ICounter counter = cube.GetCounter(definition.Code);
                        avg = (counter != null) ? counter.GetValue(CounterStatType.Avg) : 0;
                        writer.Write(string.Format(CultureInfo.CurrentCulture, "{0:0.##}", avg));
                        writer.Write(";");
                    }
                }

                writer.WriteLine();
            }
        }
예제 #5
0
    private void Hold(ICube selectedCube)
    {
        switch (_weapon)
        {
        case EWeaponType.Cutter:

            Ray ray = _camera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out var hit, _rayDistance, _touchMask))
            {
                _lastPoint = hit.point;
                GizmoSize  = _lastPoint;
            }

            break;

        case EWeaponType.Area:
            _curAreaTime += Time.deltaTime;

            float timer = _curAreaTime / _areaTime;

            timer = 1 - timer;

            _config.CallAreaTimeEvent(timer);

            if (_curAreaTime >= _areaTime)
            {
                AreaAttack(selectedCube.GetPosition());
                AreaDismiss();
            }

            break;
        }
    }
예제 #6
0
        public static ICube MergeQuick(this ICube baseCube, ICube otherCube)
        {
            if (!Enumerable.SequenceEqual(baseCube.DataTypes.Keys, otherCube.DataTypes.Keys) ||
                !Enumerable.SequenceEqual(baseCube.DataTypes.Values, otherCube.DataTypes.Values))
            {
                throw new Exception("Cubes must be of same type to be merged");
            }

            var o = new ResultCube();

            o.Initialize(baseCube.DataTypes);
            var baseRows  = baseCube.GetAllRows().ToArray();
            var otherRows = otherCube.GetAllRows().ToArray();

            for (var i = 0; i < baseRows.Length; i++)
            {
                var br = baseRows[i];
                o.AddRow(br.MetaData, br.Value);
            }

            for (var i = 0; i < otherRows.Length; i++)
            {
                var br = otherRows[i];
                o.AddRow(br.MetaData, br.Value);
            }

            return(o);
        }
예제 #7
0
        public static ICube BucketTimeAxis(this ICube cube, string timeFieldName, string bucketedFieldName, Dictionary <DateTime, string> bucketBoundaries)
        {
            if (!cube.DataTypes.ContainsKey(timeFieldName))
            {
                throw new Exception($"Cannot filter on field {timeFieldName} as it is not present");
            }

            var outCube  = new ResultCube();
            var newTypes = new Dictionary <string, Type>(cube.DataTypes);

            newTypes.Add(bucketedFieldName, typeof(string));
            outCube.Initialize(newTypes);

            var buckets       = bucketBoundaries.Keys.OrderBy(x => x).ToList();
            var bucketFieldIx = cube.GetColumnIndex(timeFieldName);

            foreach (var row in cube.GetAllRows())
            {
                var date   = (DateTime)row.MetaData[bucketFieldIx];
                var bucket = buckets.BinarySearch(date);
                if (bucket < 0)
                {
                    bucket = ~bucket;
                }
                var bucketLabel = bucketBoundaries[buckets[bucket]];

                var metaList = new List <object>(row.MetaData)
                {
                    bucketLabel
                };
                outCube.AddRow(metaList.ToArray(), row.Value);
            }

            return(outCube);
        }
예제 #8
0
        public static ICube Filter(this ICube cube, List <KeyValuePair <string, object> > fieldsToFilterOn, bool filterOut = false)
        {
            foreach (var fieldToFilterOn in fieldsToFilterOn.Select(x => x.Key))
            {
                if (!cube.DataTypes.ContainsKey(fieldToFilterOn))
                {
                    throw new Exception($"Cannot filter on field {fieldToFilterOn} as it is not present");
                }
            }

            var outCube = new ResultCube();

            outCube.Initialize(cube.DataTypes);

            var fieldNames = cube.DataTypes.Keys.ToList();
            var indexes    = fieldsToFilterOn
                             .Select(x => x.Key)
                             .Distinct()
                             .ToDictionary(x => x, x => fieldNames.IndexOf(x));
            var values = new Dictionary <string, List <object> >();

            foreach (var kv in fieldsToFilterOn)
            {
                if (!values.ContainsKey(kv.Key))
                {
                    values[kv.Key] = new List <object> {
                        kv.Value
                    }
                }
                ;
                else
                {
                    values[kv.Key].Add(kv.Value);
                }
            }

            foreach (var row in cube.GetAllRows())
            {
                var rowIsRelevant = true;
                foreach (var kv in values)
                {
                    if (!kv.Value.Any(v => IsEqual(row.MetaData[indexes[kv.Key]], v)))
                    {
                        rowIsRelevant = false;
                        break;
                    }
                }
                if (filterOut)
                {
                    rowIsRelevant = !rowIsRelevant;
                }

                if (rowIsRelevant)
                {
                    outCube.AddRow(row.MetaData, row.Value);
                }
            }

            return(outCube);
        }
예제 #9
0
        public static (double FBA, double FCA) FVA(DateTime originDate, ICube EPE, ICube ENE, HazzardCurve hazzardCurve, IIrCurve discountCurve, IIrCurve fundingCurve)
        {
            if (!EPE.DataTypes.TryGetValue("ExposureDate", out var type) || type != typeof(DateTime))
            {
                throw new Exception("EPE cube input not valid");
            }

            if (!ENE.DataTypes.TryGetValue("ExposureDate", out var type2) || type2 != typeof(DateTime))
            {
                throw new Exception("ENE cube input not valid");
            }

            var rowsEPE = EPE.GetAllRows();
            var rowsENE = ENE.GetAllRows();

            if (rowsEPE.Length != rowsENE.Length)
            {
                throw new Exception("EPE and ENE curves not of same size");
            }

            var dateIx    = EPE.GetColumnIndex("ExposureDate");
            var epeDates  = new DateTime[rowsEPE.Length];
            var epeValues = new double[rowsEPE.Length];
            var eneValues = new double[rowsENE.Length];

            for (var i = 0; i < rowsENE.Length; i++)
            {
                epeDates[i]  = (DateTime)rowsEPE[i].MetaData[dateIx];
                epeValues[i] = rowsEPE[i].Value;
                eneValues[i] = rowsENE[i].Value;
            }
            return(FVA(originDate, epeDates, epeValues, eneValues, hazzardCurve, discountCurve, fundingCurve));
        }
예제 #10
0
        public bool AgregarConsultaPrueba(string query)
        {
            bool isUpdate = Regex.Match(query, @"^UPDATE\s[0-9]*\s[0-9]*\s[0-9]*\s[0-9]*$").Success;
            bool isQuery  = Regex.Match(query, @"^QUERY\s[0-9]*\s[0-9]*\s[0-9]*\s[0-9]*\s[0-9]*\s-?[0-9]*$").Success;
            bool resp     = isUpdate || isQuery;

            if (!resp)
            {
                string message = CO_MensajesSistema.FormatoQuery;
                MensajeAlgoritmo += "- " + (String.IsNullOrEmpty(MensajeAlgoritmo) ? message : System.Environment.NewLine + message);
            }
            else
            {
                ICube q = null;
                if (isQuery)
                {
                    q = new CA_Operacion(query, dimension);
                }
                else
                {
                    q = new CA_Update(query, dimension);
                }

                consultas.Add(q);
            }
            return(resp);
        }
예제 #11
0
 public MainScreen()
 {
     AssertXmlFilesExist();
     AssertAlgFilesExist();
     SubsetFile       = new SubsetFile(subsetFilePath);
     XmlSubsetFile    = new XmlSubsetFile("subsets.xml");
     CustomSubsetFile = new CustomSubsetFile("customSubsets.xml");
     RecentSubsetFile = new RecentSubsetFile("recentSubsets.xml");
     InitializeComponent();
     Info.MainForm = this;
     StartPosition = FormStartPosition.CenterScreen;
     Update();
     //cube = new ZbllCube(PreviewCubeSize);
     foreach (var set1 in Enum.GetValues(typeof(AlgSet)).Cast <AlgSet>())
     {
         if (set1 != AlgSet.All)
         {
             AlgSetSelector.Items.Add(set1);
         }
     }
     AlgSetSelector.SelectedItem = AlgSet.ZBLL;
     Set    = AlgSet.ZBLL;
     Cube   = Info.GetCube(Set);
     PosNum = -1;
 }
예제 #12
0
        /// <summary>
        /// Compare la valeur de 2 axes d'un cube.
        /// Les valeurs utilisés dépendent des paramètres du constructeur.
        /// </summary>
        /// <param name="x">Premier axe de comparaison.</param>
        /// <param name="y">Second axe de comparaison.</param>
        /// <returns>Résultat de la comparaison des valeurs.</returns>
        int IComparer <string> .Compare(string x, string y)
        {
            ICube cube1 = _hyperCube.GetCube(new CubeKey(_date, x, _level));
            ICube cube2 = _hyperCube.GetCube(new CubeKey(_date, y, _level));

            double v1 = double.NaN;
            double v2 = double.NaN;

            if (cube1 != null)
            {
                ICounter counter1 = cube1.GetCounter(_counterDefinitionCode);
                if (counter1 != null)
                {
                    v1 = counter1.GetValue(_statType);
                }
            }

            if (cube2 != null)
            {
                ICounter counter2 = cube2.GetCounter(_counterDefinitionCode);
                if (counter2 != null)
                {
                    v2 = counter2.GetValue(_statType);
                }
            }

            // Tri descendant
            return(-v1.CompareTo(v2));
        }
예제 #13
0
        /// <summary>
        /// Differences two cubes, assuming same number and same order of rows in both
        /// </summary>
        /// <param name="baseCube"></param>
        /// <param name="cubeToSubtract"></param>
        /// <returns></returns>
        public static ICube QuickDifference(this ICube baseCube, ICube cubeToSubtract)
        {
            if (!Enumerable.SequenceEqual(baseCube.DataTypes.Keys, cubeToSubtract.DataTypes.Keys) ||
                !Enumerable.SequenceEqual(baseCube.DataTypes.Values, cubeToSubtract.DataTypes.Values))
            {
                throw new Exception("Cubes must be of same type to be differenced");
            }

            var o = new ResultCube();

            o.Initialize(baseCube.DataTypes);
            var baseRows = baseCube.GetAllRows().ToArray();
            var subRows  = cubeToSubtract.GetAllRows().ToArray();

            if (baseRows.Length != subRows.Length)
            {
                throw new Exception("Cubes must have same number of rows to quick-diff them");
            }

            for (var i = 0; i < baseRows.Length; i++)
            {
                var br = baseRows[i];
                var sr = subRows[i];
                o.AddRow(br.MetaData, br.Value - sr.Value);
            }

            return(o);
        }
예제 #14
0
        public static object[,] ToMatrix(this ICube cube, string verticalField, string horizontalField, bool sort)
        {
            if (!cube.DataTypes.ContainsKey(verticalField))
            {
                throw new Exception($"Cubes does contain field {verticalField}");
            }

            if (!cube.DataTypes.ContainsKey(horizontalField))
            {
                throw new Exception($"Cubes does contain field {horizontalField}");
            }

            var aggregated = cube.Pivot(new string[] { verticalField, horizontalField }, AggregationAction.Sum);

            var distinctV = cube.KeysForField(verticalField);
            var distinctH = cube.KeysForField(horizontalField);

            if (sort)
            {
                //catch date labels
                if (distinctH.All(x => DateTime.TryParseExact(x as string, new string[] { "MMMyy", "MMM-yy" }, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dt)))
                {
                    distinctH = distinctH.OrderBy(x => DateTime.ParseExact(x as string, new string[] { "MMMyy", "MMM-yy" }, CultureInfo.InvariantCulture, DateTimeStyles.None)).ToArray();
                }
                else
                {
                    distinctH = distinctH.OrderBy(x => x).ToArray();
                }

                if (distinctV.All(x => DateTime.TryParseExact(x as string, new string[] { "MMMyy", "MMM-yy" }, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dt)))
                {
                    distinctV = distinctV.OrderBy(x => DateTime.ParseExact(x as string, new string[] { "MMMyy", "MMM-yy" }, CultureInfo.InvariantCulture, DateTimeStyles.None)).ToArray();
                }
예제 #15
0
        public bool Collide(ICube first, ICube second)
        {
            CheckArguments(first, second);

            return(first.XAxis.IntersectsWith(second.XAxis) &&
                   first.YAxis.IntersectsWith(second.YAxis) &&
                   first.ZAxis.IntersectsWith(second.ZAxis));
        }
예제 #16
0
 public ICube Merge(ICube neighbor)
 {
     if (IsNeighbor(neighbor))
     {
         return(StatewiseMerge(neighbor));
     }
     throw new ArgumentOutOfRangeException("neighbor", "cubes aren't neighbors");
 }
예제 #17
0
 /// <summary>
 /// Creates a new AlgRunner with the given cube, alg number generator and alg client
 /// </summary>
 /// <param name="cube">The cube with the algorithm set to run</param>
 /// <param name="gen">A generator with the positions to generate</param>
 /// <param name="algClient">An algClient uwed to retrieve algorithms for positions</param>
 public AlgRunner(ICube cube, IAlgNumberGenerator gen, IAlgClient algClient)
 {
     Start     = DateTime.Now;
     Cube      = cube;
     Gen       = gen;
     PosNum    = Gen.Generate();
     AlgClient = algClient;
 }
예제 #18
0
 public void Shuffle(ICube cube, int rotations)
 {
     for (int i = 0; i < rotations; i++ )
     {
         var row = m_table.Rows[i];
         cube.Rotate(CubeSpecModelContext.StringToLayer(row[0]), CubeSpecModelContext.StringToDirection(row[1]));
     }
 }
예제 #19
0
        public double GetIntersectionVolume(ICube first, ICube second)
        {
            CheckArguments(first, second);

            return(first.XAxis.Overlap(second.XAxis)
                   * first.YAxis.Overlap(second.YAxis)
                   * first.ZAxis.Overlap(second.ZAxis));
        }
예제 #20
0
    private void OnDestroyCube(ICube cube)
    {
        cube.DestroyBody();

        _cubesPool.Enqueue(cube);

        _curTotalCubes--;
    }
예제 #21
0
파일: RiskMatrix.cs 프로젝트: zhangz/qwack
        public ICube Generate(IPvModel model, Portfolio portfolio = null)
        {
            var o = new ResultCube();

            o.Initialize(new Dictionary <string, Type>
            {
                { "AxisA", typeof(string) },
                { "AxisB", typeof(string) }
            });

            var scenarios = GenerateScenarios(model);

            ICube baseRiskCube = null;

            if (ReturnDifferential)
            {
                var baseModel = model;
                if (portfolio != null)
                {
                    baseModel = baseModel.Rebuild(baseModel.VanillaModel, portfolio);
                }
                baseRiskCube = GetRisk(baseModel);
            }

            var threadLock = new object();
            var results    = new ICube[scenarios.Count];
            var scList     = scenarios.ToList();

            ParallelUtils.Instance.For(0, scList.Count, 1, i =>
            {
                var scenario = scList[i];
                var pvModel  = scenario.Value;
                if (portfolio != null)
                {
                    pvModel = pvModel.Rebuild(pvModel.VanillaModel, portfolio);
                }
                var result = GetRisk(pvModel);

                if (ReturnDifferential)
                {
                    result = result.Difference(baseRiskCube);
                }

                results[i] = result;
            }).Wait();

            for (var i = 0; i < results.Length; i++)
            {
                o = (ResultCube)o.Merge(results[i],
                                        new Dictionary <string, object>
                {
                    { "AxisA", scList[i].Key.Item1 },
                    { "AxisB", scList[i].Key.Item2 }
                }, null, true);
            }

            return(o);
        }
예제 #22
0
    private void OnAttackCube(ICube cube, int damage)
    {
        if (!cube.Damaged(damage))
        {
            return;
        }

        _config.CallDestroyCubeEvent(cube);
    }
예제 #23
0
        /// <summary>
        /// Checks if the given cube shares some
        /// area with this cube.
        /// </summary>
        /// <param name="ICube">A cube of type T.</param>
        /// <returns>True if the cube shares some area with this cube; False otherwise.</returns>
        public Boolean Overlaps(ICube <T> ICube)
        {
            #region Initial Checks

            if (ICube == null)
            {
                throw new ArgumentNullException("The given cube must not be null!");
            }

            #endregion


            // Check if any corner of the given cube
            // is located within this cube

            if (Contains(ICube.Left, ICube.Top, ICube.Front))
            {
                return(true);
            }

            if (Contains(ICube.Right, ICube.Top, ICube.Front))
            {
                return(true);
            }

            if (Contains(ICube.Left, ICube.Bottom, ICube.Front))
            {
                return(true);
            }

            if (Contains(ICube.Right, ICube.Bottom, ICube.Front))
            {
                return(true);
            }

            if (Contains(ICube.Left, ICube.Top, ICube.Behind))
            {
                return(true);
            }

            if (Contains(ICube.Right, ICube.Top, ICube.Behind))
            {
                return(true);
            }

            if (Contains(ICube.Left, ICube.Bottom, ICube.Behind))
            {
                return(true);
            }

            if (Contains(ICube.Right, ICube.Bottom, ICube.Behind))
            {
                return(true);
            }

            return(false);
        }
예제 #24
0
        private static void RotateAroundDepth <T>(ICube <T> cube)
        {
            var temp = cube[CubeSide.Up];

            cube[CubeSide.Up]    = cube[CubeSide.Right];
            cube[CubeSide.Right] = cube[CubeSide.Down];
            cube[CubeSide.Down]  = cube[CubeSide.Left];
            cube[CubeSide.Left]  = temp;
        }
예제 #25
0
        private static void RotateAroundTop <T>(ICube <T> cube)
        {
            var temp = cube[CubeSide.Front];

            cube[CubeSide.Front] = cube[CubeSide.Left];
            cube[CubeSide.Left]  = cube[CubeSide.Back];
            cube[CubeSide.Back]  = cube[CubeSide.Right];
            cube[CubeSide.Right] = temp;
        }
예제 #26
0
        private static void RotateAroundLeft <T>(ICube <T> cube)
        {
            var temp = cube[CubeSide.Up];

            cube[CubeSide.Up]    = cube[CubeSide.Front];
            cube[CubeSide.Front] = cube[CubeSide.Down];
            cube[CubeSide.Down]  = cube[CubeSide.Back];
            cube[CubeSide.Back]  = temp;
        }
예제 #27
0
        public static int TrowCube(ICube cube, byte times)
        {
            var result = 0;

            for (int i = 0; i < times; ++i)
            {
                result += cube.Trow();
            }
            return(result);
        }
예제 #28
0
 public void Reset()
 {
     Cube = Info.GetCube(Set);
     PositionBox.Clear();
     PosNum                        = -1;
     AlgLabel.Visible              = false;
     AlgorithmBox.Visible          = false;
     ChangeAlgorithmButton.Visible = false;
     Update();
 }
예제 #29
0
    private void InstantiatePool(int totalCubes)
    {
        while (_cubesPool.Count <= totalCubes)
        {
            ICube cube = Instantiate(_cubePrefab, Vector3.zero, Quaternion.identity).GetComponent <ICube>();

            cube.HasActive = false;

            _cubesPool.Enqueue(cube);
        }
    }
예제 #30
0
 private void AlgSetSelector_SelectedValueChanged(object sender, EventArgs e)
 {
     Set  = (AlgSet)AlgSetSelector.SelectedItem;
     Cube = Info.GetCube(Set);
     UpdateGroupSelector();
     UpdateCustomSubsetSelector();
     UpdateRecentSubsetSelector();
     RangeBox.Text = "";
     Reset();
     Refresh();
 }
예제 #31
0
 public ICube Intersection(ICube intrsctCube)
 {
     try
     {
         return(StatewiseIntersection(intrsctCube));
     }
     catch (InvalidOperationException)
     {
         return(new EmptyCube());
     }
 }