Skip to content

Commit

Permalink
update client
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 10, 2020
1 parent bb3de57 commit 6e5df2c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion last_updated.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
last updated: Sat Oct 10 07:19:32 UTC 2020
last updated: Sat Oct 10 07:54:03 UTC 2020
16 changes: 8 additions & 8 deletions src/api/AbstractGameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ export default interface AbstractGameManager extends EventEmitter {

// estimation utils. used for scripting only (not in core client functions)
getMyPlanets(): Planet[];
getDist(from: Planet, to: Planet): number;
getMaxMoveDist(planet: Planet, sendingPercent: number): number;
getPlanetsInRange(planet: Planet, sendingPercent: number): Planet[];
getDist(fromId: LocationId, toId: LocationId): number;
getMaxMoveDist(planetId: LocationId, sendingPercent: number): number;
getPlanetsInRange(planetId: LocationId, sendingPercent: number): Planet[];
getEnergyNeededForMove(
from: Planet,
to: Planet,
fromId: LocationId,
toId: LocationId,
arrivingEnergy: number
): number;
getEnergyArrivingForMove(
from: Planet,
to: Planet,
fromId: LocationId,
toId: LocationId,
sentEnergy: number
): number;
getTimeForMove(from: Planet, to: Planet): number;
getTimeForMove(fromId: LocationId, toId: LocationId): number;
getTemperature(coords: WorldCoords): number;
}
42 changes: 27 additions & 15 deletions src/api/GameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,17 +884,19 @@ class GameManager extends EventEmitter implements AbstractGameManager {
);
}

getMaxMoveDist(planet: Planet, sendingPercent: number): number {
getMaxMoveDist(planetId: LocationId, sendingPercent: number): number {
const planet = this.getPlanetWithId(planetId);
if (!planet) throw new Error('origin planet unknown');
// log_2(sendingPercent / 5%)
let ratio = Math.log(sendingPercent / 5) / Math.log(2);
ratio = Math.max(ratio, 0);
return ratio * planet.range;
}

getDist(from: Planet, to: Planet) {
const fromLoc = this.planetHelper.getLocationOfPlanet(from.locationId);
getDist(fromId: LocationId, toId: LocationId): number {
const fromLoc = this.planetHelper.getLocationOfPlanet(fromId);
if (!fromLoc) throw new Error('origin location unknown');
const toLoc = this.planetHelper.getLocationOfPlanet(to.locationId);
const toLoc = this.planetHelper.getLocationOfPlanet(toId);
if (!toLoc) throw new Error('destination location unknown');

const { x: fromX, y: fromY } = fromLoc.coords;
Expand All @@ -903,12 +905,12 @@ class GameManager extends EventEmitter implements AbstractGameManager {
return Math.sqrt((fromX - toX) ** 2 + (fromY - toY) ** 2);
}

getPlanetsInRange(planet: Planet, sendingPercent: number): Planet[] {
const loc = this.planetHelper.getLocationOfPlanet(planet.locationId);
getPlanetsInRange(planetId: LocationId, sendingPercent: number): Planet[] {
const loc = this.planetHelper.getLocationOfPlanet(planetId);
if (!loc) throw new Error('origin planet location unknown');

const ret: Planet[] = [];
const maxDist = this.getMaxMoveDist(planet, sendingPercent);
const maxDist = this.getMaxMoveDist(planetId, sendingPercent);
const planetsIt = this.planetHelper.getAllPlanets();
for (const toPlanet of planetsIt) {
const toLoc = this.planetHelper.getLocationOfPlanet(toPlanet.locationId);
Expand All @@ -920,29 +922,39 @@ class GameManager extends EventEmitter implements AbstractGameManager {
ret.push(toPlanet);
}
}
return [];
return ret;
}

getEnergyNeededForMove(
from: Planet,
to: Planet,
fromId: LocationId,
toId: LocationId,
arrivingEnergy: number
): number {
const dist = this.getDist(from, to);
const from = this.getPlanetWithId(fromId);
if (!from) throw new Error('origin planet unknown');
const dist = this.getDist(fromId, toId);
const rangeSteps = dist / from.range;

const arrivingProp = arrivingEnergy / from.energyCap + 0.05;

return arrivingProp * Math.pow(2, rangeSteps) * from.energyCap;
}

getEnergyArrivingForMove(from: Planet, to: Planet, sentEnergy: number) {
const dist = this.getDist(from, to);
getEnergyArrivingForMove(
fromId: LocationId,
toId: LocationId,
sentEnergy: number
) {
const from = this.getPlanetWithId(fromId);
if (!from) throw new Error('origin planet unknown');
const dist = this.getDist(fromId, toId);
return moveShipsDecay(sentEnergy, from, dist);
}

getTimeForMove(from: Planet, to: Planet): number {
const dist = this.getDist(from, to);
getTimeForMove(fromId: LocationId, toId: LocationId): number {
const from = this.getPlanetWithId(fromId);
if (!from) throw new Error('origin planet unknown');
const dist = this.getDist(fromId, toId);
return dist / (from.speed / 100);
}

Expand Down

0 comments on commit 6e5df2c

Please sign in to comment.