コード例 #1
0
        public void TestGiveInfoForwardedPayloadDeserialization()
        {
            // Arrange
            var jsonString = "{\"respondingID\":1,\"distances\":[1, 2, 0, 1]," +
                             "\"redTeamGoalAreaInformations\":[\"IDK\",\"IDK\",\"N\",\"G\"]," +
                             "\"blueTeamGoalAreaInformations\":[\"IDK\",\"IDK\",\"N\",\"G\"]}";
            int x = 2, y = 2;

            GoalInfo[] expectedRedTeamGoalAreaInformations = new GoalInfo[x * y];
            GoalInfo[] expectedBlueTeamGoalAreaInformations = new GoalInfo[x * y];

            // Act
            expectedRedTeamGoalAreaInformations[0] = GoalInfo.IDK;
            expectedRedTeamGoalAreaInformations[1] = GoalInfo.IDK;
            expectedRedTeamGoalAreaInformations[2] = GoalInfo.DiscoveredNotGoal;
            expectedRedTeamGoalAreaInformations[3] = GoalInfo.DiscoveredGoal;

            expectedBlueTeamGoalAreaInformations[0] = GoalInfo.IDK;
            expectedBlueTeamGoalAreaInformations[1] = GoalInfo.IDK;
            expectedBlueTeamGoalAreaInformations[2] = GoalInfo.DiscoveredNotGoal;
            expectedBlueTeamGoalAreaInformations[3] = GoalInfo.DiscoveredGoal;
            var deserializedObject = JsonConvert.DeserializeObject <GiveInfoForwardedPayload>(jsonString);

            // Assert
            Assert.Equal(expectedRedTeamGoalAreaInformations, deserializedObject.RedTeamGoalAreaInformations);
            Assert.Equal(expectedBlueTeamGoalAreaInformations, deserializedObject.BlueTeamGoalAreaInformations);
        }
コード例 #2
0
        public async Task TestAcceptMessagePutAnswerShouldMarkFields()
        {
            // Arrange
            PlayerConfiguration              configuration = GenerateSampleConfiguration();
            BufferBlock <Message>            inputBuffer   = new BufferBlock <Message>();
            ISocketClient <Message, Message> client        = GenerateSocketClient();
            var player = new Models.Player(configuration, inputBuffer, client, logger);

            Message messageStart = CreateStartMessage();

            inputBuffer.Post(messageStart);
            await player.AcceptMessage(CancellationToken.None);

            PutAnswerPayload payload = new PutAnswerPayload()
            {
                PutEvent = PutEvent.NormalOnGoalField,
            };
            Message putAnswer = new Message(MessageID.PutAnswer, agentID, payload);

            // Act
            inputBuffer.Post(putAnswer);
            await player.AcceptMessage(CancellationToken.None);

            // Assert
            GoalInfo actualGoalInfo = player.Board[player.Position.y, player.Position.x].GoalInfo;

            Assert.Equal(GoalInfo.DiscoveredGoal, actualGoalInfo);
        }
コード例 #3
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
        public ProjectInfo GetProject(GoalInfo goal)
        {
            ProjectInfo project   = new ProjectInfo();
            int         projectID = 0;

            if (goal.GoalType == GoalTypeInfo.TypeEnum.ProjectGoal)
            {
                projectID = goal.ItemID;
            }
            if (goal.GoalType == GoalTypeInfo.TypeEnum.Block)
            {
                BlockInfo block = DB.Blocks.GetBlock(goal.ItemID);
                projectID = block.ProjectID;
            }
            else if (goal.GoalType == GoalTypeInfo.TypeEnum.Segment)
            {
                SegmentInfo segment = DB.Segments.GetSegment(goal.ItemID);
                BlockInfo   block   = DB.Blocks.GetBlock(segment.BlockID);
                projectID = block.ProjectID;
            }

            if (projectID > 0)
            {
                project = DB.Projects.GetProject(projectID);
            }
            return(project);
        }
コード例 #4
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
        private float GetNormFactor(GoalInfo goal)
        {
            float weightGroup   = GetGroupWeight(goal.GroupID);
            float contrGroupMax = GetGroupContributionForAll(goal.GroupID, true, PerformanceNatureEnum.Normal);

            float weightedMax = weightGroup * 100;
            float nF          = weightedMax / contrGroupMax; // norm factor

            return(nF);
        }
コード例 #5
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
        public GoalInfo CloneGoal(GoalInfo goal, PeriodInfo newPeriod)
        {
            GoalInfo cloneGoal = (GoalInfo)((ICloneable)goal).Clone();

            cloneGoal.StartDate  = newPeriod.StartDate;
            cloneGoal.DueDate    = newPeriod.EndDate;
            cloneGoal.EndDate    = newPeriod.EndDate;
            cloneGoal.Definition = "CLONE --- " + goal.Definition;
            cloneGoal.Status     = DTC.StatusEnum.Running;
            cloneGoal.OwnerID    = DB.Owner.GetOwnerID(cloneGoal.Range, cloneGoal.StartDate);

            return(cloneGoal);
        }
