Exemple #1
0
        public void SensorsUpdated(int nC, float[] sI, float[] cI, float[] colI)
        {
            int temp;

            nCollectiblesLeft = nC;

            rectangleInfo[0] = sI[0];
            rectangleInfo[1] = sI[1];
            rectangleInfo[2] = sI[2];
            rectangleInfo[3] = sI[3];
            rectangleInfo[4] = sI[4];

            this.CurrentRectangle = new RectangleCharacter(this.Model, rectangleInfo[0], rectangleInfo[1], sI[4]);

            circleInfo[0] = cI[0];
            circleInfo[1] = cI[1];
            circleInfo[2] = cI[2];
            circleInfo[3] = cI[3];
            circleInfo[4] = cI[4];

            Array.Resize(ref collectiblesInfo, (nCollectiblesLeft * 2));

            temp = 1;
            while (temp <= nCollectiblesLeft)
            {
                collectiblesInfo[(temp * 2) - 2] = colI[(temp * 2) - 2];
                collectiblesInfo[(temp * 2) - 1] = colI[(temp * 2) - 1];

                temp++;
            }


            //  ConsolePrinter.PrintLine(sI[4].ToString());
        }
Exemple #2
0
 public DecisionMakingProcess(WorldModel WM) : base(WM)
 {
     this.AStar  = new NodeArrayAStarPathFinding(WM, new ZeroHeuristic());
     this.Manual = new InstructionManualProcessor(WM);
     this.CurrentConnectionID = -1;
     this.CurrentActionID     = -1;
     this.CurrentRectangle    = WM.Character;
     this.CurrentSolution     = new int[0];
 }
Exemple #3
0
        public int GetNextAction(RectangleCharacter cube)
        {
            if ((cube.Equals(CurrentRectangle) && this.CurrentConnectionID != -1) ||
                (((this.CurrentConnectionID != -1) && (this.CurrentActionID >= this.CurrentSolution.Length - 1) && !isOutConn(this.WM.Path[this.CurrentConnectionID]) && !isOnGoal())))
            {
                ConsolePrinter.PrintLine("Improvise");
                this.calculateNewAction();
            }

            this.CurrentRectangle = cube;

            if ((this.CurrentConnectionID != -1) && isOnGoal())
            {
                this.Manual.Update(this.WM.Path[this.CurrentConnectionID], getSolution());
                this.CurrentConnectionID++;
                this.ResetSolution();

                ConsolePrinter.PrintLine("Follow");
            }

            if (this.CurrentConnectionID == -1 || this.isOutPath())
            {
                this.AStar.InitializePathfindingSearch(this.CurrentRectangle);

                if (this.AStar.InProgress)
                {
                    if (this.AStar.Search())
                    {
                        this.CurrentConnectionID = 0;
                        this.ResetSolution();
                        ConsolePrinter.PrintLine("Search");
                    }
                }
            }

            this.CurrentActionID++;

            /*  if ((this.CurrentActionID >= this.CurrentSolution.Length - 1))
             * {
             *
             *    ConsolePrinter.PrintLine("Improvise a lot");
             *    this.calculateNewAction();
             * }*/


            ConsolePrinter.PrintLine("ActionID: " + this.CurrentActionID);
            ConsolePrinter.PrintLine("Action  : " + this.CurrentSolution[this.CurrentActionID]);
            return(this.CurrentSolution[this.CurrentActionID]);
        }
Exemple #4
0
        public void InitializePathfindingSearch(RectangleCharacter startPosition)
        {
            Point initp = new Point(WM, WM.Character.xPos, WM.Character.yPos);
            Point aux   = new Point(WM, 9999, 9999);
            float dist  = 99999999999;

            foreach (Point p in WM.Mesh)
            {
                float auxd = initp.DistanceTo(p);
                if (auxd <= dist)
                {
                    aux  = p;
                    dist = auxd;
                }
            }
            Connection c = new Connection(WM, initp, aux);

            c.categorie = c.SLIDEONPLATFORM;
            initp.addConnection(c);
            NodeRecord nri = new NodeRecord();

            nri.node   = initp;
            nri.gValue = 0;
            nri.hValue = 0;
            nri.fValue = 0;
            nri.Points = 0;
            var bestNode = nri;

            this.StartNode = initp;



            this.InProgress          = true;
            this.TotalProcessedNodes = 0;
            this.MaxOpenNodes        = 0;


            this.Open.Initialize();

            this.Open.AddToOpen(bestNode);
            this.Closed.Initialize();
        }
