public void updateRectanglePosition(RectangleRepresentation rI) { int rectangleX = (int)rI.X; int rectangleY = (int)rI.Y; this.rectangleNode.location = new Point(rectangleX, rectangleY); }
public override void SensorsUpdated(int nC, RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI) { DeprecatedSensorsUpdated(nC, rI.ToArray(), cI.ToArray(), CollectibleRepresentation.RepresentationArrayToFloatArray(colI)); }
public override void Setup(CountInformation nI, RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area, double timeLimit) { base.Setup(nI, rI, cI, oI, rPI, cPI, colI, area, timeLimit); actionStatesCircle[currentStateCircle].Setup(nI, rI, cI, oI, rPI, cPI, colI, area, timeLimit); actionStatesRectangle[currentStateRectangle].Setup(nI, rI, cI, oI, rPI, cPI, colI, area, timeLimit); }
public void SensorsUpdated(RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI) { if (!finished) { if (!actionRules[currentAction].isFinished() && (currentRuleTime.TotalSeconds < 30 || currentAction == actionRules.Count)) { actionRules[currentAction].SensorsUpdate(rI, cI, colI); } else { currentAction++; finished = (currentAction >= actionRules.Count); if (currentRuleTime.TotalSeconds >= 30) { actionRules.Add(actionRules[currentAction - 1]); } currentRuleTime = new TimeSpan(0); if (!finished) { actionRules[currentAction].Setup(nI, rI, cI, oI, rPI, cPI, colI, area, 100.0); } } } }
/// <summary> /// Generates matrix describing the level and runs A star to find paths to every diamond /// </summary> private void runAStar(RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area) { // create game matrix this.matrix = Matrix.generateMatrixFomGameInfo(rI, cI, oI, rPI, cPI, colI, area); // create node graph this.graph = new Graph(this.type, this.matrix); this.graph.generateNodes(rI, cI, oI, rPI, cPI, colI, this.type); this.graph.generateAdjacencyMatrix(this.matrix); for (int i = 0; i < this.graph.diamondNodes.Count; i++) // find shortest path to every node { SearchParameters searchParameters = new SearchParameters(this.graph.rectangleNode.index, this.graph.diamondNodes[i].index, this.graph); PathFinder pathFinder = new PathFinder(searchParameters, this.type); Path knownPath = pathFinder.FindPath(); if (knownPath != null) { System.Diagnostics.Debug.WriteLine("A* found a path between: [" + searchParameters.startNode + " and " + searchParameters.endNode + "."); this.graph.knownPaths.Add(knownPath); } else { System.Diagnostics.Debug.WriteLine("A* did NOT find a path between: [" + searchParameters.startNode + " and " + searchParameters.endNode + "."); } } }
//implements abstract rectangle interface: registers updates from the agent's sensors that it is up to date with the latest environment information public override void SensorsUpdated(int nC, RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI) { nCollectiblesLeft = nC; rectangleInfo = rI; circleInfo = cI; collectiblesInfo = colI; }
/********************************************************************************************/ /********************************************************************************************/ /*** ***/ /*** MAIN SETUP ***/ /*** ***/ /********************************************************************************************/ /********************************************************************************************/ //implements abstract rectangle interface: used to setup the initial information so that the agent has basic knowledge about the level public void Setup(CountInformation nI, RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area, double timeLimit) { ground = new Platform(0, area.Bottom, 0, 0, PlatformType.Black); utils = new Utils(ground, circleInfo.Radius, area); numbersInfo = nI; nCollectiblesLeft = nI.CollectiblesCount; rectangleInfo = rI; circleInfo = cI; obstaclesInfo = utils.joinObstacles(oI, rPI); rectanglePlatformsInfo = rPI; circlePlatformsInfo = cPI; collectiblesInfo = colI; uncaughtCollectibles = new List <CollectibleRepresentation>(collectiblesInfo); this.area = area; gSpeed = 1.0f; goalMode = GoalType.FirstPossible; //setup level layout levelLayout = utils.getLevelLayout(obstaclesInfo, area); //calculates the area of the rectangle since only the info of the height is available rectangleArea = utils.setRectangleArea(rectangleInfo.Height); //gets the initial position of the Rectangle to test is the game has started or is still at the menu previousRectanglePosX = rectangleInfo.X; previousRectanglePosY = rectangleInfo.Y; Platforms = utils.setupPlatforms(obstaclesInfo, rPI, cPI); Diamonds = utils.setupDiamonds(collectiblesInfo, levelLayout); /*************TESTS*************/ //inform a level has started utils.writeStart(1); //search - state - original; action - original; no partial plans //RRT = new RRTUtilsGS(actionTime, simTime, simTimeFinish, getPossibleMoves(), type, area, collectiblesInfo.Length, RRTTypes.Original, RRTTypes.Original, obstaclesInfo, gSpeed, Diamonds, Platforms, utils, false, false); //search - state - original; action - STP; biasSTP - 0.25/0.5/0.75; no partial plans //RRT = new RRTUtils(actionTime, simTime, simTimeFinish, getPossibleMoves(), type, area, collectiblesInfo.Length, RRTTypes.Original, RRTTypes.STP, obstaclesInfo, gSpeed, Diamonds, Platforms, utils, false, false); //search - state - bias - 0.25/0.50/0.75; action - STP; biasSTP; no partial plans //RRT = new RRTUtils(actionTime, simTime, simTimeFinish, getPossibleMoves(), type, area, collectiblesInfo.Length, RRTTypes.Bias, RRTTypes.STP, obstaclesInfo, gSpeed, Diamonds, Platforms, utils, false, false); //search - state - bgt - 10/50/10; action - STP; biasSTP; no partial plans //RRT = new RRTUtils(actionTime, simTime, simTimeFinish, getPossibleMoves(), type, area, collectiblesInfo.Length, RRTTypes.BGT, RRTTypes.STP, obstaclesInfo, gSpeed, Diamonds, Platforms, utils, false, false); //search - state - bgt zoom - 50; action - STP; biasSTP; no partial plans //RRT = new RRTUtils(actionTime, simTime, simTimeFinish, getPossibleMoves(), type, area, collectiblesInfo.Length, RRTTypes.BGTAreaBias, RRTTypes.STP, obstaclesInfo, gSpeed, Diamonds, Platforms, utils, false, false); //search - state - bgt bias - 50; action - STP; biasSTP; no partial plans //RRT = new RRTUtils(actionTime, simTime, simTimeFinish, getPossibleMoves(), type, area, collectiblesInfo.Length, RRTTypes.BGTBias, RRTTypes.STP, obstaclesInfo, gSpeed, Diamonds, Platforms, utils, false, false); //search - state - zoom; action - STP; biasSTP; no partial plans //RRT = new RRTUtils(actionTime, simTime, simTimeFinish, getPossibleMoves(), type, area, collectiblesInfo.Length, RRTTypes.AreaBias, RRTTypes.STP, obstaclesInfo, gSpeed, Diamonds, Platforms, utils, false, false); /*************FINAL*************/ RRT = new RRTUtilsGS(actionTime, simTime, simTimeFinish, getPossibleMoves(), type, area, collectiblesInfo.Length, RRTTypes.BGT, RRTTypes.STP, obstaclesInfo, gSpeed, Diamonds, Platforms, utils, true, true); //RRT = new RRTUtils(actionTime, simTime, simTimeFinish, getPossibleMoves(), type, area, collectiblesInfo.Length, RRTTypes.BGT, RRTTypes.Original, obstaclesInfo, gSpeed, Diamonds, Platforms, utils, false, false); RRT.setRadius(rectangleInfo.Height / 2); pathPlan = new PathPlan(cutplan, colI.GetLength(0), utils); controller = new RectangleController(gSpeed, utils); }
/// <summary> /// Updates the position of the rectangle and circle on the Matrix. Diamonds are disregarded becaus ethey make no difference in collisions. /// </summary> public void updateMatrix(RectangleRepresentation rI, CircleRepresentation cI) { // 'Clean' every space occupied by rectangle or circle for (int i = 0; i < this.pixels.GetLength(0); i++) { for (int j = 0; j < this.pixels.GetLength(1); j++) { Pixel currentPixel = this.getPixel(i, j); if (currentPixel.type == Pixel.Type.Rectangle || currentPixel.type == Pixel.Type.Circle || currentPixel.type == Pixel.Type.Diamond) { currentPixel.type = Pixel.Type.Space; } } } int rectangleX = (int)rI.X; int rectangleY = (int)rI.Y; int rectangleHeight = (int)rI.Height; // TODO: calculate width from height int rectangleWidth = (int)Utils.getRectangleWidth(rectangleHeight); int circleX = (int)cI.X; int circleY = (int)cI.Y; int circleRadius = (int)cI.Radius - 20; // RECTANGLE update for (int x = rectangleX - rectangleWidth / 2; x < rectangleX + rectangleWidth / 2; x++) { for (int y = rectangleY - rectangleHeight / 2; y < rectangleY + rectangleHeight / 2; y++) { if (!this.inBounds(x, y)) // x and y out of bounds { continue; } else { this.getPixel(x, y).type = Pixel.Type.Rectangle; } } } // CIRCLE update for (int x = circleX - circleRadius / 2; x < circleX + circleRadius / 2; x++) { for (int y = circleY - circleRadius / 2; y < circleY + circleRadius / 2; y++) { if (!this.inBounds(x, y)) // x and y out of bounds { continue; } else { this.getPixel(x, y).type = Pixel.Type.Circle; } } } }
//implements abstract rectangle interface: registers updates from the agent's sensors that it is up to date with the latest environment information /*WARNING: this method is called independently from the agent update - Update(TimeSpan elapsedGameTime) - so care should be taken when using complex * structures that are modified in both (e.g. see operation on the "remaining" collection) */ public override void SensorsUpdated(int nC, RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI) { if (gameMode == 0) { singlePlayer.SensorsUpdated(nC, rI, cI, colI); } else { multiPlayer.SensorsUpdated(nC, rI, cI, colI); } }
public virtual void Setup(CountInformation nI, RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area, double timeLimit) { this.nI = nI; this.rI = rI; this.cI = cI; this.oI = oI; this.rPI = rPI; this.cPI = cPI; this.colI = colI; this.area = area; }
public override void SensorsUpdate(RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI) { if (!isFinished() && Math.Abs(cI.X - objectiveDiamond[0].X) < 5 && Math.Abs(cI.Y - objectiveDiamond[0].Y) < 5) { setFinished(); objectiveDiamond = new CollectibleRepresentation[0]; } singleplayer.SensorsUpdated(objectiveDiamond.Length, rI, cI, objectiveDiamond); }
private void updateAStar(RectangleRepresentation rI, CircleRepresentation cI) { this.matrix.updateMatrix(rI, cI); this.graph.updateGraph(rI, cI); if (nextDiamondIndex != -1) { SearchParameters searchParameters = new SearchParameters(this.graph.rectangleNode.index, this.graph.diamondNodes[nextDiamondIndex].index, this.graph); PathFinder pathFinder = new PathFinder(searchParameters, this.type); this.nextDiamondPath = pathFinder.FindPath(); } }
//implements abstract circle interface: registers updates from the agent's sensors that it is up to date with the latest environment information /*WARNING: this method is called independently from the agent update - Update(TimeSpan elapsedGameTime) - so care should be taken when using complex * structures that are modified in both (e.g. see operation on the "remaining" collection) */ public override void SensorsUpdated(int nC, RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI) { nCollectiblesLeft = nC; rectangleInfo = rI; circleInfo = cI; collectiblesInfo = colI; lock (remaining) { remaining = new List <CollectibleRepresentation>(collectiblesInfo); } }
public void generateNodes(RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, AgentType agentType) { int rectangleX = (int)rI.X; int rectangleY = (int)rI.Y; int circleX = (int)cI.X; int circleY = (int)cI.Y; Node rectangle = new Node(rectangleX, rectangleY, Node.Type.Rectangle); this.addNode(rectangle); this.rectangleNode = rectangle; Node circle = new Node(circleX, circleY, Node.Type.Circle); this.addNode(circle); this.circleNode = circle; // OBSTACLE for (int i = 0; i < oI.Length; i++) { ObstacleRepresentation obstacle = oI[i]; createNodesForObstacle(obstacle, Node.Type.Obstacle); } // CIRCLE PLATFORM for (int i = 0; i < cPI.Length; i++) { ObstacleRepresentation circlePlatform = cPI[i]; createNodesForObstacle(circlePlatform, Node.Type.CirclePlatform); } // RECTANGLE PLATFORM for (int i = 0; i < rPI.Length; i++) { ObstacleRepresentation rectanglePlatform = rPI[i]; createNodesForObstacle(rectanglePlatform, Node.Type.RectanglePlatform); } // DIAMONDS for (int i = 0; i < colI.Length; i++) { CollectibleRepresentation diamond = colI[i]; Node diamondNode = new Node((int)diamond.X, (int)diamond.Y, Node.Type.Diamond); this.addNode(diamondNode); this.diamondNodes.Add(diamondNode); } }
// See [email protected] for parameter details public override void SensorsUpdated(int nC, RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI) { nCollectiblesLeft = nC; rectangleInfo = rI; circleInfo = cI; collectiblesInfo = colI; if (!Utils.AIAD_DEMO_A_STAR_INITIAL_PATHS) { this.updateAStar(rI, cI); } }
public override void Setup(CountInformation nI, RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area, double timeLimit) { //convert to old way in order to maintain compatibility DeprecatedSetup( nI.ToArray(), rI.ToArray(), cI.ToArray(), ObstacleRepresentation.RepresentationArrayToFloatArray(oI), ObstacleRepresentation.RepresentationArrayToFloatArray(rPI), ObstacleRepresentation.RepresentationArrayToFloatArray(cPI), CollectibleRepresentation.RepresentationArrayToFloatArray(colI), area, timeLimit); }
//implements abstract rectangle interface: used to setup the initial information so that the agent has basic knowledge about the level public override void Setup(CountInformation nI, RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area, double timeLimit) { numbersInfo = nI; nCollectiblesLeft = nI.CollectiblesCount; rectangleInfo = rI; circleInfo = cI; obstaclesInfo = oI; rectanglePlatformsInfo = rPI; circlePlatformsInfo = cPI; collectiblesInfo = colI; this.area = area; //DebugSensorsInfo(); }
//simple algorithm for choosing a random action for the circle agent private void DecideAction() { /* * Circle Actions * ROLL_LEFT = 1 * ROLL_RIGHT = 2 * JUMP = 3 * GROW = 4 */ if (Utils.AIAD_DEMO_A_STAR_INITIAL_PATHS) { currentAction = Moves.NO_ACTION; } else { //Update Status CircleRepresentation[] circles = new CircleRepresentation[] { circleInfo, new CircleRepresentation() }; RectangleRepresentation[] rectangles = new RectangleRepresentation[] { rectangleInfo, new RectangleRepresentation() }; if (this.collectiblesInfo.Length <= 0) { currentAction = Moves.NO_ACTION; // collected all } else { this.agentStatus.Update(circles[0], rectangles[0], this.collectiblesInfo[0], AgentType.Circle, currentAction); Log.LogInformation(this.agentStatus.ToString()); if (this.diamondsToCatchCollectivelly.Contains(nextDiamond)) // next diamond has to be caugh cooperatively { currentAction = LaunchCoop(nextDiamond); } else if (this.diamondsToCatch.Contains(nextDiamond)) { currentAction = decideActionFromCurrentPath(); } } //send a message to the rectangle agent telling what action it chose lock (messages) { messages.Add(new AgentMessage("Going to :" + currentAction)); } Log.LogInformation(this.circleInfo.ToString()); } }
private void updateAStar(RectangleRepresentation rI, CircleRepresentation cI) { this.matrix.updateMatrix(rI, cI); this.graph.updateGraph(rI, cI); SearchParameters searchParameters = new SearchParameters(this.graph.circleNode.index, this.graph.diamondNodes[nextDiamondIndex].index, this.graph); PathFinder pathFinder = new PathFinder(searchParameters, this.type); for (int i = 0; i < this.graph.knownPaths.Count; i++) { if (this.graph.knownPaths[i].getGoalNode() == this.graph.diamondNodes[nextDiamondIndex]) { this.graph.knownPaths[i] = pathFinder.FindPath(); } } }
public override void SensorsUpdate(RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI) { if (maxHeight - rI.Height < 0.5 || sameCount > 10) { setFinished(); } else if (rI.Height - previousHeight < 0.1) { sameCount++; previousHeight = rI.Height; } else { sameCount = 0; } }
//implements abstract circle interface: used to setup the initial information so that the agent has basic knowledge about the level public override void Setup(CountInformation nI, RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area, double timeLimit) { singlePlayer = new CircleSingleplayer(cutplan, testing, timer); //check if it is a single or multiplayer level if (rI.X < 0 || rI.Y < 0) { //if the circle has negative position then this is a single player level gameMode = 0; singlePlayer.Setup(nI, rI, cI, oI, rPI, cPI, colI, area, timeLimit); } else { gameMode = 1; multiPlayer = new CircleCoopAgent(area, colI, oI, rPI, cPI); multiPlayer.Setup(nI, rI, cI, oI, rPI, cPI, colI, area, timeLimit); } }
/* * * Does only independent linear progressions between states (So if, for example, there is a circle state that to finish depends on a rectangle state, then this function must be overriden) * */ public virtual void SensorsUpdate(RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI) { if (isFinished() || actionStatesRectangle == null || actionStatesCircle == null || (actionStatesRectangle != null && currentStateRectangle < actionStatesRectangle.Count) || (actionStatesCircle != null && currentStateCircle < actionStatesCircle.Count)) { return; } this.rI = rI; this.cI = cI; this.colI = colI; //Caution: its each state's responsibility to filter the information sent to it by the ation rule if (!actionStatesCircle[currentStateCircle].isFinished()) { actionStatesCircle[currentStateCircle].SensorsUpdate(rI, cI, colI); } else { if (currentStateCircle < actionStatesCircle.Count - 1) { currentStateCircle++; actionStatesCircle[currentStateCircle].Setup(nI, rI, cI, oI, rPI, cPI, colI, area, 100.0); } else if (currentStateRectangle >= actionStatesRectangle.Count - 1 && actionStatesRectangle[currentStateRectangle].isFinished()) { setFinished(); return; } } if (!actionStatesRectangle[currentStateRectangle].isFinished()) { actionStatesRectangle[currentStateRectangle].SensorsUpdate(rI, cI, colI); } else { if (currentStateRectangle < actionStatesRectangle.Count - 1) { currentStateRectangle++; actionStatesRectangle[currentStateRectangle].Setup(nI, rI, cI, oI, rPI, cPI, colI, area, 100.0); } } }
public List <ActionRule> ApplyRules(CircleRepresentation c, RectangleRepresentation r) { List <ActionRule> actionRules = new List <ActionRule>(); foreach (CollectibleRepresentation diamond in diamonds) { foreach (FilterRule filter in filters) { ActionRule rule = filter.filter(r, c, diamond); if (rule != null) { actionRules.Add(rule); break; } } } return(actionRules); }
public override ActionRule filter(RectangleRepresentation r, CircleRepresentation c, CollectibleRepresentation diamond) { ObstacleRepresentation closestAbove = new ObstacleRepresentation(diamond.X, getArea().Y, 0, 0), closestBelow = new ObstacleRepresentation(diamond.X, getArea().Height + getArea().Y, 0, 0); // Might be able to be changed into logarithmic complexity // Might not work for some combinations of Circle and regular platforms foreach (ObstacleRepresentation platform in yPlatforms) { // Check that diamond is above or below platform (same X) if (platform.X - platform.Width / 2 < diamond.X && diamond.X < platform.X + platform.Width / 2) { // Since its ordered the first below is the closest if (platform.Y > diamond.Y && platform.Y < closestBelow.Y) { closestBelow = platform; break; } else if (platform.Y < diamond.Y && platform.Y > closestAbove.Y) { closestAbove = platform; } } } // Either rectangle or coop if (closestBelow.Y - closestBelow.Height / 2 - closestAbove.Y - closestAbove.Height / 2 <= getMaxRadius() * 2) { // If rectangle is on top of the platform below, it can get there alone if (r.Y + (r.Height / 2) - closestBelow.Y + closestBelow.Height / 2 <= 10) { return(new RectangleSingleplayerRule(diamond)); } // Else, it needs the help from the circle else { return(new TightSpaceRule()); } } return(null); }
public override void SensorsUpdate(RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI) { if (isFinished()) { return; } circleSingleplayer.SensorsUpdated(objectiveDiamond.Length, rI, cI, objectiveDiamond); foreach (CollectibleRepresentation diamond in colI) { if (objectiveDiamond.Length > 0 && diamond.X == objectiveDiamond[0].X && diamond.Y == objectiveDiamond[0].Y) { return; } } setFinished(); objectiveDiamond = new CollectibleRepresentation[0]; }
public override void Setup(CountInformation nI, RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area, double timeLimit) { CountInformation nIFixed = new CountInformation(nI.ObstaclesCount + (rectangleAsPlatform ? 1 : 0), nI.RectanglePlatformsCount, nI.CirclePlatformsCount, 1); ObstacleRepresentation[] oIFixed; if (rectangleAsPlatform) { List <ObstacleRepresentation> oIList = new List <ObstacleRepresentation>(oI); oIList.Add(new ObstacleRepresentation(rI.X, rI.Y, rectangleArea / rI.Height, rI.Height)); oIFixed = oIList.ToArray(); } else { oIFixed = oI; } singleplayer.Setup(nIFixed, rI, cI, oIFixed, rPI, cPI, objectiveDiamond, area, timeLimit); setup = true; }
public void Setup(CountInformation nI, RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area, double timeLimit) { //Splits the diamonds into each category actionRules = coopRules.ApplyRules(cI, rI); if (actionRules == null || actionRules.Count == 0) { finished = true; return; } actionRules[currentAction].Setup(nI, rI, cI, oI, rPI, cPI, colI, area, 100.0); this.nI = nI; this.rI = rI; this.cI = cI; this.oI = oI; this.rPI = rPI; this.cPI = cPI; this.colI = colI; this.area = area; }
/// <summary> /// implements abstract circle interface: registers updates from the agent's sensors that it is up to date with the latest environment information /// ***WARNING***: this method is called independently from the agent update - Update(TimeSpan elapsedGameTime) - so care should be taken when using complex /// structures that are modified in both(e.g.see operation on the "remaining" collection) /// </summary> /// <param name="nC">The current number of collectibles within the level.</param> /// <param name="rI">This structure contains the current information on the rectangle agent, such as position (X and Y), velocity (X and Y) and its current height.</param> /// <param name="cI">This array contains the current information on the circle agent, such as position (X and Y) and velocity (X and Y).</param> /// <param name="colI">This array contains the information about the coordinates (center X and Y positions) of all the collectibles (purple diamonds) in the level.</param> public override void SensorsUpdated(int nC, RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI) { this.nCollectiblesLeft = nC; this.rectangleInfo = rI; this.circleInfo = cI; this.collectiblesInfo = colI; /* The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical section. * If another thread tries to enter a locked code, it will wait, block, until the object is released. */ lock (remaining) { this.remaining = new List <CollectibleRepresentation>(collectiblesInfo); } if (!Utils.AIAD_DEMO_A_STAR_INITIAL_PATHS) { this.updateAStar(rI, cI); } //DebugSensorsInfo(); }
// See [email protected] for parameter details public override void Setup(CountInformation nI, RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area, double timeLimit) { numbersInfo = nI; nCollectiblesLeft = nI.CollectiblesCount; rectangleInfo = rI; circleInfo = cI; obstaclesInfo = oI; rectanglePlatformsInfo = rPI; circlePlatformsInfo = cPI; collectiblesInfo = colI; this.area = area; //send a message to the rectangle informing that the circle setup is complete and show how to pass an attachment: a pen object messages.Add(new AgentMessage("Setup complete, testing to send an object as an attachment.", new Pen(Color.BlanchedAlmond))); this.runAStar(rI, cI, oI, rPI, cPI, colI, area); this.movementAnalyser = new MovementAnalyser(this.matrix); InitDiamondsToCatch(); //DebugSensorsInfo(); }
/// <summary> /// implements abstract circle interface: used to setup the initial information so that the agent has basic knowledge about the level /// </summary> /// <param name="nI">This structure contains the number of obstacles, the number of character specific platforms (Circle & Rectangle Platforms) and the total number of purple diamonds within the level.</param> /// <param name="rI">This structure contains the current information on the rectangle agent, such as position (X and Y), velocity (X and Y) and its current height.</param> /// <param name="cI">This array contains the current information on the circle agent, such as position (X and Y) and velocity (X and Y).</param> /// <param name="oI">This array contains all the information about the obstacles (default obstacles, not character specific obstacles) in the level, such as the center coordinates of the platform (X and Y) and the platform’s height and width.</param> /// <param name="rPI">This array contains all the information about Rectangle specific platforms in the level, such as the center coordinates of the platform (X and Y) and the platform’s height and width.</param> /// <param name="cPI">This array contains all the information about Circle specific platforms in the level, such as the center coordinates of the platform (X and Y) and the platform’s height and width.</param> /// <param name="colI">This array contains the information about the coordinates (center X and Y positions) of all the collectibles (purple diamonds) in the level.</param> /// <param name="area">Specifies the definition of the rectangle area in which the game unfolds.</param> /// <param name="timeLimit">Specifies the amount of time the agent has to solve the level during the competition.</param> public override void Setup(CountInformation nI, RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area, double timeLimit) { this.numbersInfo = nI; this.nCollectiblesLeft = nI.CollectiblesCount; this.rectangleInfo = rI; this.circleInfo = cI; this.obstaclesInfo = oI; this.rectanglePlatformsInfo = rPI; this.circlePlatformsInfo = cPI; this.collectiblesInfo = colI; this.uncaughtCollectibles = new List <CollectibleRepresentation>(collectiblesInfo); this.area = area; //send a message to the rectangle informing that the circle setup is complete and show how to pass an attachment: a pen object this.messages.Add(new AgentMessage("Setup complete, testing to send an object as an attachment.", new Pen(Color.AliceBlue))); // create game matrix this.matrix = Matrix.generateMatrixFomGameInfo(rI, cI, oI, rPI, cPI, colI, area); // create graph with reachable paths according to A* this.runAStarForInitialPaths(rI, cI, oI, rPI, cPI, colI, area); // create restrictions related to movement according to level data this.movementAnalyser = new MovementAnalyser(this.matrix); // initialize the diamonds to catch according to the A* known paths and movement restrictions this.initDiamondsToCatch(); // initialize state machine to catch diamonds if (!Utils.AIAD_DEMO_A_STAR_INITIAL_PATHS) { this.pathsToFollowStateMachine(); } DebugSensorsInfo(); }