public override void Update(TimeSpan elapsedGameTime) { if (circleInfo[0] > 0 && circleInfo[1] > 0) { pointToTarget = walker.hasReached(pointToTarget, circleInfo[0], circleInfo[1], collectiblesInfo.Length / 2); SetAction(walker.WalkToPoint(pointToTarget, circleInfo[2], circleInfo[0], circleInfo[1], circleInfo[4])); } }
public CircleWalkingPoint hasReached(CircleWalkingPoint wp, float x, float y, int numberOfCollectibles) { if (Math.Abs(x - wp.XCoordinate) < 50 && Math.Abs(y - wp.YCoordinate) < 50) { if (numberOfCollectibles <= wp.Collectibles) { if (!(currentWalkingPoint + 1 >= walkingPoints.Count)) { 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)) { CircleWalkingPoint aux = (CircleWalkingPoint)walkingPoints[currentWalkingPoint + 1]; if (x < aux.Obs.maxWidth() && x > aux.Obs.minWidth() && y < aux.Obs.maxHeight()) { if (numberOfCollectibles >= aux.Collectibles) { currentWalkingPoint++; currentPathPosition++; } } } } } } return((CircleWalkingPoint)walkingPoints[currentWalkingPoint]); }
private Moves normalWalk(CircleWalkingPoint wp, float v, float x, float y) { if (wp.XCoordinate < x) { if (x - wp.XCoordinate < 150) { if (Math.Abs(v) > 25) { return(controller.calculateAction(x, Math.Abs(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.ROLL_LEFT); } } else { return(Moves.ROLL_LEFT); } } else { if (wp.XCoordinate - x < 150) { if (Math.Abs(v) > 25) { 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.ROLL_RIGHT); } } else { return(Moves.ROLL_RIGHT); } } }
public Moves WalkToPoint(CircleWalkingPoint wp, float v, float x, float y, float agentSize) { Point p = (Point)path.path[currentPathPosition]; if (currentPathPosition == 1) { firstPointX = x; } if (p.ToPlatform) { float limit = Math.Abs(wp.YCoordinate - y) * (Math.Abs(v) / Math.Abs(wp.XCoordinate - x)); if (wp.Obs.maxWidth() - wp.Obs.minWidth() < 400) { limit += ((wp.Obs.maxWidth() - wp.Obs.minWidth()) / 400) * 50; } if (limit < 100) { limit = 100; } bool isRightJump = false; bool isLeftJump = false; float aux = 0; if (currentPathPosition <= 1) { aux = firstPointX; } else { aux = ((Point)path.path[currentPathPosition - 1]).x; } if (aux > p.x) { isRightJump = true; } else { isLeftJump = true; } if (Math.Abs(wp.XCoordinate - x) <= limit) { if ((isRightJump && x > wp.XCoordinate && v < 0) || (isLeftJump && x < wp.XCoordinate && v > 0)) { return(Moves.JUMP); } else { return(normalWalk(wp, v, x, y)); } } else { return(normalWalk(wp, v, x, y)); } } else if (p.DiamondAbove) { if (Math.Abs(wp.XCoordinate - x) < 80) { return(Moves.JUMP); } else { return(normalWalk(wp, v, x, y)); } } else if (p.Fall || p.FallGap) { if (Math.Abs(wp.XCoordinate - x) < 200) { return(normalWalk(wp, v, x, y)); } else { if (x < wp.XCoordinate) { return(Moves.ROLL_RIGHT); } else { return(Moves.ROLL_LEFT); } } } else if (p.StartGap) { if (Math.Abs(wp.XCoordinate - x) < 100 && Math.Abs(v) > 20) { return(Moves.JUMP); } else { return(normalWalk(wp, v, x, y)); } } else if (p.Gap) { currentPathPosition++; return(Moves.NO_ACTION); } else if (p.TurningPoint) { if (Math.Abs(wp.XCoordinate - x) < 100) { return(normalWalk(wp, v, x, y)); } else { if (x < wp.XCoordinate) { return(Moves.ROLL_RIGHT); } else { return(Moves.ROLL_LEFT); } } } else { if (Math.Abs(wp.XCoordinate - x) < 100) { return(normalWalk(wp, v, x, y)); } else { if (x < wp.XCoordinate) { return(Moves.ROLL_RIGHT); } else { return(Moves.ROLL_LEFT); } } } }
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; // 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, 0); 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 (cI[0] > 0 && cI[1] > 0) { State root = new State(cI[2], cI[3], cI[0], cI[1], -1, collectibles, new ArrayList()); root.setSizeOfAgent(80); CircleValidator validator = new CircleValidator(); CircleTactics tactics = new CircleTactics(); Obstacles.Obstacle o = domain.AllObstacles.getNextPlatform(root); root.CurrentPlatform = o; root.setPosY(root.CurrentPlatform.maxHeight() - root.getSizeOfAgent() / 2); CircleGFRRT gfrrt = new CircleGFRRT(root, domain, 10000000, validator, tactics); plays = gfrrt.run(); walker = new CircleWalker(plays); pointToTarget = walker.getFirstPoint(); DebugSensorsInfo(); //p.Print(); } }