@supalosa/chronodivide-bot 0.2.0 → 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 +11 -3
- package/dist/bot/bot.js +15 -7
- 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 +57 -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 +5 -4
- 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 +7 -8
- package/dist/bot/logic/mission/missions/attackMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/defenceMission.js +12 -7
- 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 +6 -3
- package/dist/bot/logic/squad/behaviours/combatSquad.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/common.js +7 -4
- 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 +6 -10
- 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 +73 -23
- 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 +24 -7
- package/dist/exampleBot.js.map +1 -0
- package/package.json +9 -6
- package/src/bot/bot.ts +17 -11
- package/src/bot/logic/awareness.ts +22 -5
- 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 +72 -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 +7 -6
- package/src/bot/logic/mission/missionFactories.ts +3 -0
- package/src/bot/logic/mission/missions/attackMission.ts +19 -13
- package/src/bot/logic/mission/missions/defenceMission.ts +35 -15
- 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 +6 -2
- package/src/bot/logic/squad/behaviours/common.ts +6 -4
- package/src/bot/logic/squad/behaviours/retreatSquad.ts +10 -12
- 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 +136 -69
- package/src/bot/logic/threat/threat.ts +15 -15
- package/src/bot/logic/threat/threatCalculator.ts +99 -99
- package/src/exampleBot.ts +25 -6
- 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,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;
|
|
@@ -84,6 +142,7 @@ export const BUILDING_NAME_TO_RULES = new Map<string, AiBuildingRules>([
|
|
|
84
142
|
["GAAIRC", new BasicBuilding(8, 1, 6000)], // Airforce Command
|
|
85
143
|
|
|
86
144
|
["GATECH", new BasicBuilding(20, 1, 4000)], // Allied Battle Lab
|
|
145
|
+
["GAYARD", new BasicBuilding(0, 0, 0)], // Naval Yard, disabled
|
|
87
146
|
|
|
88
147
|
["GAPILL", new AntiGroundStaticDefence(5, 1, 5)], // Pillbox
|
|
89
148
|
["ATESLA", new AntiGroundStaticDefence(5, 1, 10)], // Prism Cannon
|
|
@@ -109,6 +168,7 @@ export const BUILDING_NAME_TO_RULES = new Map<string, AiBuildingRules>([
|
|
|
109
168
|
["NADEPT", new BasicBuilding(1, 1, 10000)], // Repair Depot
|
|
110
169
|
["NARADR", new BasicBuilding(8, 1, 4000)], // Radar
|
|
111
170
|
["NANRCT", new PowerPlant()], // Nuclear Reactor
|
|
171
|
+
["NAYARD", new BasicBuilding(0, 0, 0)], // Naval Yard, disabled
|
|
112
172
|
|
|
113
173
|
["NATECH", new BasicBuilding(20, 1, 4000)], // Soviet Battle Lab
|
|
114
174
|
|
|
@@ -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
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { GameApi, PlayerData, Point2D, TechnoRules, Tile } from "@chronodivide/game-api";
|
|
2
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
-
import { BasicBuilding } from "./basicBuilding.js";
|
|
4
|
-
import {
|
|
5
|
-
AiBuildingRules,
|
|
6
|
-
getDefaultPlacementLocation,
|
|
7
|
-
numBuildingsOwnedOfName,
|
|
8
|
-
numBuildingsOwnedOfType,
|
|
9
|
-
} from "./building.js";
|
|
10
|
-
|
|
11
|
-
export class ResourceCollectionBuilding extends BasicBuilding {
|
|
12
|
-
constructor(basePriority: number, maxNeeded: number, onlyBuildWhenFloatingCreditsAmount?: number) {
|
|
13
|
-
super(basePriority, maxNeeded, onlyBuildWhenFloatingCreditsAmount);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
getPlacementLocation(
|
|
17
|
-
game: GameApi,
|
|
18
|
-
playerData: PlayerData,
|
|
19
|
-
technoRules: TechnoRules
|
|
20
|
-
): { rx: number; ry: number } | undefined {
|
|
21
|
-
// Prefer spawning close to ore.
|
|
22
|
-
let selectedLocation = playerData.startLocation;
|
|
23
|
-
|
|
24
|
-
var closeOre: Tile | undefined;
|
|
25
|
-
var closeOreDist: number | undefined;
|
|
26
|
-
let allTileResourceData = game.mapApi.getAllTilesResourceData();
|
|
27
|
-
for (let i = 0; i < allTileResourceData.length; ++i) {
|
|
28
|
-
let tileResourceData = allTileResourceData[i];
|
|
29
|
-
if (tileResourceData.spawnsOre) {
|
|
30
|
-
let dist = Math.sqrt(
|
|
31
|
-
(selectedLocation.x - tileResourceData.tile.rx) ** 2 +
|
|
32
|
-
(selectedLocation.y - tileResourceData.tile.ry) ** 2
|
|
33
|
-
);
|
|
34
|
-
if (closeOreDist == undefined || dist < closeOreDist) {
|
|
35
|
-
closeOreDist = dist;
|
|
36
|
-
closeOre = tileResourceData.tile;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (closeOre) {
|
|
41
|
-
selectedLocation = { x: closeOre.rx, y: closeOre.ry };
|
|
42
|
-
}
|
|
43
|
-
return getDefaultPlacementLocation(game, playerData, selectedLocation, technoRules);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Don't build/start selling these if we don't have any harvesters
|
|
47
|
-
getMaxCount(
|
|
48
|
-
game: GameApi,
|
|
49
|
-
playerData: PlayerData,
|
|
50
|
-
technoRules: TechnoRules,
|
|
51
|
-
threatCache: GlobalThreat | null
|
|
52
|
-
): number | null {
|
|
53
|
-
const harvesters = game.getVisibleUnits(playerData.name, "self", (r) => r.harvester).length;
|
|
54
|
-
return Math.max(1, harvesters * 2);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
import { GameApi, PlayerData, Point2D, TechnoRules, Tile } from "@chronodivide/game-api";
|
|
2
|
+
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
+
import { BasicBuilding } from "./basicBuilding.js";
|
|
4
|
+
import {
|
|
5
|
+
AiBuildingRules,
|
|
6
|
+
getDefaultPlacementLocation,
|
|
7
|
+
numBuildingsOwnedOfName,
|
|
8
|
+
numBuildingsOwnedOfType,
|
|
9
|
+
} from "./building.js";
|
|
10
|
+
|
|
11
|
+
export class ResourceCollectionBuilding extends BasicBuilding {
|
|
12
|
+
constructor(basePriority: number, maxNeeded: number, onlyBuildWhenFloatingCreditsAmount?: number) {
|
|
13
|
+
super(basePriority, maxNeeded, onlyBuildWhenFloatingCreditsAmount);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getPlacementLocation(
|
|
17
|
+
game: GameApi,
|
|
18
|
+
playerData: PlayerData,
|
|
19
|
+
technoRules: TechnoRules
|
|
20
|
+
): { rx: number; ry: number } | undefined {
|
|
21
|
+
// Prefer spawning close to ore.
|
|
22
|
+
let selectedLocation = playerData.startLocation;
|
|
23
|
+
|
|
24
|
+
var closeOre: Tile | undefined;
|
|
25
|
+
var closeOreDist: number | undefined;
|
|
26
|
+
let allTileResourceData = game.mapApi.getAllTilesResourceData();
|
|
27
|
+
for (let i = 0; i < allTileResourceData.length; ++i) {
|
|
28
|
+
let tileResourceData = allTileResourceData[i];
|
|
29
|
+
if (tileResourceData.spawnsOre) {
|
|
30
|
+
let dist = Math.sqrt(
|
|
31
|
+
(selectedLocation.x - tileResourceData.tile.rx) ** 2 +
|
|
32
|
+
(selectedLocation.y - tileResourceData.tile.ry) ** 2
|
|
33
|
+
);
|
|
34
|
+
if (closeOreDist == undefined || dist < closeOreDist) {
|
|
35
|
+
closeOreDist = dist;
|
|
36
|
+
closeOre = tileResourceData.tile;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (closeOre) {
|
|
41
|
+
selectedLocation = { x: closeOre.rx, y: closeOre.ry };
|
|
42
|
+
}
|
|
43
|
+
return getDefaultPlacementLocation(game, playerData, selectedLocation, technoRules);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Don't build/start selling these if we don't have any harvesters
|
|
47
|
+
getMaxCount(
|
|
48
|
+
game: GameApi,
|
|
49
|
+
playerData: PlayerData,
|
|
50
|
+
technoRules: TechnoRules,
|
|
51
|
+
threatCache: GlobalThreat | null
|
|
52
|
+
): number | null {
|
|
53
|
+
const harvesters = game.getVisibleUnits(playerData.name, "self", (r) => r.harvester).length;
|
|
54
|
+
return Math.max(1, harvesters * 2);
|
|
55
|
+
}
|
|
56
|
+
}
|