コード例 #6
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
        /// <summary>
        /// This is the compact and sufficient method to get the overall contribution
        /// of a single goal, among a given "goals" dictionary. This method, also takes
        /// care of group weights, thus gives a complete contribution figure.
        /// </summary>
        /// <param name="goal">The goal of interest</param>
        /// <param name="goals">Goals dictionary. This method assumes that 'goals' dictionary contains 'goal' object.</param>
        /// <param name="isMax">True if you need the maximum contribution of the goal - if it's achieved</param>
        /// <returns>The contribution value of the goal.</returns>
        public float GetGoalContributionWeighted(GoalInfo goal, bool isMax, PerformanceNatureEnum performanceNature)
        {
            float nF = GetNormFactor(goal);

            if (isMax)
            {
                return(nF * GetGoalContributionForAll(goal, true, performanceNature));
            }
            else
            {
                return(nF * GetGoalContributionForAll(goal, false, performanceNature));
            }
        }
コード例 #7
0
ファイル: GoalExtensions.cs プロジェクト: Turnerj/RocketBot
        public static void Update(this Goal goal, GoalInfo partial)
        {
            goal.Team = partial.TeamNum;

            if (partial.Location.HasValue)
            {
                goal.Location = partial.Location.Value.ToNumerics();;
            }

            if (partial.Direction.HasValue)
            {
                goal.Direction = partial.Direction.Value.ToNumerics();
            }
        }
コード例 #8
0
        public FieldInfo(rlbot.flat.FieldInfo fieldInfo)
        {
            Goals     = new GoalInfo[fieldInfo.GoalsLength];
            BoostPads = new BoostPad[fieldInfo.BoostPadsLength];

            for (int i = 0; i < fieldInfo.GoalsLength; i++)
            {
                Goals[i] = new GoalInfo(fieldInfo.Goals(i).Value);
            }

            for (int i = 0; i < fieldInfo.BoostPadsLength; i++)
            {
                BoostPads[i] = new BoostPad(fieldInfo.BoostPads(i).Value);
            }
        }
コード例 #9
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
        /// <summary>
        /// This is the full complete method for getting a 'goal's grade contribution'.
        /// The grades of the goals within a GoalGroup sums up to 100,
        /// thus the grade contributions are given as integers.
        /// </summary>
        /// <param name="goal">The goal of interest</param>
        /// <param name="goals">The goals dictionary. The complete set of goals should be provided - not only the goals in the group.</param>
        /// <param name="isMax">The grade contribution of the goal</param>
        /// <returns></returns>
        public int GetGoalContributionGrade(GoalInfo goal, bool isMax, PerformanceNatureEnum performanceNature)
        {
            float nF              = GetNormFactor(goal);
            float contribution    = GetGoalContributionWeighted(goal, false, performanceNature);
            float contributionMax = GetGoalContributionWeighted(goal, true, performanceNature);
            float contrGroupMax   = GetGroupContributionForAll(goal.GroupID, true, performanceNature);

            if (isMax)
            {
                return((int)Math.Round(100 * contributionMax / (nF * contrGroupMax)));
            }
            else
            {
                return((int)Math.Round(100 * contribution / (nF * contrGroupMax)));
            }
        }
コード例 #10
0
    void BeginGoal(GoalInfo goalInfo)
    {
        if (efficiencyQuest != null)
        {
            efficiencyQuest.Delete();
        }

        for (int i = 0, len = goalInfo.machinesUnlockedAtStart.Length; i < len; ++i)
        {
            MachineUnlockSystem.instance.Unlock(goalInfo.machinesUnlockedAtStart[i]);
        }

        if (goalInfo.restrictLand)
        {
            foreach (LandParcel restrict in LandSystem.instance.landParcelSet)
            {
                if (restrict.flags == LandParcelFlags.Valid)
                {
                    restrict.flags = LandParcelFlags.Restricted;
                }
            }
        }

        if (goalInfo.createAddon)
        {
            Bounds3Int[]  spacePlatformBounds = AddonGen.Addon(goalInfo.addon);
            SpacePlatform spacePlatform       = new SpacePlatform();
            spacePlatform.save.bounds = spacePlatformBounds;
            spacePlatform.Initialize();
            OverviewCameraController.instance.MoveTo(spacePlatform.visual.floors[0].transform.position);
        }

        efficiencyQuest = new EfficiencyQuest
        {
            goalInfo = goalInfo
        };
        efficiencyQuest.Initialize();
    }
コード例 #11
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
        public float GetGoalContributionForAll(GoalInfo goal, bool isMax, PerformanceNatureEnum perfNature)
        {
            float goalSize = 0;

            if (isMax)
            {
                goalSize = (float)((int)goal.Size);
            }
            else
            {
                goalSize = GetGoalContributionSimple(goal, perfNature);
            }

            float totalSize = GetTotalSize();

            if (totalSize > 0)
            {
                return(100 * goalSize / totalSize);
            }
            else
            {
                return(0);
            }
        }
