Exemple #1
0
        static minCoordinate[,] calculateArea(mainCoordinate[] coords)
        {
            int maxX = 0;
            int maxY = 0;

            minCoordinate[,] area;

            foreach (mainCoordinate coord in coords)
            {
                if (coord.getX() > maxX)
                {
                    maxX = coord.getX();
                }
                if (coord.getY() > maxY)
                {
                    maxY = coord.getY();
                }
            }
            area = new minCoordinate[maxX + 1, maxY + 1];

            for (int i = 0; i < area.GetLength(0); i++)
            {
                for (int j = 0; j < area.GetLength(1); j++)
                {
                    area[i, j] = new minCoordinate("0", 0);
                }
            }

            for (int i = 0; i < coords.Length; i++)
            {
                area[coords[i].getX(), coords[i].getY()] = new minCoordinate(coords[i].getValue(true), 0);
            }

            return(area);
        }
Exemple #2
0
        static bool free(minCoordinate mc, int length)
        {
            if (!mc.getValue().Equals('0'))
            {
                if (mc.getDistance() < length)
                {
                    return(false);
                }

                if (mc.getValue().Equals('1'))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #3
0
        static minCoordinate[,] fillArea(minCoordinate[,] area, mainCoordinate[] coords)
        {
            int  maxX = area.GetLength(0);
            int  maxY = area.GetLength(1);
            int  startX;
            int  startY;
            bool done;

            foreach (mainCoordinate c in coords)
            {
                startX = c.getX();
                startY = c.getY();
                done   = false;
                for (int i = 1; i < 100000; i++)
                {
                    //search north
                    for (int j = i; j > 0; j++)
                    {
                        done = true;
                        if (startY - j >= 0)
                        {
                            if (startX - (i - j) >= 0)
                            {
                                if (free(area[startX - (i - j), startY - j], i))
                                {
                                    if (equalDistance(area[startX - (i - j), startY - j].getDistance(), i))
                                    {
                                        area[startX - (i - j), startY - j] = new minCoordinate("1", 0);
                                    }
                                    else
                                    {
                                        area[startX - (i - j), startY - j] = new minCoordinate(c.getValue(false), i);
                                        done = false;
                                    }
                                }
                            }
                            if (startX + (i - j) < maxX)
                            {
                                if (free(area[startX - (i - j), startY - j], i))
                                {
                                    if (equalDistance(area[startX - (i - j), startY - j].getDistance(), i))
                                    {
                                        area[startX - (i - j), startY - j] = new minCoordinate("1", 0);
                                    }
                                    else
                                    {
                                        area[startX + (i - j), startY - j] = new minCoordinate(c.getValue(false), i);
                                        done = false;
                                    }
                                }
                            }

                            //out of bonds varför?
                        }
                    }
                    //search west
                    //search south
                    //search east
                    if (done)
                    {
                        break;
                    }
                }
            }
            return(area);
        }