@supalosa/chronodivide-bot 0.5.4 → 0.6.6-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/.env.template +4 -4
  2. package/.github/workflows/npm-publish.yml +24 -0
  3. package/README.md +108 -103
  4. package/dist/bot/bot.js +105 -105
  5. package/dist/bot/logic/awareness.js +136 -136
  6. package/dist/bot/logic/building/antiAirStaticDefence.js +42 -42
  7. package/dist/bot/logic/building/antiGroundStaticDefence.js +34 -34
  8. package/dist/bot/logic/building/{ArtilleryUnit.js → artilleryUnit.js} +18 -18
  9. package/dist/bot/logic/building/basicAirUnit.js +19 -19
  10. package/dist/bot/logic/building/basicBuilding.js +26 -26
  11. package/dist/bot/logic/building/basicGroundUnit.js +19 -19
  12. package/dist/bot/logic/building/buildingRules.js +175 -175
  13. package/dist/bot/logic/building/common.js +19 -19
  14. package/dist/bot/logic/building/harvester.js +16 -16
  15. package/dist/bot/logic/building/powerPlant.js +20 -20
  16. package/dist/bot/logic/building/queueController.js +183 -183
  17. package/dist/bot/logic/building/resourceCollectionBuilding.js +36 -36
  18. package/dist/bot/logic/common/scout.js +126 -126
  19. package/dist/bot/logic/common/utils.js +95 -95
  20. package/dist/bot/logic/composition/alliedCompositions.js +12 -12
  21. package/dist/bot/logic/composition/common.js +1 -1
  22. package/dist/bot/logic/composition/sovietCompositions.js +12 -12
  23. package/dist/bot/logic/map/map.js +44 -44
  24. package/dist/bot/logic/map/sector.js +137 -137
  25. package/dist/bot/logic/mission/actionBatcher.js +91 -91
  26. package/dist/bot/logic/mission/mission.js +122 -122
  27. package/dist/bot/logic/mission/missionController.js +321 -321
  28. package/dist/bot/logic/mission/missionFactories.js +12 -12
  29. package/dist/bot/logic/mission/missions/attackMission.js +214 -214
  30. package/dist/bot/logic/mission/missions/defenceMission.js +82 -82
  31. package/dist/bot/logic/mission/missions/engineerMission.js +63 -63
  32. package/dist/bot/logic/mission/missions/expansionMission.js +60 -60
  33. package/dist/bot/logic/mission/missions/retreatMission.js +33 -33
  34. package/dist/bot/logic/mission/missions/scoutingMission.js +133 -133
  35. package/dist/bot/logic/mission/missions/squads/combatSquad.js +115 -115
  36. package/dist/bot/logic/mission/missions/squads/common.js +57 -57
  37. package/dist/bot/logic/mission/missions/squads/squad.js +1 -1
  38. package/dist/bot/logic/threat/threat.js +22 -22
  39. package/dist/bot/logic/threat/threatCalculator.js +73 -73
  40. package/dist/exampleBot.js +100 -100
  41. package/package.json +32 -29
  42. package/src/bot/bot.ts +161 -161
  43. package/src/bot/logic/awareness.ts +245 -245
  44. package/src/bot/logic/building/antiAirStaticDefence.ts +64 -64
  45. package/src/bot/logic/building/antiGroundStaticDefence.ts +55 -55
  46. package/src/bot/logic/building/artilleryUnit.ts +39 -39
  47. package/src/bot/logic/building/basicAirUnit.ts +39 -39
  48. package/src/bot/logic/building/basicBuilding.ts +49 -49
  49. package/src/bot/logic/building/basicGroundUnit.ts +39 -39
  50. package/src/bot/logic/building/buildingRules.ts +250 -250
  51. package/src/bot/logic/building/common.ts +21 -21
  52. package/src/bot/logic/building/harvester.ts +31 -31
  53. package/src/bot/logic/building/powerPlant.ts +32 -32
  54. package/src/bot/logic/building/queueController.ts +297 -297
  55. package/src/bot/logic/building/resourceCollectionBuilding.ts +52 -52
  56. package/src/bot/logic/common/scout.ts +183 -183
  57. package/src/bot/logic/common/utils.ts +120 -120
  58. package/src/bot/logic/composition/alliedCompositions.ts +22 -22
  59. package/src/bot/logic/composition/common.ts +3 -3
  60. package/src/bot/logic/composition/sovietCompositions.ts +21 -21
  61. package/src/bot/logic/map/map.ts +66 -66
  62. package/src/bot/logic/map/sector.ts +174 -174
  63. package/src/bot/logic/mission/actionBatcher.ts +124 -124
  64. package/src/bot/logic/mission/mission.ts +232 -232
  65. package/src/bot/logic/mission/missionController.ts +413 -413
  66. package/src/bot/logic/mission/missionFactories.ts +51 -51
  67. package/src/bot/logic/mission/missions/attackMission.ts +336 -336
  68. package/src/bot/logic/mission/missions/defenceMission.ts +151 -151
  69. package/src/bot/logic/mission/missions/engineerMission.ts +113 -113
  70. package/src/bot/logic/mission/missions/expansionMission.ts +104 -104
  71. package/src/bot/logic/mission/missions/retreatMission.ts +54 -54
  72. package/src/bot/logic/mission/missions/scoutingMission.ts +186 -186
  73. package/src/bot/logic/mission/missions/squads/combatSquad.ts +160 -160
  74. package/src/bot/logic/mission/missions/squads/common.ts +63 -63
  75. package/src/bot/logic/mission/missions/squads/squad.ts +19 -19
  76. package/src/bot/logic/threat/threat.ts +15 -15
  77. package/src/bot/logic/threat/threatCalculator.ts +100 -100
  78. package/src/exampleBot.ts +111 -111
  79. package/tsconfig.json +73 -73
  80. package/dist/bot/logic/awarenessImpl.js +0 -132
  81. package/dist/bot/logic/awarenessImpl.js.map +0 -1
  82. package/dist/bot/logic/building/building.js +0 -126
  83. package/dist/bot/logic/building/building.js.map +0 -1
  84. package/dist/bot/logic/mission/behaviours/combatSquad.js +0 -124
  85. package/dist/bot/logic/mission/behaviours/combatSquad.js.map +0 -1
  86. package/dist/bot/logic/mission/behaviours/common.js +0 -58
  87. package/dist/bot/logic/mission/behaviours/common.js.map +0 -1
  88. package/dist/bot/logic/mission/behaviours/engineerSquad.js +0 -39
  89. package/dist/bot/logic/mission/behaviours/engineerSquad.js.map +0 -1
  90. package/dist/bot/logic/mission/behaviours/expansionSquad.js +0 -46
  91. package/dist/bot/logic/mission/behaviours/expansionSquad.js.map +0 -1
  92. package/dist/bot/logic/mission/behaviours/retreatSquad.js +0 -31
  93. package/dist/bot/logic/mission/behaviours/retreatSquad.js.map +0 -1
  94. package/dist/bot/logic/mission/behaviours/scoutingSquad.js +0 -94
  95. package/dist/bot/logic/mission/behaviours/scoutingSquad.js.map +0 -1
  96. package/dist/bot/logic/mission/missions/basicMission.js +0 -13
  97. package/dist/bot/logic/mission/missions/basicMission.js.map +0 -1
  98. package/dist/bot/logic/mission/missions/missionBehaviour.js +0 -2
  99. package/dist/bot/logic/mission/missions/missionBehaviour.js.map +0 -1
  100. package/dist/bot/logic/mission/missions/oneTimeMission.js +0 -27
  101. package/dist/bot/logic/mission/missions/oneTimeMission.js.map +0 -1
  102. package/dist/bot/logic/squad/behaviours/attackSquad.js +0 -89
  103. package/dist/bot/logic/squad/behaviours/combatSquad.js +0 -102
  104. package/dist/bot/logic/squad/behaviours/combatSquad.js.map +0 -1
  105. package/dist/bot/logic/squad/behaviours/common.js +0 -40
  106. package/dist/bot/logic/squad/behaviours/common.js.map +0 -1
  107. package/dist/bot/logic/squad/behaviours/defenceSquad.js +0 -61
  108. package/dist/bot/logic/squad/behaviours/engineerSquad.js +0 -36
  109. package/dist/bot/logic/squad/behaviours/engineerSquad.js.map +0 -1
  110. package/dist/bot/logic/squad/behaviours/expansionSquad.js +0 -43
  111. package/dist/bot/logic/squad/behaviours/expansionSquad.js.map +0 -1
  112. package/dist/bot/logic/squad/behaviours/retreatSquad.js +0 -28
  113. package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +0 -1
  114. package/dist/bot/logic/squad/behaviours/scoutingSquad.js +0 -86
  115. package/dist/bot/logic/squad/behaviours/scoutingSquad.js.map +0 -1
  116. package/dist/bot/logic/squad/squad.js +0 -126
  117. package/dist/bot/logic/squad/squad.js.map +0 -1
  118. package/dist/bot/logic/squad/squadBehaviour.js +0 -6
  119. package/dist/bot/logic/squad/squadBehaviour.js.map +0 -1
  120. package/dist/bot/logic/squad/squadBehaviours.js +0 -7
  121. package/dist/bot/logic/squad/squadBehaviours.js.map +0 -1
  122. package/dist/bot/logic/squad/squadController.js +0 -199
  123. package/dist/bot/logic/squad/squadController.js.map +0 -1
  124. /package/dist/bot/logic/building/{ArtilleryUnit.js.map → artilleryUnit.js.map} +0 -0
