Ejemplo n.º 1
0
        public static float ProgramRunner(World cWorld, BaseProgram progEvaulateProgram,
                                          Graphics grpGraphics, bool fDisplayProgress)
        {
            // Reset the variables of all the programs.
            for (int i = 0; i < progEvaulateProgram.Variables.Length; i++)
            {
                progEvaulateProgram.Variables[i].Value = 0;
            }

            ImprovedRandom rndRandom = GlobalRandom.m_rndRandom;
            bool           fFoundGoodPlayerPosition = false;
            float          dPlayerInitialPositionX  = 0;
            float          dPlayerInitialPositionY  = 0;

            while (fFoundGoodPlayerPosition == false)
            {
                dPlayerInitialPositionX = rndRandom.Next(0, cWorld.GetWorldWidth());
                dPlayerInitialPositionY = rndRandom.Next(0, cWorld.GetWorldHeight());
                if (cWorld.CheckIfPositionIsBlocked(new PointF(dPlayerInitialPositionX, dPlayerInitialPositionY)) == false)
                {
                    fFoundGoodPlayerPosition = true;
                }
            }

            Runner cRunner = new Runner(new PointF(dPlayerInitialPositionX, dPlayerInitialPositionY));
            float  dTotalPassedDistnace = 0;

            // Running the matrix players.
            int nNumberOfIterations = 100;

            if (fDisplayProgress == true)
            {
                nNumberOfIterations = 200;
            }

            int nNumOfTimesPlayerHadDistanceZero = 0;
            int nNumOfTimesPlayerWasBlocked      = 1;

            for (int i = 0; i < nNumberOfIterations; i++)
            {
                if (fDisplayProgress == true)
                {
                    DisplayWorld(cWorld, cRunner, grpGraphics);
                    Thread.Sleep(30);
                }

                PointF pntLastRunnerPosition = cRunner.GetPosition();

                progEvaulateProgram.Run(cRunner);
                cRunner.RunTimestep(cWorld);
                PointF pntCurrRunnerPosition = cRunner.GetPosition();
                float  dPassedDistnace       = new Vector(pntLastRunnerPosition, pntCurrRunnerPosition).Distance();

                // If the player did not move, it's gonna cost him.
                if (dPassedDistnace == 0f)
                {
                    nNumOfTimesPlayerHadDistanceZero++;
                }

                if (cRunner.WasBlockedThisTurn() == true)
                {
                    nNumOfTimesPlayerWasBlocked++;
                }

                dTotalPassedDistnace += dPassedDistnace;
            }

            //dTotalPassedDistnace *= (1 - ((float)nNumOfTimesPlayerHadDistanceZero / nNumberOfIterations));
            float dDivision = nNumOfTimesPlayerWasBlocked;

            dTotalPassedDistnace /= dDivision;

            return(dTotalPassedDistnace);
        }
Ejemplo n.º 2
0
            public override float action(Node[] arrNodes, TreeLanguageEvolute.TreeProgram progOwner)
            {
                Runner cRunner = ((Runner)progOwner.AdditionalInformation);

                return(cRunner.GetSpeed());
            }