X position
Y position
Id of the craftsman
Side of the craftsman
Craftsmen position
Craftsmen Id
Craftsmen side
X position
Y position
List of positions
Get 8 positions (top, right, bottom, left, upper left, upper right, lower right, lower left)
const pos = new Position(1, 1);
const [topPos, rightPos, bottomPos, leftPos, upperLeftPos, upperRightPos, lowerRightPos, lowerLeftPos] = pos.allNears();
console.log(topPos); // { x: 1, y: 0 }
console.log(rightPos); // { x: 2, y: 1 }
console.log(bottomPos); // { x: 1, y: 2 }
console.log(leftPos); // { x: 0, y: 1 }
console.log(upperLeftPos); // { x: 0, y: 0 }
console.log(upperRightPos); // { x: 2, y: 0 }
console.log(lowerRightPos); // { x: 2, y: 2 }
console.log(lowerLeftPos); // { x: 0, y: 2 }
Position to calculate distance
Formular to calculate distance (mahata, euclid)
Distance between two positions
Get distance between two positions
const pos1 = new Position(1, 1);
const pos2 = new Position(1, 2);
const distance = pos1.distance(pos2);
console.log(distance); // | 1 - 1 | + | 2 - 1 | = 1
const pos1 = new Position(1, 1);
const pos2 = new Position(1, 2);
const distance = pos1.distance(pos2, 'euclid');
console.log(distance); // sqrt((1 - 1) ^ 2 + (2 - 1) ^ 2) = 1
Private
getPrivate
getBuild action param
Build action
Get build action
Destroy action param
Destroy action
Get destroy action
Move action param
Move action
Get move action
Action param
Position by action param
Get position by action param
const pos = new Position(1, 1);
const posByActionParam = pos.getPositionByActionParam('UP');
console.log(posByActionParam); // { x: 1, y: 0 }
Position to check
Whether the position is equal
Check if the position is equal
const pos1 = new Position(1, 1);
const pos2 = new Position(1, 1);
const isEqual = pos1.equals(pos2)
console.log(isEqual) // true
Position to check
Whether the position is near
Check if the position is near
const pos1 = new Position(1, 1);
const pos2 = new Position(1, 2);
const isNear = pos1.isNear(pos2)
console.log(isNear) // true
const pos1 = new Position(1, 1);
const pos2 = new Position(1, 3);
const isNear = pos1.isNear(pos2)
console.log(isNear) // false
The width of the map
The height of the map
Whether the position is valid
Check if the position is valid
const pos = new Position(1, 1);
const isValid = pos.isValid(10, 10);
console.log(isValid); // true
const pos = new Position(-1, 1);
const isValid = pos.isValid(10, 10);
console.log(isValid); // false
Move param
Move action
Create a move action for the craftsman
List of positions
Get 4 positions (top, right, bottom, left)
const pos = new Position(1, 1);
const [topPos, rightPos, bottomPos, leftPos] = pos.topRightBottomLeft();
console.log(topPos); // { x: 1, y: 0 }
console.log(rightPos); // { x: 2, y: 1 }
console.log(bottomPos); // { x: 1, y: 2 }
console.log(leftPos); // { x: 0, y: 1 }
List of positions
Get 4 positions (upper left, upper right, lower right, lower left)
const pos = new Position(1, 1);
const [upperLeftPos, upperRightPos, lowerRightPos, lowerLeftPos] = pos.upperLeftUpperRightLowerRightLowerLeft();
console.log(upperLeftPos); // { x: 0, y: 0 }
console.log(upperRightPos); // { x: 2, y: 0 }
console.log(lowerRightPos); // { x: 2, y: 2 }
console.log(lowerLeftPos); // { x: 0, y: 2 }
Static
randomGenerated using TypeDoc
Description
Craftsmen position
Implements
ICraftsmenPosition