qpremake 1.5.3 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/README.md +5 -3
  2. package/package.json +2 -7
  3. package/lib/_localizationFiles/English.d.ts +0 -2
  4. package/lib/_localizationFiles/English.js +0 -307
  5. package/lib/_mods/parserModules/addSymbol.d.ts +0 -7
  6. package/lib/_mods/parserModules/addSymbol.js +0 -18
  7. package/lib/_mods/parserModules/expression.d.ts +0 -7
  8. package/lib/_mods/parserModules/expression.js +0 -45
  9. package/lib/_mods/parserModules/expression_parser.d.ts +0 -143
  10. package/lib/_mods/parserModules/expression_parser.js +0 -728
  11. package/lib/_mods/parserModules/img.d.ts +0 -8
  12. package/lib/_mods/parserModules/img.js +0 -42
  13. package/lib/_mods/parserModules/qpOriginal.d.ts +0 -5
  14. package/lib/_mods/parserModules/qpOriginal.js +0 -27
  15. package/lib/_mods/parserModules/sectionID.d.ts +0 -13
  16. package/lib/_mods/parserModules/sectionID.js +0 -56
  17. package/lib/_mods/parserModules/tags.d.ts +0 -9
  18. package/lib/_mods/parserModules/tags.js +0 -29
  19. package/lib/_mods/parserModules/uaddminus.d.ts +0 -9
  20. package/lib/_mods/parserModules/uaddminus.js +0 -42
  21. package/lib/_mods/parserModules/variantCheck.d.ts +0 -10
  22. package/lib/_mods/parserModules/variantCheck.js +0 -53
  23. package/lib/_queenSystem/handler/actionGenrator.d.ts +0 -994
  24. package/lib/_queenSystem/handler/actionGenrator.js +0 -646
  25. package/lib/_queenSystem/handler/actionInputGenerator.d.ts +0 -95
  26. package/lib/_queenSystem/handler/actionInputGenerator.js +0 -373
  27. package/lib/_queenSystem/handler/actionInputRequesterGenerator.d.ts +0 -92
  28. package/lib/_queenSystem/handler/actionInputRequesterGenerator.js +0 -341
  29. package/lib/_queenSystem/handler/cardHandler.d.ts +0 -20
  30. package/lib/_queenSystem/handler/cardHandler.js +0 -61
  31. package/lib/_queenSystem/handler/effectGenerator.d.ts +0 -1
  32. package/lib/_queenSystem/handler/effectGenerator.js +0 -127
  33. package/lib/_queenSystem/handler/localizationHandler.d.ts +0 -28
  34. package/lib/_queenSystem/handler/localizationHandler.js +0 -166
  35. package/lib/_queenSystem/handler/modHandler.d.ts +0 -10
  36. package/lib/_queenSystem/handler/modHandler.js +0 -36
  37. package/lib/_queenSystem/handler/oldDataProcessor.d.ts +0 -9
  38. package/lib/_queenSystem/handler/oldDataProcessor.js +0 -129
  39. package/lib/_queenSystem/handler/registryHandler.d.ts +0 -36
  40. package/lib/_queenSystem/handler/registryHandler.js +0 -63
  41. package/lib/_queenSystem/handler/zoneHandler.d.ts +0 -102
  42. package/lib/_queenSystem/handler/zoneHandler.js +0 -606
  43. package/lib/_queenSystem/loader/loader_card.d.ts +0 -20
  44. package/lib/_queenSystem/loader/loader_card.js +0 -124
  45. package/lib/_queenSystem/loader/loader_effect.d.ts +0 -27
  46. package/lib/_queenSystem/loader/loader_effect.js +0 -163
  47. package/lib/_queenSystem/loader/loader_handler.d.ts +0 -11
  48. package/lib/_queenSystem/loader/loader_handler.js +0 -24
  49. package/lib/_queenSystem/loader/loader_localization.d.ts +0 -11
  50. package/lib/_queenSystem/loader/loader_localization.js +0 -73
  51. package/lib/_queenSystem/loader/loader_mod.d.ts +0 -10
  52. package/lib/_queenSystem/loader/loader_mod.js +0 -72
  53. package/lib/_queenSystem/loader/loader_subtype.d.ts +0 -9
  54. package/lib/_queenSystem/loader/loader_subtype.js +0 -39
  55. package/lib/_queenSystem/loader/loader_type.d.ts +0 -9
  56. package/lib/_queenSystem/loader/loader_type.js +0 -39
  57. package/lib/_queenSystem/loader/loader_zone.d.ts +0 -14
  58. package/lib/_queenSystem/loader/loader_zone.js +0 -35
  59. package/lib/_queenSystem/queenSystem.d.ts +0 -127
  60. package/lib/_queenSystem/queenSystem.js +0 -996
  61. package/lib/_queenSystem/renderer/rendererInterface.d.ts +0 -27
  62. package/lib/_queenSystem/renderer/rendererInterface.js +0 -25
  63. package/lib/data/actionRegistry.d.ts +0 -56
  64. package/lib/data/actionRegistry.js +0 -60
  65. package/lib/data/cardRegistry.d.ts +0 -1162
  66. package/lib/data/cardRegistry.js +0 -716
  67. package/lib/data/deckRegistry.d.ts +0 -19
  68. package/lib/data/deckRegistry.js +0 -41
  69. package/lib/data/effectRegistry.d.ts +0 -465
  70. package/lib/data/effectRegistry.js +0 -151
  71. package/lib/data/effectTypeRegistry.d.ts +0 -14
  72. package/lib/data/effectTypeRegistry.js +0 -14
  73. package/lib/data/operatorRegistry.d.ts +0 -92
  74. package/lib/data/operatorRegistry.js +0 -82
  75. package/lib/data/rarityRegistry.d.ts +0 -28
  76. package/lib/data/rarityRegistry.js +0 -63
  77. package/lib/data/registryRegistry.d.ts +0 -10
  78. package/lib/data/registryRegistry.js +0 -14
  79. package/lib/data/subtypeRegistry.d.ts +0 -15
  80. package/lib/data/subtypeRegistry.js +0 -15
  81. package/lib/data/systemRegistry.d.ts +0 -253
  82. package/lib/data/systemRegistry.js +0 -56
  83. package/lib/data/zoneRegistry.d.ts +0 -43
  84. package/lib/data/zoneRegistry.js +0 -157
  85. package/lib/effectTextParser/index.d.ts +0 -42
  86. package/lib/effectTextParser/index.js +0 -316
  87. package/lib/global/index.d.ts +0 -8
  88. package/lib/global/index.js +0 -12
  89. package/lib/index.d.ts +0 -6335
  90. package/lib/index.js +0 -205
  91. package/lib/specificEffects/e_cond.d.ts +0 -11
  92. package/lib/specificEffects/e_cond.js +0 -36
  93. package/lib/specificEffects/e_fruit.d.ts +0 -3
  94. package/lib/specificEffects/e_fruit.js +0 -187
  95. package/lib/specificEffects/e_generic.d.ts +0 -191
  96. package/lib/specificEffects/e_generic.js +0 -662
  97. package/lib/specificEffects/e_generic_cardTargetting.d.ts +0 -38
  98. package/lib/specificEffects/e_generic_cardTargetting.js +0 -82
  99. package/lib/specificEffects/e_generic_noneTargetting.d.ts +0 -10
  100. package/lib/specificEffects/e_generic_noneTargetting.js +0 -26
  101. package/lib/specificEffects/e_status.d.ts +0 -80
  102. package/lib/specificEffects/e_status.js +0 -151
  103. package/lib/specificEffects/e_test.d.ts +0 -3
  104. package/lib/specificEffects/e_test.js +0 -21
  105. package/lib/types/abstract/gameComponents/API.d.ts +0 -19
  106. package/lib/types/abstract/gameComponents/API.js +0 -2
  107. package/lib/types/abstract/gameComponents/card.d.ts +0 -108
  108. package/lib/types/abstract/gameComponents/card.js +0 -771
  109. package/lib/types/abstract/gameComponents/effect.d.ts +0 -82
  110. package/lib/types/abstract/gameComponents/effect.js +0 -331
  111. package/lib/types/abstract/gameComponents/effectSubtype.d.ts +0 -22
  112. package/lib/types/abstract/gameComponents/effectSubtype.js +0 -40
  113. package/lib/types/abstract/gameComponents/effectType.d.ts +0 -11
  114. package/lib/types/abstract/gameComponents/effectType.js +0 -8
  115. package/lib/types/abstract/gameComponents/settings.d.ts +0 -80
  116. package/lib/types/abstract/gameComponents/settings.js +0 -72
  117. package/lib/types/abstract/gameComponents/zone.d.ts +0 -113
  118. package/lib/types/abstract/gameComponents/zone.js +0 -614
  119. package/lib/types/abstract/gameComponents/zone_gridBased.d.ts +0 -18
  120. package/lib/types/abstract/gameComponents/zone_gridBased.js +0 -58
  121. package/lib/types/abstract/gameComponents/zone_stackBased.d.ts +0 -13
  122. package/lib/types/abstract/gameComponents/zone_stackBased.js +0 -55
  123. package/lib/types/abstract/generics/node.d.ts +0 -23
  124. package/lib/types/abstract/generics/node.js +0 -46
  125. package/lib/types/abstract/generics/position.d.ts +0 -23
  126. package/lib/types/abstract/generics/position.js +0 -91
  127. package/lib/types/abstract/generics/tree.d.ts +0 -25
  128. package/lib/types/abstract/generics/tree.js +0 -153
  129. package/lib/types/abstract/generics/universalResponse.d.ts +0 -4
  130. package/lib/types/abstract/generics/universalResponse.js +0 -2
  131. package/lib/types/abstract/generics/wraper.d.ts +0 -21
  132. package/lib/types/abstract/generics/wraper.js +0 -56
  133. package/lib/types/abstract/parser/component.d.ts +0 -88
  134. package/lib/types/abstract/parser/component.js +0 -132
  135. package/lib/types/abstract/parser/index.d.ts +0 -6
  136. package/lib/types/abstract/parser/index.js +0 -28
  137. package/lib/types/abstract/parser/modPack.d.ts +0 -21
  138. package/lib/types/abstract/parser/modPack.js +0 -48
  139. package/lib/types/abstract/parser/moduleInputObject.d.ts +0 -12
  140. package/lib/types/abstract/parser/moduleInputObject.js +0 -21
  141. package/lib/types/abstract/parser/options.d.ts +0 -31
  142. package/lib/types/abstract/parser/options.js +0 -45
  143. package/lib/types/abstract/serializedGameComponents/Gamestate.d.ts +0 -46
  144. package/lib/types/abstract/serializedGameComponents/Gamestate.js +0 -70
  145. package/lib/types/abstract/serializedGameComponents/Localized.d.ts +0 -69
  146. package/lib/types/abstract/serializedGameComponents/Localized.js +0 -84
  147. package/lib/types/defaultZones/ability.d.ts +0 -10
  148. package/lib/types/defaultZones/ability.js +0 -22
  149. package/lib/types/defaultZones/deck.d.ts +0 -25
  150. package/lib/types/defaultZones/deck.js +0 -90
  151. package/lib/types/defaultZones/drop.d.ts +0 -5
  152. package/lib/types/defaultZones/drop.js +0 -13
  153. package/lib/types/defaultZones/field.d.ts +0 -11
  154. package/lib/types/defaultZones/field.js +0 -35
  155. package/lib/types/defaultZones/grave.d.ts +0 -8
  156. package/lib/types/defaultZones/grave.js +0 -21
  157. package/lib/types/defaultZones/hand.d.ts +0 -5
  158. package/lib/types/defaultZones/hand.js +0 -14
  159. package/lib/types/defaultZones/storage.d.ts +0 -9
  160. package/lib/types/defaultZones/storage.js +0 -21
  161. package/lib/types/defaultZones/system.d.ts +0 -12
  162. package/lib/types/defaultZones/system.js +0 -35
  163. package/lib/types/defaultZones/void.d.ts +0 -4
  164. package/lib/types/defaultZones/void.js +0 -10
  165. package/lib/types/effects/effectSubtypes/subtype_chained.d.ts +0 -10
  166. package/lib/types/effects/effectSubtypes/subtype_chained.js +0 -17
  167. package/lib/types/effects/effectSubtypes/subtype_delayed.d.ts +0 -9
  168. package/lib/types/effects/effectSubtypes/subtype_delayed.js +0 -16
  169. package/lib/types/effects/effectSubtypes/subtype_fieldLock.d.ts +0 -9
  170. package/lib/types/effects/effectSubtypes/subtype_fieldLock.js +0 -21
  171. package/lib/types/effects/effectSubtypes/subtype_graveLock.d.ts +0 -9
  172. package/lib/types/effects/effectSubtypes/subtype_graveLock.js +0 -21
  173. package/lib/types/effects/effectSubtypes/subtype_hand_or_fieldLock.d.ts +0 -9
  174. package/lib/types/effects/effectSubtypes/subtype_hand_or_fieldLock.js +0 -21
  175. package/lib/types/effects/effectSubtypes/subtype_hardUnique.d.ts +0 -9
  176. package/lib/types/effects/effectSubtypes/subtype_hardUnique.js +0 -15
  177. package/lib/types/effects/effectSubtypes/subtype_instant.d.ts +0 -8
  178. package/lib/types/effects/effectSubtypes/subtype_instant.js +0 -20
  179. package/lib/types/effects/effectSubtypes/subtype_once.d.ts +0 -12
  180. package/lib/types/effects/effectSubtypes/subtype_once.js +0 -27
  181. package/lib/types/effects/effectSubtypes/subtype_unique.d.ts +0 -9
  182. package/lib/types/effects/effectSubtypes/subtype_unique.js +0 -16
  183. package/lib/types/effects/effectTypes/initEffect.d.ts +0 -7
  184. package/lib/types/effects/effectTypes/initEffect.js +0 -23
  185. package/lib/types/effects/effectTypes/lockEffect.d.ts +0 -9
  186. package/lib/types/effects/effectTypes/lockEffect.js +0 -25
  187. package/lib/types/effects/effectTypes/manualEffect.d.ts +0 -9
  188. package/lib/types/effects/effectTypes/manualEffect.js +0 -18
  189. package/lib/types/effects/effectTypes/passiveEffect.d.ts +0 -9
  190. package/lib/types/effects/effectTypes/passiveEffect.js +0 -23
  191. package/lib/types/effects/effectTypes/triggerEffect.d.ts +0 -9
  192. package/lib/types/effects/effectTypes/triggerEffect.js +0 -28
  193. package/lib/types/errors/cannotLoad.d.ts +0 -5
  194. package/lib/types/errors/cannotLoad.js +0 -13
  195. package/lib/types/errors/cardNotExist.d.ts +0 -5
  196. package/lib/types/errors/cardNotExist.js +0 -13
  197. package/lib/types/errors/cardNotInApplicableZone.d.ts +0 -5
  198. package/lib/types/errors/cardNotInApplicableZone.js +0 -13
  199. package/lib/types/errors/effectCondNotMet.d.ts +0 -5
  200. package/lib/types/errors/effectCondNotMet.js +0 -13
  201. package/lib/types/errors/effectNotExist.d.ts +0 -5
  202. package/lib/types/errors/effectNotExist.js +0 -13
  203. package/lib/types/errors/error.d.ts +0 -17
  204. package/lib/types/errors/error.js +0 -42
  205. package/lib/types/errors/incorrectActionType.d.ts +0 -5
  206. package/lib/types/errors/incorrectActionType.js +0 -13
  207. package/lib/types/errors/index.d.ts +0 -16
  208. package/lib/types/errors/index.js +0 -36
  209. package/lib/types/errors/invalidOrderMap.d.ts +0 -6
  210. package/lib/types/errors/invalidOrderMap.js +0 -14
  211. package/lib/types/errors/invalidPosition.d.ts +0 -6
  212. package/lib/types/errors/invalidPosition.js +0 -13
  213. package/lib/types/errors/subTypeOverrideConflict.d.ts +0 -7
  214. package/lib/types/errors/subTypeOverrideConflict.js +0 -15
  215. package/lib/types/errors/unknownError.d.ts +0 -5
  216. package/lib/types/errors/unknownError.js +0 -13
  217. package/lib/types/errors/unregisteredAction.d.ts +0 -6
  218. package/lib/types/errors/unregisteredAction.js +0 -13
  219. package/lib/types/errors/wrongEffectIdx.d.ts +0 -5
  220. package/lib/types/errors/wrongEffectIdx.js +0 -14
  221. package/lib/types/errors/zoneAttrConflict.d.ts +0 -5
  222. package/lib/types/errors/zoneAttrConflict.js +0 -15
  223. package/lib/types/errors/zoneFull.d.ts +0 -5
  224. package/lib/types/errors/zoneFull.js +0 -13
  225. package/lib/types/errors/zoneNotExist.d.ts +0 -5
  226. package/lib/types/errors/zoneNotExist.js +0 -13
  227. package/lib/types/misc.d.ts +0 -97
  228. package/lib/types/misc.js +0 -8
  229. package/lib/types/mods/effectTextParserModule.d.ts +0 -16
  230. package/lib/types/mods/effectTextParserModule.js +0 -81
  231. package/lib/types/mods/gameModule.d.ts +0 -5
  232. package/lib/types/mods/gameModule.js +0 -8
  233. package/lib/utils/index.d.ts +0 -78
  234. package/lib/utils/index.js +0 -562