Exemple #5
0
        public void Setup(int[] nI, float[] sI, float[] cI, float[] oI, float[] sPI, float[] cPI, float[] colI, Rectangle area, double timeLimit)
        {
            // Time limit is the time limit of the level - if negative then there is no time constrains
            this.area = area;
            int temp;

            // numbersInfo[] Description
            //
            // Index - Information
            //
            //   0   - Number of Obstacles
            //   1   - Number of Rectangle Platforms
            //   2   - Number of Circle Platforms
            //   3   - Number of Collectibles

            numbersInfo = new int[4];
            int i;

            for (i = 0; i < nI.Length; i++)
            {
                numbersInfo[i] = nI[i];
            }

            nCollectiblesLeft = nI[3];

            // rectangleInfo[] Description
            //
            // Index - Information
            //
            //   0   - Rectangle X Position
            //   1   - Rectangle Y Position
            //   2   - Rectangle X Velocity
            //   3   - Rectangle Y Velocity
            //   4   - Rectangle Height

            rectangleInfo = new float[5];

            rectangleInfo[0] = sI[0];
            rectangleInfo[1] = sI[1];
            rectangleInfo[2] = sI[2];
            rectangleInfo[3] = sI[3];
            rectangleInfo[4] = sI[4];

            // circleInfo[] Description
            //
            // Index - Information
            //
            //   0  - Circle X Position
            //   1  - Circle Y Position
            //   2  - Circle X Velocity
            //   3  - Circle Y Velocity
            //   4  - Circle Radius

            circleInfo = new float[5];

            circleInfo[0] = cI[0];
            circleInfo[1] = cI[1];
            circleInfo[2] = cI[2];
            circleInfo[3] = cI[3];
            circleInfo[4] = cI[4];


            // Obstacles and Platforms Info Description
            //
            //  X = Center X Coordinate
            //  Y = Center Y Coordinate
            //
            //  H = Platform Height
            //  W = Platform Width
            //
            //  Position (X=0,Y=0) = Left Superior Corner

            // obstaclesInfo[] Description
            //
            // Index - Information
            //
            // If (Number of Obstacles > 0)
            //  [0 ; (NumObstacles * 4) - 1]      - Obstacles' info [X,Y,H,W]
            // Else
            //   0                                - 0
            //   1                                - 0
            //   2                                - 0
            //   3                                - 0

            if (numbersInfo[0] > 0)
            {
                obstaclesInfo = new float[numbersInfo[0] * 4];
            }
            else
            {
                obstaclesInfo = new float[4];
            }

            temp = 1;
            if (nI[0] > 0)
            {
                while (temp <= nI[0])
                {
                    obstaclesInfo[(temp * 4) - 4] = oI[(temp * 4) - 4];
                    obstaclesInfo[(temp * 4) - 3] = oI[(temp * 4) - 3];
                    obstaclesInfo[(temp * 4) - 2] = oI[(temp * 4) - 2];
                    obstaclesInfo[(temp * 4) - 1] = oI[(temp * 4) - 1];
                    temp++;
                }
            }
            else
            {
                obstaclesInfo[0] = oI[0];
                obstaclesInfo[1] = oI[1];
                obstaclesInfo[2] = oI[2];
                obstaclesInfo[3] = oI[3];
            }

            // rectanglePlatformsInfo[] Description
            //
            // Index - Information
            //
            // If (Number of Rectangle Platforms > 0)
            //  [0; (numRectanglePlatforms * 4) - 1]   - Rectangle Platforms' info [X,Y,H,W]
            // Else
            //   0                                  - 0
            //   1                                  - 0
            //   2                                  - 0
            //   3                                  - 0

            if (numbersInfo[1] > 0)
            {
                rectanglePlatformsInfo = new float[numbersInfo[1] * 4];
            }
            else
            {
                rectanglePlatformsInfo = new float[4];
            }

            temp = 1;
            if (nI[1] > 0)
            {
                while (temp <= nI[1])
                {
                    rectanglePlatformsInfo[(temp * 4) - 4] = sPI[(temp * 4) - 4];
                    rectanglePlatformsInfo[(temp * 4) - 3] = sPI[(temp * 4) - 3];
                    rectanglePlatformsInfo[(temp * 4) - 2] = sPI[(temp * 4) - 2];
                    rectanglePlatformsInfo[(temp * 4) - 1] = sPI[(temp * 4) - 1];
                    temp++;
                }
            }
            else
            {
                rectanglePlatformsInfo[0] = sPI[0];
                rectanglePlatformsInfo[1] = sPI[1];
                rectanglePlatformsInfo[2] = sPI[2];
                rectanglePlatformsInfo[3] = sPI[3];
            }

            // circlePlatformsInfo[] Description
            //
            // Index - Information
            //
            // If (Number of Circle Platforms > 0)
            //  [0; (numCirclePlatforms * 4) - 1]   - Circle Platforms' info [X,Y,H,W]
            // Else
            //   0                                  - 0
            //   1                                  - 0
            //   2                                  - 0
            //   3                                  - 0

            if (numbersInfo[2] > 0)
            {
                circlePlatformsInfo = new float[numbersInfo[2] * 4];
            }
            else
            {
                circlePlatformsInfo = new float[4];
            }

            temp = 1;
            if (nI[2] > 0)
            {
                while (temp <= nI[2])
                {
                    circlePlatformsInfo[(temp * 4) - 4] = cPI[(temp * 4) - 4];
                    circlePlatformsInfo[(temp * 4) - 3] = cPI[(temp * 4) - 3];
                    circlePlatformsInfo[(temp * 4) - 2] = cPI[(temp * 4) - 2];
                    circlePlatformsInfo[(temp * 4) - 1] = cPI[(temp * 4) - 1];
                    temp++;
                }
            }
            else
            {
                circlePlatformsInfo[0] = cPI[0];
                circlePlatformsInfo[1] = cPI[1];
                circlePlatformsInfo[2] = cPI[2];
                circlePlatformsInfo[3] = cPI[3];
            }

            //Collectibles' To Catch Coordinates (X,Y)
            //
            //  [0; (numCollectibles * 2) - 1]   - Collectibles' Coordinates (X,Y)

            collectiblesInfo = new float[numbersInfo[3] * 2];

            temp = 1;
            while (temp <= nI[3])
            {
                collectiblesInfo[(temp * 2) - 2] = colI[(temp * 2) - 2];
                collectiblesInfo[(temp * 2) - 1] = colI[(temp * 2) - 1];

                temp++;
            }


            this.Model                   = new WorldModel(nI, sI, cI, oI, sPI, cPI, colI, area);
            this.CurrentRectangle        = this.Model.Character;
            this.CurrentRectangle.heigth = sI[4];
            this.PdA = new ProblemDectectionAlgorithm(this.Model);

            this.PdA.GeneratePoints();
            this.PdA.GenerateConnections();

            this.DMP = new DecisionMakingProcess(this.Model);

            DebugSensorsInfo();
        }