Skip to content

Commit

Permalink
- fixed bugs related to corners and facilities
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry committed Dec 15, 2017
1 parent 55899fb commit 4a544a7
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 34 deletions.
Binary file added 28.jar
Binary file not shown.
100 changes: 72 additions & 28 deletions core/src/MyStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public final class MyStrategy implements Strategy {
private VehicleGroupInfo currentMapGroup;
private Map<Point2D, Integer> cornersPushers;
private Map<Point2D, Integer> sidesPushers;
private Map<Point2D, Integer> allFacCounts;
private boolean isFacilityMode;
private boolean nextIsTankIfFog = true;
private boolean allEnInvisible;
Expand Down Expand Up @@ -167,6 +166,8 @@ private void potentialMove() {
continue;
}

if (initialRotate(myGroup)) continue;

if (initialScale(myGroup)) continue;

if (myGroup.goToFacility != null && myGroup.getAveragePoint().getDistanceTo(myGroup.getGoToFacilityPoint()) < 14) {
Expand Down Expand Up @@ -638,7 +639,7 @@ private PlainArray calcMap(VehicleGroupInfo group) { //TODO improve logic at fin


//if someone closer then my then pass that facility
removeFacilityIfSomeoneCloser(group);
//removeFacilityIfSomeoneCloser(group);

addToArrayNotOurFacilities(plainArray, range, .9f, group);

Expand Down Expand Up @@ -754,15 +755,19 @@ private PlainArray calcMap(VehicleGroupInfo group) { //TODO improve logic at fin
{ //add negative to corners
int maxDistanceSquare = 8 * 8;

int distanceToFac = 6;

int maxIndex = plainArray.cellsWidth - 1;
Map<Point2D, Integer> allFacCounts;

if (allFacCounts == null) {
allFacCounts = new HashMap<>();
for (Map<FacilityType, Map<Point2D, Integer>> map : getFacilitiesCount().values()) {
for (Map<Point2D, Integer> counts : map.values()) {
allFacCounts.putAll(counts);
}
}

allFacCounts = new HashMap<>();
for (Map<Point2D, Integer> counts : getFacilitiesCount().get(opponent.getId()).values()) {
allFacCounts.putAll(counts);
}

for (Map<Point2D, Integer> counts : getFacilitiesCount().get(-1L).values()) {
allFacCounts.putAll(counts);
}

if (cornersPushers == null) {
Expand All @@ -774,18 +779,18 @@ private PlainArray calcMap(VehicleGroupInfo group) { //TODO improve logic at fin
cornersPushers.put(new Point2D(maxIndex, maxIndex), 1);


cornersPushers.keySet().removeIf(corner -> {
for (Point2D facPoint : allFacCounts.keySet()) {
if (facPoint.squareDistance(corner) < 13 * 13) {
return true;
}
}
HashMap<Point2D, Integer> cornerPushersFiltered = new HashMap<>(cornersPushers);
cornerPushersFiltered.keySet().removeIf(corner -> {
for (Point2D facPoint : allFacCounts.keySet()) {
if (facPoint.squareDistance(corner) < maxDistanceSquare) {
return true;
}
return false;
});
}
return false;
});

}

HashMap<Point2D, Integer> cornerPushersFiltered = new HashMap<>(cornersPushers);

cornerPushersFiltered.keySet().removeIf(corner -> {
int distanceThreshold = 13 * 13;
Expand Down Expand Up @@ -820,6 +825,7 @@ private PlainArray calcMap(VehicleGroupInfo group) { //TODO improve logic at fin
return false;
});


subFromArray(plainArray, cornerPushersFiltered.entrySet(), 3 * 4, 3, -1);

if (sidesPushers == null) {
Expand All @@ -832,18 +838,32 @@ private PlainArray calcMap(VehicleGroupInfo group) { //TODO improve logic at fin
sidesPushers.put(new Point2D(maxIndex, i), 1);

}
}
HashMap<Point2D, Integer> sidesPushersFiltered = new HashMap<>(sidesPushers);

sidesPushers.keySet().removeIf(side -> {
for (Point2D facPoint : allFacCounts.keySet()) {
if (facPoint.squareDistance(side) < maxDistanceSquare) {
return true;
}
sidesPushersFiltered.keySet().removeIf(side -> {
for (Point2D facPoint : allFacCounts.keySet()) {
if (facPoint.squareDistance(side) < maxDistanceSquare) {
return true;
}
return false;
});
}
}
return false;
});


subFromArray(plainArray, sidesPushersFiltered.entrySet(), 3 * 3, 1, -1);

subFromArray(plainArray, sidesPushers.entrySet(), 3 * 3, 1, -1);

//strict {

for (int x = 0; x < plainArray.cellsWidth; x++) {
for (int y = 0; y < plainArray.cellsHeight; y++) {

if (x == 0 || y == 0 || x == plainArray.cellsWidth - 1 || y == plainArray.cellsHeight - 1) {
plainArray.set(x, y, plainArray.get(x, y) - 30);
}
}
}
}


Expand Down Expand Up @@ -1272,6 +1292,30 @@ private boolean executeDelayedMove() {
return true;
}

private boolean initialRotate(VehicleGroupInfo myGroup) {
if (!myGroup.isRotated && myGroup.vehicles.get(0).v.isAerial()) {
myGroup.isRotated = true;
scheduleSelectAll(myGroup);
delayedMoves.add(move1 -> {
move1.setAction(ActionType.ROTATE);
move1.setX(myGroup.getAveragePoint().getX());
move1.setY(myGroup.getAveragePoint().getY());
move1.setAngle(Math.PI / 4);
});

delayedMoves.add(move1 -> {
//pass
});

delayedMoves.add(move1 -> {
//pass
});

return true;
}
return false;
}


private boolean initialScale(VehicleGroupInfo myGroup) {
if (!myGroup.isScaled) {
Expand Down Expand Up @@ -1722,7 +1766,7 @@ private void actualMoveToPoint(VehicleGroupInfo myGroup, Point2D point, Move mov
// boolean shouldScale = separatedVehicles.size() > 0;
boolean shouldScale = Math.sqrt(myGroup.count) * 6 < Math.max(myGroup.pointsInfo.rect.getWidth(), myGroup.pointsInfo.rect.getHeight());

shouldScale = world.getTickIndex() - myGroup.lastShrinkForGatherI > 400 && shouldScale;
shouldScale = world.getTickIndex() - myGroup.lastShrinkForGatherI > 350 && shouldScale;
if (shouldScale) {
myGroup.lastShrinkForGatherI = world.getTickIndex();

Expand Down
12 changes: 7 additions & 5 deletions core/src/RewindClientWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ private void drawPP(VehicleGroupInfo myGroup) {

double root = root(delta, delta);

double squareMaxDistance = Math.pow(cellSize * (6 + 3), 2);
int maxDistance = 15;
double squareMaxDistance = Math.pow(cellSize * maxDistance, 2);


mys.log("start draw " + myGroup.vehicleType);
for (int x = 0; x < cellsX; x++) {
for (int y = 0; y < cellsY; y++) {
double v = plainArray.get(x, y) - min;
Expand All @@ -208,16 +210,16 @@ private void drawPP(VehicleGroupInfo myGroup) {
if (RESTRICTED_PP_DRAW && myGroup.getAveragePoint().squareDistance(centerX, centerY) > squareMaxDistance) {
continue; // too far for decide
}

//mys.log(String.format("%s %s %s - v: %s", myGroup.vehicleType, realX, realY, (int) v));
//System.out.print(String.format("%s %s %s - v: %s", myGroup.vehicleType, realX, realY, (int) v));
// System.out.print((int) v + " ");
rc.rect(realX, realY, realX + cellSize, realY + cellSize, new Color(133, alpha, 255 - alpha, 100), 1);

}
}
// System.out.println();
}

// rc.message(String.format("\\n%s\\nMap Draw: min %.2f max %.2f \\ndelta %.2f", myGroup.vehicleType, min, max, delta));


}

private void drawMoveActual() {
Expand Down
3 changes: 2 additions & 1 deletion core/src/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public static void main(String[] args) throws IOException {
//runProc(null, true, "java", "-cp", "23.4.jar", "Runner");
//runProc(null, true, "java", "-cp", "23.5.jar", "Runner");
//runProc(null, true, "java", "-cp", "24.jar", "Runner");
runProc(null, true, "java", "-cp", "25.jar", "Runner");
//runProc(null, true, "java", "-cp", "25.jar", "Runner");
runProc(null, true, "java", "-cp", "27.jar", "Runner");
}
}).start();
new Runner(new String[]{"127.0.0.1", hasArgs ? "31001" : "31002", "0000000000000000"}).run();
Expand Down
1 change: 1 addition & 0 deletions core/src/VehicleGroupInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class VehicleGroupInfo {
public int lastShrinkI;
public int lastShrinkForGatherI;
public boolean isScaled;
public boolean isRotated;
public boolean shouldHeal;
public int groupNumber;
public PlainArray potentialMap;
Expand Down
1 change: 1 addition & 0 deletions lr/local-runner-sync.default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fog-of-war-quality=1
#seed=536603617854755
#seed=539675860738317
#seed=541562105365045
#seed=560101143593578
seed=

# Путь к каталогу с плагинами или пустая строка для работы без плагинов.
Expand Down

0 comments on commit 4a544a7

Please sign in to comment.