Ejemplo n.º 1
0
Archivo: Grid.cs Proyecto: xposure/BOTA
 public void Reset()
 {
     g = 0;
     h = 0;
     parent = null;
     State = CellState.Empty;
     Path = PathState.None;
 }
Ejemplo n.º 2
0
        /*
         *  写入excel
         */
        private void ToExcel(string way, int deep,
                             double up, double down, double max, double accum_up, double accum_down,
                             double location_up, double location_down, double location,
                             double location_accum_up, double location_accum_down)
        {
            Cell cellItem1 = workSheet_excel.Cells["B3"];
            Cell cellItem2 = workSheet_excel.Cells["B5"];

            cellItem1.PutValue(work_face + "胶运顺槽");
            cellItem2.PutValue(work_face + "辅运顺槽");


            if (way.Equals("皮带顺槽") && deep == 7)
            {
                Cell cellItem_max                 = workSheet_excel.Cells["D3"];
                Cell cellItem_up                  = workSheet_excel.Cells["F3"];
                Cell cellItem_down                = workSheet_excel.Cells["H3"];
                Cell cellItem_location            = workSheet_excel.Cells["E3"];
                Cell cellItem_location_up         = workSheet_excel.Cells["G3"];
                Cell cellItem_location_down       = workSheet_excel.Cells["I3"];
                Cell cellItem_accum_up            = workSheet_excel.Cells["J3"];
                Cell cellItem_accum_down          = workSheet_excel.Cells["L3"];
                Cell cellItem_location_accum_up   = workSheet_excel.Cells["K3"];
                Cell cellItem_location_accum_down = workSheet_excel.Cells["M3"];

                cellItem_max.PutValue(max);
                cellItem_location.PutValue(location);

                if (up != 0)
                {
                    cellItem_up.PutValue(up);
                }
                if (down != 0)
                {
                    cellItem_down.PutValue(down);
                }
                if (location_down != 0)
                {
                    cellItem_location_down.PutValue(location_down);
                }
                if (location_up != 0)
                {
                    cellItem_location_up.PutValue(location_up);
                }

                if (accum_up != 0)
                {
                    cellItem_accum_up.PutValue(accum_up);
                }
                if (accum_down != 0)
                {
                    cellItem_accum_down.PutValue(accum_down);
                }
                if (location_accum_up != 0)
                {
                    cellItem_location_accum_up.PutValue(location_accum_up);
                }
                if (location_accum_down != 0)
                {
                    cellItem_location_accum_down.PutValue(location_accum_down);
                }
            }
            else if (way.Equals("皮带顺槽") && deep == 12)
            {
                Cell cellItem_max           = workSheet_excel.Cells["D4"];
                Cell cellItem_up            = workSheet_excel.Cells["F4"];
                Cell cellItem_down          = workSheet_excel.Cells["H4"];
                Cell cellItem_location      = workSheet_excel.Cells["E4"];
                Cell cellItem_location_up   = workSheet_excel.Cells["G4"];
                Cell cellItem_location_down = workSheet_excel.Cells["I4"];

                Cell cellItem_accum_up            = workSheet_excel.Cells["J4"];
                Cell cellItem_accum_down          = workSheet_excel.Cells["L4"];
                Cell cellItem_location_accum_up   = workSheet_excel.Cells["K4"];
                Cell cellItem_location_accum_down = workSheet_excel.Cells["M4"];

                cellItem_max.PutValue(max);
                cellItem_location.PutValue(location);

                if (up != 0)
                {
                    cellItem_up.PutValue(up);
                }
                if (down != 0)
                {
                    cellItem_down.PutValue(down);
                }
                if (location_down != 0)
                {
                    cellItem_location_down.PutValue(location_down);
                }
                if (location_up != 0)
                {
                    cellItem_location_up.PutValue(location_up);
                }
                if (accum_up != 0)
                {
                    cellItem_accum_up.PutValue(accum_up);
                }
                if (accum_down != 0)
                {
                    cellItem_accum_down.PutValue(accum_down);
                }
                if (location_accum_up != 0)
                {
                    cellItem_location_accum_up.PutValue(location_accum_up);
                }
                if (location_accum_down != 0)
                {
                    cellItem_location_accum_down.PutValue(location_accum_down);
                }
            }
            else if (way.Equals("轨道巷") && deep == 7)
            {
                Cell cellItem_max           = workSheet_excel.Cells["D5"];
                Cell cellItem_up            = workSheet_excel.Cells["F5"];
                Cell cellItem_down          = workSheet_excel.Cells["H5"];
                Cell cellItem_location      = workSheet_excel.Cells["E5"];
                Cell cellItem_location_up   = workSheet_excel.Cells["G5"];
                Cell cellItem_location_down = workSheet_excel.Cells["I5"];

                Cell cellItem_accum_up            = workSheet_excel.Cells["J5"];
                Cell cellItem_accum_down          = workSheet_excel.Cells["L5"];
                Cell cellItem_location_accum_up   = workSheet_excel.Cells["K5"];
                Cell cellItem_location_accum_down = workSheet_excel.Cells["M5"];

                cellItem_max.PutValue(max);
                cellItem_location.PutValue(location);

                if (up != 0)
                {
                    cellItem_up.PutValue(up);
                }
                if (down != 0)
                {
                    cellItem_down.PutValue(down);
                }
                if (location_down != 0)
                {
                    cellItem_location_down.PutValue(location_down);
                }
                if (location_up != 0)
                {
                    cellItem_location_up.PutValue(location_up);
                }

                if (accum_up != 0)
                {
                    cellItem_accum_up.PutValue(accum_up);
                }
                if (accum_down != 0)
                {
                    cellItem_accum_down.PutValue(accum_down);
                }
                if (location_accum_up != 0)
                {
                    cellItem_location_accum_up.PutValue(location_accum_up);
                }
                if (location_accum_down != 0)
                {
                    cellItem_location_accum_down.PutValue(location_accum_down);
                }
            }
            else if (way.Equals("轨道巷") && deep == 12)
            {
                Cell cellItem_max           = workSheet_excel.Cells["D6"];
                Cell cellItem_up            = workSheet_excel.Cells["F6"];
                Cell cellItem_down          = workSheet_excel.Cells["H6"];
                Cell cellItem_location      = workSheet_excel.Cells["E6"];
                Cell cellItem_location_up   = workSheet_excel.Cells["G6"];
                Cell cellItem_location_down = workSheet_excel.Cells["I6"];

                Cell cellItem_accum_up            = workSheet_excel.Cells["J6"];
                Cell cellItem_accum_down          = workSheet_excel.Cells["L6"];
                Cell cellItem_location_accum_up   = workSheet_excel.Cells["K6"];
                Cell cellItem_location_accum_down = workSheet_excel.Cells["M6"];

                cellItem_max.PutValue(max);
                cellItem_location.PutValue(location);

                if (up != 0)
                {
                    cellItem_up.PutValue(up);
                }
                if (down != 0)
                {
                    cellItem_down.PutValue(down);
                }
                if (location_down != 0)
                {
                    cellItem_location_down.PutValue(location_down);
                }
                if (location_up != 0)
                {
                    cellItem_location_up.PutValue(location_up);
                }

                if (accum_up != 0)
                {
                    cellItem_accum_up.PutValue(accum_up);
                }
                if (accum_down != 0)
                {
                    cellItem_accum_down.PutValue(accum_down);
                }
                if (location_accum_up != 0)
                {
                    cellItem_location_accum_up.PutValue(location_accum_up);
                }
                if (location_accum_down != 0)
                {
                    cellItem_location_accum_down.PutValue(location_accum_down);
                }
            }
        }
