public override void Update(TimeSpan elapsedGameTime) { if (rectangleInfo[0] > 0 && rectangleInfo[1] > 0) { SetAction(walker.WalkToPoint(pointToTarget, rectangleInfo[2], rectangleInfo[0], rectangleInfo[1], rectangleInfo[4])); pointToTarget = walker.hasReached(pointToTarget, rectangleInfo[0], rectangleInfo[1], collectiblesInfo.Length / 2, rectangleInfo[4]); } }
public Moves WalkToPoint(RectangleWalkingPoint wp, float v, float x, float y, float agentSize) { Point p = (Point)path.path[currentPathPosition]; float sizeOfAgent = 0; if (wp.yCondition) // Special Condition for Morph { sizeOfAgent = agentSize; } else { sizeOfAgent = 1000; } if (Math.Abs(x - wp.XCoordinate) < wp.distanceToMorph && Math.Abs(agentSize - p.Size) > wp.errorSize && Math.Abs(v) < wp.minVelocity && Math.Abs(y - wp.YCoordinate) < sizeOfAgent / 2) { if (agentSize > p.Size) { return(Moves.MORPH_DOWN); } else { return(Moves.MORPH_UP); } } else { Moves act; if ((act = gainBalance(wp.XCoordinate, x, v, p.Size, agentSize)) != 0) { return(act); } if (Math.Abs(wp.XCoordinate - x) < wp.distanceToMorph) { return(normalWalk(wp, v, x, y, wp.distanceToMorph)); } else { if (p.FallGap) // Special Condition for FallGap { if (agentSize > 60) { return(Moves.MORPH_DOWN); } } if (x < wp.XCoordinate) { return(Moves.MOVE_RIGHT); } else { return(Moves.MOVE_LEFT); } } } }
private Moves normalWalk(RectangleWalkingPoint wp, float v, float x, float y, float distanceForController) { if (wp.XCoordinate < x && v > 0) { return(Moves.MOVE_LEFT); } if (wp.XCoordinate > x && v < 0) { return(Moves.MOVE_RIGHT); } if (wp.XCoordinate < x) { if (x - wp.XCoordinate < distanceForController) { if (Math.Abs(v) > 10) { return(controller.calculateAction(x, v, wp.Velocity, 0, 0.1F)); // 0.1 value for step is a placeholder, must be replaced with the real time value } else { return(Moves.MOVE_LEFT); } } else { return(Moves.MOVE_LEFT); } } else { if (wp.XCoordinate - x < distanceForController) { if (Math.Abs(v) > 10) { return(controller.calculateAction(x, v, wp.Velocity, 1, 0.1F)); // 0.1 value for step is a placeholder, must be replaced with the real time value } else { return(Moves.MOVE_RIGHT); } } else { return(Moves.MOVE_RIGHT); } } }
public RectangleWalkingPoint hasReached(RectangleWalkingPoint wp, float x, float y, int numberOfCollectibles, float sizeOfAgent) { Point p = (Point)path.path[currentPathPosition]; float threshold = getWidth(sizeOfAgent); if (threshold > 96) { threshold = 10; } if (p.Morph && !p.StartGap && !p.Tilt && !p.TurningPoint && !p.Gap && !p.DiamondAbove && !p.FallGap && !p.Fall) { if (Math.Abs(sizeOfAgent - p.Size) < 8) { currentWalkingPoint++; currentPathPosition++; } } else if (p.Fall || p.FallGap) { if (y > wp.YCoordinate - 32) { if (numberOfCollectibles <= wp.Collectibles) { if (!(currentWalkingPoint + 1 >= walkingPoints.Count)) { currentWalkingPoint++; currentPathPosition++; } } } } else if (Math.Abs(x - wp.XCoordinate) < getWidth(sizeOfAgent) / 2 && Math.Abs(y - wp.YCoordinate) < sizeOfAgent / 2) { if (numberOfCollectibles <= wp.Collectibles) { if (!(currentWalkingPoint + 1 >= walkingPoints.Count)) { if (p.Morph) { if (Math.Abs(sizeOfAgent - p.Size) < 10) { currentWalkingPoint++; currentPathPosition++; } } else { currentWalkingPoint++; currentPathPosition++; } } } } else if (numberOfCollectibles <= wp.Collectibles) { if (x < wp.Obs.maxWidth() && x > wp.Obs.minWidth()) { if (Math.Abs(y - wp.YCoordinate) < 100) { if (!(currentWalkingPoint + 1 >= walkingPoints.Count)) { RectangleWalkingPoint aux = (RectangleWalkingPoint)walkingPoints[currentWalkingPoint + 1]; if (x < aux.Obs.maxWidth() && x > aux.Obs.minWidth() && y < aux.Obs.maxHeight() && Math.Abs(y - aux.Obs.maxHeight()) < 98) { if (numberOfCollectibles >= aux.Collectibles) { currentWalkingPoint++; currentPathPosition++; } } } } } } return((RectangleWalkingPoint)walkingPoints[currentWalkingPoint]); }
public void DeprecatedSetup(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; TableMaker tmaker = new TableMaker(nI, oI, sPI, cPI, colI); tmaker.makeTable(); //tmaker.printTable(); // 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++; } InfoDomain domain = new InfoDomain(nI, sI, cI, oI, sPI, cPI, colI, timeLimit, 1); TableMaker table = new TableMaker(nI, oI, sPI, cPI, colI); table.makeTable(); domain.Table = table.Table; ArrayList collectibles = new ArrayList(); temp = 1; while (temp <= nI[3]) { collectibles.Add(colI[(temp * 2) - 2]); collectibles.Add(colI[(temp * 2) - 1]); temp++; } if (sI[0] > 0 && sI[1] > 0) { State root = new State(sI[2], sI[3], sI[0], sI[1], -1, collectibles, new ArrayList()); root.setSizeOfAgent(96); RectangleValidator validator = new RectangleValidator(); RectangleTactics tactics = new RectangleTactics(); Obstacles.Obstacle o = domain.AllObstacles.getNextPlatform(root); root.CurrentPlatform = o; root.setPosY(root.CurrentPlatform.maxHeight() - root.getSizeOfAgent() / 2); RectangleGFRRT gfrrt = new RectangleGFRRT(root, domain, 10000000, validator, tactics); plays = gfrrt.run(); // Begin walking test walker = new RectangleWalker(plays); pointToTarget = walker.getFirstPoint(); // End walking test DebugSensorsInfo(); } }