private void CreatePoint(Pair[] point, int[] color, uint w, uint h,
                          DTLDelegate.VoronoiDiagramDelegate function_)
 {
     for (int arrayNum = 0; arrayNum < this.drawValue; ++arrayNum)
     {
         point[arrayNum] = new Pair((int)rand.Next(w), (int)rand.Next(h));
         function_(ref point[arrayNum], ref color[arrayNum], startX, startY, w, h);
     }
 }
        /**
         * Do CellAutomaton
         */
        private void Assign(int[,] matrix, uint col, uint row)
        {
            if (matrix[row, col - 1] == matrix[row, col + 1] &&
                matrix[row, col + 1] == matrix[row - 1, col] &&
                matrix[row - 1, col] == matrix[row + 1, col])
            {
                matrix[row, col] = matrix[row, col + 1];
            }
            else
            {
                switch (rand.Next(4))
                {
                case 0:
                    matrix[row, col] = matrix[row, col - 1];
                    break;

                case 1:
                    matrix[row, col] = matrix[row, col + 1];
                    break;

                case 2:
                    matrix[row, col] = matrix[row - 1, col];
                    break;

                case 3:
                    matrix[row, col] = matrix[row + 1, col];
                    break;
                }
            }
        }
Beispiel #3
0
        private bool DrawNormal(int[,] matrix)
        {
            var width  = this.CalcEndX(MatrixUtil.GetX(matrix) - this.startX);
            var height = this.CalcEndY(MatrixUtil.GetY(matrix) - this.startY);

            var width3  = width % 2 == 0 ? width - 1 : width;
            var height3 = height % 2 == 0 ? height - 1 : height;

            for (var i = 0; i < width3 / 2; ++i)
            {
                for (var j = 0; j < height3 / 2; ++j)
                {
                    matrix[this.startY + (2 * j + 1), this.startX + (2 * i + 1)] = this.drawValue;
                }
            }

            var mWidth  = width3 / 2;
            var mHeight = height3 / 2;
            var mSize   = mWidth * mHeight;

            // Union Find, Collectionを使わずに素の配列で実装する。
            var data = new uint[mSize];
            var rank = new uint[mSize];

            for (uint i = 0; i < mSize; ++i)
            {
                data[i] = i;                              // 自分の親は自分
            }
            uint      randCellX = 0;
            uint      randCellY = 0;
            uint      outX      = 0;
            uint      outY      = 0;
            Direction outDir    = Direction.UP_DIR;

            while (!this.isAllSame(data, mSize))
            {
                randCellX = rand.Next() % (width3 / 2);
                randCellY = rand.Next() % (height3 / 2);

                this.uniteDifNeighbor(data, rank, mWidth, mHeight, mSize, randCellX, randCellY, ref outX, ref outY, ref outDir);

                // break wall
                matrix[2 * outY + 1 - this.dirDy(outDir), 2 * outX + 1 - this.dirDx(outDir)] = this.drawValue;
            }

            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Der abstrakte Insekt-Basiskonstruktor.
        /// </summary>
        /// <param name="colony">Das Volk zu dem das neue Insekt gehört.</param>
        /// <param name="vorhandeneInsekten">Hier unbenutzt!</param>
        internal virtual void Init(CoreColony colony, Random random, Dictionary <string, int> vorhandeneInsekten)
        {
            id = neueId;
            neueId++;

            this.colony     = colony;
            this.RandomBase = random;

            koordinate.Richtung = RandomBase.Next(0, 359);

            // Zufällig auf dem Spielfeldrand platzieren.
            if (colony.AntHills.Count == 0) // Am oberen oder unteren Rand platzieren.
            {
                if (RandomBase.Next(2) == 0)
                {
                    koordinate.X  = RandomBase.Next(0, colony.Playground.Width);
                    koordinate.X *= SimulationEnvironment.PLAYGROUND_UNIT;
                    if (RandomBase.Next(2) == 0)
                    {
                        koordinate.Y = 0;
                    }
                    else
                    {
                        koordinate.Y = colony.Playground.Height * SimulationEnvironment.PLAYGROUND_UNIT;
                    }
                }

                // Am linken oder rechten Rand platzieren.
                else
                {
                    if (RandomBase.Next(2) == 0)
                    {
                        koordinate.X = 0;
                    }
                    else
                    {
                        koordinate.X = colony.Playground.Width * SimulationEnvironment.PLAYGROUND_UNIT;
                    }
                    koordinate.Y  = RandomBase.Next(0, colony.Playground.Height);
                    koordinate.Y *= SimulationEnvironment.PLAYGROUND_UNIT;
                }
            }

            // In einem zufälligen Bau platzieren.
            else
            {
                int i = RandomBase.Next(colony.AntHills.Count);
                koordinate.X = colony.AntHills[i].CoordinateBase.X +
                               SimulationEnvironment.Cosinus(
                    colony.AntHills[i].CoordinateBase.Radius, koordinate.Richtung);
                koordinate.Y = colony.AntHills[i].CoordinateBase.Y +
                               SimulationEnvironment.Sinus(
                    colony.AntHills[i].CoordinateBase.Radius, koordinate.Richtung);
            }
        }
Beispiel #5
0
        private bool DrawNormal(int[,] matrix)
        {
            uint drawValueCount = (uint)this.drawValue.Count;
            var  endX           = this.CalcEndX(MatrixUtil.GetX(matrix));
            var  endY           = this.CalcEndY(MatrixUtil.GetY(matrix));

            for (var row = this.startY; row < endY; ++row)
            {
                for (var col = this.startX; col < endX; ++col)
                {
                    matrix[row, col]
                        = this.rand.Probability(0.5) ?
                          this.drawValue[0] : this.drawValue[(int)rand.Next(drawValueCount)];
                }
            }
            return(true);
        }
Beispiel #6
0
        /* 基本処理 */

        // Normal
        private bool DrawNormal(int[,] matrix_, uint endX_, uint endY_)
        {
            // マップの区分け数(部屋の個数)0~nまでの部屋ID
            var mapDivCount = divisionMin + rand.Next(divisionRandMax);

            // マップの区域 [部屋ID][X終点 , Y終点 , X始点 , Y始点]
            var dungeonDivision = new uint[mapDivCount, 4];
            // マップの部屋 [部屋ID][X終点 , Y終点 , X始点 , Y始点]
            var dungeonRoom = new uint[mapDivCount, 4];
            // マップの道 [部屋ID][X終点 , Y終点 , X始点 , Y始点]
            var dungeonRoad = new uint[mapDivCount, 4];

            dungeonDivision[0, 0] = endY_ - 1;  // マップの区分け初期サイズX終点 (マップの大きさY軸)
            dungeonDivision[0, 1] = endX_ - 1;  // マップの区分け初期サイズY終点 (マップの大きさX軸)
            dungeonDivision[0, 2] = startX + 1; // マップの区分け初期サイズX始点 (マップの大きさX軸)
            dungeonDivision[0, 3] = startY + 1; // マップの区分け初期サイズY始点 (マップの大きさY軸)

            dungeonRoad[0, 0] = uint.MaxValue;
            dungeonRoad[0, 1] = uint.MaxValue;

            CreateDivision(dungeonRoad, dungeonDivision, mapDivCount);
            CreateRoom(dungeonRoom, dungeonDivision, mapDivCount);
            AssignRoom(dungeonRoom, matrix_, mapDivCount);
            CreateRoad(dungeonRoad, dungeonRoom, dungeonDivision, matrix_, mapDivCount);
            return(true);
        }
Beispiel #7
0
        /// <summary>
        /// Berechnet die Bewegung des Insekts.
        /// </summary>
        internal void Bewegen()
        {
            reached = false;

            // Insekt dreht sich.
            if (restWinkel != 0)
            {
                // Zielwinkel wird erreicht.
                if (Math.Abs(restWinkel) < colony.Drehgeschwindigkeit[CasteIndexBase])
                {
                    koordinate.Richtung += restWinkel;
                    restWinkel           = 0;
                }

                // Insekt dreht sich nach rechts.
                else if (restWinkel >= colony.Drehgeschwindigkeit[CasteIndexBase])
                {
                    koordinate.Richtung += colony.Drehgeschwindigkeit[CasteIndexBase];
                    RestWinkelBase      -= colony.Drehgeschwindigkeit[CasteIndexBase];
                }

                // Insekt dreht sich nach links.
                else if (restWinkel <= -colony.Drehgeschwindigkeit[CasteIndexBase])
                {
                    koordinate.Richtung -= colony.Drehgeschwindigkeit[CasteIndexBase];
                    RestWinkelBase      += colony.Drehgeschwindigkeit[CasteIndexBase];
                }
            }

            // Insekt geht.
            else if (restStreckeI > 0)
            {
                if (GetragenesObstBase == null)
                {
                    int strecke = Math.Min(restStreckeI, aktuelleGeschwindigkeitI);

                    restStreckeI          -= strecke;
                    zurückgelegteStreckeI += strecke;
                    koordinate.X          += SimulationEnvironment.Cos[strecke, koordinate.Richtung];
                    koordinate.Y          += SimulationEnvironment.Sin[strecke, koordinate.Richtung];
                }
            }

            // Insekt geht auf Ziel zu.
            else if (ziel != null)
            {
                int entfernungI;

                if (ZielBase is CoreMarker)
                {
                    entfernungI = CoreCoordinate.BestimmeEntfernungDerMittelpunkteI(koordinate, ziel.CoordinateBase);
                }
                else
                {
                    entfernungI = CoreCoordinate.BestimmeEntfernungI(koordinate, ziel.CoordinateBase);
                }

                reached = entfernungI <= SimulationEnvironment.PLAYGROUND_UNIT;
                if (!reached)
                {
                    int richtung = CoreCoordinate.BestimmeRichtung(koordinate, ziel.CoordinateBase);

                    // Ziel ist in Sichtweite oder Insekt trägt Obst.
                    if (entfernungI < colony.SichtweiteI[CasteIndexBase] || getragenesObst != null)
                    {
                        restStreckeI = entfernungI;
                    }

                    // Ansonsten Richtung verfälschen.
                    else
                    {
                        richtung    += RandomBase.Next(-18, 18);
                        restStreckeI = colony.SichtweiteI[CasteIndexBase];
                    }

                    dreheInRichtung(richtung);
                }
            }

            // Koordinaten links begrenzen.
            if (koordinate.X < 0)
            {
                koordinate.X = -koordinate.X;
                if (koordinate.Richtung > 90 && koordinate.Richtung <= 180)
                {
                    koordinate.Richtung = 180 - koordinate.Richtung;
                }
                else if (koordinate.Richtung > 180 && koordinate.Richtung < 270)
                {
                    koordinate.Richtung = 540 - koordinate.Richtung;
                }
            }

            // Koordinaten rechts begrenzen.
            else if (koordinate.X > colony.BreiteI)
            {
                koordinate.X = colony.BreiteI2 - koordinate.X;
                if (koordinate.Richtung >= 0 && koordinate.Richtung < 90)
                {
                    koordinate.Richtung = 180 - koordinate.Richtung;
                }
                else if (koordinate.Richtung > 270 && koordinate.Richtung < 360)
                {
                    koordinate.Richtung = 540 - koordinate.Richtung;
                }
            }

            // Koordinaten oben begrenzen.
            if (koordinate.Y < 0)
            {
                koordinate.Y = -koordinate.Y;
                if (koordinate.Richtung > 180 && koordinate.Richtung < 360)
                {
                    koordinate.Richtung = 360 - koordinate.Richtung;
                }
            }

            // Koordinaten unten begrenzen.
            else if (koordinate.Y > colony.HöheI)
            {
                koordinate.Y = colony.HöheI2 - koordinate.Y;
                if (koordinate.Richtung > 0 && koordinate.Richtung < 180)
                {
                    koordinate.Richtung = 360 - koordinate.Richtung;
                }
            }
        }