Skip to content

Commit

Permalink
- fix nuclear;
Browse files Browse the repository at this point in the history
- fix capturing facilities
  • Loading branch information
dmitry committed Dec 15, 2017
1 parent 87ebed8 commit b798a2c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
Binary file added 26.jar
Binary file not shown.
42 changes: 32 additions & 10 deletions core/src/MyStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class MyStrategy implements Strategy {
public static final int WORLD_CELL_SIZE = 32;
public static final double GROUP_SIZE = 50;
public static final double GROUP_HALF_SIZE = GROUP_SIZE / 2;
public static final int MIN_NUCLEAR_DMG = 500;
public static final int MIN_NUCLEAR_DMG = 520;
public static final List<VehicleType> FIGHTER_PREF_TARGETS = Arrays.asList(HELICOPTER, FIGHTER);
public static final List<VehicleType> HELI_PREF_TARGETS = Arrays.asList(TANK, ARRV, HELICOPTER, IFV, FIGHTER);
public static final double SHOULD_HEAL_TRESHOLD = 0.64;
Expand Down Expand Up @@ -169,7 +169,7 @@ private void potentialMove() {

if (initialScale(myGroup)) continue;

if (myGroup.goToFacility != null && myGroup.getAveragePoint().getDistanceTo(myGroup.goToFacility.getCenterPos()) < 20) {
if (myGroup.goToFacility != null && myGroup.getAveragePoint().getDistanceTo(myGroup.getGoToFacilityPoint()) < 14) {
if (!myGroup.goToFacility.isMy() || myGroup.goToFacility.f.getCapturePoints() != game.getMaxFacilityCapturePoints()) {
log(Utils.LOG_MOVING + " skip move because of capturing " + myGroup);
continue;
Expand Down Expand Up @@ -227,6 +227,9 @@ private VehicleType getTypeForProductionByLess() {
for (VehicleType vehicleType : VehicleType.values()) {
allyCounts.putIfAbsent(vehicleType, 0L);
}
if (allyCounts.get(TANK) <= 100) {
return TANK;
}
Map.Entry<VehicleType, Long> min = Collections.min(allyCounts.entrySet(), (o1, o2) -> {
int compare = Long.compare(o1.getValue(), o2.getValue());
if (compare != 0) {
Expand Down Expand Up @@ -635,7 +638,7 @@ private PlainArray calcMap(VehicleGroupInfo group) { //TODO improve logic at fin

Set<Map.Entry<Point2D, Integer>> myGroundUnits2 = myGroundUnits.entrySet();

double range = (GROUP_SIZE * 1.3) / cellSize;
double range = (GROUP_SIZE * 1.05) / cellSize;

int factor = 2;

Expand Down Expand Up @@ -913,7 +916,7 @@ private void addToArrayNotOurFacilities(PlainArray plainArray, double range, flo
}


{
if (myGroup.goToFacility == null || myGroup.getAveragePoint().getDistanceTo(myGroup.goToFacility) > 64 * 1.4) {
Point2D ap = myGroup.getAveragePoint();
FacilityWrapper closestFree = null;

Expand Down Expand Up @@ -951,8 +954,17 @@ private void addToArrayNotOurFacilities(PlainArray plainArray, double range, flo
factor = 1.1f;
}
HashSet<Map.Entry<Point2D, Integer>> counts = new HashSet<>();
counts.add(new AbstractMap.SimpleEntry<>(myGroup.goToFacility.getCenterCellPos(), 1));
Point2D cf = myGroup.goToFacility.getCenterCellPos();
counts.add(new AbstractMap.SimpleEntry<>(cf, 1));
addToArray(plainArray, counts, range, factor);

counts.clear();
// if (myGroup.count > 50) {
counts.add(new AbstractMap.SimpleEntry<>(cf.add(1, 1), 1));
// } else {
// counts.add(new AbstractMap.SimpleEntry<>(cf.add(2, 2), 1)); //TOO FAR
// }
addToArray(plainArray, counts, 2, factor);
}
}

Expand Down Expand Up @@ -1291,10 +1303,10 @@ private void tryEvadeNuclearTarget() {
private boolean tryPickNuclearTarget() {
if (me.getRemainingNuclearStrikeCooldownTicks() == 0 && scheduledStrike == null) {
int remainingHp = um.enemyStats.remainingHp;
int minNuclearDmg = (int) Math.min(MyStrategy.MIN_NUCLEAR_DMG, remainingHp * 0.6);

int minNuclearDmg = world.getTickIndex() > 8_000 ? (int) Math.min(MyStrategy.MIN_NUCLEAR_DMG, remainingHp * 0.6) : MyStrategy.MIN_NUCLEAR_DMG;

NuclearStrike max = NuclearStrike.getMaxDmg(this);
NuclearStrike max = NuclearStrike.getMaxDmg(this, minNuclearDmg);

if (max != null && max.predictedDmg > minNuclearDmg) {
scheduledStrike = max;
Expand All @@ -1314,7 +1326,7 @@ private boolean tryPickNuclearTarget() {
log(Utils.LOG_NUCLEAR_STRIKE + " correct point to " + max.actualTarget + " distance is " + max.actualTarget.getDistanceTo(max.myVehicle) + " maxDistance: " + maxDistance);
}
max.recalcPredicted();
if (max.predictedDmg < remainingHp) {
if (max.predictedDmg < minNuclearDmg) {
log(Utils.LOG_NUCLEAR_STRIKE + " find new target or cancel");
scheduledStrike.finish();
scheduledStrike.canceled = true;
Expand Down Expand Up @@ -1570,7 +1582,6 @@ private void schedulePotentialMoveToPoint(VehicleGroupInfo myGroup) {
groups.add(myGroup);
refreshGroups(groups, false);
enemyGroups = getGroupsWithoutGeometry(Ownership.ENEMY);
;

if (groups.isEmpty()) {
log(WARN + "group " + myGroup + " is destroyed");
Expand Down Expand Up @@ -1630,6 +1641,10 @@ private void schedulePotentialMoveToPoint(VehicleGroupInfo myGroup) {
continue;
}

if (y == myY && x == myX && myGroup.noMoveCount > 10) {
continue;
}

currentChoice.setVal(myGroup.potentialMap.get(x, y));
if (true) {
if (bestChoice == null || bestChoice.getVal() < currentChoice.getVal()) {
Expand All @@ -1640,7 +1655,14 @@ private void schedulePotentialMoveToPoint(VehicleGroupInfo myGroup) {
}
}

if (bestChoice != null && !bestChoice.equals(new Point2D(myX, myY))) {
boolean noMove = bestChoice != null && !bestChoice.equals(new Point2D(myX, myY));
if (noMove) {
myGroup.noMoveCount++;
} else {
myGroup.noMoveCount = 0;
}

if (bestChoice != null && noMove) {
scheduleSelectAll(myGroup);
actualMoveToPoint(myGroup, bestChoice.mul(cellSize).add(cellSize / 2, cellSize / 2), move); //TODO scale\rotate when needed
} else {
Expand Down
6 changes: 2 additions & 4 deletions core/src/NuclearStrike.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void calcPredicted(VehicleWrapper myVehicle, VehicleWrapper target, MySt
}

if (veh.v.getType() == VehicleType.ARRV) {
dmg *= 0.6f;
dmg *= 0.2f;
}

boolean isEnemy = veh.isEnemy;
Expand Down Expand Up @@ -93,9 +93,7 @@ public String toString() {
return sb.toString();
}

public static NuclearStrike getMaxDmg(MyStrategy mys) {
int remainingHp = mys.um.enemyStats.remainingHp;
int minNuclearDmg = (int) Math.min(MyStrategy.MIN_NUCLEAR_DMG, remainingHp * 0.7);
public static NuclearStrike getMaxDmg(MyStrategy mys, int minNuclearDmg) {
return mys.um.streamVehicles(Ownership.ENEMY)
.flatMap((VehicleWrapper v) ->
mys.um.streamVehicles(Ownership.ALLY)
Expand Down
4 changes: 2 additions & 2 deletions core/src/RewindClientWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void onEndTick() {
}

if (myGroup.goToFacility != null) {
Point2D fac = myGroup.goToFacility.getCenterPos();
Point2D fac = myGroup.getGoToFacilityPoint();
rc.circle(fac.getX(), fac.getY(), 4, COLOR_FACILITY, 5);
rc.line(ap.getX(), ap.getY(), fac.getX(), fac.getY(), COLOR_FACILITY, 5);
}
Expand Down Expand Up @@ -215,7 +215,7 @@ private void drawPP(VehicleGroupInfo myGroup) {
}
}

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


}
Expand Down
11 changes: 11 additions & 0 deletions core/src/VehicleGroupInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class VehicleGroupInfo {
public int switchCount;
public boolean nextShrinkIsScale;
public boolean shrinkRotateToRight;
public int noMoveCount;

public VehicleGroupInfo(Ownership ownership, VehicleType vehicleType, MyStrategy myStrategy) {
this.ownership = ownership;
Expand Down Expand Up @@ -89,4 +90,14 @@ public Point2D getCellAveragePoint() {
public boolean isAeral() {
return vehicles.get(0).v.isAerial();
}

public Point2D getGoToFacilityPoint() {
Point2D centerPos = goToFacility.getCenterPos();
//if (count > 50) {
centerPos = centerPos.add(16, 16);
/*} else { //TOO FAR
centerPos = centerPos.add(32, 32);
}*/
return centerPos;
}
}

0 comments on commit b798a2c

Please sign in to comment.