@supalosa/chronodivide-bot 0.2.1 → 0.2.2
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.
- package/.prettierrc +5 -5
- package/README.md +3 -3
- package/dist/bot/bot.js +5 -1
- package/dist/bot/bot.js.map +1 -0
- package/dist/bot/logic/awareness.js +12 -2
- package/dist/bot/logic/awareness.js.map +1 -0
- package/dist/bot/logic/awarenessImpl.js +132 -0
- package/dist/bot/logic/awarenessImpl.js.map +1 -0
- package/dist/bot/logic/building/ArtilleryUnit.js +1 -0
- package/dist/bot/logic/building/ArtilleryUnit.js.map +1 -0
- package/dist/bot/logic/building/antiGroundStaticDefence.js +1 -0
- package/dist/bot/logic/building/antiGroundStaticDefence.js.map +1 -0
- package/dist/bot/logic/building/basicAirUnit.js +1 -0
- package/dist/bot/logic/building/basicAirUnit.js.map +1 -0
- package/dist/bot/logic/building/basicBuilding.js +1 -0
- package/dist/bot/logic/building/basicBuilding.js.map +1 -0
- package/dist/bot/logic/building/basicGroundUnit.js +1 -0
- package/dist/bot/logic/building/basicGroundUnit.js.map +1 -0
- package/dist/bot/logic/building/building.js +55 -11
- package/dist/bot/logic/building/building.js.map +1 -0
- package/dist/bot/logic/building/harvester.js +1 -0
- package/dist/bot/logic/building/harvester.js.map +1 -0
- package/dist/bot/logic/building/powerPlant.js +1 -0
- package/dist/bot/logic/building/powerPlant.js.map +1 -0
- package/dist/bot/logic/building/queueController.js +1 -0
- package/dist/bot/logic/building/queueController.js.map +1 -0
- package/dist/bot/logic/building/resourceCollectionBuilding.js +1 -0
- package/dist/bot/logic/building/resourceCollectionBuilding.js.map +1 -0
- package/dist/bot/logic/common/scout.js +100 -0
- package/dist/bot/logic/common/scout.js.map +1 -0
- package/dist/bot/logic/common/utils.js +2 -0
- package/dist/bot/logic/common/utils.js.map +1 -0
- package/dist/bot/logic/map/map.js +9 -25
- package/dist/bot/logic/map/map.js.map +1 -0
- package/dist/bot/logic/map/sector.js +33 -1
- package/dist/bot/logic/map/sector.js.map +1 -0
- package/dist/bot/logic/mission/mission.js +3 -1
- package/dist/bot/logic/mission/mission.js.map +1 -0
- package/dist/bot/logic/mission/missionController.js +3 -2
- package/dist/bot/logic/mission/missionController.js.map +1 -0
- package/dist/bot/logic/mission/missionFactories.js +1 -0
- package/dist/bot/logic/mission/missionFactories.js.map +1 -0
- package/dist/bot/logic/mission/missions/attackMission.js +6 -5
- package/dist/bot/logic/mission/missions/attackMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/defenceMission.js +11 -6
- package/dist/bot/logic/mission/missions/defenceMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/expansionMission.js +5 -4
- package/dist/bot/logic/mission/missions/expansionMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/oneTimeMission.js +3 -2
- package/dist/bot/logic/mission/missions/oneTimeMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/retreatMission.js +3 -2
- package/dist/bot/logic/mission/missions/retreatMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/scoutingMission.js +8 -9
- package/dist/bot/logic/mission/missions/scoutingMission.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/attackSquad.js +63 -56
- package/dist/bot/logic/squad/behaviours/combatSquad.js +5 -2
- package/dist/bot/logic/squad/behaviours/combatSquad.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/common.js +1 -0
- package/dist/bot/logic/squad/behaviours/common.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/defenceSquad.js +15 -2
- package/dist/bot/logic/squad/behaviours/expansionSquad.js +1 -0
- package/dist/bot/logic/squad/behaviours/expansionSquad.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/retreatSquad.js +1 -0
- package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js +66 -18
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js.map +1 -0
- package/dist/bot/logic/squad/squad.js +3 -3
- package/dist/bot/logic/squad/squad.js.map +1 -0
- package/dist/bot/logic/squad/squadBehaviour.js +1 -0
- package/dist/bot/logic/squad/squadBehaviour.js.map +1 -0
- package/dist/bot/logic/squad/squadBehaviours.js +1 -0
- package/dist/bot/logic/squad/squadBehaviours.js.map +1 -0
- package/dist/bot/logic/squad/squadController.js +56 -16
- package/dist/bot/logic/squad/squadController.js.map +1 -0
- package/dist/bot/logic/threat/threat.js +1 -0
- package/dist/bot/logic/threat/threat.js.map +1 -0
- package/dist/bot/logic/threat/threatCalculator.js +1 -0
- package/dist/bot/logic/threat/threatCalculator.js.map +1 -0
- package/dist/exampleBot.js +1 -0
- package/dist/exampleBot.js.map +1 -0
- package/package.json +9 -6
- package/src/bot/bot.ts +6 -2
- package/src/bot/logic/awareness.ts +21 -4
- package/src/bot/logic/building/ArtilleryUnit.ts +43 -43
- package/src/bot/logic/building/antiGroundStaticDefence.ts +60 -60
- package/src/bot/logic/building/basicAirUnit.ts +68 -68
- package/src/bot/logic/building/basicBuilding.ts +47 -47
- package/src/bot/logic/building/building.ts +70 -12
- package/src/bot/logic/building/powerPlant.ts +32 -32
- package/src/bot/logic/building/resourceCollectionBuilding.ts +56 -56
- package/src/bot/logic/common/scout.ts +127 -1
- package/src/bot/logic/common/utils.ts +1 -0
- package/src/bot/logic/map/map.ts +70 -84
- package/src/bot/logic/map/sector.ts +46 -4
- package/src/bot/logic/mission/mission.ts +2 -2
- package/src/bot/logic/mission/missionController.ts +2 -3
- package/src/bot/logic/mission/missionFactories.ts +3 -0
- package/src/bot/logic/mission/missions/attackMission.ts +6 -2
- package/src/bot/logic/mission/missions/defenceMission.ts +34 -14
- package/src/bot/logic/mission/missions/expansionMission.ts +6 -4
- package/src/bot/logic/mission/missions/oneTimeMission.ts +3 -2
- package/src/bot/logic/mission/missions/retreatMission.ts +3 -2
- package/src/bot/logic/mission/missions/scoutingMission.ts +9 -6
- package/src/bot/logic/squad/behaviours/combatSquad.ts +5 -1
- package/src/bot/logic/squad/behaviours/scoutingSquad.ts +81 -23
- package/src/bot/logic/squad/squad.ts +3 -2
- package/src/bot/logic/squad/squadBehaviour.ts +3 -1
- package/src/bot/logic/squad/squadController.ts +88 -41
- package/src/bot/logic/threat/threat.ts +15 -15
- package/src/bot/logic/threat/threatCalculator.ts +99 -99
- package/tsconfig.json +73 -73
- package/dist/bot/logic/building/massedAntiGroundUnit.js +0 -20
- package/dist/bot/logic/building/queues.js +0 -19
- package/dist/bot/logic/knowledge.js +0 -1
- package/dist/bot/logic/mission/basicMission.js +0 -26
- package/dist/bot/logic/mission/expansionMission.js +0 -32
- package/dist/bot/logic/squad/behaviours/squadExpansion.js +0 -31
- package/dist/bot/logic/squad/behaviours/squadScouters.js +0 -8
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { GameApi, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
-
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./building.js";
|
|
4
|
-
|
|
5
|
-
export class ArtilleryUnit implements AiBuildingRules {
|
|
6
|
-
constructor(private basePriority: number, private baseAmount: number) {}
|
|
7
|
-
|
|
8
|
-
getPlacementLocation(
|
|
9
|
-
game: GameApi,
|
|
10
|
-
playerData: PlayerData,
|
|
11
|
-
technoRules: TechnoRules
|
|
12
|
-
): { rx: number; ry: number } | undefined {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
getPriority(
|
|
17
|
-
game: GameApi,
|
|
18
|
-
playerData: PlayerData,
|
|
19
|
-
technoRules: TechnoRules,
|
|
20
|
-
threatCache: GlobalThreat | null
|
|
21
|
-
): number {
|
|
22
|
-
// If the enemy's defensive power is increasing we will start to build these.
|
|
23
|
-
if (threatCache) {
|
|
24
|
-
if (threatCache.totalDefensivePower > threatCache.totalAvailableAntiGroundFirepower) {
|
|
25
|
-
return (
|
|
26
|
-
this.basePriority *
|
|
27
|
-
(threatCache.totalAvailableAntiGroundFirepower / Math.max(1, threatCache.totalDefensivePower))
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
32
|
-
return this.basePriority * (1.0 - numOwned / this.baseAmount);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
getMaxCount(
|
|
36
|
-
game: GameApi,
|
|
37
|
-
playerData: PlayerData,
|
|
38
|
-
technoRules: TechnoRules,
|
|
39
|
-
threatCache: GlobalThreat | null
|
|
40
|
-
): number | null {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
1
|
+
import { GameApi, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
+
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
+
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./building.js";
|
|
4
|
+
|
|
5
|
+
export class ArtilleryUnit implements AiBuildingRules {
|
|
6
|
+
constructor(private basePriority: number, private baseAmount: number) {}
|
|
7
|
+
|
|
8
|
+
getPlacementLocation(
|
|
9
|
+
game: GameApi,
|
|
10
|
+
playerData: PlayerData,
|
|
11
|
+
technoRules: TechnoRules
|
|
12
|
+
): { rx: number; ry: number } | undefined {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getPriority(
|
|
17
|
+
game: GameApi,
|
|
18
|
+
playerData: PlayerData,
|
|
19
|
+
technoRules: TechnoRules,
|
|
20
|
+
threatCache: GlobalThreat | null
|
|
21
|
+
): number {
|
|
22
|
+
// If the enemy's defensive power is increasing we will start to build these.
|
|
23
|
+
if (threatCache) {
|
|
24
|
+
if (threatCache.totalDefensivePower > threatCache.totalAvailableAntiGroundFirepower) {
|
|
25
|
+
return (
|
|
26
|
+
this.basePriority *
|
|
27
|
+
(threatCache.totalAvailableAntiGroundFirepower / Math.max(1, threatCache.totalDefensivePower))
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
32
|
+
return this.basePriority * (1.0 - numOwned / this.baseAmount);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getMaxCount(
|
|
36
|
+
game: GameApi,
|
|
37
|
+
playerData: PlayerData,
|
|
38
|
+
technoRules: TechnoRules,
|
|
39
|
+
threatCache: GlobalThreat | null
|
|
40
|
+
): number | null {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { GameApi, PlayerData, Point2D, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
-
import { getPointTowardsOtherPoint } from "../map/map.js";
|
|
3
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
4
|
-
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./building.js";
|
|
5
|
-
|
|
6
|
-
export class AntiGroundStaticDefence implements AiBuildingRules {
|
|
7
|
-
constructor(private basePriority: number, private baseAmount: number, private strength: number) {}
|
|
8
|
-
|
|
9
|
-
getPlacementLocation(
|
|
10
|
-
game: GameApi,
|
|
11
|
-
playerData: PlayerData,
|
|
12
|
-
technoRules: TechnoRules
|
|
13
|
-
): { rx: number; ry: number } | undefined {
|
|
14
|
-
// Prefer front towards enemy.
|
|
15
|
-
let startLocation = playerData.startLocation;
|
|
16
|
-
let players = game.getPlayers();
|
|
17
|
-
let enemyFacingLocationCandidates: Point2D[] = [];
|
|
18
|
-
for (let i = 0; i < players.length; ++i) {
|
|
19
|
-
let playerName = players[i];
|
|
20
|
-
if (playerName == playerData.name) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
let enemyPlayer = game.getPlayerData(playerName);
|
|
24
|
-
enemyFacingLocationCandidates.push(
|
|
25
|
-
getPointTowardsOtherPoint(game, startLocation, enemyPlayer.startLocation, 4, 16, 1.5)
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
let selectedLocation =
|
|
29
|
-
enemyFacingLocationCandidates[Math.floor(game.generateRandom() * enemyFacingLocationCandidates.length)];
|
|
30
|
-
return getDefaultPlacementLocation(game, playerData, selectedLocation, technoRules);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
getPriority(
|
|
34
|
-
game: GameApi,
|
|
35
|
-
playerData: PlayerData,
|
|
36
|
-
technoRules: TechnoRules,
|
|
37
|
-
threatCache: GlobalThreat | null
|
|
38
|
-
): number {
|
|
39
|
-
// If the enemy's ground power is increasing we should try to keep up.
|
|
40
|
-
if (threatCache) {
|
|
41
|
-
let denominator =
|
|
42
|
-
threatCache.totalAvailableAntiGroundFirepower + threatCache.totalDefensivePower + this.strength;
|
|
43
|
-
if (threatCache.totalOffensiveLandThreat > denominator * 1.1) {
|
|
44
|
-
return this.basePriority * (threatCache.totalOffensiveLandThreat / Math.max(1, denominator));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const strengthPerCost = (this.strength / technoRules.cost) * 1000;
|
|
48
|
-
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
49
|
-
return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getMaxCount(
|
|
53
|
-
game: GameApi,
|
|
54
|
-
playerData: PlayerData,
|
|
55
|
-
technoRules: TechnoRules,
|
|
56
|
-
threatCache: GlobalThreat | null
|
|
57
|
-
): number | null {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
1
|
+
import { GameApi, PlayerData, Point2D, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
+
import { getPointTowardsOtherPoint } from "../map/map.js";
|
|
3
|
+
import { GlobalThreat } from "../threat/threat.js";
|
|
4
|
+
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./building.js";
|
|
5
|
+
|
|
6
|
+
export class AntiGroundStaticDefence implements AiBuildingRules {
|
|
7
|
+
constructor(private basePriority: number, private baseAmount: number, private strength: number) {}
|
|
8
|
+
|
|
9
|
+
getPlacementLocation(
|
|
10
|
+
game: GameApi,
|
|
11
|
+
playerData: PlayerData,
|
|
12
|
+
technoRules: TechnoRules
|
|
13
|
+
): { rx: number; ry: number } | undefined {
|
|
14
|
+
// Prefer front towards enemy.
|
|
15
|
+
let startLocation = playerData.startLocation;
|
|
16
|
+
let players = game.getPlayers();
|
|
17
|
+
let enemyFacingLocationCandidates: Point2D[] = [];
|
|
18
|
+
for (let i = 0; i < players.length; ++i) {
|
|
19
|
+
let playerName = players[i];
|
|
20
|
+
if (playerName == playerData.name) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
let enemyPlayer = game.getPlayerData(playerName);
|
|
24
|
+
enemyFacingLocationCandidates.push(
|
|
25
|
+
getPointTowardsOtherPoint(game, startLocation, enemyPlayer.startLocation, 4, 16, 1.5)
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
let selectedLocation =
|
|
29
|
+
enemyFacingLocationCandidates[Math.floor(game.generateRandom() * enemyFacingLocationCandidates.length)];
|
|
30
|
+
return getDefaultPlacementLocation(game, playerData, selectedLocation, technoRules);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getPriority(
|
|
34
|
+
game: GameApi,
|
|
35
|
+
playerData: PlayerData,
|
|
36
|
+
technoRules: TechnoRules,
|
|
37
|
+
threatCache: GlobalThreat | null
|
|
38
|
+
): number {
|
|
39
|
+
// If the enemy's ground power is increasing we should try to keep up.
|
|
40
|
+
if (threatCache) {
|
|
41
|
+
let denominator =
|
|
42
|
+
threatCache.totalAvailableAntiGroundFirepower + threatCache.totalDefensivePower + this.strength;
|
|
43
|
+
if (threatCache.totalOffensiveLandThreat > denominator * 1.1) {
|
|
44
|
+
return this.basePriority * (threatCache.totalOffensiveLandThreat / Math.max(1, denominator));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const strengthPerCost = (this.strength / technoRules.cost) * 1000;
|
|
48
|
+
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
49
|
+
return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getMaxCount(
|
|
53
|
+
game: GameApi,
|
|
54
|
+
playerData: PlayerData,
|
|
55
|
+
technoRules: TechnoRules,
|
|
56
|
+
threatCache: GlobalThreat | null
|
|
57
|
+
): number | null {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import { GameApi, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
-
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./building.js";
|
|
4
|
-
|
|
5
|
-
export class BasicAirUnit implements AiBuildingRules {
|
|
6
|
-
constructor(
|
|
7
|
-
private basePriority: number,
|
|
8
|
-
private baseAmount: number,
|
|
9
|
-
private antiGroundPower: number = 1, // boolean for now, but will eventually be used in weighting.
|
|
10
|
-
private antiAirPower: number = 0
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
getPlacementLocation(
|
|
14
|
-
game: GameApi,
|
|
15
|
-
playerData: PlayerData,
|
|
16
|
-
technoRules: TechnoRules
|
|
17
|
-
): { rx: number; ry: number } | undefined {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getPriority(
|
|
22
|
-
game: GameApi,
|
|
23
|
-
playerData: PlayerData,
|
|
24
|
-
technoRules: TechnoRules,
|
|
25
|
-
threatCache: GlobalThreat | null
|
|
26
|
-
): number {
|
|
27
|
-
// If the enemy's anti-air power is low we might build more.
|
|
28
|
-
if (threatCache) {
|
|
29
|
-
let priority = 0;
|
|
30
|
-
if (
|
|
31
|
-
this.antiGroundPower > 0 &&
|
|
32
|
-
threatCache.totalOffensiveLandThreat > threatCache.totalAvailableAntiGroundFirepower
|
|
33
|
-
) {
|
|
34
|
-
priority +=
|
|
35
|
-
this.basePriority *
|
|
36
|
-
(threatCache.totalOffensiveLandThreat / Math.max(1, threatCache.totalAvailableAntiGroundFirepower));
|
|
37
|
-
}
|
|
38
|
-
if (
|
|
39
|
-
this.antiAirPower > 0 &&
|
|
40
|
-
threatCache.totalOffensiveAirThreat > threatCache.totalAvailableAntiAirFirepower
|
|
41
|
-
) {
|
|
42
|
-
priority +=
|
|
43
|
-
this.basePriority *
|
|
44
|
-
(threatCache.totalOffensiveAirThreat / Math.max(1, threatCache.totalAvailableAntiAirFirepower));
|
|
45
|
-
}
|
|
46
|
-
// sqrt so we don't build too much of one unit type.
|
|
47
|
-
priority += Math.min(
|
|
48
|
-
1.0,
|
|
49
|
-
Math.max(
|
|
50
|
-
1,
|
|
51
|
-
Math.sqrt(threatCache.totalAvailableAirPower / Math.max(1, threatCache.totalOffensiveAntiAirThreat))
|
|
52
|
-
)
|
|
53
|
-
);
|
|
54
|
-
return this.baseAmount * priority;
|
|
55
|
-
}
|
|
56
|
-
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
57
|
-
return this.basePriority * (1.0 - numOwned / this.baseAmount);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getMaxCount(
|
|
61
|
-
game: GameApi,
|
|
62
|
-
playerData: PlayerData,
|
|
63
|
-
technoRules: TechnoRules,
|
|
64
|
-
threatCache: GlobalThreat | null
|
|
65
|
-
): number | null {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
1
|
+
import { GameApi, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
+
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
+
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./building.js";
|
|
4
|
+
|
|
5
|
+
export class BasicAirUnit implements AiBuildingRules {
|
|
6
|
+
constructor(
|
|
7
|
+
private basePriority: number,
|
|
8
|
+
private baseAmount: number,
|
|
9
|
+
private antiGroundPower: number = 1, // boolean for now, but will eventually be used in weighting.
|
|
10
|
+
private antiAirPower: number = 0
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
getPlacementLocation(
|
|
14
|
+
game: GameApi,
|
|
15
|
+
playerData: PlayerData,
|
|
16
|
+
technoRules: TechnoRules
|
|
17
|
+
): { rx: number; ry: number } | undefined {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getPriority(
|
|
22
|
+
game: GameApi,
|
|
23
|
+
playerData: PlayerData,
|
|
24
|
+
technoRules: TechnoRules,
|
|
25
|
+
threatCache: GlobalThreat | null
|
|
26
|
+
): number {
|
|
27
|
+
// If the enemy's anti-air power is low we might build more.
|
|
28
|
+
if (threatCache) {
|
|
29
|
+
let priority = 0;
|
|
30
|
+
if (
|
|
31
|
+
this.antiGroundPower > 0 &&
|
|
32
|
+
threatCache.totalOffensiveLandThreat > threatCache.totalAvailableAntiGroundFirepower
|
|
33
|
+
) {
|
|
34
|
+
priority +=
|
|
35
|
+
this.basePriority *
|
|
36
|
+
(threatCache.totalOffensiveLandThreat / Math.max(1, threatCache.totalAvailableAntiGroundFirepower));
|
|
37
|
+
}
|
|
38
|
+
if (
|
|
39
|
+
this.antiAirPower > 0 &&
|
|
40
|
+
threatCache.totalOffensiveAirThreat > threatCache.totalAvailableAntiAirFirepower
|
|
41
|
+
) {
|
|
42
|
+
priority +=
|
|
43
|
+
this.basePriority *
|
|
44
|
+
(threatCache.totalOffensiveAirThreat / Math.max(1, threatCache.totalAvailableAntiAirFirepower));
|
|
45
|
+
}
|
|
46
|
+
// sqrt so we don't build too much of one unit type.
|
|
47
|
+
priority += Math.min(
|
|
48
|
+
1.0,
|
|
49
|
+
Math.max(
|
|
50
|
+
1,
|
|
51
|
+
Math.sqrt(threatCache.totalAvailableAirPower / Math.max(1, threatCache.totalOffensiveAntiAirThreat))
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
return this.baseAmount * priority;
|
|
55
|
+
}
|
|
56
|
+
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
57
|
+
return this.basePriority * (1.0 - numOwned / this.baseAmount);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getMaxCount(
|
|
61
|
+
game: GameApi,
|
|
62
|
+
playerData: PlayerData,
|
|
63
|
+
technoRules: TechnoRules,
|
|
64
|
+
threatCache: GlobalThreat | null
|
|
65
|
+
): number | null {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { GameApi, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
-
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./building.js";
|
|
3
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
4
|
-
|
|
5
|
-
export class BasicBuilding implements AiBuildingRules {
|
|
6
|
-
constructor(
|
|
7
|
-
protected basePriority: number,
|
|
8
|
-
protected maxNeeded: number,
|
|
9
|
-
protected onlyBuildWhenFloatingCreditsAmount?: number
|
|
10
|
-
) {}
|
|
11
|
-
|
|
12
|
-
getPlacementLocation(
|
|
13
|
-
game: GameApi,
|
|
14
|
-
playerData: PlayerData,
|
|
15
|
-
technoRules: TechnoRules
|
|
16
|
-
): { rx: number; ry: number } | undefined {
|
|
17
|
-
return getDefaultPlacementLocation(game, playerData, playerData.startLocation, technoRules);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
getPriority(
|
|
21
|
-
game: GameApi,
|
|
22
|
-
playerData: PlayerData,
|
|
23
|
-
technoRules: TechnoRules,
|
|
24
|
-
threatCache: GlobalThreat | null
|
|
25
|
-
): number {
|
|
26
|
-
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
27
|
-
const calcMaxCount = this.getMaxCount(game, playerData, technoRules, threatCache);
|
|
28
|
-
if (numOwned >= (calcMaxCount ?? this.maxNeeded)) {
|
|
29
|
-
return -100;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (this.onlyBuildWhenFloatingCreditsAmount && playerData.credits < this.onlyBuildWhenFloatingCreditsAmount) {
|
|
33
|
-
return -100;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return this.basePriority * (1.0 - numOwned / this.maxNeeded);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
getMaxCount(
|
|
40
|
-
game: GameApi,
|
|
41
|
-
playerData: PlayerData,
|
|
42
|
-
technoRules: TechnoRules,
|
|
43
|
-
threatCache: GlobalThreat | null
|
|
44
|
-
): number | null {
|
|
45
|
-
return this.maxNeeded;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
import { GameApi, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
+
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./building.js";
|
|
3
|
+
import { GlobalThreat } from "../threat/threat.js";
|
|
4
|
+
|
|
5
|
+
export class BasicBuilding implements AiBuildingRules {
|
|
6
|
+
constructor(
|
|
7
|
+
protected basePriority: number,
|
|
8
|
+
protected maxNeeded: number,
|
|
9
|
+
protected onlyBuildWhenFloatingCreditsAmount?: number
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
getPlacementLocation(
|
|
13
|
+
game: GameApi,
|
|
14
|
+
playerData: PlayerData,
|
|
15
|
+
technoRules: TechnoRules
|
|
16
|
+
): { rx: number; ry: number } | undefined {
|
|
17
|
+
return getDefaultPlacementLocation(game, playerData, playerData.startLocation, technoRules);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getPriority(
|
|
21
|
+
game: GameApi,
|
|
22
|
+
playerData: PlayerData,
|
|
23
|
+
technoRules: TechnoRules,
|
|
24
|
+
threatCache: GlobalThreat | null
|
|
25
|
+
): number {
|
|
26
|
+
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
27
|
+
const calcMaxCount = this.getMaxCount(game, playerData, technoRules, threatCache);
|
|
28
|
+
if (numOwned >= (calcMaxCount ?? this.maxNeeded)) {
|
|
29
|
+
return -100;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (this.onlyBuildWhenFloatingCreditsAmount && playerData.credits < this.onlyBuildWhenFloatingCreditsAmount) {
|
|
33
|
+
return -100;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this.basePriority * (1.0 - numOwned / this.maxNeeded);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getMaxCount(
|
|
40
|
+
game: GameApi,
|
|
41
|
+
playerData: PlayerData,
|
|
42
|
+
technoRules: TechnoRules,
|
|
43
|
+
threatCache: GlobalThreat | null
|
|
44
|
+
): number | null {
|
|
45
|
+
return this.maxNeeded;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
BuildingPlacementData,
|
|
3
|
+
GameApi,
|
|
4
|
+
ObjectType,
|
|
5
|
+
PlayerData,
|
|
6
|
+
Point2D,
|
|
7
|
+
Size,
|
|
8
|
+
TechnoRules,
|
|
9
|
+
Tile,
|
|
10
|
+
} from "@chronodivide/game-api";
|
|
2
11
|
import { GlobalThreat } from "../threat/threat.js";
|
|
3
12
|
import { AntiGroundStaticDefence } from "./antiGroundStaticDefence.js";
|
|
4
13
|
import { ArtilleryUnit } from "./ArtilleryUnit.js";
|
|
@@ -39,6 +48,60 @@ export function numBuildingsOwnedOfName(game: GameApi, playerData: PlayerData, n
|
|
|
39
48
|
return game.getVisibleUnits(playerData.name, "self", (r) => r.name === name).length;
|
|
40
49
|
}
|
|
41
50
|
|
|
51
|
+
function computeAdjacentRect(point: Point2D, t: Size, adjacent: number) {
|
|
52
|
+
return {
|
|
53
|
+
x: point.x - adjacent,
|
|
54
|
+
y: point.y - adjacent,
|
|
55
|
+
width: t.width + 2 * adjacent,
|
|
56
|
+
height: t.height + 2 * adjacent
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function getAdjacencyTiles(game: GameApi,playerData: PlayerData,technoRules: TechnoRules){
|
|
60
|
+
let tiles = []
|
|
61
|
+
let buildings= game.getVisibleUnits(playerData.name,"self",(tech:TechnoRules)=>{ return tech.type === ObjectType.Building })
|
|
62
|
+
for(let i in buildings){
|
|
63
|
+
let building = game.getUnitData(buildings[i])
|
|
64
|
+
|
|
65
|
+
if(building?.rules?.baseNormal){
|
|
66
|
+
let foundation = building?.foundation;
|
|
67
|
+
let range = computeAdjacentRect({x:building?.tile.rx,y:building?.tile.ry},{width:foundation?.width,height:foundation?.height},technoRules.adjacent)
|
|
68
|
+
let baseTile = game.mapApi.getTile(range.x,range.y)
|
|
69
|
+
if (!baseTile){
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
tiles.push(...game.mapApi.getTilesInRect(baseTile,{width:range.width,height:range.height}))
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return tiles
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
function getTileDistances(startPoint: Point2D, tiles: Tile[]) {
|
|
80
|
+
let ret = [];
|
|
81
|
+
for (let i in tiles) {
|
|
82
|
+
let currentTile = tiles[i]
|
|
83
|
+
ret.push({
|
|
84
|
+
tile:currentTile,
|
|
85
|
+
distance:distance(currentTile.rx, currentTile.ry, startPoint.x, startPoint.y)
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
ret.sort((a,b)=>{
|
|
89
|
+
return a.distance - b. distance
|
|
90
|
+
})
|
|
91
|
+
return ret
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function distance(x1: number, y1 :number, x2:number, y2:number) {
|
|
95
|
+
var dx = x1 - x2
|
|
96
|
+
var dy = y1 - y2;
|
|
97
|
+
let tmp = dx * dx + dy * dy;
|
|
98
|
+
if (0 === tmp) {
|
|
99
|
+
return 0
|
|
100
|
+
}
|
|
101
|
+
return Math.sqrt(tmp)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
42
105
|
export function getDefaultPlacementLocation(
|
|
43
106
|
game: GameApi,
|
|
44
107
|
playerData: PlayerData,
|
|
@@ -47,21 +110,16 @@ export function getDefaultPlacementLocation(
|
|
|
47
110
|
space: number = 1,
|
|
48
111
|
): { rx: number; ry: number } | undefined {
|
|
49
112
|
// Random location, preferably near start location.
|
|
50
|
-
let startX = startPoint.x;
|
|
51
|
-
let startY = startPoint.y;
|
|
52
113
|
let size: BuildingPlacementData = game.getBuildingPlacementData(technoRules.name);
|
|
53
114
|
if (!size) {
|
|
54
115
|
return undefined;
|
|
55
116
|
}
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return { rx: xx, ry: yy };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
117
|
+
let tiles = getAdjacencyTiles(game, playerData, technoRules)
|
|
118
|
+
let tileDistances = getTileDistances(startPoint, tiles)
|
|
119
|
+
|
|
120
|
+
for (let tileDistance of tileDistances) {
|
|
121
|
+
if (tileDistance.tile && game.canPlaceBuilding(playerData.name, technoRules.name, tileDistance.tile)) {
|
|
122
|
+
return tileDistance.tile;
|
|
65
123
|
}
|
|
66
124
|
}
|
|
67
125
|
return undefined;
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { GameApi, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
-
import { AiBuildingRules, getDefaultPlacementLocation } from "./building.js";
|
|
3
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
4
|
-
|
|
5
|
-
export class PowerPlant implements AiBuildingRules {
|
|
6
|
-
getPlacementLocation(
|
|
7
|
-
game: GameApi,
|
|
8
|
-
playerData: PlayerData,
|
|
9
|
-
technoRules: TechnoRules
|
|
10
|
-
): { rx: number; ry: number } | undefined {
|
|
11
|
-
return getDefaultPlacementLocation(game, playerData, playerData.startLocation, technoRules);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
getPriority(game: GameApi, playerData: PlayerData, technoRules: TechnoRules): number {
|
|
15
|
-
if (playerData.power.total < playerData.power.drain) {
|
|
16
|
-
return 100;
|
|
17
|
-
} else if (playerData.power.total < playerData.power.drain + technoRules.power / 2) {
|
|
18
|
-
return 20;
|
|
19
|
-
} else {
|
|
20
|
-
return 0;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getMaxCount(
|
|
25
|
-
game: GameApi,
|
|
26
|
-
playerData: PlayerData,
|
|
27
|
-
technoRules: TechnoRules,
|
|
28
|
-
threatCache: GlobalThreat | null
|
|
29
|
-
): number | null {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
import { GameApi, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
+
import { AiBuildingRules, getDefaultPlacementLocation } from "./building.js";
|
|
3
|
+
import { GlobalThreat } from "../threat/threat.js";
|
|
4
|
+
|
|
5
|
+
export class PowerPlant implements AiBuildingRules {
|
|
6
|
+
getPlacementLocation(
|
|
7
|
+
game: GameApi,
|
|
8
|
+
playerData: PlayerData,
|
|
9
|
+
technoRules: TechnoRules
|
|
10
|
+
): { rx: number; ry: number } | undefined {
|
|
11
|
+
return getDefaultPlacementLocation(game, playerData, playerData.startLocation, technoRules);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getPriority(game: GameApi, playerData: PlayerData, technoRules: TechnoRules): number {
|
|
15
|
+
if (playerData.power.total < playerData.power.drain) {
|
|
16
|
+
return 100;
|
|
17
|
+
} else if (playerData.power.total < playerData.power.drain + technoRules.power / 2) {
|
|
18
|
+
return 20;
|
|
19
|
+
} else {
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getMaxCount(
|
|
25
|
+
game: GameApi,
|
|
26
|
+
playerData: PlayerData,
|
|
27
|
+
technoRules: TechnoRules,
|
|
28
|
+
threatCache: GlobalThreat | null
|
|
29
|
+
): number | null {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|