@@ -1,137 +1,137 @@
1
- import { Vector2 } from "@chronodivide/game-api";
2
- import { calculateGlobalThreat } from "./threat/threatCalculator.js";
3
- import { getPointTowardsOtherPoint } from "./map/map.js";
4
- import { Circle, Quadtree } from "@timohausmann/quadtree-ts";
5
- import { ScoutingManager } from "./common/scout.js";
6
- const SECTORS_TO_UPDATE_PER_CYCLE = 8;
7
- const RALLY_POINT_UPDATE_INTERVAL_TICKS = 90;
8
- const THREAT_UPDATE_INTERVAL_TICKS = 30;
9
- const rebuildQuadtree = (quadtree, units) => {
10
- quadtree.clear();
11
- units.forEach((unit) => {
12
- quadtree.insert(new Circle({ x: unit.tile.rx, y: unit.tile.ry, r: 1, data: unit.id }));
13
- });
14
- };
15
- export class MatchAwarenessImpl {
16
- constructor(threatCache, sectorCache, mainRallyPoint, logger) {
17
- this.threatCache = threatCache;
18
- this.sectorCache = sectorCache;
19
- this.mainRallyPoint = mainRallyPoint;
20
- this.logger = logger;
21
- this._shouldAttack = false;
22
- const { width, height } = sectorCache.getMapBounds();
23
- this.hostileQuadTree = new Quadtree({ width, height });
24
- this.scoutingManager = new ScoutingManager(logger);
25
- }
26
- getHostilesNearPoint2d(point, radius) {
27
- return this.getHostilesNearPoint(point.x, point.y, radius);
28
- }
29
- getHostilesNearPoint(searchX, searchY, radius) {
30
- const intersections = this.hostileQuadTree.retrieve(new Circle({ x: searchX, y: searchY, r: radius }));
31
- return intersections
32
- .map(({ x, y, data: unitId }) => ({ x, y, unitId: unitId }))
33
- .filter(({ x, y }) => new Vector2(x, y).distanceTo(new Vector2(searchX, searchY)) <= radius)
34
- .filter(({ unitId }) => !!unitId);
35
- }
36
- getThreatCache() {
37
- return this.threatCache;
38
- }
39
- getSectorCache() {
40
- return this.sectorCache;
41
- }
42
- getMainRallyPoint() {
43
- return this.mainRallyPoint;
44
- }
45
- getScoutingManager() {
46
- return this.scoutingManager;
47
- }
48
- shouldAttack() {
49
- return this._shouldAttack;
50
- }
51
- checkShouldAttack(threatCache, threatFactor) {
52
- let scaledGroundPower = threatCache.totalAvailableAntiGroundFirepower * 1.1;
53
- let scaledGroundThreat = (threatFactor * threatCache.totalOffensiveLandThreat + threatCache.totalDefensiveThreat) * 1.1;
54
- let scaledAirPower = threatCache.totalAvailableAirPower * 1.1;
55
- let scaledAirThreat = (threatFactor * threatCache.totalOffensiveAntiAirThreat + threatCache.totalDefensiveThreat) * 1.1;
56
- return scaledGroundPower > scaledGroundThreat || scaledAirPower > scaledAirThreat;
57
- }
58
- isHostileUnit(unit, hostilePlayerNames) {
59
- if (!unit) {
60
- return false;
61
- }
62
- return hostilePlayerNames.includes(unit.owner);
63
- }
64
- onGameStart(gameApi, playerData) {
65
- this.scoutingManager.onGameStart(gameApi, playerData, this.sectorCache);
66
- }
67
- onAiUpdate(game, playerData) {
68
- const sectorCache = this.sectorCache;
69
- sectorCache.updateSectors(game.getCurrentTick(), SECTORS_TO_UPDATE_PER_CYCLE, game.mapApi, playerData);
70
- this.scoutingManager.onAiUpdate(game, playerData, sectorCache);
71
- let updateRatio = sectorCache?.getSectorUpdateRatio(game.getCurrentTick() - game.getTickRate() * 60);
72
- if (updateRatio && updateRatio < 1.0) {
73
- this.logger(`${updateRatio * 100.0}% of sectors updated in last 60 seconds.`);
74
- }
75
- const hostilePlayerNames = game
76
- .getPlayers()
77
- .map((name) => game.getPlayerData(name))
78
- .filter((other) => other.name !== playerData.name &&
79
- other.isCombatant &&
80
- !game.areAlliedPlayers(playerData.name, other.name))
81
- .map((other) => other.name);
82
- // Build the quadtree, if this is too slow we should consider doing this periodically.
83
- const hostileUnitIds = game.getVisibleUnits(playerData.name, "enemy");
84
- try {
85
- const hostileUnits = hostileUnitIds
86
- .map((id) => game.getGameObjectData(id))
87
- .filter((gameObjectData) => gameObjectData !== undefined);
88
- rebuildQuadtree(this.hostileQuadTree, hostileUnits);
89
- }
90
- catch (err) {
91
- // Hack. Will be fixed soon.
92
- console.error(`caught error`, hostileUnitIds);
93
- }
94
- if (game.getCurrentTick() % THREAT_UPDATE_INTERVAL_TICKS == 0) {
95
- let visibility = sectorCache?.getOverallVisibility();
96
- if (visibility) {
97
- this.logger(`${Math.round(visibility * 1000.0) / 10}% of tiles visible. Calculating threat.`);
98
- // Update the global threat cache
99
- this.threatCache = calculateGlobalThreat(game, playerData, visibility);
100
- // As the game approaches 2 hours, be more willing to attack. (15 ticks per second)
101
- const gameLengthFactor = Math.max(0, 1.0 - game.getCurrentTick() / (15 * 7200.0));
102
- this.logger(`Game length multiplier: ${gameLengthFactor}`);
103
- if (!this._shouldAttack) {
104
- // If not attacking, make it harder to switch to attack mode by multiplying the opponent's threat.
105
- this._shouldAttack = this.checkShouldAttack(this.threatCache, 1.25 * gameLengthFactor);
106
- if (this._shouldAttack) {
107
- this.logger(`Globally switched to attack mode.`);
108
- }
109
- }
110
- else {
111
- // If currently attacking, make it harder to switch to defence mode my dampening the opponent's threat.
112
- this._shouldAttack = this.checkShouldAttack(this.threatCache, 0.75 * gameLengthFactor);
113
- if (!this._shouldAttack) {
114
- this.logger(`Globally switched to defence mode.`);
115
- }
116
- }
117
- }
118
- }
119
- // Update rally point every few ticks.
120
- if (game.getCurrentTick() % RALLY_POINT_UPDATE_INTERVAL_TICKS === 0) {
121
- const enemyPlayers = game
122
- .getPlayers()
123
- .filter((p) => p !== playerData.name && !game.areAlliedPlayers(playerData.name, p));
124
- const enemy = game.getPlayerData(enemyPlayers[0]);
125
- this.mainRallyPoint = getPointTowardsOtherPoint(game, playerData.startLocation, enemy.startLocation, 10, 10, 0);
126
- }
127
- }
128
- getGlobalDebugText() {
129
- if (!this.threatCache) {
130
- return undefined;
131
- }
132
- return (`Threat LAND: Them ${Math.round(this.threatCache.totalOffensiveLandThreat)}, us: ${Math.round(this.threatCache.totalAvailableAntiGroundFirepower)}.\n` +
133
- `Threat DEFENSIVE: Them ${Math.round(this.threatCache.totalDefensiveThreat)}, us: ${Math.round(this.threatCache.totalDefensivePower)}.\n` +
134
- `Threat AIR: Them ${Math.round(this.threatCache.totalOffensiveAirThreat)}, us: ${Math.round(this.threatCache.totalAvailableAntiAirFirepower)}.`);
135
- }
136
- }
1
+ import { Vector2 } from "@chronodivide/game-api";
2
+ import { calculateGlobalThreat } from "./threat/threatCalculator.js";
3
+ import { getPointTowardsOtherPoint } from "./map/map.js";
4
+ import { Circle, Quadtree } from "@timohausmann/quadtree-ts";
5
+ import { ScoutingManager } from "./common/scout.js";
6
+ const SECTORS_TO_UPDATE_PER_CYCLE = 8;
7
+ const RALLY_POINT_UPDATE_INTERVAL_TICKS = 90;
8
+ const THREAT_UPDATE_INTERVAL_TICKS = 30;
9
+ const rebuildQuadtree = (quadtree, units) => {
10
+ quadtree.clear();
11
+ units.forEach((unit) => {
12
+ quadtree.insert(new Circle({ x: unit.tile.rx, y: unit.tile.ry, r: 1, data: unit.id }));
13
+ });
14
+ };
15
+ export class MatchAwarenessImpl {
16
+ constructor(threatCache, sectorCache, mainRallyPoint, logger) {
17
+ this.threatCache = threatCache;
18
+ this.sectorCache = sectorCache;
19
+ this.mainRallyPoint = mainRallyPoint;
20
+ this.logger = logger;
21
+ this._shouldAttack = false;
22
+ const { width, height } = sectorCache.getMapBounds();
23
+ this.hostileQuadTree = new Quadtree({ width, height });
24
+ this.scoutingManager = new ScoutingManager(logger);
25
+ }
26
+ getHostilesNearPoint2d(point, radius) {
27
+ return this.getHostilesNearPoint(point.x, point.y, radius);
28
+ }
29
+ getHostilesNearPoint(searchX, searchY, radius) {
30
+ const intersections = this.hostileQuadTree.retrieve(new Circle({ x: searchX, y: searchY, r: radius }));
31
+ return intersections
32
+ .map(({ x, y, data: unitId }) => ({ x, y, unitId: unitId }))
33
+ .filter(({ x, y }) => new Vector2(x, y).distanceTo(new Vector2(searchX, searchY)) <= radius)
34
+ .filter(({ unitId }) => !!unitId);
35
+ }
36
+ getThreatCache() {
37
+ return this.threatCache;
38
+ }
39
+ getSectorCache() {
40
+ return this.sectorCache;
41
+ }
42
+ getMainRallyPoint() {
43
+ return this.mainRallyPoint;
44
+ }
45
+ getScoutingManager() {
46
+ return this.scoutingManager;
47
+ }
48
+ shouldAttack() {
49
+ return this._shouldAttack;
50
+ }
51
+ checkShouldAttack(threatCache, threatFactor) {
52
+ let scaledGroundPower = threatCache.totalAvailableAntiGroundFirepower * 1.1;
53
+ let scaledGroundThreat = (threatFactor * threatCache.totalOffensiveLandThreat + threatCache.totalDefensiveThreat) * 1.1;
54
+ let scaledAirPower = threatCache.totalAvailableAirPower * 1.1;
55
+ let scaledAirThreat = (threatFactor * threatCache.totalOffensiveAntiAirThreat + threatCache.totalDefensiveThreat) * 1.1;
56
+ return scaledGroundPower > scaledGroundThreat || scaledAirPower > scaledAirThreat;
57
+ }
58
+ isHostileUnit(unit, hostilePlayerNames) {
59
+ if (!unit) {
60
+ return false;
61
+ }
62
+ return hostilePlayerNames.includes(unit.owner);
63
+ }
64
+ onGameStart(gameApi, playerData) {
65
+ this.scoutingManager.onGameStart(gameApi, playerData, this.sectorCache);
66
+ }
67
+ onAiUpdate(game, playerData) {
68
+ const sectorCache = this.sectorCache;
69
+ sectorCache.updateSectors(game.getCurrentTick(), SECTORS_TO_UPDATE_PER_CYCLE, game.mapApi, playerData);
70
+ this.scoutingManager.onAiUpdate(game, playerData, sectorCache);
71
+ let updateRatio = sectorCache?.getSectorUpdateRatio(game.getCurrentTick() - game.getTickRate() * 60);
72
+ if (updateRatio && updateRatio < 1.0) {
73
+ this.logger(`${updateRatio * 100.0}% of sectors updated in last 60 seconds.`);
74
+ }
75
+ const hostilePlayerNames = game
76
+ .getPlayers()
77
+ .map((name) => game.getPlayerData(name))
78
+ .filter((other) => other.name !== playerData.name &&
79
+ other.isCombatant &&
80
+ !game.areAlliedPlayers(playerData.name, other.name))
81
+ .map((other) => other.name);
82
+ // Build the quadtree, if this is too slow we should consider doing this periodically.
83
+ const hostileUnitIds = game.getVisibleUnits(playerData.name, "enemy");
84
+ try {
85
+ const hostileUnits = hostileUnitIds
86
+ .map((id) => game.getGameObjectData(id))
87
+ .filter((gameObjectData) => gameObjectData !== undefined);
88
+ rebuildQuadtree(this.hostileQuadTree, hostileUnits);
89
+ }
90
+ catch (err) {
91
+ // Hack. Will be fixed soon.
92
+ console.error(`caught error`, hostileUnitIds);
93
+ }
94
+ if (game.getCurrentTick() % THREAT_UPDATE_INTERVAL_TICKS == 0) {
95
+ let visibility = sectorCache?.getOverallVisibility();
96
+ if (visibility) {
97
+ this.logger(`${Math.round(visibility * 1000.0) / 10}% of tiles visible. Calculating threat.`);
98
+ // Update the global threat cache
99
+ this.threatCache = calculateGlobalThreat(game, playerData, visibility);
100
+ // As the game approaches 2 hours, be more willing to attack. (15 ticks per second)
101
+ const gameLengthFactor = Math.max(0, 1.0 - game.getCurrentTick() / (15 * 7200.0));
102
+ this.logger(`Game length multiplier: ${gameLengthFactor}`);
103
+ if (!this._shouldAttack) {
104
+ // If not attacking, make it harder to switch to attack mode by multiplying the opponent's threat.
105
+ this._shouldAttack = this.checkShouldAttack(this.threatCache, 1.25 * gameLengthFactor);
106
+ if (this._shouldAttack) {
107
+ this.logger(`Globally switched to attack mode.`);
108
+ }
109
+ }
110
+ else {
111
+ // If currently attacking, make it harder to switch to defence mode my dampening the opponent's threat.
112
+ this._shouldAttack = this.checkShouldAttack(this.threatCache, 0.75 * gameLengthFactor);
113
+ if (!this._shouldAttack) {
114
+ this.logger(`Globally switched to defence mode.`);
115
+ }
116
+ }
117
+ }
118
+ }
119
+ // Update rally point every few ticks.
120
+ if (game.getCurrentTick() % RALLY_POINT_UPDATE_INTERVAL_TICKS === 0) {
121
+ const enemyPlayers = game
122
+ .getPlayers()
123
+ .filter((p) => p !== playerData.name && !game.areAlliedPlayers(playerData.name, p));
124
+ const enemy = game.getPlayerData(enemyPlayers[0]);
125
+ this.mainRallyPoint = getPointTowardsOtherPoint(game, playerData.startLocation, enemy.startLocation, 10, 10, 0);
126
+ }
127
+ }
128
+ getGlobalDebugText() {
129
+ if (!this.threatCache) {
130
+ return undefined;
131
+ }
132
+ return (`Threat LAND: Them ${Math.round(this.threatCache.totalOffensiveLandThreat)}, us: ${Math.round(this.threatCache.totalAvailableAntiGroundFirepower)}.\n` +
133
+ `Threat DEFENSIVE: Them ${Math.round(this.threatCache.totalDefensiveThreat)}, us: ${Math.round(this.threatCache.totalDefensivePower)}.\n` +
134
+ `Threat AIR: Them ${Math.round(this.threatCache.totalOffensiveAirThreat)}, us: ${Math.round(this.threatCache.totalAvailableAntiAirFirepower)}.`);
135
+ }
136
+ }
137
137
  //# sourceMappingURL=awareness.js.map
