void addCoordFacingCombos(Iterator<CoordFacingCombo> cfit) { final String METHOD_NAME = "addCoordFacingCombos(Iterator<CoordFacingCombo>)"; owner.methodBegin(getClass(), METHOD_NAME); try { while (cfit.hasNext()) { CoordFacingCombo cf = cfit.next(); if(cf != null && owner.getGame().getBoard().contains(cf.coords)) { expandToInclude(cf.getCoords()); } } } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
Coords getClosestCoordsTo(int unitId, Coords location) { ConvexBoardArea box = pathEnumerator.getUnitMovableAreas().get(unitId); if (box == null) { return null; } return box.getClosestCoordsTo(location); }
/** * returns true if a point is inside the area * false if it is not */ public boolean contains(Coords c) { final String METHOD_NAME = "contains(Coords)"; owner.methodBegin(getClass(), METHOD_NAME); try { HexLine[] edges = getEdges(); if (edges[0] == null) { return false; } for (int i = 0; i < 6; i++) { if (edges[i].judgePoint(c) > 0) { return false; } } return true; } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
Coords areapt2 = new Coords(3, 1); Coords areapt3 = new Coords(2, 3); ConvexBoardArea area = new ConvexBoardArea(owner); area.expandToInclude(areapt1); area.expandToInclude(areapt2); area.expandToInclude(areapt3); owner.log(BotGeometry.class, METHOD_NAME, "Checking area contains proper points... "); msg.append("\n\tChecking area contains proper points... "); if (!area.contains(new Coords(1, 1))) { passed = false; if (!area.contains(new Coords(2, 1))) { passed = false; if (!area.contains(new Coords(3, 1))) { passed = false; if (!area.contains(new Coords(1, 2))) { passed = false; if (!area.contains(new Coords(2, 2))) { passed = false; if (!area.contains(new Coords(3, 2))) { passed = false; if (!area.contains(new Coords(2, 3))) { passed = false;
ConvexBoardArea myArea = new ConvexBoardArea(owner); myArea.addCoordFacingCombos(getUnitPotentialLocations().get( mover.getId()).iterator()); getUnitMovableAreas().put(mover.getId(), myArea);
Coords vertex = movableArea.getVertexNum(vertexNum);
Coords c = new Coords(x, y); if(cba.contains(c)) { Coords c = cba.getVertexNum(x); if(c == null) { continue;
Coords closest = null; int closest_dist = 0; HexLine[] edges = getEdges(); for (int i = 0; i < 6; i++) { if (edges[i] == null) { Coords vert = getVertexNum(i); int vdist = vert.distance(c); if ((closest == null) || (vdist < closest_dist)) { if (contains(online)) { int ldist = online.distance(c); if (ldist < closest_dist) {
/** * expands the board area to include point onc */ void expandToInclude(Coords onc) { final String METHOD_NAME = "expandToInclude(Coords)"; owner.methodBegin(getClass(), METHOD_NAME); try { HexLine[] edges = getEdges(); for (int i = 0; i < 6; i++) { if ((edges[i] == null) || (edges[i].judgePoint(onc) > 0)) { edges[i] = new HexLine(onc, i, owner); } } setEdges(edges); } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
@Override public String toString() { StringBuilder msg = new StringBuilder("Edges:"); HexLine[] edges = getEdges(); for (int i = 0; i < edges.length; i++) { if (i != 0) { msg.append("; "); } if (edges[i] == null) { msg.append("null"); } else { msg.append(edges[i].toString()); } } return msg.toString(); }
/** * Returns a vertex, with zero starting at the upper left of the hex */ public Coords getVertexNum(int i) { final String METHOD_NAME = "getVertexNum(int)"; owner.methodBegin(getClass(), METHOD_NAME); try { HexLine[] edges = getEdges(); if (edges[i] == null || edges[(i + 1) % 6] == null) { System.err.println(new IllegalStateException("Edge[" + i + "] is NULL.")); return null; } return edges[i].getIntersection(edges[(i + 1) % 6]); } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
ConvexBoardArea(Princess owner) { this.owner = owner; clearEdges(); }