@@ -1,562 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Heap = void 0;
7
- const settings_1 = require("../types/abstract/gameComponents/settings");
8
- // import { partitionData } from "../types/data/cardRegistry";
9
- const settings_2 = require("../types/abstract/gameComponents/settings");
10
- const position_1 = __importDefault(require("../types/abstract/generics/position"));
11
- class utils {
12
- static toProper(str) {
13
- return str.toLowerCase().replace(/(?:^|\s)\w/g, function (match) {
14
- return match.toUpperCase();
15
- });
16
- }
17
- //find the element occurs the most in an array
18
- static most(arr) {
19
- var _a;
20
- const countMap = new Map();
21
- let maxCount = 0;
22
- let mostElement = undefined;
23
- for (const item of arr) {
24
- const count = ((_a = countMap.get(item)) !== null && _a !== void 0 ? _a : 0) + 1;
25
- countMap.set(item, count);
26
- if (count > maxCount) {
27
- maxCount = count;
28
- mostElement = item;
29
- }
30
- }
31
- // If arr is empty, mostElement will be undefined
32
- return mostElement;
33
- }
34
- static rng(max, min, round) {
35
- return (round) ? Math.round(Math.random() * (max - min) + min) : Math.random() * (max - min) + min;
36
- }
37
- static rngArr(len, max, min, round) {
38
- return new Array(len).fill(0).map(_ => utils.rng(max, min, round));
39
- }
40
- static rngChoice(choices) {
41
- return choices[this.rng(choices.length - 1, 0, true)];
42
- }
43
- static rngArrChoice(len, choices) {
44
- return new Array(len).fill(0).map(_ => this.rngChoice(choices));
45
- }
46
- static round(num, precision) {
47
- return Math.round((num + Number.EPSILON) * Math.pow(10, precision)) / Math.pow(10, precision);
48
- }
49
- static clamp(num, max, min = num) {
50
- return Math.min(Math.max(num, min), max);
51
- }
52
- static toSafeNumber(n, doTruncation = false) {
53
- if (!n)
54
- return 0;
55
- if (n === true) {
56
- return 1;
57
- }
58
- if (typeof n === "string") {
59
- n = doTruncation ? parseInt(n) : parseFloat(n);
60
- }
61
- if (isNaN(n))
62
- return 0;
63
- if (isFinite(n))
64
- return n;
65
- return doTruncation ? Math.trunc(n) : n;
66
- }
67
- static generateID(length = 10) {
68
- if (length <= 0)
69
- return "";
70
- const valid = "01234566789ABCDEF"; //stops at F to guaranteed hex
71
- const s = [];
72
- for (let i = 0; i < length; i++) {
73
- const c = this.rng(0, valid.length - 1, true);
74
- s.push(valid[c]);
75
- }
76
- return s.join("");
77
- }
78
- static dataIDToUniqueID(id, num, s, ...append) {
79
- let randID = this.generateID(s.dynamic_id_len);
80
- let arr = [randID, num];
81
- switch (s.id_style) {
82
- case settings_1.id_style.MINIMAL: return arr.join(s.id_separator);
83
- case settings_1.id_style.REDUCED: {
84
- arr.unshift(id);
85
- return arr.join(s.id_separator);
86
- }
87
- case settings_1.id_style.FULL: {
88
- arr.unshift(...append);
89
- arr.unshift(id);
90
- return arr.join(s.id_separator);
91
- }
92
- }
93
- }
94
- static removeDuplicates(...arr) {
95
- return [...new Set([].concat(...arr))];
96
- }
97
- static pushReadOnlyReference(arr, b, prop) {
98
- Object.defineProperty(arr, arr.length, {
99
- get() {
100
- return b[prop];
101
- },
102
- set(value) { },
103
- enumerable: true
104
- });
105
- }
106
- static pushReference(arr, b, prop) {
107
- Object.defineProperty(arr, arr.length, {
108
- get() {
109
- return b[prop];
110
- },
111
- set(value) {
112
- b[prop] = value;
113
- },
114
- enumerable: true
115
- });
116
- }
117
- static indexToPosition(index, shapeArr) {
118
- const position = new Array(shapeArr.length);
119
- let remainingIndex = index;
120
- const l = shapeArr.length - 1;
121
- for (let i = l; i >= 0; i--) {
122
- position[l - i] = remainingIndex % shapeArr[l - i];
123
- remainingIndex = Math.floor(remainingIndex / shapeArr[l - i]);
124
- }
125
- return position;
126
- }
127
- /**
128
- *
129
- * @param position
130
- * @param shapeArr the base
131
- * @returns
132
- * Imagine counting up in the base [2, 2]
133
- * That would go: [0, 0], [1, 0], [0, 1], [1, 1] [x, y]
134
- * Once the previous index hits the limit, the next count up and this index is back to 0
135
- * so Pos -> index of [1, 0] is 1 (0 indexing)
136
- *
137
- * Invalid indexes like [0, 3] in base [2, 2] would be disallow but i didnt code this part in
138
- */
139
- static positionToIndex(position, shapeArr) {
140
- if (!shapeArr.length || !position.length)
141
- return -1;
142
- let flatIndex = 0;
143
- let stride = 1;
144
- const l = shapeArr.length - 1;
145
- for (let i = l; i >= 0; i--) {
146
- flatIndex += position[l - i] * stride;
147
- stride *= shapeArr[l - i];
148
- }
149
- return flatIndex;
150
- }
151
- static isPositionOutOfBounds(position, shapeArr) {
152
- return position.some((i, index) => i >= shapeArr[index] || i < 0);
153
- }
154
- static isPartitioningManual(ps) {
155
- return ps === settings_2.partitionSetting.manual_mapping_no_ghost || ps === settings_2.partitionSetting.manual_mapping_with_ghost || ps === settings_2.partitionSetting.manual_mapping_with_ghost_spread;
156
- }
157
- static isPartitioningAuto(ps) {
158
- return ps === settings_2.partitionSetting.auto_mapping_one_to_one || ps === settings_2.partitionSetting.auto_mapping_types || ps === settings_2.partitionSetting.auto_mapping_subtypes || ps === settings_2.partitionSetting.auto_mapping_ygo;
159
- }
160
- static patchCardData(cData, patchData) {
161
- Object.keys(patchData).forEach(i => {
162
- if (patchData[i] !== undefined &&
163
- cData[i] !== undefined) {
164
- cData[i] = patchData[i];
165
- }
166
- });
167
- }
168
- //apply a partial onto an original
169
- static patchGeneric(original, patch, merge = false) {
170
- let k = Object.keys(patch);
171
- if (merge) {
172
- const temp = new Set(k.concat(...Object.keys(patch)));
173
- k = Array.from(temp);
174
- }
175
- k.forEach(i => {
176
- if (original[i] !== undefined &&
177
- patch[i] !== undefined) {
178
- original[i] = patch[i]; //as any here cause even though i checked b4, ts still says undefine is possible here, kinda dum
179
- }
180
- });
181
- }
182
- static range(len, min = 0) {
183
- return Array.from({ length: len }, (_, index) => index + min);
184
- }
185
- //assumes arr is sorted
186
- static insertionSort(arr, insertElement, comparator) {
187
- let indexToBeInserted = arr.findIndex((a) => { let x = comparator(a, insertElement); return isNaN(x) ? false : x > 0; });
188
- //changed x >= 0 to x > 0 for new equal elements be inserted last
189
- if (indexToBeInserted < 0)
190
- arr.push(insertElement);
191
- else
192
- arr.splice(indexToBeInserted, 0, insertElement);
193
- }
194
- static getTypeSigature(val, simpleParse = false) {
195
- let k = typeof val;
196
- if (k !== "object")
197
- return k;
198
- if (Array.isArray(val)) {
199
- if (val.length === 0)
200
- return "empty[]";
201
- if (simpleParse)
202
- return "any[]";
203
- let t = typeof val[0];
204
- for (let i = 1; i < val.length; i++) {
205
- let t2 = typeof val[i];
206
- if (t2 !== t)
207
- return "any[]";
208
- }
209
- return `${t}[]`;
210
- }
211
- return k;
212
- }
213
- static genericCurrier(f, callback, res = []) {
214
- if (!f.length)
215
- return callback([]);
216
- const [first, ...rest] = f;
217
- if (typeof first === "function") {
218
- return (...p) => {
219
- res.push(first(...p));
220
- if (rest.length === 0)
221
- return callback(res);
222
- return this.genericCurrier(rest, callback, res);
223
- };
224
- }
225
- else {
226
- res.push(first);
227
- return this.genericCurrier(rest, callback, res);
228
- }
229
- ;
230
- }
231
- static clone(obj, recurDepth = 0) {
232
- if (recurDepth >= 1e8) {
233
- throw new Error("Maximum recursion depth reached when cloning object");
234
- }
235
- const res = {};
236
- Object.entries(obj).forEach(([key, val]) => {
237
- if (typeof val === "object")
238
- res[key] = this.clone(val, recurDepth + 1);
239
- else
240
- res[key] = val;
241
- });
242
- return res;
243
- }
244
- static flat(nested) {
245
- if (!Array.isArray(nested))
246
- return [nested];
247
- const res = [];
248
- nested.forEach(i => res.push(...this.flat(i)));
249
- return res;
250
- }
251
- static splitArrToShape(arr, shape) {
252
- let res = new Array(shape.length).fill([]);
253
- let c = 0;
254
- shape.forEach((i, index) => {
255
- while (i !== 0) {
256
- res[index].push(arr[c]);
257
- i--;
258
- c++;
259
- }
260
- });
261
- return res;
262
- }
263
- static getRandomElement(arr) {
264
- if (!arr.length)
265
- return undefined;
266
- if (arr.length === 1)
267
- return arr[0];
268
- const n = this.rng(arr.length - 1, 0, true);
269
- return arr[n];
270
- }
271
- //generators API
272
- static *mergeGeneratorReturn(gen1, gen2) {
273
- let input1 = undefined;
274
- let input2 = undefined;
275
- while (true) {
276
- let n = gen1.next(input1);
277
- if (n.done) {
278
- if (Array.isArray(n.value)) {
279
- input1 = n.value;
280
- break;
281
- }
282
- else {
283
- gen1 = n.value;
284
- input1 = undefined;
285
- }
286
- }
287
- else
288
- input1 = yield n.value;
289
- }
290
- while (true) {
291
- let n = gen2.next(input2);
292
- if (n.done) {
293
- if (Array.isArray(n.value)) {
294
- input2 = n.value;
295
- break;
296
- }
297
- else {
298
- gen2 = n.value;
299
- input2 = undefined;
300
- }
301
- }
302
- else
303
- input2 = yield n.value;
304
- }
305
- return [...input1, ...input2];
306
- }
307
- static *addFinalToGenerator(gen, f) {
308
- let input = undefined;
309
- while (true) {
310
- let n = gen.next(input);
311
- if (n.done) {
312
- if (Array.isArray(n.value)) {
313
- input = n.value;
314
- break;
315
- }
316
- else {
317
- gen = n.value;
318
- input = undefined;
319
- }
320
- }
321
- else
322
- input = yield n.value;
323
- }
324
- const res = f(input);
325
- if (res === undefined)
326
- return input;
327
- return res;
328
- }
329
- static getRandomNumberArr(len) {
330
- const res = [];
331
- if (!isNaN(len) && Number.isFinite(len) && len > 0) {
332
- for (let i = 0; i < len; i++) {
333
- res.push(this.rng(100, 0, true));
334
- }
335
- }
336
- return res;
337
- }
338
- static isPositionable(o) {
339
- return typeof o === "object" && o.pos instanceof position_1.default;
340
- }
341
- static isPlayerSpecific(o) {
342
- return typeof o === "object" && typeof o.playerIndex === "number" && typeof o.playerType === "number";
343
- }
344
- /**
345
- *
346
- * @param arr1
347
- * @param arr2
348
- * Returns the intersection of the two array
349
- */
350
- static intersect(arr1, arr2) {
351
- const hasMap = new Set(arr2);
352
- return arr1.filter(i => hasMap.has(i));
353
- }
354
- static assert(a, b, returns = false, depth = 0) {
355
- if (depth >= 20) {
356
- throw new Error(`Assertion error, stack overflowed`);
357
- }
358
- const t1 = typeof a;
359
- const t2 = typeof b;
360
- if (t1 !== t2) {
361
- if (returns)
362
- return false;
363
- throw new Error(`Assertion error: ${a} is not ${b}, type check fails ${t1} is not ${t2}.`);
364
- }
365
- const equallableTypes = ["bigint", "boolean", "number", "string", "symbol", "undefined"];
366
- if (equallableTypes.includes(t1))
367
- return returns ? true : undefined;
368
- if (a === b)
369
- return returns ? true : undefined; //reference checking
370
- const c1 = Array.isArray(a);
371
- const c2 = Array.isArray(b);
372
- if (c1 !== c2) {
373
- if (returns)
374
- return false;
375
- throw new Error(`Assertion error: ${a} is not ${b}, array check fails ${c1} is not ${c2}.`);
376
- }
377
- //recursive section
378
- if (c1) {
379
- //both are arrays
380
- if (a.length !== b.length) {
381
- if (returns)
382
- return false;
383
- throw new Error(`Assertion error: ${a} is not ${b}, not same len arrays.`);
384
- }
385
- const c3 = a.every((k, i) => this.assert(k, b[i], true));
386
- if (c3)
387
- return returns ? true : undefined;
388
- if (returns)
389
- return false;
390
- throw new Error(`Assertion error: ${a} is not ${b}, arrays have not the same elements.`);
391
- }
392
- //both are objects
393
- const k1 = Object.keys(a);
394
- const k2 = Object.keys(b);
395
- if (k1.length !== k2.length) {
396
- if (returns)
397
- return false;
398
- throw new Error(`Assertion error: ${a} is not ${b}, not same len objects.`);
399
- }
400
- const c4 = k1.every((k, i) => k === k2[i]);
401
- if (!c4) {
402
- if (returns)
403
- return false;
404
- throw new Error(`Assertion error: ${a} is not ${b}, not same key-ed objects.`);
405
- }
406
- const c5 = k1.every((k, i) => this.assert(a[k], b[k2[i]], true));
407
- if (c5)
408
- return returns ? true : undefined;
409
- if (returns)
410
- return false;
411
- throw new Error(`Assertion error: ${a} is not ${b}, objects not have the same values.`);
412
- }
413
- static a_star(startState, identity, evaluateState, //cheaper = better
414
- evaluateTransition, //cheaper = better
415
- getNextStates, stopCondition, maxDepth = Infinity) {
416
- //min heap
417
- const currentlyExploring = new Heap((a, b) => a[0] - b[0]);
418
- const curretlyExploringSet = new Set();
419
- //reverse mapping of the best path
420
- const preceedMap = new Map();
421
- //f[n] : best guess so far as to lowest score if cheapest path goes through n
422
- //g[n] : cheapest cost from start to n
423
- const fscoreMap = new Map();
424
- const gscoreMap = new Map();
425
- const startScore = evaluateState(startState);
426
- const startIdentity = identity(startState);
427
- gscoreMap.set(startIdentity, 0);
428
- fscoreMap.set(startIdentity, startScore);
429
- curretlyExploringSet.add(startIdentity);
430
- currentlyExploring.push([startScore, startState]);
431
- let depth = 0;
432
- const savedIdentityMap = new Map();
433
- function getIdentity(state) {
434
- let res = savedIdentityMap.get(state);
435
- if (res === undefined) {
436
- res = identity(state);
437
- savedIdentityMap.set(state, res);
438
- }
439
- return res;
440
- }
441
- //assume get -> undefined is Infinity
442
- function getScore(type, state) {
443
- var _a, _b;
444
- const i = getIdentity(state);
445
- return type === "f" ? ((_a = fscoreMap.get(i)) !== null && _a !== void 0 ? _a : Infinity) : ((_b = gscoreMap.get(i)) !== null && _b !== void 0 ? _b : Infinity);
446
- }
447
- function getPathFromPreceedMap(state) {
448
- const res = [state];
449
- let i = getIdentity(state);
450
- let pre = preceedMap.get(i);
451
- while (pre) {
452
- res.unshift(pre);
453
- state = pre;
454
- i = getIdentity(state);
455
- pre = preceedMap.get(i);
456
- }
457
- return res;
458
- }
459
- //technically explores if not in list already
460
- //eh, whatever
461
- function explores(state, score = getScore("f", state), identity = getIdentity(state)) {
462
- if (curretlyExploringSet.has(identity))
463
- return;
464
- curretlyExploringSet.add(identity);
465
- currentlyExploring.push([score, state]);
466
- }
467
- while (currentlyExploring.length !== 0 && depth < maxDepth) {
468
- const [currentfScore, current] = currentlyExploring.pop();
469
- curretlyExploringSet.delete(getIdentity(current));
470
- const path = getPathFromPreceedMap(current);
471
- if (stopCondition &&
472
- stopCondition(current, currentfScore, getScore("g", current), path, depth)) {
473
- return path;
474
- }
475
- const neighbors = getNextStates(current);
476
- for (const neighbor of neighbors) {
477
- const edgeCost = evaluateTransition(current, neighbor);
478
- const gScore = getScore("g", current) + edgeCost; //g score if move to neighbor
479
- const neighborgScore = getScore("g", neighbor);
480
- if (gScore < neighborgScore) {
481
- const neighborIdentity = getIdentity(neighbor);
482
- const fScore = evaluateState(neighbor, current) + gScore;
483
- preceedMap.set(neighborIdentity, current);
484
- gscoreMap.set(neighborIdentity, gScore);
485
- fscoreMap.set(neighborIdentity, fScore);
486
- explores(neighbor, fScore, neighborIdentity);
487
- }
488
- }
489
- depth++;
490
- }
491
- return currentlyExploring.length === 0 ? [startState] : getPathFromPreceedMap(currentlyExploring.top()[1]);
492
- }
493
- }
494
- class Heap {
495
- //comparator works the same as the function in sort()
496
- constructor(comparator, ...start) {
497
- this.comparator = comparator;
498
- this.data = start;
499
- }
500
- push(item) {
501
- this.data.push(item);
502
- this.bubbleUp();
503
- }
504
- pop() {
505
- if (this.data.length === 0)
506
- return undefined;
507
- const top = this.data[0];
508
- const end = this.data.pop();
509
- if (this.data.length > 0 && end !== undefined) {
510
- this.data[0] = end;
511
- this.bubbleDown();
512
- }
513
- return top;
514
- }
515
- top() {
516
- return this.data[0];
517
- }
518
- get length() {
519
- return this.data.length;
520
- }
521
- bubbleUp() {
522
- let index = this.data.length - 1;
523
- const element = this.data[index];
524
- while (index > 0) {
525
- const parentIndex = Math.floor((index - 1) / 2);
526
- const parent = this.data[parentIndex];
527
- if (this.comparator(element, parent) >= 0)
528
- break;
529
- this.data[index] = parent;
530
- this.data[parentIndex] = element;
531
- index = parentIndex;
532
- }
533
- }
534
- bubbleDown() {
535
- let index = 0;
536
- const length = this.data.length;
537
- const element = this.data[0];
538
- while (true) {
539
- let leftChildIdx = 2 * index + 1;
540
- let rightChildIdx = 2 * index + 2;
541
- let swapIdx = -1;
542
- if (leftChildIdx < length) {
543
- if (this.comparator(this.data[leftChildIdx], element) < 0) {
544
- swapIdx = leftChildIdx;
545
- }
546
- }
547
- if (rightChildIdx < length) {
548
- if (this.comparator(this.data[rightChildIdx], element) < 0 &&
549
- (swapIdx === -1 || this.comparator(this.data[rightChildIdx], this.data[leftChildIdx]) < 0)) {
550
- swapIdx = rightChildIdx;
551
- }
552
- }
553
- if (swapIdx === -1)
554
- break;
555
- this.data[index] = this.data[swapIdx];
556
- this.data[swapIdx] = element;
557
- index = swapIdx;
558
- }
559
- }
560
- }
561
- exports.Heap = Heap;
562
- exports.default = utils;