예제 #1
0
        protected override Rectangle?SelectNextLot(RectangleIntervalTree placedFragments, SimpleRandom random)
        {
            var boundingRectangle = placedFragments.BoundingRectangle;

            while (_lotSize.Width > boundingRectangle.Width || _lotSize.Height > boundingRectangle.Height)
            {
                _lotSize = new Dimensions((byte)(_lotSize.Width - 1), (byte)(_lotSize.Height - 1));
            }

            while (_lotSize.Contains(MinLotSize))
            {
                // TODO: Optimize using
                // "Polygon Decomposition". Handbook of Computational Geometry. p. 491 or
                // "Graph-Theoretic Solutions to Computational Geometry Problems"
                // https://stackoverflow.com/questions/5919298/algorithm-for-finding-the-fewest-rectangles-to-cover-a-set-of-rectangles-without

                for (var attempt = 0; attempt < LotPlacementAttempts; attempt++)
                {
                    var x1 = (byte)random.Next(boundingRectangle.TopLeft.X,
                                               boundingRectangle.BottomRight.X - _lotSize.Width + 1);
                    var y1 = (byte)random.Next(boundingRectangle.TopLeft.Y,
                                               boundingRectangle.BottomRight.Y - _lotSize.Height + 1);
                    var potentialLot = new Rectangle(new Point(x1, y1), (byte)(_lotSize.Width - 1),
                                                     (byte)(_lotSize.Height - 1));
                    if (!placedFragments.GetOverlapping(potentialLot).Any())
                    {
                        return(potentialLot);
                    }
                }

                _lotSize = new Dimensions((byte)(_lotSize.Width - 1), (byte)(_lotSize.Height - 1));
            }

            return(null);
        }
예제 #2
0
        public static Rectangle CreateRandom(SimpleRandom random, Rectangle boundingRectangle, Dimensions minSize)
        {
            var width = (byte)random.Next(minSize.Width, boundingRectangle.Width + 1);
            var x1    = (byte)random.Next(boundingRectangle.TopLeft.X, boundingRectangle.BottomRight.X + 2 - width);

            var height = (byte)random.Next(minSize.Height, boundingRectangle.Height + 1);
            var y1     = (byte)random.Next(boundingRectangle.TopLeft.Y, boundingRectangle.BottomRight.Y + 2 - height);

            return(new Rectangle(new Point(x1, y1), width, height));
        }
예제 #3
0
        public Point?PlaceInside(Rectangle rectangleToPlace, SimpleRandom random)
        {
            if (rectangleToPlace.Width > Width || rectangleToPlace.Height > Height)
            {
                return(null);
            }

            var xOffset = random.Next(Width - rectangleToPlace.Width + 1);
            var yOffset = random.Next(Height - rectangleToPlace.Height + 1);

            return(new Point((byte)(TopLeft.X + xOffset), (byte)(TopLeft.Y + yOffset)));
        }
 public static void Shuffle <T>(this IList <T> list, int times = 1)
 {
     for (int i = 0; i < times; ++i)
     {
         int n = list.Count;
         while (n > 1)
         {
             n--;
             int k     = (int)rand.Next((uint)n + 1);
             T   value = list[k];
             list[k] = list[n];
             list[n] = value;
         }
     }
 }
예제 #5
0
        public void Init()
        {
            ServerCommandLine.Instance.Init();
            ResControl.Instance.Init();
            NodeControl.Instance.Init();
            EntityContent.Instance.Init();

            IPEndPoint point = UdpConfig.DnsToIPEndPoint(Config.primarilyIp);

            if (point == null)
            {
                Server = new UdpPoint(Config.primarilyPort, false);
            }
            else
            {
                Server = new UdpPoint(point, false);
            }

            m_isBroadcast = Config.isEnableBroadcast;
            //最大存储1000帧指令
            MaxQueueBuffer = 1000;
            //缓存队列计数
            QueueBufferCount = 0;
            //设置一个随机验证值
            LocalNetNode.license = random.Next();
            //新的服务器信息
            HostInfo             = new ServerInfo();
            HostInfo.name        = Config.name;
            HostInfo.description = Config.description;
            //服务端启动时间
            //StartTickTime = RealityTickTime;
            Console.WriteLine("[Server状态机执行初始化]" + IsBroadcast);

            Server.Mgr.OnRequestDataHandle += NetRequestData.OnRequestDataServer;
            Server.Mgr.OnCmdDataHandle     += NetCmdData.OnCmdDataServer;
            Server.Mgr.OnReadBufferHandle  += NetReadBuffer.OnReadBufferServer;
            Server.Mgr.OnRequestCmdHandle  += NetRequestCmd.OnRequestCmdServer;

            //Console.WriteLine(Server.LocalEndPoint);
        }
예제 #6
0
 public byte RandomPoint(SimpleRandom random) => (byte)random.Next(Beginning, End + 1);