private CommandJsonNode(CommandJsonNode node, CommandTranslateJsonNode translateNode)
     : base(node.Key)
 {
     if (!node.IsKeyEqual(translateNode.Key))
     {
         throw new InvalidOperationException($"translate node key {translateNode.Key} is not equal to {node.Key}");
     }
     if ((node.Parameters == null || node.Parameters.Length == 0) && translateNode.Parameters != null)
     {
         throw new InvalidOperationException($"translate node {translateNode.Key} should not contains params");
     }
     if (node.Parameters != null && translateNode.Parameters != null && node.Parameters.Length != translateNode.Parameters.Length)
     {
         throw new InvalidOperationException($"translate node {translateNode.Key} should contains same params count");
     }
     Name        = translateNode.Name;
     Category    = node.Category;
     Description = translateNode.Description ?? node.Description;
     if (node.Parameters != null)
     {
         Parameters = ArrayHelper.Clone(node.Parameters);
         if (translateNode.Parameters != null)
         {
             for (int i = 0; i < translateNode.Parameters.Length; i++)
             {
                 Parameters[i] = node.Parameters[i].TranslateWith(translateNode.Parameters[i]);
             }
         }
     }
 }
Пример #2
0
        public void Copy_Returns_New_Two_Dimension_Array()
        {
            var array = new int[2][] { new int[] { 1, 2 }, new int[] { 3, 4, 5 } };

            var result = ArrayHelper.Clone(array);

            CollectionAssert.AreEqual(array, result);
        }
Пример #3
0
        static void Solve()
        {
            var queue = new Queue <Node>();

            var set    = new HashSet <string>();
            var srcStr = MatrixHelper.GetHashString(src);
            var desStr = MatrixHelper.GetHashString(des);

            set.Add(srcStr);

            queue.Enqueue(new Node(src, x, y, new List <string> {
                srcStr
            }));

            while (queue.Count() > 0)
            {
                var p = queue.Dequeue();

                for (int i = 0; i < 4; i++)
                {
                    int tx = dx[i] + p.X;
                    int ty = dy[i] + p.Y;

                    if (IsSafe(tx, ty))
                    {
                        var newMatrix = ArrayHelper.Clone(p.Matrix);
                        var newList   = new List <string>(p.Path);
                        var tmp       = newMatrix[tx, ty];
                        newMatrix[tx, ty]   = 0;
                        newMatrix[p.X, p.Y] = tmp;

                        var hashKey = MatrixHelper.GetHashString(newMatrix);
                        newList.Add(hashKey);
                        if (!set.Contains(hashKey))
                        {
                            queue.Enqueue(new Node(newMatrix, tx, ty, newList));
                        }

                        if (desStr == hashKey)
                        {
                            Print(newList);
                            return;
                        }
                    }
                }
            }
        }
 private CommandsJsonNode(CommandsJsonNode node, CommandsTranslateJsonNode translateNode)
     : base(ArrayHelper.Clone(node.Categories), ArrayHelper.Clone(node.Items))
 {
     foreach (var categoryTranslateNode in translateNode.Categories)
     {
         int index = node.GetCategoryIndex(categoryTranslateNode.Key);
         if (index != -1)
         {
             Categories[index] = node.Categories[index].TranslateWith(categoryTranslateNode);
         }
     }
     foreach (var itemTranslateNode in translateNode.Items)
     {
         int index = node.GetItemIndex(itemTranslateNode.Key);
         if (index != -1)
         {
             Items[index] = node.Items[index].TranslateWith(itemTranslateNode);
         }
     }
 }
Пример #5
0
 private ValuesJsonNode(ValuesJsonNode node, ValueJsonNode[]?translateNodes)
 {
     Type         = node.Type;
     DefaultValue = node.DefaultValue;
     if (node.List != null)
     {
         List = ArrayHelper.Clone(node.List);
         if (translateNodes != null)
         {
             foreach (var translateNode in translateNodes)
             {
                 int index = node.GetValueIndex(translateNode.Value);
                 if (index != -1)
                 {
                     List[index] = node.List[index].TranslateWith(translateNode);
                 }
             }
         }
     }
 }
Пример #6
0
 private void BackLastFormations()
 {
     ClearFormations(_formations);
     _formations = ArrayHelper.Clone <Model_UnitGroup>(_lastFormations);
 }