コード例 #12
0
        public async Task TestAcceptMessageGiveInfoForwardedShouldChangeBoardInfo()
        {
            // Arrange
            PlayerConfiguration              configuration = GenerateSampleConfiguration();
            BufferBlock <Message>            inputBuffer   = new BufferBlock <Message>();
            ISocketClient <Message, Message> client        = GenerateSocketClient();
            var player = new Models.Player(configuration, inputBuffer, client, logger);

            Message messageStart = CreateStartMessage();

            inputBuffer.Post(messageStart);
            await player.AcceptMessage(CancellationToken.None);

            int randomDistance1 = 7;
            int randomDistance2 = 0;

            (int y, int x) = player.Position;
            Position randomPosition1 = new Position {
                X = x + 1, Y = y + 2
            };
            Position randomPosition2 = new Position {
                X = x + 2, Y = y + 2
            };
            Position randomPosition3 = new Position {
                X = x + 2, Y = y + 1
            };

            int[]      distBoard = new int[playerBoardSize.Y * playerBoardSize.X];
            GoalInfo[] infoBoard = new GoalInfo[playerBoardSize.Y * playerBoardSize.X];
            for (int i = 0; i < distBoard.Length; i += playerBoardSize.X)
            {
                for (int j = 0; j < playerBoardSize.X; j++)
                {
                    distBoard[i + j] = randomDistance1;
                    infoBoard[i + j] = GoalInfo.IDK;
                }
            }
            distBoard[(randomPosition2.Y * playerBoardSize.X) + randomPosition2.X] = randomDistance2;
            infoBoard[(randomPosition3.Y * playerBoardSize.X) + randomPosition3.X] = GoalInfo.DiscoveredGoal;
            GiveInfoForwardedPayload payload = new GiveInfoForwardedPayload()
            {
                Distances = distBoard,
                RedTeamGoalAreaInformations  = infoBoard,
                BlueTeamGoalAreaInformations = infoBoard,
            };
            Message giveFwInfoMessage = new Message(MessageID.GiveInfoForwarded, agentID, payload);

            // Act
            inputBuffer.Post(giveFwInfoMessage);
            await player.AcceptMessage(CancellationToken.None);

            // Assert
            GoalInfo actualGoalInfo = player.Board[randomPosition3.Y, randomPosition3.X].GoalInfo;

            Assert.Equal(GoalInfo.DiscoveredGoal, actualGoalInfo);

            int actualDist1 = player.Board[randomPosition1.Y, randomPosition1.X].DistToPiece;

            Assert.Equal(randomDistance1, actualDist1);

            int actualDist2 = player.Board[randomPosition2.Y, randomPosition2.X].DistToPiece;

            Assert.Equal(randomDistance2, actualDist2);
        }
コード例 #13
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
        private float GetGoalContributionSimple(GoalInfo goal, PerformanceNatureEnum perfNature)
        {
            float okSize  = 0;
            float divider = 0;

            if (perfNature == PerformanceNatureEnum.Worst)
            {
                divider = 100;
            }
            else
            {
                divider = goal.GetDesiredPercentage(today);
            }

            float presentValue      = goal.GetPresentValue();
            float presentPercentage = goal.GetPresentPercentage();

            // we used to use pow2 in calculating the performance, this was a geometric penalty
            // for uncompleted goals, but it resulted a lack of motivation to start a task, so
            // we set it to 1
            // remove it after August 2010
            if (goal.Status == DTC.StatusEnum.Success)
            {
                okSize = (float)((int)goal.Size);
            }
            else if (goal.Status == DTC.StatusEnum.Running)
            {
                if (presentPercentage == 0)
                {
                    okSize = 0;
                }
                else
                {
                    if (presentPercentage > divider)
                    {
                        okSize = (float)((int)goal.Size);
                    }
                    else
                    {
                        if (goal.IsBlackAndWhite)
                        {
                            okSize = 0;
                        }
                        else
                        {
                            okSize = (float)((int)goal.Size)
                                     * (float)Math.Pow((double)(presentPercentage / divider), 1);
                        }
                    }
                }
            }
            else if (goal.Status == DTC.StatusEnum.Fail)
            {
                if (presentPercentage == 0)
                {
                    okSize = 0;
                }
                else
                {
                    if (presentPercentage > divider)
                    {
                        okSize = (float)((int)goal.Size);
                    }
                    else
                    {
                        if (goal.IsBlackAndWhite)
                        {
                            okSize = 0;
                        }
                        else
                        {
                            okSize = (float)((int)goal.Size)
                                     * (float)Math.Pow((double)(presentPercentage / divider), 1);
                        }
                    }
                }
            }

            return(okSize);
        }
コード例 #14
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
        public GoalInfo CloneGoal(GoalInfo goal)
        {
            PeriodInfo period = new PeriodInfo(goal.StartDate, goal.DueDate);

            return(CloneGoal(goal, period));
        }
コード例 #15
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
 public void CloneGoalToDB(GoalInfo goal, PeriodInfo newPeriod)
 {
     DB.Goals.AddGoal(CloneGoal(goal, newPeriod));
 }