コード例 #1
0
        public bool WorksWithBucket(int timeNum, TransitionVote userVote)
        {
            var execTime     = userVote.ExecutionLengthMs[timeNum];
            var planningTime = userVote.PlanningTimestampMs[timeNum];

            return(_minAllowedExecTime <= execTime && execTime <= _maxAllowedExecTime &&
                   _minAllowedPlanningTime <= planningTime && planningTime <= _maxAllowedPlanningTime);
        }
コード例 #2
0
        public void AddToBucket(int userNum, int timeNum, TransitionVote userVote)
        {
            var execTime     = userVote.ExecutionLengthMs[timeNum];
            var planningTime = userVote.PlanningTimestampMs[timeNum];

            _minAllowedPlanningTime = Math.Max(_minAllowedPlanningTime, planningTime - _maximumPlanningOffset);
            _maxAllowedPlanningTime = Math.Min(_maxAllowedPlanningTime, planningTime + _maximumPlanningOffset);

            _minAllowedExecTime = Math.Max(_minAllowedExecTime, execTime - _maximumExecOffset);
            _maxAllowedExecTime = Math.Min(_maxAllowedExecTime, execTime + _maximumExecOffset);

            UserNumToTimeNum[userNum] = timeNum;
            UserNumToVotes[userNum]   = userVote;
        }
コード例 #3
0
        public override double GetUserValue(TransitionVote userVote, AssignedVote assignedVote)
        {
            var value = userVote.NormalizedValue;

            if (_useTimeValue)
            {
                value *= assignedVote.TimeValue;
            }
            if (userVote.Transition == VSUserTransition.Undefocus)
            {
                value /= 2;
            }
            return(value);
        }
コード例 #4
0
 public override double GetUserValue(TransitionVote userVote, AssignedVote assignedVote)
 {
     return(userVote.Value);
 }
コード例 #5
0
 public abstract double GetUserValue(TransitionVote userVote, AssignedVote assignedVote);
