@supalosa/chronodivide-bot 0.5.3 → 0.6.4

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 (134) hide show
  1. package/.env.template +4 -4
  2. package/.github/workflows/npm-publish.yml +24 -0
  3. package/README.md +108 -97
  4. package/dist/bot/bot.js +105 -105
  5. package/dist/bot/bot.js.map +1 -1
  6. package/dist/bot/logic/awareness.js +136 -136
  7. package/dist/bot/logic/building/antiAirStaticDefence.js +42 -42
  8. package/dist/bot/logic/building/antiGroundStaticDefence.js +34 -30
  9. package/dist/bot/logic/building/antiGroundStaticDefence.js.map +1 -1
  10. package/dist/bot/logic/building/{ArtilleryUnit.js → artilleryUnit.js} +18 -18
  11. package/dist/bot/logic/building/basicAirUnit.js +19 -19
  12. package/dist/bot/logic/building/basicBuilding.js +26 -26
  13. package/dist/bot/logic/building/basicGroundUnit.js +19 -19
  14. package/dist/bot/logic/building/buildingRules.js +175 -174
  15. package/dist/bot/logic/building/buildingRules.js.map +1 -1
  16. package/dist/bot/logic/building/common.js +19 -18
  17. package/dist/bot/logic/building/common.js.map +1 -1
  18. package/dist/bot/logic/building/harvester.js +16 -16
  19. package/dist/bot/logic/building/powerPlant.js +20 -20
  20. package/dist/bot/logic/building/queueController.js +183 -183
  21. package/dist/bot/logic/building/resourceCollectionBuilding.js +36 -36
  22. package/dist/bot/logic/common/scout.js +126 -126
  23. package/dist/bot/logic/common/utils.js +95 -85
  24. package/dist/bot/logic/common/utils.js.map +1 -1
  25. package/dist/bot/logic/composition/alliedCompositions.js +12 -12
  26. package/dist/bot/logic/composition/common.js +1 -1
  27. package/dist/bot/logic/composition/sovietCompositions.js +12 -12
  28. package/dist/bot/logic/map/map.js +44 -44
  29. package/dist/bot/logic/map/sector.js +137 -137
  30. package/dist/bot/logic/mission/actionBatcher.js +91 -91
  31. package/dist/bot/logic/mission/mission.js +122 -122
  32. package/dist/bot/logic/mission/missionController.js +321 -321
  33. package/dist/bot/logic/mission/missionFactories.js +12 -12
  34. package/dist/bot/logic/mission/missions/attackMission.js +214 -214
  35. package/dist/bot/logic/mission/missions/defenceMission.js +82 -82
  36. package/dist/bot/logic/mission/missions/engineerMission.js +63 -63
  37. package/dist/bot/logic/mission/missions/expansionMission.js +60 -60
  38. package/dist/bot/logic/mission/missions/retreatMission.js +33 -33
  39. package/dist/bot/logic/mission/missions/scoutingMission.js +133 -133
  40. package/dist/bot/logic/mission/missions/squads/combatSquad.js +115 -115
  41. package/dist/bot/logic/mission/missions/squads/common.js +57 -57
  42. package/dist/bot/logic/mission/missions/squads/squad.js +1 -1
  43. package/dist/bot/logic/threat/threat.js +22 -22
  44. package/dist/bot/logic/threat/threatCalculator.js +73 -73
  45. package/dist/exampleBot.js +100 -112
  46. package/dist/exampleBot.js.map +1 -1
  47. package/package.json +32 -29
  48. package/src/bot/bot.ts +161 -161
  49. package/src/bot/logic/awareness.ts +245 -245
  50. package/src/bot/logic/building/antiAirStaticDefence.ts +64 -64
  51. package/src/bot/logic/building/antiGroundStaticDefence.ts +55 -51
  52. package/src/bot/logic/building/artilleryUnit.ts +39 -39
  53. package/src/bot/logic/building/basicAirUnit.ts +39 -39
  54. package/src/bot/logic/building/basicBuilding.ts +49 -49
  55. package/src/bot/logic/building/basicGroundUnit.ts +39 -39
  56. package/src/bot/logic/building/buildingRules.ts +250 -247
  57. package/src/bot/logic/building/common.ts +21 -23
  58. package/src/bot/logic/building/harvester.ts +31 -31
  59. package/src/bot/logic/building/powerPlant.ts +32 -32
  60. package/src/bot/logic/building/queueController.ts +297 -297
  61. package/src/bot/logic/building/resourceCollectionBuilding.ts +52 -52
  62. package/src/bot/logic/common/scout.ts +183 -183
  63. package/src/bot/logic/common/utils.ts +120 -112
  64. package/src/bot/logic/composition/alliedCompositions.ts +22 -22
  65. package/src/bot/logic/composition/common.ts +3 -3
  66. package/src/bot/logic/composition/sovietCompositions.ts +21 -21
  67. package/src/bot/logic/map/map.ts +66 -66
  68. package/src/bot/logic/map/sector.ts +174 -174
  69. package/src/bot/logic/mission/actionBatcher.ts +124 -124
  70. package/src/bot/logic/mission/mission.ts +232 -232
  71. package/src/bot/logic/mission/missionController.ts +413 -413
  72. package/src/bot/logic/mission/missionFactories.ts +51 -51
  73. package/src/bot/logic/mission/missions/attackMission.ts +336 -336
  74. package/src/bot/logic/mission/missions/defenceMission.ts +151 -151
  75. package/src/bot/logic/mission/missions/engineerMission.ts +113 -113
  76. package/src/bot/logic/mission/missions/expansionMission.ts +104 -104
  77. package/src/bot/logic/mission/missions/retreatMission.ts +54 -54
  78. package/src/bot/logic/mission/missions/scoutingMission.ts +186 -186
  79. package/src/bot/logic/mission/missions/squads/combatSquad.ts +160 -160
  80. package/src/bot/logic/mission/missions/squads/common.ts +63 -63
  81. package/src/bot/logic/mission/missions/squads/squad.ts +19 -19
  82. package/src/bot/logic/threat/threatCalculator.ts +100 -100
  83. package/src/exampleBot.ts +111 -124
  84. package/tsconfig.json +73 -73
  85. package/dist/bot/logic/building/building.js +0 -82
  86. package/dist/bot/logic/building/massedAntiGroundUnit.js +0 -20
  87. package/dist/bot/logic/building/queues.js +0 -19
  88. package/dist/bot/logic/knowledge.js +0 -1
  89. package/dist/bot/logic/mission/basicMission.js +0 -26
  90. package/dist/bot/logic/mission/behaviours/combatSquad.js +0 -124
  91. package/dist/bot/logic/mission/behaviours/combatSquad.js.map +0 -1
  92. package/dist/bot/logic/mission/behaviours/common.js +0 -56
  93. package/dist/bot/logic/mission/behaviours/common.js.map +0 -1
  94. package/dist/bot/logic/mission/behaviours/engineerSquad.js +0 -39
  95. package/dist/bot/logic/mission/behaviours/engineerSquad.js.map +0 -1
  96. package/dist/bot/logic/mission/behaviours/expansionSquad.js +0 -46
  97. package/dist/bot/logic/mission/behaviours/expansionSquad.js.map +0 -1
  98. package/dist/bot/logic/mission/behaviours/retreatSquad.js +0 -31
  99. package/dist/bot/logic/mission/behaviours/retreatSquad.js.map +0 -1
  100. package/dist/bot/logic/mission/behaviours/scoutingSquad.js +0 -94
  101. package/dist/bot/logic/mission/behaviours/scoutingSquad.js.map +0 -1
  102. package/dist/bot/logic/mission/expansionMission.js +0 -32
  103. package/dist/bot/logic/mission/missions/basicMission.js +0 -13
  104. package/dist/bot/logic/mission/missions/basicMission.js.map +0 -1
  105. package/dist/bot/logic/mission/missions/missionBehaviour.js +0 -2
  106. package/dist/bot/logic/mission/missions/missionBehaviour.js.map +0 -1
  107. package/dist/bot/logic/mission/missions/oneTimeMission.js +0 -27
  108. package/dist/bot/logic/mission/missions/oneTimeMission.js.map +0 -1
  109. package/dist/bot/logic/squad/behaviours/actionBatcher.js +0 -36
  110. package/dist/bot/logic/squad/behaviours/actionBatcher.js.map +0 -1
  111. package/dist/bot/logic/squad/behaviours/attackSquad.js +0 -82
  112. package/dist/bot/logic/squad/behaviours/combatSquad.js +0 -106
  113. package/dist/bot/logic/squad/behaviours/combatSquad.js.map +0 -1
  114. package/dist/bot/logic/squad/behaviours/common.js +0 -55
  115. package/dist/bot/logic/squad/behaviours/common.js.map +0 -1
  116. package/dist/bot/logic/squad/behaviours/defenceSquad.js +0 -48
  117. package/dist/bot/logic/squad/behaviours/engineerSquad.js +0 -38
  118. package/dist/bot/logic/squad/behaviours/engineerSquad.js.map +0 -1
  119. package/dist/bot/logic/squad/behaviours/expansionSquad.js +0 -45
  120. package/dist/bot/logic/squad/behaviours/expansionSquad.js.map +0 -1
  121. package/dist/bot/logic/squad/behaviours/retreatSquad.js +0 -31
  122. package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +0 -1
  123. package/dist/bot/logic/squad/behaviours/scoutingSquad.js +0 -93
  124. package/dist/bot/logic/squad/behaviours/scoutingSquad.js.map +0 -1
  125. package/dist/bot/logic/squad/behaviours/squadExpansion.js +0 -31
  126. package/dist/bot/logic/squad/behaviours/squadScouters.js +0 -8
  127. package/dist/bot/logic/squad/squad.js +0 -126
  128. package/dist/bot/logic/squad/squad.js.map +0 -1
  129. package/dist/bot/logic/squad/squadBehaviour.js +0 -6
  130. package/dist/bot/logic/squad/squadBehaviour.js.map +0 -1
  131. package/dist/bot/logic/squad/squadBehaviours.js +0 -7
  132. package/dist/bot/logic/squad/squadBehaviours.js.map +0 -1
  133. package/dist/bot/logic/squad/squadController.js +0 -215
  134. package/dist/bot/logic/squad/squadController.js.map +0 -1
