Пример #1
0
        private void SetAllocationAndRecalculateIntersections(PlayerAllocationRequest request)
        {
            if (PlayerData.Instance.TryGetEntry(request.UserId, out PlayerDataEntry entry))
            {
                lock (_intersectionLock)
                {
                    Allocation playerAllocation = arranger.PlaceSingle(request);

                    if (playerAllocation == null)
                    {
                        Logger.Warn($"Couldn't find allocation for player {request.UserId} ({entry.UserName})");
                        SendReliable(new AllocationDenied()
                        {
                            UserId = request.UserId,
                        });
                        return;
                    }

                    entry.Allocation = playerAllocation;

                    Logger.Info($"{request.UserId} ({entry.UserName}) got {entry.Allocation.Degrees} degrees orientation");

                    SendReliable(new AllocationGranted
                    {
                        UserId = request.UserId,
                        Offset = playerAllocation.Offset,
                        RotationAroundFirstPoint = playerAllocation.Rotation
                    });

                    //SendInitialEmptyArea(request.UserId);

                    StrategyManager.Instance.UpdatePlayerList();
                }
            }
        }
Пример #2
0
        public Allocation PlaceSingle(PlayerAllocationRequest request)
        {
            double minMustHaveOverlap = double.MaxValue;
            double minNiceHaveOverlap = double.MaxValue;
            int    minIndex           = -1;

            for (int i = 0; i < _numPlacements; i++)
            {
                var offset   = _possibleOffsets[i];
                var rotation = _possibleRotations[i];

                var mustHaveArea = request.MustHave.DeepClone();
                mustHaveArea.Rotate(rotation);
                mustHaveArea += offset;
                var niceHaveArea = request.NiceHave.DeepClone();
                niceHaveArea.Rotate(rotation);
                niceHaveArea += offset;

                var mustHaveOverlap = .0;
                var niceHaveOverlap = .0;
                foreach (var allocation in _playerData.GetAllocations())
                {
                    if (allocation == null)
                    {
                        continue;
                    }

                    var playerMustHaveOverlap = ClipperUtility.GetArea(ClipperUtility.Intersection(allocation.GlobalMustHave, mustHaveArea));
                    var playerNiceHaveOverlap = ClipperUtility.GetArea(ClipperUtility.Intersection(allocation.GlobalNiceHave, niceHaveArea));

                    //Logger.Debug($"Overlap {request.PlayerId} with {playerId}: {playerMustHaveOverlap}");

                    mustHaveOverlap += playerMustHaveOverlap;
                    niceHaveOverlap += playerNiceHaveOverlap;
                }

                if (mustHaveOverlap < minMustHaveOverlap || Math.Abs(mustHaveOverlap - minMustHaveOverlap) < .001 && niceHaveOverlap < minNiceHaveOverlap)
                {
                    minMustHaveOverlap = mustHaveOverlap;
                    minNiceHaveOverlap = niceHaveOverlap;
                    minIndex           = i;
                }
            }

            if (minIndex < 0)
            {
                return(null);
            }

            var newAllocation = new Allocation(request.MustHave, request.NiceHave, _possibleOffsets[minIndex], _possibleRotations[minIndex]);

            return(newAllocation);
        }
Пример #3
0
        private void _handleAllocationRequest(IMessageBase messageBase)
        {
            int playerId = ((MessageBase)messageBase).UserId;

            if (playerId < 0)
            {
                Logger.Warn("Received invalid player id " + playerId);
                return;
            }

            PlayerAllocationRequest allocation = (PlayerAllocationRequest)messageBase;

            Logger.Debug("Allocation request from player " + allocation.UserId);

            {
                //MustArea/NiceArea

                // automatic placement based on CMAES
                // hack for now: auto-accept
                SetAllocationAndRecalculateIntersections(allocation);
            }
        }