Ejemplo n.º 3
0
Archivo: Grid.cs Proyecto: xposure/BOTA
 public int CalculateG(Cell cell)
 {
     var a = x - cell.x;
     var b = y - cell.y;
     return ((a * a) + (b * b)) <= 1 ? 10 : 14;
 }
Ejemplo n.º 4
0
Archivo: Grid.cs Proyecto: xposure/BOTA
 public int CalculateH(Cell cell)
 {
     return (int)(Math.Abs(x - cell.x) + Math.Abs(y - cell.y)) * 10;
 }
Ejemplo n.º 5
0
Archivo: Grid.cs Proyecto: xposure/BOTA
        private void DrawCell(Cell cell)
        {
            var clientArea = new Rectangle(cell.x * size, cell.y * size, size, size);

            if (cell.State == CellState.Block)
                gridGraphics.FillRectangle(Brushes.Blue, clientArea);
            else if (cell.State == CellState.End)
                gridGraphics.FillRectangle(Brushes.Red, clientArea);
            else if (cell.State == CellState.Start)
                gridGraphics.FillRectangle(Brushes.Green, clientArea);
            else
                gridGraphics.FillRectangle(Brushes.Black, clientArea);

            gridGraphics.DrawRectangle(Pens.MediumPurple, clientArea);
            clientArea.Inflate(-1, -1);

            if (cell.Path == PathState.Open)
                gridGraphics.DrawRectangle(Pens.Green, clientArea);
            else if (cell.Path == PathState.Closed)
                gridGraphics.DrawRectangle(Pens.Teal, clientArea);
            else if (cell.Path == PathState.Found)
                gridGraphics.DrawRectangle(Pens.Yellow, clientArea);

            clientArea.Inflate(-1, -1);
            if (cell.parent != null)
            {
                var s = gridGraphics.MeasureString(cell.h.ToString(), font);
                gridGraphics.DrawString(cell.f.ToString(), font, Brushes.White, new Point(clientArea.X, clientArea.Y));
                gridGraphics.DrawString(cell.g.ToString(), font, Brushes.White, new Point(clientArea.X, clientArea.Y + size - (int)s.Height - 1));
                gridGraphics.DrawString(cell.h.ToString(), font, Brushes.White, new Point(clientArea.X + size - 1 - (int)s.Width, clientArea.Y + size - (int)s.Height - 1));

                var cx = (clientArea.Width / 2) + clientArea.Left;
                var cy = (clientArea.Height / 2) + clientArea.Top;

                var dx = cell.parent.x - cell.x;
                var dy = cell.parent.y - cell.y;
                var mod = 7;
                if (dx * dx + dy * dy == 1)
                    mod = 9;

                if (cell.Path == PathState.Found)
                {
                    mod += 2;
                    gridGraphics.DrawLine(Pens.White, cx, cy, cx + dx * mod, cy + dy * mod);
                    gridGraphics.FillEllipse(Brushes.Red, new Rectangle(cx - 5, cy - 5, 10, 10));
                    gridGraphics.DrawEllipse(Pens.White, new Rectangle(cx - 5, cy - 5, 10, 10));
                }
                else
                {
                    gridGraphics.DrawLine(Pens.White, cx, cy, cx + dx * mod, cy + dy * mod);
                    gridGraphics.FillEllipse(Brushes.Black, new Rectangle(cx - 3, cy - 3, 6, 6));
                    gridGraphics.DrawEllipse(Pens.White, new Rectangle(cx - 3, cy - 3, 6, 6));
                }
            }
        }