@@ -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,31 +1,35 @@
1
- import { numBuildingsOwnedOfType } from "./buildingRules.js";
2
- import { getStaticDefencePlacement } from "./common.js";
3
- export class AntiGroundStaticDefence {
4
- constructor(basePriority, baseAmount, groundStrength) {
5
- this.basePriority = basePriority;
6
- this.baseAmount = baseAmount;
7
- this.groundStrength = groundStrength;
8
- }
9
- getPlacementLocation(game, playerData, technoRules) {
10
- return getStaticDefencePlacement(game, playerData, technoRules);
11
- }
12
- getPriority(game, playerData, technoRules, threatCache) {
13
- // If the enemy's ground power is increasing we should try to keep up.
14
- if (threatCache) {
15
- let denominator = threatCache.totalAvailableAntiGroundFirepower + threatCache.totalDefensivePower + this.groundStrength;
16
- if (threatCache.totalOffensiveLandThreat > denominator * 1.1) {
17
- return this.basePriority * (threatCache.totalOffensiveLandThreat / Math.max(1, denominator));
18
- }
19
- else {
20
- return 0;
21
- }
22
- }
23
- const strengthPerCost = (this.groundStrength / technoRules.cost) * 1000;
24
- const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
25
- return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
26
- }
27
- getMaxCount(game, playerData, technoRules, threatCache) {
28
- return null;
29
- }
30
- }
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
+ }
31
35
  //# sourceMappingURL=antiGroundStaticDefence.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"antiGroundStaticDefence.js","sourceRoot":"","sources":["../../../../src/bot/logic/building/antiGroundStaticDefence.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgD,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC3G,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,OAAO,uBAAuB;IAChC,YACY,YAAoB,EACpB,UAAkB,EAClB,cAAsB;QAFtB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,eAAU,GAAV,UAAU,CAAQ;QAClB,mBAAc,GAAd,cAAc,CAAQ;IAC/B,CAAC;IAEJ,oBAAoB,CAChB,IAAa,EACb,UAAsB,EACtB,WAAwB;QAExB,OAAO,yBAAyB,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IACpE,CAAC;IAED,WAAW,CACP,IAAa,EACb,UAAsB,EACtB,WAAwB,EACxB,WAAgC;QAEhC,sEAAsE;QACtE,IAAI,WAAW,EAAE;YACb,IAAI,WAAW,GACX,WAAW,CAAC,iCAAiC,GAAG,WAAW,CAAC,mBAAmB,GAAG,IAAI,CAAC,cAAc,CAAC;YAC1G,IAAI,WAAW,CAAC,wBAAwB,GAAG,WAAW,GAAG,GAAG,EAAE;gBAC1D,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,WAAW,CAAC,wBAAwB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;aAChG;iBAAM;gBACH,OAAO,CAAC,CAAC;aACZ;SACJ;QACD,MAAM,eAAe,GAAG,CAAC,IAAI,CAAC,cAAc,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QACxE,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QACxE,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,GAAG,GAAG,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,eAAe,CAAC;IACpF,CAAC;IAED,WAAW,CACP,IAAa,EACb,UAAsB,EACtB,WAAwB,EACxB,WAAgC;QAEhC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
