Exemplo n.º 1
0
        public static Image GetSwapResultPicture(SwapResult result, Image image)
        {
            Bitmap bmp    = image as Bitmap;
            var    g      = Graphics.FromImage(bmp);
            var    width  = bmp.Width / result.Result.Count();
            var    height = bmp.Height;
            Font   f      = new Font("Arial", 10, FontStyle.Regular);
            Brush  p      = new SolidBrush(Color.Black);

            foreach (var resultCell in result.Result)
            {
                var totalCnt = resultCell.Value.Sum(r => r.Value);
                g.DrawString(totalCnt.ToString(), f, p, resultCell.Key * width + 10, 5);
                var items = resultCell.Value.SelectMany(i => Enumerable.Repeat(i.Key, i.Value));
                int currX = 5;
                int currY = height / 2 + 5;
                foreach (var item in items)
                {
                    Rectangle r = new Rectangle(width * resultCell.Key + currX, currY, 5, 5);
                    Brush     b = new SolidBrush(GetCellColor(item));
                    g.FillRectangle(b, r);
                    currX += 8;
                    if (currX + 5 >= width)
                    {
                        currX  = 5;
                        currY += 8;
                    }
                }
            }
            g.Save();
            return((Image)bmp);
        }
Exemplo n.º 2
0
//		for i = 1:n,
//		swapped = false
//			for j = n:i+1,
//			if a[j] < a[j-1],
//			swap a[j,j-1]
//			swapped = true
//				→ invariant: a[1..i] in final position
//				break if not swapped
//					end

        #region ISortingBotAbility implementation
        public SwapResult SwapItems()
        {
            var result = new SwapResult();
            var items  = m_context.Items;

            for (int i = 0; i < items.Length; i++)
            {
                for (int j = items.Length - 1; j > i; j--)
                {
                    if (items [j] < items [j - 1])
                    {
                        result.FirstItemIndex  = j;
                        result.SecondItemIndex = j - 1;

                        return(result);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        public static void DrawSwap(Bitmap pbResult, SwapResult swapResult)
        {
            var   pen   = new Pen(Color.Black, 3);
            Point start = new Point(swapResult.X * 60 + 30, swapResult.Y * 60 + 30);
            Point end   = start;
            var   g     = Graphics.FromImage(pbResult);

            switch (swapResult.Direction)
            {
            case SwapType.Down:
                end = new Point(start.X, start.Y + 60);
                break;

            case SwapType.Right:
                end = new Point(start.X + 60, start.Y);
                break;

            case SwapType.Point:
                g.DrawLine(pen, swapResult.X * 60, swapResult.Y * 60, swapResult.X * 60 + 60, swapResult.Y * 60 + 60);
                g.DrawLine(pen, swapResult.X * 60, swapResult.Y * 60 + 60, swapResult.X * 60 + 60, swapResult.Y * 60);
                break;
            }
            g.DrawLine(pen, start, end);
        }