Ejemplo n.º 6
0
Archivo: Grid.cs Proyecto: xposure/BOTA
        public void SetState(Cell cell, CellState state)
        {
            if (state == CellState.Empty || state == CellState.Block)
            {
                if (cell.State == CellState.Start)
                {
                    cell.State = state;
                    start = null;
                }
                else if (cell.State == CellState.End)
                {
                    cell.State = state;
                    end = null;
                }
                else
                    cell.State = state;
            }
            else if (state == CellState.Start)
            {
                if (start != null)
                {
                    start.State = CellState.Empty;
                    DrawCell(start);
                }

                cell.State = CellState.Start;
                start = cell;
            }
            else if (state == CellState.End)
            {
                if (end != null)
                {
                    end.State = CellState.Empty;
                    DrawCell(end);
                }

                cell.State = CellState.End;
                end = cell;
            }

            DrawCell(cell);
        }
Ejemplo n.º 7
0
Archivo: Grid.cs Proyecto: xposure/BOTA
        public bool Resize(int w, int h)
        {
            var gw = w / size;
            var gh = h / size;
            if (gw != width || gh != height)
            {
                //resize grid
                var newGrid = new Cell[gw, gh];

                for (var x = 0; x < gw; x++)
                {
                    for (var y = 0; y < gh; y++)
                    {
                        if (x <= width || y <= height)
                            newGrid[x, y] = cells[x, y];

                        if (newGrid[x, y] == null)
                            newGrid[x, y] = new Cell() { x = x, y = y };
                    }
                }

                cells = newGrid;
                width = gw;
                height = gh;

                if (gridBitmap != null)
                {
                    gridBitmap.Dispose();
                    gridGraphics.Dispose();
                }

                var gbWidth = Math.Max(w, width * size + 2);
                var gbHeight = Math.Max(h, height * size + 2);

                gridBitmap = new Bitmap(gbWidth, gbHeight);

                gridGraphics = Graphics.FromImage(gridBitmap);
                gridGraphics.FillRectangle(Brushes.Black, new Rectangle(0, 0, gbWidth, gbHeight));

                for (var x = 0; x < width; x++)
                    for (var y = 0; y < height; y++)
                        DrawCell(cells[x, y]);

                return true;
            }

            return false;
        }
Ejemplo n.º 8
0
Archivo: Grid.cs Proyecto: xposure/BOTA
        public void Reset()
        {
            openList.Clear();
            closedList.Clear();
            start = null;
            end = null;

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    cells[x, y].Reset();
                    DrawCell(cells[x, y]);
                }
            }
        }
Ejemplo n.º 9
0
Archivo: Grid.cs Proyecto: xposure/BOTA
        public IEnumerable<Cell> AdjacentCells(Cell cell)
        {
            var x0y0 = GetCell(cell.x - 1, cell.y - 1);
            var x1y0 = GetCell(cell.x, cell.y - 1);
            var x2y0 = GetCell(cell.x + 1, cell.y - 1);

            var x0y2 = GetCell(cell.x - 1, cell.y + 1);
            var x1y2 = GetCell(cell.x, cell.y + 1);
            var x2y2 = GetCell(cell.x + 1, cell.y + 1);

            var x0y1 = GetCell(cell.x - 1, cell.y);
            var x2y1 = GetCell(cell.x + 1, cell.y);

            if (x1y0 != null) yield return x1y0;
            if (x2y1 != null) yield return x2y1;
            if (x1y2 != null) yield return x1y2;
            if (x0y1 != null) yield return x0y1;

            if (x0y0 != null && x1y0 != null && x0y1 != null && (x1y0.State != CellState.Block && x0y1.State != CellState.Block)) yield return x0y0;
            if (x2y0 != null && x1y0 != null && x2y1 != null && (x1y0.State != CellState.Block && x2y1.State != CellState.Block)) yield return x2y0;
            if (x2y2 != null && x1y2 != null && x2y1 != null && (x1y2.State != CellState.Block && x2y1.State != CellState.Block)) yield return x2y2;
            if (x0y2 != null && x0y1 != null && x1y2 != null && (x0y1.State != CellState.Block && x1y2.State != CellState.Block)) yield return x0y2;
        }