1
+ {"version":3,"file":"antiGroundStaticDefence.js","sourceRoot":"","sources":["../../../../src/bot/logic/building/antiGroundStaticDefence.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgD,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC3G,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,OAAO,uBAAuB;IAChC,YACY,YAAoB,EACpB,UAAkB,EAClB,cAAsB,EACtB,KAAa;QAHb,iBAAY,GAAZ,YAAY,CAAQ;QACpB,eAAU,GAAV,UAAU,CAAQ;QAClB,mBAAc,GAAd,cAAc,CAAQ;QACtB,UAAK,GAAL,KAAK,CAAQ;IACtB,CAAC;IAEJ,oBAAoB,CAChB,IAAa,EACb,UAAsB,EACtB,WAAwB;QAExB,OAAO,yBAAyB,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IACpE,CAAC;IAED,WAAW,CACP,IAAa,EACb,UAAsB,EACtB,WAAwB,EACxB,WAAgC;QAEhC,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QACxE,IAAI,QAAQ,IAAI,IAAI,CAAC,KAAK,EAAE;YACxB,OAAO,CAAC,CAAC;SACZ;QACD,sEAAsE;QACtE,IAAI,WAAW,EAAE;YACb,IAAI,WAAW,GACX,WAAW,CAAC,iCAAiC,GAAG,WAAW,CAAC,mBAAmB,GAAG,IAAI,CAAC,cAAc,CAAC;YAC1G,IAAI,WAAW,CAAC,wBAAwB,GAAG,WAAW,GAAG,GAAG,EAAE;gBAC1D,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,WAAW,CAAC,wBAAwB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;aAChG;iBAAM;gBACH,OAAO,CAAC,CAAC;aACZ;SACJ;QACD,MAAM,eAAe,GAAG,CAAC,IAAI,CAAC,cAAc,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QACxE,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,GAAG,GAAG,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,eAAe,CAAC;IACpF,CAAC;IAED,WAAW,CACP,IAAa,EACb,UAAsB,EACtB,WAAwB,EACxB,WAAgC;QAEhC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
@@ -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