Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var CellCurrentStatus;
- (function (CellCurrentStatus) {
- CellCurrentStatus[CellCurrentStatus["NOT_AVAILABLE"] = 0] = "NOT_AVAILABLE";
- CellCurrentStatus[CellCurrentStatus["MYSELF"] = 200] = "MYSELF";
- CellCurrentStatus[CellCurrentStatus["SHOOTER_CAN_REACH_WITHOUT_PENALTY"] = 210] = "SHOOTER_CAN_REACH_WITHOUT_PENALTY";
- CellCurrentStatus[CellCurrentStatus["OCCUPIED"] = 211] = "OCCUPIED";
- CellCurrentStatus[CellCurrentStatus["AVAILABLE"] = 250] = "AVAILABLE";
- })(CellCurrentStatus || (CellCurrentStatus = {}));
- var UnitType;
- (function (UnitType) {
- UnitType["barbarianChar"] = "pers_barbani";
- UnitType["barbarianBirds"] = "rocani";
- UnitType["barbarianOrcs"] = "orcani";
- UnitType["barbarianOgres"] = "ogreani";
- UnitType["barbarianHobgoblins"] = "hobgoblinani";
- UnitType["barbarianWolvesUpgraded"] = "hobwolfriderani";
- UnitType["necromancerChar"] = "pers_necrani";
- UnitType["necromancerSkeletons"] = "sceletonani";
- UnitType["necromancerGhosts"] = "ghostani";
- UnitType["necromancerVampires"] = "vampireani";
- UnitType["demonChar"] = "wpers_demonani";
- UnitType["demonDogs"] = "demondogani";
- UnitType["stepGoblin"] = "goblinusani";
- UnitType["demonImp"] = "familiarani";
- UnitType["demonHorned"] = "hdemonani";
- UnitType["demonSuccub"] = "succubani";
- })(UnitType || (UnitType = {}));
- function getClosestStack(selectedStack, otherStacks) {
- let distanceToClosest = Infinity;
- let closestStack = otherStacks[0];
- otherStacks.forEach((s) => {
- const distanceToStack = calculateDistance(selectedStack, s);
- if (distanceToStack < distanceToClosest) {
- distanceToClosest = distanceToStack;
- closestStack = s;
- }
- });
- return closestStack;
- }
- function getReachableEnemyCell(enemyStacks, currentStack) {
- const closestEnemy = getClosestStack(currentStack, enemyStacks);
- if (!closestEnemy) {
- return null;
- }
- const closestEnemySurroundingCells = getSurroundingCells(closestEnemy.x, closestEnemy.y);
- const isEnemyReachable = closestEnemySurroundingCells.some(c => getCellCurrentStatus(c.x, c.y) === CellCurrentStatus.AVAILABLE);
- if (isEnemyReachable) {
- return {
- x: closestEnemy.x,
- y: closestEnemy.y,
- };
- }
- return null;
- }
- function calculateDistance(cell1, cell2, powFactor = 2) {
- const xDiff = Math.abs(cell1.x - cell2.x);
- const yDiff = Math.abs(cell1.y - cell2.y);
- return +Math.pow(xDiff ** powFactor + yDiff ** powFactor, 1 / powFactor).toFixed(2);
- }
- function getSurroundingCells(x, y, fieldWidth = 12, fieldHeight = 10) {
- let result = [];
- for (let i = x - 1; i <= x + 1; i++) {
- for (let j = y - 1; j <= y + 1; j++) {
- if (i < 1 || j < 1 || i > fieldWidth || j > fieldHeight) {
- continue;
- }
- result.push({ x: i, y: j });
- }
- }
- return result;
- }
- function getCellCurrentStatus(x, y, battlefieldFullWidth = 12, battlefieldVisibleHeight = 10, battlefieldArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 211, 211, 0, 0, 0, 0, 0, 0, 0, 0, 0, 210, 0, 211, 0, 211, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0, 0, 250, 250, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0, 0, 250, 250, 250, 250, 250, 211, 0, 0, 0, 0, 0, 0, 0, 0, 250, 250, 250, 250, 250, 211, 0, 0, 0, 0, 0, 0, 0, 0, 250, 250, 250, 250, 250, 211, 210, 210, 0, 211, 250, 250, 0, 0, 250, 250, 250, 250, 250, 200, 200, 210, 250, 250, 250, 250, 0, 0, 250, 250, 250, 250, 250, 200, 200, 250, 250, 250, 250, 250, 0, 0, 250, 250, 211, 250, 250, 250, 250, 250, 250, 250, 250, 250, 0, 0, 250, 250, 0, 250, 250, 250, 250, 250, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) {
- if ((y < 1) || (y > battlefieldVisibleHeight) || (x < 0) || (x > battlefieldFullWidth - 1)) {
- return 0;
- }
- return battlefieldArray[y * battlefieldFullWidth + x];
- }
- function convertCellIdToCoordinates(cellId) {
- const [x, y] = cellId.split(':');
- return {
- x: Number(x),
- y: Number(y),
- };
- }
- var row = '';
- [
- '1:1', '2:1', '3:1', '4:1', '5:1', '6:1', '7:1', '8:1', '9:1', '10:1', '11:1', '12:1',
- '1:2', '2:2', '3:2', '4:2', '5:2', '6:2', '7:2', '8:2', '9:2', '10:2', '11:2', '12:2',
- '1:3', '2:3', '3:3', '4:3', '5:3', '6:3', '7:3', '8:3', '9:3', '10:3', '11:3', '12:3',
- '1:4', '2:4', '3:4', '4:4', '5:4', '6:4', '7:4', '8:4', '9:4', '10:4', '11:4', '12:4',
- '1:5', '2:5', '3:5', '4:5', '5:5', '6:5', '7:5', '8:5', '9:5', '10:5', '11:5', '12:5',
- '1:6', '2:6', '3:6', '4:6', '5:6', '6:6', '7:6', '8:6', '9:6', '10:6', '11:6', '12:6',
- '1:7', '2:7', '3:7', '4:7', '5:7', '6:7', '7:7', '8:7', '9:7', '10:7', '11:7', '12:7',
- '1:8', '2:8', '3:8', '4:8', '5:8', '6:8', '7:8', '8:8', '9:8', '10:8', '11:8', '12:8',
- '1:9', '2:9', '3:9', '4:9', '5:9', '6:9', '7:9', '8:9', '9:9', '10:9', '11:9', '12:9',
- '1:10', '2:10', '3:10', '4:10', '5:10', '6:10', '7:10', '8:10', '9:10', '10:10', '11:10', '12:10',
- ].map(convertCellIdToCoordinates).map(c => calculateDistance(c, {x:11, y:8}, 2.5)).forEach((v, i) => {
- if (i % 12 === 0) {
- console.log();
- console.log(row);
- row = '';
- }
- row += String(v).padEnd(10);
- });
- /*
- output:
- 11.47 10.68 9.93 9.24 8.61 8.08 7.65 7.33 7.12 7.02 7 7.02
- 11.03 10.19 9.38 8.61 7.92 7.3 6.79 6.4 6.15 6.03 6 6.03
- 10.67 9.78 8.91 8.08 7.3 6.6 5.99 5.52 5.2 5.04 5 5.04
- 10.39 9.46 8.54 7.65 6.79 5.99 5.28 4.69 4.27 4.05 4 4.05
- 10.19 9.23 8.27 7.33 6.4 5.52 4.69 3.96 3.4 3.08 3 3.08
- 10.07 9.08 8.1 7.12 6.15 5.2 4.27 3.4 2.64 2.13 2 2.13
- 10.01 9.01 8.02 7.02 6.03 5.04 4.05 3.08 2.13 1.32 1 1.32
- 10 9 8 7 6 5 4 3 2 1 0 1
- 10.01 9.01 8.02 7.02 6.03 5.04 4.05 3.08 2.13 1.32 1 1.32
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement