public void calculateNextHop() { // look at list of travel points, and the list of occupiedPoints. // calculate next 3 areas and put them in the list movementQueue if (this.uiMap == null) return; if (this.uiMap.getCells() == null) return; if (this.travelPoints.size() == 0) return; this.moveMentQueue.clear(); Point nextDest = this.travelPoints.get(0); AStar finder = new AStar(); if (location.x == nextDest.x && location.y == nextDest.y) { this.moveMentQueue.add(location); movementVerified = true; return; } else { Cell[] path = finder.findPath(uiMap, location, nextDest); if (path != null) { if (path.length > 1) { this.moveMentQueue.add(path[1].getPosition()); } if (path.length > 2) { this.moveMentQueue.add(path[2].getPosition()); } if (path.length > 3) { this.moveMentQueue.add(path[3].getPosition()); } // this.moveMentQueue.add(path[0].getPosition()); } else { /*if(!lastClaimRejected) { this.moveMentQueue.clear(); this.moveMentQueue.add(location); }*/ uiMap = null; /*ACLMessage mapReq = new ACLMessage(ACLMessage.QUERY_IF); mapReq.addReceiver(guiAgents[0]); mapReq.setContent("Give me map"); mapReq.setConversationId("map-request"); this.send(mapReq);*/ lastClaimRejected = true; addBehaviour(new MapUpdateRequest()); return; } } // fill moveMentQueue with the 3 found locations addBehaviour(new HopRequest()); // one shot behaviour to claim the hop }
public Integer calculatePathCost(Point l) { // the agent has a current position and a list of points (travelPoints) // orderd to visit. return the current amount of spaces it has to move // before being idle again // temporarily add the given point to the end of travelPoints, a request // has been made how far the robot has to move to THAT point if (uiMap == null) return 1000000000; if (location.x == l.x && location.y == l.y) { return 0; } AStar finder = new AStar(); Cell[] path = finder.findPath(uiMap, location, l); if (path != null) { int totalLength = path.length; // System.out.println("robot: " + this.getName() + " holdingitem: " + holdingItem.toString()); if (holdingItem.x != 0 && holdingItem.y != 0 || nextDestination.size() > 0) { // System.out.println("I'm holding an item: " + this.getName()); if (travelPoints.size() > 0) { Cell[] pth = finder.findPath(uiMap, location, travelPoints.get(0)); if (pth != null) { totalLength += pth.length; } else { totalLength += 100; } for (int i = 0; i < travelPoints.size() - 1; i++) { Point srcDest = this.travelPoints.get(i); Point nxtDest = this.travelPoints.get(i + 1); Cell[] npth = finder.findPath(uiMap, srcDest, nxtDest); if (npth != null) { totalLength += npth.length; } else { totalLength += 100; } // totalLength += finder.findPath(uiMap, srcDest, nxtDest).length; } } } // System.out.println("This is the total length: " + totalLength + " me: " + this.getName()); return totalLength; } return (5); // Debugging purpose in version without a loaded map }