@supalosa/chronodivide-bot 0.5.4 → 0.6.6-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.template +4 -4
- package/.github/workflows/npm-publish.yml +24 -0
- package/README.md +108 -103
- package/dist/bot/bot.js +105 -105
- package/dist/bot/logic/awareness.js +136 -136
- package/dist/bot/logic/building/antiAirStaticDefence.js +42 -42
- package/dist/bot/logic/building/antiGroundStaticDefence.js +34 -34
- package/dist/bot/logic/building/{ArtilleryUnit.js → artilleryUnit.js} +18 -18
- package/dist/bot/logic/building/basicAirUnit.js +19 -19
- package/dist/bot/logic/building/basicBuilding.js +26 -26
- package/dist/bot/logic/building/basicGroundUnit.js +19 -19
- package/dist/bot/logic/building/buildingRules.js +175 -175
- package/dist/bot/logic/building/common.js +19 -19
- package/dist/bot/logic/building/harvester.js +16 -16
- package/dist/bot/logic/building/powerPlant.js +20 -20
- package/dist/bot/logic/building/queueController.js +183 -183
- package/dist/bot/logic/building/resourceCollectionBuilding.js +36 -36
- package/dist/bot/logic/common/scout.js +126 -126
- package/dist/bot/logic/common/utils.js +95 -95
- package/dist/bot/logic/composition/alliedCompositions.js +12 -12
- package/dist/bot/logic/composition/common.js +1 -1
- package/dist/bot/logic/composition/sovietCompositions.js +12 -12
- package/dist/bot/logic/map/map.js +44 -44
- package/dist/bot/logic/map/sector.js +137 -137
- package/dist/bot/logic/mission/actionBatcher.js +91 -91
- package/dist/bot/logic/mission/mission.js +122 -122
- package/dist/bot/logic/mission/missionController.js +321 -321
- package/dist/bot/logic/mission/missionFactories.js +12 -12
- package/dist/bot/logic/mission/missions/attackMission.js +214 -214
- package/dist/bot/logic/mission/missions/defenceMission.js +82 -82
- package/dist/bot/logic/mission/missions/engineerMission.js +63 -63
- package/dist/bot/logic/mission/missions/expansionMission.js +60 -60
- package/dist/bot/logic/mission/missions/retreatMission.js +33 -33
- package/dist/bot/logic/mission/missions/scoutingMission.js +133 -133
- package/dist/bot/logic/mission/missions/squads/combatSquad.js +115 -115
- package/dist/bot/logic/mission/missions/squads/common.js +57 -57
- package/dist/bot/logic/mission/missions/squads/squad.js +1 -1
- package/dist/bot/logic/threat/threat.js +22 -22
- package/dist/bot/logic/threat/threatCalculator.js +73 -73
- package/dist/exampleBot.js +100 -100
- package/package.json +32 -29
- package/src/bot/bot.ts +161 -161
- package/src/bot/logic/awareness.ts +245 -245
- package/src/bot/logic/building/antiAirStaticDefence.ts +64 -64
- package/src/bot/logic/building/antiGroundStaticDefence.ts +55 -55
- package/src/bot/logic/building/artilleryUnit.ts +39 -39
- package/src/bot/logic/building/basicAirUnit.ts +39 -39
- package/src/bot/logic/building/basicBuilding.ts +49 -49
- package/src/bot/logic/building/basicGroundUnit.ts +39 -39
- package/src/bot/logic/building/buildingRules.ts +250 -250
- package/src/bot/logic/building/common.ts +21 -21
- package/src/bot/logic/building/harvester.ts +31 -31
- package/src/bot/logic/building/powerPlant.ts +32 -32
- package/src/bot/logic/building/queueController.ts +297 -297
- package/src/bot/logic/building/resourceCollectionBuilding.ts +52 -52
- package/src/bot/logic/common/scout.ts +183 -183
- package/src/bot/logic/common/utils.ts +120 -120
- package/src/bot/logic/composition/alliedCompositions.ts +22 -22
- package/src/bot/logic/composition/common.ts +3 -3
- package/src/bot/logic/composition/sovietCompositions.ts +21 -21
- package/src/bot/logic/map/map.ts +66 -66
- package/src/bot/logic/map/sector.ts +174 -174
- package/src/bot/logic/mission/actionBatcher.ts +124 -124
- package/src/bot/logic/mission/mission.ts +232 -232
- package/src/bot/logic/mission/missionController.ts +413 -413
- package/src/bot/logic/mission/missionFactories.ts +51 -51
- package/src/bot/logic/mission/missions/attackMission.ts +336 -336
- package/src/bot/logic/mission/missions/defenceMission.ts +151 -151
- package/src/bot/logic/mission/missions/engineerMission.ts +113 -113
- package/src/bot/logic/mission/missions/expansionMission.ts +104 -104
- package/src/bot/logic/mission/missions/retreatMission.ts +54 -54
- package/src/bot/logic/mission/missions/scoutingMission.ts +186 -186
- package/src/bot/logic/mission/missions/squads/combatSquad.ts +160 -160
- package/src/bot/logic/mission/missions/squads/common.ts +63 -63
- package/src/bot/logic/mission/missions/squads/squad.ts +19 -19
- package/src/bot/logic/threat/threat.ts +15 -15
- package/src/bot/logic/threat/threatCalculator.ts +100 -100
- package/src/exampleBot.ts +111 -111
- package/tsconfig.json +73 -73
- package/dist/bot/logic/awarenessImpl.js +0 -132
- package/dist/bot/logic/awarenessImpl.js.map +0 -1
- package/dist/bot/logic/building/building.js +0 -126
- package/dist/bot/logic/building/building.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/combatSquad.js +0 -124
- package/dist/bot/logic/mission/behaviours/combatSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/common.js +0 -58
- package/dist/bot/logic/mission/behaviours/common.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/engineerSquad.js +0 -39
- package/dist/bot/logic/mission/behaviours/engineerSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/expansionSquad.js +0 -46
- package/dist/bot/logic/mission/behaviours/expansionSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/retreatSquad.js +0 -31
- package/dist/bot/logic/mission/behaviours/retreatSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/scoutingSquad.js +0 -94
- package/dist/bot/logic/mission/behaviours/scoutingSquad.js.map +0 -1
- package/dist/bot/logic/mission/missions/basicMission.js +0 -13
- package/dist/bot/logic/mission/missions/basicMission.js.map +0 -1
- package/dist/bot/logic/mission/missions/missionBehaviour.js +0 -2
- package/dist/bot/logic/mission/missions/missionBehaviour.js.map +0 -1
- package/dist/bot/logic/mission/missions/oneTimeMission.js +0 -27
- package/dist/bot/logic/mission/missions/oneTimeMission.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/attackSquad.js +0 -89
- package/dist/bot/logic/squad/behaviours/combatSquad.js +0 -102
- package/dist/bot/logic/squad/behaviours/combatSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/common.js +0 -40
- package/dist/bot/logic/squad/behaviours/common.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/defenceSquad.js +0 -61
- package/dist/bot/logic/squad/behaviours/engineerSquad.js +0 -36
- package/dist/bot/logic/squad/behaviours/engineerSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/expansionSquad.js +0 -43
- package/dist/bot/logic/squad/behaviours/expansionSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/retreatSquad.js +0 -28
- package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js +0 -86
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js.map +0 -1
- package/dist/bot/logic/squad/squad.js +0 -126
- package/dist/bot/logic/squad/squad.js.map +0 -1
- package/dist/bot/logic/squad/squadBehaviour.js +0 -6
- package/dist/bot/logic/squad/squadBehaviour.js.map +0 -1
- package/dist/bot/logic/squad/squadBehaviours.js +0 -7
- package/dist/bot/logic/squad/squadBehaviours.js.map +0 -1
- package/dist/bot/logic/squad/squadController.js +0 -199
- package/dist/bot/logic/squad/squadController.js.map +0 -1
- /package/dist/bot/logic/building/{ArtilleryUnit.js.map → artilleryUnit.js.map} +0 -0
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
import { GameObjectData, TechnoRules, UnitData } from "@chronodivide/game-api";
|
|
2
|
-
|
|
3
|
-
export enum Countries {
|
|
4
|
-
USA = "Americans",
|
|
5
|
-
KOREA = "Alliance",
|
|
6
|
-
FRANCE = "French",
|
|
7
|
-
GERMANY = "Germans",
|
|
8
|
-
GREAT_BRITAIN = "British",
|
|
9
|
-
LIBYA = "Africans",
|
|
10
|
-
IRAQ = "Arabs",
|
|
11
|
-
CUBA = "Confederation",
|
|
12
|
-
RUSSIA = "Russians",
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type DebugLogger = (message: string, sayInGame?: boolean) => void;
|
|
16
|
-
|
|
17
|
-
export const isOwnedByNeutral = (unitData: UnitData | undefined) => unitData?.owner === "@@NEUTRAL@@";
|
|
18
|
-
|
|
19
|
-
// Return if the given unit would have .isSelectableCombatant = true.
|
|
20
|
-
// Usable on GameObjectData (which is faster to get than TechnoRules)
|
|
21
|
-
export const isSelectableCombatant = (rules: GameObjectData | undefined) =>
|
|
22
|
-
!!(rules?.rules as any)?.isSelectableCombatant;
|
|
23
|
-
|
|
24
|
-
// Thanks use-strict!
|
|
25
|
-
export function formatTimeDuration(timeSeconds: number, skipZeroHours = false) {
|
|
26
|
-
let h = Math.floor(timeSeconds / 3600);
|
|
27
|
-
timeSeconds -= h * 3600;
|
|
28
|
-
let m = Math.floor(timeSeconds / 60);
|
|
29
|
-
timeSeconds -= m * 60;
|
|
30
|
-
let s = Math.floor(timeSeconds);
|
|
31
|
-
|
|
32
|
-
return [...(h || !skipZeroHours ? [h] : []), pad(m, "00"), pad(s, "00")].join(":");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function pad(n: any, format = "0000") {
|
|
36
|
-
let str = "" + n;
|
|
37
|
-
return format.substring(0, format.length - str.length) + str;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// So we don't need lodash
|
|
41
|
-
export function minBy<T>(array: T[], predicate: (arg: T) => number | null): T | null {
|
|
42
|
-
if (array.length === 0) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
let minIdx = 0;
|
|
46
|
-
let minVal = predicate(array[0]);
|
|
47
|
-
for (let i = 1; i < array.length; ++i) {
|
|
48
|
-
const newVal = predicate(array[i]);
|
|
49
|
-
if (minVal === null || (newVal !== null && newVal < minVal)) {
|
|
50
|
-
minIdx = i;
|
|
51
|
-
minVal = newVal;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return array[minIdx];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function maxBy<T>(array: T[], predicate: (arg: T) => number | null): T | null {
|
|
58
|
-
if (array.length === 0) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
let maxIdx = 0;
|
|
62
|
-
let maxVal = predicate(array[0]);
|
|
63
|
-
for (let i = 1; i < array.length; ++i) {
|
|
64
|
-
const newVal = predicate(array[i]);
|
|
65
|
-
if (maxVal === null || (newVal !== null && newVal > maxVal)) {
|
|
66
|
-
maxIdx = i;
|
|
67
|
-
maxVal = newVal;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return array[maxIdx];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function uniqBy<T>(array: T[], predicate: (arg: T) => string | number): T[] {
|
|
74
|
-
return Object.values(
|
|
75
|
-
array.reduce(
|
|
76
|
-
(prev, newVal) => {
|
|
77
|
-
const val = predicate(newVal);
|
|
78
|
-
if (!prev[val]) {
|
|
79
|
-
prev[val] = newVal;
|
|
80
|
-
}
|
|
81
|
-
return prev;
|
|
82
|
-
},
|
|
83
|
-
{} as Record<string, T>,
|
|
84
|
-
),
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function countBy<T>(array: T[], predicate: (arg: T) => string | undefined): { [key: string]: number } {
|
|
89
|
-
return array.reduce(
|
|
90
|
-
(prev, newVal) => {
|
|
91
|
-
const val = predicate(newVal);
|
|
92
|
-
if (val === undefined) {
|
|
93
|
-
return prev;
|
|
94
|
-
}
|
|
95
|
-
if (!prev[val]) {
|
|
96
|
-
prev[val] = 0;
|
|
97
|
-
}
|
|
98
|
-
prev[val] = prev[val] + 1;
|
|
99
|
-
return prev;
|
|
100
|
-
},
|
|
101
|
-
{} as Record<string, number>,
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function groupBy<K extends string, V>(array: V[], predicate: (arg: V) => K): { [key in K]: V[] } {
|
|
106
|
-
return array.reduce(
|
|
107
|
-
(prev, newVal) => {
|
|
108
|
-
const val = predicate(newVal);
|
|
109
|
-
if (val === undefined) {
|
|
110
|
-
return prev;
|
|
111
|
-
}
|
|
112
|
-
if (!prev.hasOwnProperty(val)) {
|
|
113
|
-
prev[val] = [];
|
|
114
|
-
}
|
|
115
|
-
prev[val].push(newVal);
|
|
116
|
-
return prev;
|
|
117
|
-
},
|
|
118
|
-
{} as Record<K, V[]>,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
1
|
+
import { GameObjectData, TechnoRules, UnitData } from "@chronodivide/game-api";
|
|
2
|
+
|
|
3
|
+
export enum Countries {
|
|
4
|
+
USA = "Americans",
|
|
5
|
+
KOREA = "Alliance",
|
|
6
|
+
FRANCE = "French",
|
|
7
|
+
GERMANY = "Germans",
|
|
8
|
+
GREAT_BRITAIN = "British",
|
|
9
|
+
LIBYA = "Africans",
|
|
10
|
+
IRAQ = "Arabs",
|
|
11
|
+
CUBA = "Confederation",
|
|
12
|
+
RUSSIA = "Russians",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type DebugLogger = (message: string, sayInGame?: boolean) => void;
|
|
16
|
+
|
|
17
|
+
export const isOwnedByNeutral = (unitData: UnitData | undefined) => unitData?.owner === "@@NEUTRAL@@";
|
|
18
|
+
|
|
19
|
+
// Return if the given unit would have .isSelectableCombatant = true.
|
|
20
|
+
// Usable on GameObjectData (which is faster to get than TechnoRules)
|
|
21
|
+
export const isSelectableCombatant = (rules: GameObjectData | undefined) =>
|
|
22
|
+
!!(rules?.rules as any)?.isSelectableCombatant;
|
|
23
|
+
|
|
24
|
+
// Thanks use-strict!
|
|
25
|
+
export function formatTimeDuration(timeSeconds: number, skipZeroHours = false) {
|
|
26
|
+
let h = Math.floor(timeSeconds / 3600);
|
|
27
|
+
timeSeconds -= h * 3600;
|
|
28
|
+
let m = Math.floor(timeSeconds / 60);
|
|
29
|
+
timeSeconds -= m * 60;
|
|
30
|
+
let s = Math.floor(timeSeconds);
|
|
31
|
+
|
|
32
|
+
return [...(h || !skipZeroHours ? [h] : []), pad(m, "00"), pad(s, "00")].join(":");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function pad(n: any, format = "0000") {
|
|
36
|
+
let str = "" + n;
|
|
37
|
+
return format.substring(0, format.length - str.length) + str;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// So we don't need lodash
|
|
41
|
+
export function minBy<T>(array: T[], predicate: (arg: T) => number | null): T | null {
|
|
42
|
+
if (array.length === 0) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
let minIdx = 0;
|
|
46
|
+
let minVal = predicate(array[0]);
|
|
47
|
+
for (let i = 1; i < array.length; ++i) {
|
|
48
|
+
const newVal = predicate(array[i]);
|
|
49
|
+
if (minVal === null || (newVal !== null && newVal < minVal)) {
|
|
50
|
+
minIdx = i;
|
|
51
|
+
minVal = newVal;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return array[minIdx];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function maxBy<T>(array: T[], predicate: (arg: T) => number | null): T | null {
|
|
58
|
+
if (array.length === 0) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
let maxIdx = 0;
|
|
62
|
+
let maxVal = predicate(array[0]);
|
|
63
|
+
for (let i = 1; i < array.length; ++i) {
|
|
64
|
+
const newVal = predicate(array[i]);
|
|
65
|
+
if (maxVal === null || (newVal !== null && newVal > maxVal)) {
|
|
66
|
+
maxIdx = i;
|
|
67
|
+
maxVal = newVal;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return array[maxIdx];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function uniqBy<T>(array: T[], predicate: (arg: T) => string | number): T[] {
|
|
74
|
+
return Object.values(
|
|
75
|
+
array.reduce(
|
|
76
|
+
(prev, newVal) => {
|
|
77
|
+
const val = predicate(newVal);
|
|
78
|
+
if (!prev[val]) {
|
|
79
|
+
prev[val] = newVal;
|
|
80
|
+
}
|
|
81
|
+
return prev;
|
|
82
|
+
},
|
|
83
|
+
{} as Record<string, T>,
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function countBy<T>(array: T[], predicate: (arg: T) => string | undefined): { [key: string]: number } {
|
|
89
|
+
return array.reduce(
|
|
90
|
+
(prev, newVal) => {
|
|
91
|
+
const val = predicate(newVal);
|
|
92
|
+
if (val === undefined) {
|
|
93
|
+
return prev;
|
|
94
|
+
}
|
|
95
|
+
if (!prev[val]) {
|
|
96
|
+
prev[val] = 0;
|
|
97
|
+
}
|
|
98
|
+
prev[val] = prev[val] + 1;
|
|
99
|
+
return prev;
|
|
100
|
+
},
|
|
101
|
+
{} as Record<string, number>,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function groupBy<K extends string, V>(array: V[], predicate: (arg: V) => K): { [key in K]: V[] } {
|
|
106
|
+
return array.reduce(
|
|
107
|
+
(prev, newVal) => {
|
|
108
|
+
const val = predicate(newVal);
|
|
109
|
+
if (val === undefined) {
|
|
110
|
+
return prev;
|
|
111
|
+
}
|
|
112
|
+
if (!prev.hasOwnProperty(val)) {
|
|
113
|
+
prev[val] = [];
|
|
114
|
+
}
|
|
115
|
+
prev[val].push(newVal);
|
|
116
|
+
return prev;
|
|
117
|
+
},
|
|
118
|
+
{} as Record<K, V[]>,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { GameApi, PlayerData } from "@chronodivide/game-api";
|
|
2
|
-
import { MatchAwareness } from "../awareness";
|
|
3
|
-
import { UnitComposition } from "./common";
|
|
4
|
-
|
|
5
|
-
export const getAlliedCompositions = (
|
|
6
|
-
gameApi: GameApi,
|
|
7
|
-
playerData: PlayerData,
|
|
8
|
-
matchAwareness: MatchAwareness,
|
|
9
|
-
): UnitComposition => {
|
|
10
|
-
const hasWarFactory = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GAWEAP").length > 0;
|
|
11
|
-
const hasAirforce =
|
|
12
|
-
gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GAAIRC" || r.name === "AMRADR").length > 0;
|
|
13
|
-
const hasBattleLab = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GATECH").length > 0;
|
|
14
|
-
|
|
15
|
-
const includeInfantry = !hasAirforce && !hasBattleLab;
|
|
16
|
-
return {
|
|
17
|
-
...(includeInfantry && { E1: 5 }),
|
|
18
|
-
...(hasWarFactory && { MTNK: 3, FV: 2 }),
|
|
19
|
-
...(hasAirforce && { JUMPJET: 6 }),
|
|
20
|
-
...(hasBattleLab && { SREF: 2, MGTK: 3 }),
|
|
21
|
-
};
|
|
22
|
-
};
|
|
1
|
+
import { GameApi, PlayerData } from "@chronodivide/game-api";
|
|
2
|
+
import { MatchAwareness } from "../awareness";
|
|
3
|
+
import { UnitComposition } from "./common";
|
|
4
|
+
|
|
5
|
+
export const getAlliedCompositions = (
|
|
6
|
+
gameApi: GameApi,
|
|
7
|
+
playerData: PlayerData,
|
|
8
|
+
matchAwareness: MatchAwareness,
|
|
9
|
+
): UnitComposition => {
|
|
10
|
+
const hasWarFactory = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GAWEAP").length > 0;
|
|
11
|
+
const hasAirforce =
|
|
12
|
+
gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GAAIRC" || r.name === "AMRADR").length > 0;
|
|
13
|
+
const hasBattleLab = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GATECH").length > 0;
|
|
14
|
+
|
|
15
|
+
const includeInfantry = !hasAirforce && !hasBattleLab;
|
|
16
|
+
return {
|
|
17
|
+
...(includeInfantry && { E1: 5 }),
|
|
18
|
+
...(hasWarFactory && { MTNK: 3, FV: 2 }),
|
|
19
|
+
...(hasAirforce && { JUMPJET: 6 }),
|
|
20
|
+
...(hasBattleLab && { SREF: 2, MGTK: 3 }),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type UnitComposition = {
|
|
2
|
-
[unitType: string]: number;
|
|
3
|
-
};
|
|
1
|
+
export type UnitComposition = {
|
|
2
|
+
[unitType: string]: number;
|
|
3
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { GameApi, PlayerData } from "@chronodivide/game-api";
|
|
2
|
-
import { MatchAwareness } from "../awareness";
|
|
3
|
-
import { UnitComposition } from "./common";
|
|
4
|
-
|
|
5
|
-
export const getSovietComposition = (
|
|
6
|
-
gameApi: GameApi,
|
|
7
|
-
playerData: PlayerData,
|
|
8
|
-
matchAwareness: MatchAwareness,
|
|
9
|
-
): UnitComposition => {
|
|
10
|
-
const hasWarFactory = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NAWEAP").length > 0;
|
|
11
|
-
const hasRadar = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NARADR").length > 0;
|
|
12
|
-
const hasBattleLab = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NATECH").length > 0;
|
|
13
|
-
|
|
14
|
-
const includeInfantry = !hasBattleLab;
|
|
15
|
-
return {
|
|
16
|
-
...(includeInfantry && { E2: 10 }),
|
|
17
|
-
...(hasWarFactory && { HTNK: 3, HTK: 2 }),
|
|
18
|
-
...(hasRadar && { V3: 1 }),
|
|
19
|
-
...(hasBattleLab && { APOC: 2 }),
|
|
20
|
-
};
|
|
21
|
-
};
|
|
1
|
+
import { GameApi, PlayerData } from "@chronodivide/game-api";
|
|
2
|
+
import { MatchAwareness } from "../awareness";
|
|
3
|
+
import { UnitComposition } from "./common";
|
|
4
|
+
|
|
5
|
+
export const getSovietComposition = (
|
|
6
|
+
gameApi: GameApi,
|
|
7
|
+
playerData: PlayerData,
|
|
8
|
+
matchAwareness: MatchAwareness,
|
|
9
|
+
): UnitComposition => {
|
|
10
|
+
const hasWarFactory = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NAWEAP").length > 0;
|
|
11
|
+
const hasRadar = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NARADR").length > 0;
|
|
12
|
+
const hasBattleLab = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NATECH").length > 0;
|
|
13
|
+
|
|
14
|
+
const includeInfantry = !hasBattleLab;
|
|
15
|
+
return {
|
|
16
|
+
...(includeInfantry && { E2: 10 }),
|
|
17
|
+
...(hasWarFactory && { HTNK: 3, HTK: 2 }),
|
|
18
|
+
...(hasRadar && { V3: 1 }),
|
|
19
|
+
...(hasBattleLab && { APOC: 2 }),
|
|
20
|
+
};
|
|
21
|
+
};
|
package/src/bot/logic/map/map.ts
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { GameApi, GameMath, MapApi, PlayerData, Size, Tile, UnitData, Vector2 } from "@chronodivide/game-api";
|
|
2
|
-
import { maxBy } from "../common/utils.js";
|
|
3
|
-
|
|
4
|
-
export function determineMapBounds(mapApi: MapApi): Size {
|
|
5
|
-
return mapApi.getRealMapSize();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function calculateAreaVisibility(
|
|
9
|
-
mapApi: MapApi,
|
|
10
|
-
playerData: PlayerData,
|
|
11
|
-
startPoint: Vector2,
|
|
12
|
-
endPoint: Vector2,
|
|
13
|
-
): { visibleTiles: number; validTiles: number } {
|
|
14
|
-
let validTiles: number = 0,
|
|
15
|
-
visibleTiles: number = 0;
|
|
16
|
-
for (let xx = startPoint.x; xx < endPoint.x; ++xx) {
|
|
17
|
-
for (let yy = startPoint.y; yy < endPoint.y; ++yy) {
|
|
18
|
-
let tile = mapApi.getTile(xx, yy);
|
|
19
|
-
if (tile) {
|
|
20
|
-
++validTiles;
|
|
21
|
-
if (mapApi.isVisibleTile(tile, playerData.name)) {
|
|
22
|
-
++visibleTiles;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
let result = { visibleTiles, validTiles };
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function getPointTowardsOtherPoint(
|
|
32
|
-
gameApi: GameApi,
|
|
33
|
-
startLocation: Vector2,
|
|
34
|
-
endLocation: Vector2,
|
|
35
|
-
minRadius: number,
|
|
36
|
-
maxRadius: number,
|
|
37
|
-
randomAngle: number,
|
|
38
|
-
): Vector2 {
|
|
39
|
-
// TODO: Use proper vector maths here.
|
|
40
|
-
let radius = minRadius + Math.round(gameApi.generateRandom() * (maxRadius - minRadius));
|
|
41
|
-
let directionToEndLocation = GameMath.atan2(endLocation.y - startLocation.y, endLocation.x - startLocation.x);
|
|
42
|
-
let randomisedDirection =
|
|
43
|
-
directionToEndLocation -
|
|
44
|
-
(randomAngle * (Math.PI / 12) + 2 * randomAngle * gameApi.generateRandom() * (Math.PI / 12));
|
|
45
|
-
let candidatePointX = Math.round(startLocation.x + GameMath.cos(randomisedDirection) * radius);
|
|
46
|
-
let candidatePointY = Math.round(startLocation.y + GameMath.sin(randomisedDirection) * radius);
|
|
47
|
-
return new Vector2(candidatePointX, candidatePointY);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function getDistanceBetweenPoints(startLocation: Vector2, endLocation: Vector2): number {
|
|
51
|
-
// TODO: Remove this now we have Vector2s.
|
|
52
|
-
return startLocation.distanceTo(endLocation);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function getDistanceBetweenTileAndPoint(tile: Tile, vector: Vector2): number {
|
|
56
|
-
// TODO: Remove this now we have Vector2s.
|
|
57
|
-
return new Vector2(tile.rx, tile.ry).distanceTo(vector);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function getDistanceBetweenUnits(unit1: UnitData, unit2: UnitData): number {
|
|
61
|
-
return new Vector2(unit1.tile.rx, unit1.tile.ry).distanceTo(new Vector2(unit2.tile.rx, unit2.tile.ry));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function getDistanceBetween(unit: UnitData, point: Vector2): number {
|
|
65
|
-
return getDistanceBetweenPoints(new Vector2(unit.tile.rx, unit.tile.ry), point);
|
|
66
|
-
}
|
|
1
|
+
import { GameApi, GameMath, MapApi, PlayerData, Size, Tile, UnitData, Vector2 } from "@chronodivide/game-api";
|
|
2
|
+
import { maxBy } from "../common/utils.js";
|
|
3
|
+
|
|
4
|
+
export function determineMapBounds(mapApi: MapApi): Size {
|
|
5
|
+
return mapApi.getRealMapSize();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function calculateAreaVisibility(
|
|
9
|
+
mapApi: MapApi,
|
|
10
|
+
playerData: PlayerData,
|
|
11
|
+
startPoint: Vector2,
|
|
12
|
+
endPoint: Vector2,
|
|
13
|
+
): { visibleTiles: number; validTiles: number } {
|
|
14
|
+
let validTiles: number = 0,
|
|
15
|
+
visibleTiles: number = 0;
|
|
16
|
+
for (let xx = startPoint.x; xx < endPoint.x; ++xx) {
|
|
17
|
+
for (let yy = startPoint.y; yy < endPoint.y; ++yy) {
|
|
18
|
+
let tile = mapApi.getTile(xx, yy);
|
|
19
|
+
if (tile) {
|
|
20
|
+
++validTiles;
|
|
21
|
+
if (mapApi.isVisibleTile(tile, playerData.name)) {
|
|
22
|
+
++visibleTiles;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let result = { visibleTiles, validTiles };
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getPointTowardsOtherPoint(
|
|
32
|
+
gameApi: GameApi,
|
|
33
|
+
startLocation: Vector2,
|
|
34
|
+
endLocation: Vector2,
|
|
35
|
+
minRadius: number,
|
|
36
|
+
maxRadius: number,
|
|
37
|
+
randomAngle: number,
|
|
38
|
+
): Vector2 {
|
|
39
|
+
// TODO: Use proper vector maths here.
|
|
40
|
+
let radius = minRadius + Math.round(gameApi.generateRandom() * (maxRadius - minRadius));
|
|
41
|
+
let directionToEndLocation = GameMath.atan2(endLocation.y - startLocation.y, endLocation.x - startLocation.x);
|
|
42
|
+
let randomisedDirection =
|
|
43
|
+
directionToEndLocation -
|
|
44
|
+
(randomAngle * (Math.PI / 12) + 2 * randomAngle * gameApi.generateRandom() * (Math.PI / 12));
|
|
45
|
+
let candidatePointX = Math.round(startLocation.x + GameMath.cos(randomisedDirection) * radius);
|
|
46
|
+
let candidatePointY = Math.round(startLocation.y + GameMath.sin(randomisedDirection) * radius);
|
|
47
|
+
return new Vector2(candidatePointX, candidatePointY);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getDistanceBetweenPoints(startLocation: Vector2, endLocation: Vector2): number {
|
|
51
|
+
// TODO: Remove this now we have Vector2s.
|
|
52
|
+
return startLocation.distanceTo(endLocation);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function getDistanceBetweenTileAndPoint(tile: Tile, vector: Vector2): number {
|
|
56
|
+
// TODO: Remove this now we have Vector2s.
|
|
57
|
+
return new Vector2(tile.rx, tile.ry).distanceTo(vector);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getDistanceBetweenUnits(unit1: UnitData, unit2: UnitData): number {
|
|
61
|
+
return new Vector2(unit1.tile.rx, unit1.tile.ry).distanceTo(new Vector2(unit2.tile.rx, unit2.tile.ry));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function getDistanceBetween(unit: UnitData, point: Vector2): number {
|
|
65
|
+
return getDistanceBetweenPoints(new Vector2(unit.tile.rx, unit.tile.ry), point);
|
|
66
|
+
}
|