Exemplo n.º 1
0
        public static double NextGaussian(double mu = 0, double sigma = 1)
        {
            double x, u, v, s;

            if (isStored)
            {
                isStored = !isStored;
                return(prevGauss * sigma + mu);
            }
            do
            {
                u = 2 * StaticRandom.NextDouble() - 1;
                v = 2 * StaticRandom.NextDouble() - 1;
                s = u * u + v * v;
            } while (s >= 1 || s == 0);
            x         = Math.Sqrt(-2 * Math.Log(s) / s);
            prevGauss = x * u;
            isStored  = !isStored;
            return(x * v * sigma + mu);
        }
Exemplo n.º 2
0
 private void TrollCalmMode(Troll t)
 {
     map[t.Position] = MazeMap.Empty;
     if (StaticRandom.Next(6) > 1 && map.isFree(t.DesirePosition))
     {
         t.Position += t.Dir;
     }
     else
     {
         double j = t.Dir.X == 0 ? Math.Acos(t.Dir.Y) : -Math.Asin(t.Dir.X);
         for (double k = j + Math.PI / 2; k > double.MinValue; k += Math.PI / 2)
         {
             t.Dir = Extensions.Direction(k);
             if (StaticRandom.Next(3) > 1 && (map.isFree(t.DesirePosition) ||
                                              Player.arrows.Contains(map[t.DesirePosition])))
             {
                 break;
             }
         }
         t.Position = t.DesirePosition;
     }
     map[t.Position] = Troll.calmCursor;
     CheckForPlayer(t);
 }
Exemplo n.º 3
0
        private void BuildByDivide(int x, int y, int _height, int _width, Orientation or, MazeMode mode)
        {
            if (_width < 2 || _height < 2)
            {
                return;
            }
            if (_width < 3 || _height < 3)
            {
                if (StaticRandom.Next(0, 3) > 1)
                {
                    return;
                }
            }
            bool hor = or == Orientation.HOR;
            int  hy1, hx1, hy2, hx2, hx3, hy3;

            int wy = y + (hor ? 0 : StaticRandom.Next(_width - 2));
            int wx = x + (hor ? StaticRandom.Next(_height - 2) : 0);

            if ((mode == MazeMode.OneWay) || _height < 5 || _width < 5)
            {
                hy1 = hy2 = hy3 = wy + (hor ? StaticRandom.Next(_width) : 0);
                hx1 = hx2 = hx3 = wx + (hor ? 0 : StaticRandom.Next(_height));
            }
            else if (!hor && _width >= 5 && _width <= 15)
            {
                hy1 = hy2 = hy3 = wy;
                hx1 = wx + StaticRandom.Next(_height / 2 - 1);
                hx2 = hx3 = wx + StaticRandom.Next(_height / 2, _height);
            }
            else if (hor && _height >= 5 && _height <= 15)
            {
                hy1 = wy + StaticRandom.Next(_width / 2 - 1);
                hx1 = hx2 = hx3 = wx;
                hy2 = hy3 = wy + StaticRandom.Next(_width / 2, _width);
            }
            else
            {
                hy1 = wy + (hor ? StaticRandom.Next(_width / 3 - 1) : 0);
                hx1 = wx + (hor ? 0 : StaticRandom.Next(_height / 3));
                hy2 = wy + (hor ? StaticRandom.Next(_width / 3 + 1, 2 * _width / 3 - 1) : 0);
                hx2 = wx + (hor ? 0 : StaticRandom.Next(_height / 3 + 1, 2 * _height / 3 - 1));
                hy3 = wy + (hor ? StaticRandom.Next(2 * _width / 3 + 1, _width) : 0);
                hx3 = wx + (hor ? 0 : StaticRandom.Next(2 * _height / 3 + 1, _height));
            }

            for (int i = 0; i < (hor ? _width : _height); i++)
            {
                if (!((wx == hx1 && wy == hy1) || (wx == hx2 && wy == hy2) || (wx == hx3 && wy == hy3)))
                {
                    if (map[wx][wy] != ' ')
                    {
                        map[wx][wy] = 'b';
                    }
                    else
                    {
                        map[wx][wy] = hor ? 'h' : 'v';
                    }
                }
                wy += (hor ? 1 : 0);
                wx += (hor ? 0 : 1);
            }

            int newh = hor ? wx - x + 1 : _height;
            int neww = hor ? _width : wy - y + 1;

            BuildByDivide(x, y, newh, neww, ChooseOrientation(newh, neww), mode);
            newh = hor ? _height - wx + x - 1 : _height;
            neww = hor ? _width : _width - wy + y - 1;
            BuildByDivide(hor ? wx + 1 : x, hor ? y : wy + 1, newh, neww, ChooseOrientation(newh, neww), mode);
        }