コード例 #6
0
        public void OnStateInfo(IMessageBase baseMessage)
        {
            if (_sendAlive)
            {
                _sendAlive = false;
                //_sendVotingThread.Abort();
            }

            StateInfo info = (StateInfo)baseMessage;

            TransitionVoting voting = new TransitionVoting();

            voting.StateId = info.StateId;

            //Logger.Debug($"Receive at turn: {VirtualSpaceTime.CurrentTurn}, Millis: {VirtualSpaceTime.CurrentTimeInMillis}");

            //_map.GetPlayerStatus(info.SystemRotationState, info.SystemPlayerInFocusState, info.SystemPlayerNum,
            //    out Vector startPosition, out Polygon startPolygon);

            //if (info.SystemPlayerNum == 0)
            //{
            //    Logger.Debug($"=============");
            //    Logger.Debug($"{info.SystemPlayerNum} at {startPosition}");
            //}

            if (!VirtualSpaceTime.IsInitialized)
            {
                Logger.Warn("Current VS time is not initialized");
                Thread.Sleep(200);
            }

            for (int i = 0; i < info.PossibleTransitions.Count; i++)
            {
                VSUserTransition transition = info.PossibleTransitions[i];

                TransitionVote vote = new TransitionVote();

                //_map.GetPlayerStatus(info.SystemRotationState, info.SystemPlayerInFocusState, transition, info.SystemPlayerNum,
                //    out Vector endPosition, out Polygon endPolygon);

                //if (info.SystemPlayerNum == 0)
                //{
                //    Logger.Debug($"{info.SystemPlayerNum} with {transition} at {endPosition}");
                //    Logger.Debug($"{endPolygon.Points.ToPrintableString()}");
                //    Logger.Debug($"{info.TransitionEndPositions[i]}");
                //    Logger.Debug($"{info.TransitionEndAreas[i].Points.ToPrintableString()}");
                //}

                //var timeMultiplier = 100; // for debugging
                var timeMultiplier = 1000; // realistic

                //if (_botIndex == 0)
                //{
                //vote.PlanningTimeType = PlanningTimeType.RelativeExecution;
                vote.PlanningTimestampMs = new List <double>()
                {
                    1000, 2000
                };
                //} else if (_botIndex == 1)
                //{
                //    vote.PlanningTimeType = PlanningTimeType.Absolute;
                //    var nowMs = VirtualSpaceTime.CurrentTimeInMillis;
                //    vote.PlanningTimestampMs = new List<double>() { nowMs + (2 + 2 * _random.NextDouble()) * timeMultiplier, nowMs + 4 * timeMultiplier };
                //}
                //else
                //{
                //    vote.PlanningTimeType = PlanningTimeType.RelativeArrival;
                //    vote.PlanningTimestampMs = new List<double>() { (2 + _random.NextDouble() * .3) * timeMultiplier, (2 + _random.NextDouble() * .3) * timeMultiplier };
                //}

                vote.Transition        = transition;
                vote.ExecutionLengthMs = new List <double> {
                    1000, 2000
                };

                //for (int j = 0; j < vote.PlanningTimestampMs.Count; j++)
                //{
                //    if (vote.PlanningTimeType == PlanningTimeType.RelativeExecution || vote.PlanningTimeType == PlanningTimeType.RelativeArrival)
                //        vote.PlanningTimestampMs[j] *= timeMultiplier;
                //    vote.ExecutionLengthMs[j] *= timeMultiplier;
                //}

                //for (int po = 500; po < 5000; po += 500)
                //{
                //    for (int eo = 500; eo < 5000; eo += 500)
                //    {
                //        vote.PlanningTimestampMs.Add(po + _random.NextDouble() * 100);
                //        vote.ExecutionLengthMs.Add(eo + _random.NextDouble() * 100);
                //    }
                //}

                List <TimeCondition> timeConditions = new List <TimeCondition>();
                var prepTime        = new Variable(VariableTypes.PreperationTime);
                var execTime        = new Variable(VariableTypes.ExecutionTime);
                var arrivalTime     = new Variable(VariableTypes.ArrivalTime);
                var calculationTime = new Variable(VariableTypes.CalculationTime);

                var proxyPrep = new Variable(VariableTypes.Continuous);

                var now            = VirtualSpaceTime.CurrentTimeInMillis;
                var offset         = 1000;
                var multiple       = new Variable(VariableTypes.Integer);
                var intervalLength = 300;
                var tolerance      = 100;
                if (_botIndex % 2 == 0)
                {
                    timeConditions.Add(proxyPrep == now + offset + multiple * intervalLength);
                    timeConditions.Add(prepTime >= proxyPrep - tolerance);
                    timeConditions.Add(prepTime <= proxyPrep + tolerance);
                }
                else
                {
                    timeConditions.Add(prepTime >= now + _random.NextDouble() * 200);
                }
                timeConditions.Add(execTime >= 1200 + _random.NextDouble() * 100);
                timeConditions.Add(execTime <= 1400 + _random.NextDouble() * 100);

                vote.TimeConditions = timeConditions;

                if (transition == VSUserTransition.Defocus || (info.YourCurrentTransition == VSUserTransition.Defocus && transition == VSUserTransition.Stay))
                {
                    vote.Value = _random.Next(0, 25);
                }
                else
                {
                    switch (transition)
                    {
                    case VSUserTransition.Stay:
                        vote.Value = _random.Next(40, 90);
                        if (_botIndex == 0)
                        {
                            //vote.RequiredTransition = _random.NextDouble() < .5f;
                        }

                        break;

                    case VSUserTransition.SwitchLeft:
                    case VSUserTransition.SwitchRight:
                        vote.Value = 0;
                        break;

                    case VSUserTransition.RotateLeft:
                    case VSUserTransition.RotateRight:
                        vote.Value = _random.Next(50, 100);
                        break;

                    case VSUserTransition.Focus:
                        vote.Value = 0;
                        break;

                    case VSUserTransition.Rotate45Left:
                    case VSUserTransition.Rotate45Right:
                        vote.Value = _random.Next(60, 100);
                        break;

                    default:
                        vote.Value = _random.Next(50, 100);
                        break;
                    }
                }

                voting.Votes.Add(vote);
            }

            _voting = voting;

            if (_botIndex == 0)
            {
                // send once
                _worker.SendReliable(_voting);
                //}
                //else if (_botIndex == 1)
                //{
                //    // too hard
                //    // recalc + send in loop
                //    _worker.SendReliable(_voting);
            }
            else
            {
                // send in loop
                _sendAlive        = true;
                _sendVotingThread = new Thread(SendVoting);
                _sendVotingThread.Start();
            }
        }
コード例 #7
0
 public AssignedVote(int numVotes)
 {
     Votes = new TransitionVote[numVotes];
 }
 public override double GetUserValue(TransitionVote userVote, AssignedVote assignedVote)
 {
     throw new System.NotImplementedException();
 }