public void CheckDown(int i)
        {
            Debug.Assert(Comp != null);
            do
            {
                int s = i + i + 1;
                if (s >= arr.Count)
                {
                    return;
                }

                if (s + 1 < arr.Count &&
                    Comp.Compare(arr[s], arr[s + 1]) > 0)
                {
                    s++;
                }

                if (Comp.Compare(arr[i], arr[s]) <= 0)
                {
                    return;
                }

                Swap(i, s);
                i = s;
            }while (true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Получить максимальный из аргументов типа T
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 private T GetMaximal(T x, T y)
 {
     if (Comp.Compare(x, y) == -1)
     {
         return(y);
     }
     return(x);
 }
Ejemplo n.º 3
0
        private void Schedule(List <PlayerTask> cards, POGame.POGame poGame)
        {
            var simulation = DepthCardSearch(cards, poGame);
            var best       = simulation.Where(it => it.Item2 != null).MaxElement(Comp, (it => it.Item2));

            if (best.Item1 != null && best.Item1.Count > 0 && Comp.Compare(best.Item2, poGame) >= 0)
            {
                Plan = new Queue <PlayerTask>(best.Item1);
            }
        }
        protected void CheckUp(int i)
        {
            Debug.Assert(Comp != null);

            while (i > 0)
            {
                int p = (i - 1) / 2;
                if (Comp.Compare(arr[p], arr[i]) <= 0)
                {
                    return;
                }

                Swap(p, i);
                i = p;
            }
        }
Ejemplo n.º 5
0
        public ISeq Seq(object key, bool ascending)
        {
            if (this._count > 0)
            {
                ISeq stack = null;
                var  t     = Tree;
                while (t != null)
                {
                    int c = Comp.Compare(key, t.Key);
                    if (c == 0)
                    {
                        stack = (ISeq) new funclib.Components.Core.Cons().Invoke(t, stack);
                        return(new SortedMapSeq(stack, ascending));
                    }
                    else if (ascending)
                    {
                        if (c < 0)
                        {
                            stack = (ISeq) new funclib.Components.Core.Cons().Invoke(t, stack);
                            t     = t.Left;
                        }
                        else
                        {
                            t = t.Right;
                        }
                    }
                    else
                    {
                        if (c > 0)
                        {
                            stack = (ISeq) new funclib.Components.Core.Cons().Invoke(t, stack);
                            t     = t.Right;
                        }
                        else
                        {
                            t = t.Left;
                        }
                    }
                }
                if (stack != null)
                {
                    return(new SortedMapSeq(stack, ascending));
                }
            }

            return(null);
        }
Ejemplo n.º 6
0
        private List <Tuple <List <PlayerTask>, POGame.POGame> > DepthCardSearch(List <PlayerTask> cards, POGame.POGame poGame)
        {
            var result = new List <Tuple <List <PlayerTask>, POGame.POGame> >();

            result.Add(Tuple.Create(new List <PlayerTask>(), poGame));
            if (TurnStopwatch.Elapsed.TotalSeconds > 70)
            {
                var simulation = poGame.Simulate(cards)
                                 .Where(it => it.Value != null &&
                                        Comp.Compare(it.Value, poGame) > 0);
                foreach (var(card, nextState) in simulation)
                {
                    var nextDive = DepthCardSearch(nextState.Cards(), nextState);
                    for (int i = 0; i < nextDive.Count; i++)
                    {
                        nextDive[i].Item1.Insert(0, card);
                    }
                    var best = nextDive.Where(it => it.Item2 != null).MaxElement(Comp, (it => it.Item2));
                    result.Add(best);
                }
            }
            return(result);
        }
Ejemplo n.º 7
0
    string calc(Data D)
    {
        if (H.Contains(D))
        {
            return((string)H[D]);
        }
        string result = "";
        int    m      = D.image.Length;
        int    n      = D.image[0].Length;

        if (m == 1 && D.image[0] == new string( D.image[0][0], n ))
        {
            result = D.image[0][0].ToString();
        }
        else if (n == 1)
        {
            bool flag = true;
            for (int i = 1; flag && i < m; i++)
            {
                flag = D.image[i] == D.image[i - 1];
            }
            if (flag)
            {
                result = D.image[0];
            }
        }
        if (result == "")
        {
            string s = "";
            if (m > 1)
            {
                string[] x1 = new string[(m + 1) / 2];
                string[] x2 = new string[m / 2];
                for (int i = 0; i < m / 2; i++)
                {
                    x1[i] = D.image[i];
                    x2[i] = D.image[(m + 1) / 2 + i];
                }
                if (m % 2 > 0)
                {
                    x1[(m - 1) / 2] = D.image[m / 2];
                }
                s = get(calc(new Data(x1)), calc(new Data(x2)), "U");
                if (comp.Compare(result, s) > 0)
                {
                    result = s;
                }
                for (int i = 0; i < m / 2; i++)
                {
                    x1[i] = D.image[2 * i];
                    x2[i] = D.image[2 * i + 1];
                }
                if (m % 2 > 0)
                {
                    x1[(m - 1) / 2] = D.image[m - 1];
                }
                s = get(calc(new Data(x1)), calc(new Data(x2)), "R");
                if (comp.Compare(result, s) > 0)
                {
                    result = s;
                }
            }
            if (n > 1)
            {
                string[] x1 = new string[m];
                string[] x2 = new string[m];
                for (int i = 0; i < m; i++)
                {
                    for (int j = 0; j < n / 2; j++)
                    {
                        x1[i] += D.image[i][j];
                        x2[i] += D.image[i][(n + 1) / 2 + j];
                    }
                    if (n % 2 > 0)
                    {
                        x1[i] += D.image[i][(n - 1) / 2];
                    }
                }
                s = get(calc(new Data(x1)), calc(new Data(x2)), "L");
                if (comp.Compare(result, s) > 0)
                {
                    result = s;
                }
                for (int i = 0; i < m; i++)
                {
                    x1[i] = "";
                    x2[i] = "";
                    for (int j = 0; j < n / 2; j++)
                    {
                        x1[i] += D.image[i][2 * j];
                        x2[i] += D.image[i][2 * j + 1];
                    }
                    if (n % 2 > 0)
                    {
                        x1[i] += D.image[i][n - 1];
                    }
                }
                s = get(calc(new Data(x1)), calc(new Data(x2)), "C");
                if (comp.Compare(result, s) > 0)
                {
                    result = s;
                }
            }
        }
        H[D] = result;
        return(result);
    }