@@ -1,43 +1,43 @@
1
- import { getPointTowardsOtherPoint } from "../map/map.js";
2
- import { getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
3
- export class AntiAirStaticDefence {
4
- constructor(basePriority, baseAmount, airStrength) {
5
- this.basePriority = basePriority;
6
- this.baseAmount = baseAmount;
7
- this.airStrength = airStrength;
8
- }
9
- getPlacementLocation(game, playerData, technoRules) {
10
- // Prefer front towards enemy.
11
- let startLocation = playerData.startLocation;
12
- let players = game.getPlayers();
13
- let enemyFacingLocationCandidates = [];
14
- for (let i = 0; i < players.length; ++i) {
15
- let playerName = players[i];
16
- if (playerName == playerData.name) {
17
- continue;
18
- }
19
- let enemyPlayer = game.getPlayerData(playerName);
20
- enemyFacingLocationCandidates.push(getPointTowardsOtherPoint(game, startLocation, enemyPlayer.startLocation, 4, 16, 1.5));
21
- }
22
- let selectedLocation = enemyFacingLocationCandidates[Math.floor(game.generateRandom() * enemyFacingLocationCandidates.length)];
23
- return getDefaultPlacementLocation(game, playerData, selectedLocation, technoRules, false, 0);
24
- }
25
- getPriority(game, playerData, technoRules, threatCache) {
26
- if (threatCache) {
27
- let denominator = threatCache.totalAvailableAntiAirFirepower + this.airStrength;
28
- if (threatCache.totalOffensiveAirThreat > denominator * 1.1) {
29
- return this.basePriority * (threatCache.totalOffensiveAirThreat / Math.max(1, denominator));
30
- }
31
- else {
32
- return 0;
33
- }
34
- }
35
- const strengthPerCost = (this.airStrength / technoRules.cost) * 1000;
36
- const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
37
- return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
38
- }
39
- getMaxCount(game, playerData, technoRules, threatCache) {
40
- return null;
41
- }
42
- }
1
+ import { getPointTowardsOtherPoint } from "../map/map.js";
2
+ import { getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
3
+ export class AntiAirStaticDefence {
4
+ constructor(basePriority, baseAmount, airStrength) {
5
+ this.basePriority = basePriority;
6
+ this.baseAmount = baseAmount;
7
+ this.airStrength = airStrength;
8
+ }
9
+ getPlacementLocation(game, playerData, technoRules) {
10
+ // Prefer front towards enemy.
11
+ let startLocation = playerData.startLocation;
12
+ let players = game.getPlayers();
13
+ let enemyFacingLocationCandidates = [];
14
+ for (let i = 0; i < players.length; ++i) {
15
+ let playerName = players[i];
16
+ if (playerName == playerData.name) {
17
+ continue;
18
+ }
19
+ let enemyPlayer = game.getPlayerData(playerName);
20
+ enemyFacingLocationCandidates.push(getPointTowardsOtherPoint(game, startLocation, enemyPlayer.startLocation, 4, 16, 1.5));
21
+ }
22
+ let selectedLocation = enemyFacingLocationCandidates[Math.floor(game.generateRandom() * enemyFacingLocationCandidates.length)];
23
+ return getDefaultPlacementLocation(game, playerData, selectedLocation, technoRules, false, 0);
24
+ }
25
+ getPriority(game, playerData, technoRules, threatCache) {
26
+ if (threatCache) {
27
+ let denominator = threatCache.totalAvailableAntiAirFirepower + this.airStrength;
28
+ if (threatCache.totalOffensiveAirThreat > denominator * 1.1) {
29
+ return this.basePriority * (threatCache.totalOffensiveAirThreat / Math.max(1, denominator));
30
+ }
31
+ else {
32
+ return 0;
33
+ }
34
+ }
35
+ const strengthPerCost = (this.airStrength / technoRules.cost) * 1000;
36
+ const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
37
+ return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
38
+ }
39
+ getMaxCount(game, playerData, technoRules, threatCache) {
40
+ return null;
41
+ }
42
+ }
43
43
  //# sourceMappingURL=antiAirStaticDefence.js.map
@@ -1,35 +1,35 @@
1
- import { numBuildingsOwnedOfType } from "./buildingRules.js";
2
- import { getStaticDefencePlacement } from "./common.js";
3
- export class AntiGroundStaticDefence {
4
- constructor(basePriority, baseAmount, groundStrength, limit) {
5
- this.basePriority = basePriority;
6
- this.baseAmount = baseAmount;
7
- this.groundStrength = groundStrength;
8
- this.limit = limit;
9
- }
10
- getPlacementLocation(game, playerData, technoRules) {
11
- return getStaticDefencePlacement(game, playerData, technoRules);
12
- }
13
- getPriority(game, playerData, technoRules, threatCache) {
14
- const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
15
- if (numOwned >= this.limit) {
16
- return 0;
17
- }
18
- // If the enemy's ground power is increasing we should try to keep up.
19
- if (threatCache) {
20
- let denominator = threatCache.totalAvailableAntiGroundFirepower + threatCache.totalDefensivePower + this.groundStrength;
21
- if (threatCache.totalOffensiveLandThreat > denominator * 1.1) {
22
- return this.basePriority * (threatCache.totalOffensiveLandThreat / Math.max(1, denominator));
23
- }
24
- else {
25
- return 0;
26
- }
27
- }
28
- const strengthPerCost = (this.groundStrength / technoRules.cost) * 1000;
29
- return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
30
- }
31
- getMaxCount(game, playerData, technoRules, threatCache) {
32
- return null;
33
- }
34
- }
1
+ import { numBuildingsOwnedOfType } from "./buildingRules.js";
2
+ import { getStaticDefencePlacement } from "./common.js";
3
+ export class AntiGroundStaticDefence {
4
+ constructor(basePriority, baseAmount, groundStrength, limit) {
5
+ this.basePriority = basePriority;
6
+ this.baseAmount = baseAmount;
7
+ this.groundStrength = groundStrength;
8
+ this.limit = limit;
9
+ }
10
+ getPlacementLocation(game, playerData, technoRules) {
11
+ return getStaticDefencePlacement(game, playerData, technoRules);
12
+ }
13
+ getPriority(game, playerData, technoRules, threatCache) {
14
+ const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
15
+ if (numOwned >= this.limit) {
16
+ return 0;
17
+ }
18
+ // If the enemy's ground power is increasing we should try to keep up.
19
+ if (threatCache) {
20
+ let denominator = threatCache.totalAvailableAntiGroundFirepower + threatCache.totalDefensivePower + this.groundStrength;
21
+ if (threatCache.totalOffensiveLandThreat > denominator * 1.1) {
22
+ return this.basePriority * (threatCache.totalOffensiveLandThreat / Math.max(1, denominator));
23
+ }
24
+ else {
25
+ return 0;
26
+ }
27
+ }
28
+ const strengthPerCost = (this.groundStrength / technoRules.cost) * 1000;
29
+ return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
30
+ }
31
+ getMaxCount(game, playerData, technoRules, threatCache) {
32
+ return null;
33
+ }
34
+ }
35
35
  //# sourceMappingURL=antiGroundStaticDefence.js.map
@@ -1,19 +1,19 @@
1
- export class ArtilleryUnit {
2
- constructor(basePriority, artilleryPower, antiGroundPower, baseAmount) {
3
- this.basePriority = basePriority;
4
- this.artilleryPower = artilleryPower;
5
- this.antiGroundPower = antiGroundPower;
6
- this.baseAmount = baseAmount;
7
- }
8
- getPlacementLocation(game, playerData, technoRules) {
9
- return undefined;
10
- }
11
- getPriority(game, playerData, technoRules, threatCache) {
12
- // Units aren't built automatically, but are instead requested by missions.
13
- return 0;
14
- }
15
- getMaxCount(game, playerData, technoRules, threatCache) {
16
- return null;
17
- }
18
- }
1
+ export class ArtilleryUnit {
2
+ constructor(basePriority, artilleryPower, antiGroundPower, baseAmount) {
3
+ this.basePriority = basePriority;
4
+ this.artilleryPower = artilleryPower;
5
+ this.antiGroundPower = antiGroundPower;
6
+ this.baseAmount = baseAmount;
7
+ }
8
+ getPlacementLocation(game, playerData, technoRules) {
9
+ return undefined;
10
+ }
11
+ getPriority(game, playerData, technoRules, threatCache) {
12
+ // Units aren't built automatically, but are instead requested by missions.
13
+ return 0;
14
+ }
15
+ getMaxCount(game, playerData, technoRules, threatCache) {
16
+ return null;
17
+ }
18
+ }
19
19
  //# sourceMappingURL=artilleryUnit.js.map
@@ -1,20 +1,20 @@
1
- export class BasicAirUnit {
2
- constructor(basePriority, baseAmount, antiGroundPower = 1, // boolean for now, but will eventually be used in weighting.
3
- antiAirPower = 0) {
4
- this.basePriority = basePriority;
5
- this.baseAmount = baseAmount;
6
- this.antiGroundPower = antiGroundPower;
7
- this.antiAirPower = antiAirPower;
8
- }
9
- getPlacementLocation(game, playerData, technoRules) {
10
- return undefined;
11
- }
12
- getPriority(game, playerData, technoRules, threatCache) {
13
- // Units aren't built automatically, but are instead requested by missions.
14
- return 0;
15
- }
16
- getMaxCount(game, playerData, technoRules, threatCache) {
17
- return null;
18
- }
19
- }
1
+ export class BasicAirUnit {
2
+ constructor(basePriority, baseAmount, antiGroundPower = 1, // boolean for now, but will eventually be used in weighting.
3
+ antiAirPower = 0) {
4
+ this.basePriority = basePriority;
5
+ this.baseAmount = baseAmount;
6
+ this.antiGroundPower = antiGroundPower;
7
+ this.antiAirPower = antiAirPower;
8
+ }
9
+ getPlacementLocation(game, playerData, technoRules) {
10
+ return undefined;
11
+ }
12
+ getPriority(game, playerData, technoRules, threatCache) {
13
+ // Units aren't built automatically, but are instead requested by missions.
14
+ return 0;
15
+ }
16
+ getMaxCount(game, playerData, technoRules, threatCache) {
17
+ return null;
18
+ }
19
+ }
20
20
  //# sourceMappingURL=basicAirUnit.js.map
@@ -1,27 +1,27 @@
1
- import { getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
2
- export class BasicBuilding {
3
- constructor(basePriority, maxNeeded, onlyBuildWhenFloatingCreditsAmount) {
4
- this.basePriority = basePriority;
5
- this.maxNeeded = maxNeeded;
6
- this.onlyBuildWhenFloatingCreditsAmount = onlyBuildWhenFloatingCreditsAmount;
7
- }
8
- getPlacementLocation(game, playerData, technoRules) {
9
- return getDefaultPlacementLocation(game, playerData, playerData.startLocation, technoRules);
10
- }
11
- getPriority(game, playerData, technoRules, threatCache) {
12
- const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
13
- const calcMaxCount = this.getMaxCount(game, playerData, technoRules, threatCache);
14
- if (numOwned >= (calcMaxCount ?? this.maxNeeded)) {
15
- return -100;
16
- }
17
- const priority = this.basePriority * (1.0 - numOwned / this.maxNeeded);
18
- if (this.onlyBuildWhenFloatingCreditsAmount && playerData.credits < this.onlyBuildWhenFloatingCreditsAmount) {
19
- return priority * (playerData.credits / this.onlyBuildWhenFloatingCreditsAmount);
20
- }
21
- return priority;
22
- }
23
- getMaxCount(game, playerData, technoRules, threatCache) {
24
- return this.maxNeeded;
25
- }
26
- }
1
+ import { getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
2
+ export class BasicBuilding {
3
+ constructor(basePriority, maxNeeded, onlyBuildWhenFloatingCreditsAmount) {
4
+ this.basePriority = basePriority;
5
+ this.maxNeeded = maxNeeded;
6
+ this.onlyBuildWhenFloatingCreditsAmount = onlyBuildWhenFloatingCreditsAmount;
7
+ }
8
+ getPlacementLocation(game, playerData, technoRules) {
9
+ return getDefaultPlacementLocation(game, playerData, playerData.startLocation, technoRules);
10
+ }
11
+ getPriority(game, playerData, technoRules, threatCache) {
12
+ const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
13
+ const calcMaxCount = this.getMaxCount(game, playerData, technoRules, threatCache);
14
+ if (numOwned >= (calcMaxCount ?? this.maxNeeded)) {
15
+ return -100;
16
+ }
17
+ const priority = this.basePriority * (1.0 - numOwned / this.maxNeeded);
18
+ if (this.onlyBuildWhenFloatingCreditsAmount && playerData.credits < this.onlyBuildWhenFloatingCreditsAmount) {
19
+ return priority * (playerData.credits / this.onlyBuildWhenFloatingCreditsAmount);
20
+ }
21
+ return priority;
22
+ }
23
+ getMaxCount(game, playerData, technoRules, threatCache) {
24
+ return this.maxNeeded;
25
+ }
26
+ }
27
27
  //# sourceMappingURL=basicBuilding.js.map
@@ -1,20 +1,20 @@
1
- export class BasicGroundUnit {
2
- constructor(basePriority, baseAmount, antiGroundPower = 1, // boolean for now, but will eventually be used in weighting.
3
- antiAirPower = 0) {
4
- this.basePriority = basePriority;
5
- this.baseAmount = baseAmount;
6
- this.antiGroundPower = antiGroundPower;
7
- this.antiAirPower = antiAirPower;
8
- }
9
- getPlacementLocation(game, playerData, technoRules) {
10
- return undefined;
11
- }
12
- getPriority(game, playerData, technoRules, threatCache) {
13
- // Units aren't built automatically, but are instead requested by missions.
14
- return 0;
15
- }
16
- getMaxCount(game, playerData, technoRules, threatCache) {
17
- return null;
18
- }
19
- }
1
+ export class BasicGroundUnit {
2
+ constructor(basePriority, baseAmount, antiGroundPower = 1, // boolean for now, but will eventually be used in weighting.
3
+ antiAirPower = 0) {
4
+ this.basePriority = basePriority;
5
+ this.baseAmount = baseAmount;
6
+ this.antiGroundPower = antiGroundPower;
7
+ this.antiAirPower = antiAirPower;
8
+ }
9
+ getPlacementLocation(game, playerData, technoRules) {
10
+ return undefined;
11
+ }
12
+ getPriority(game, playerData, technoRules, threatCache) {
13
+ // Units aren't built automatically, but are instead requested by missions.
14
+ return 0;
15
+ }
16
+ getMaxCount(game, playerData, technoRules, threatCache) {
17
+ return null;
18
+ }
19
+ }
20
20
  //# sourceMappingURL=basicGroundUnit.js.map