Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- var _interopRequireDefault =
- require("@babel/runtime/helpers/interopRequireDefault");
- exports.__esModule = true;
- exports.default = void 0;
- var _getOwnPropertyDescriptor =
- _interopRequireDefault(require("@babel/runtime/core-js/object/get-own-
- property-descriptor"));
- var _applyDecoratedDescriptor2 =
- `_interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));`
- var _decorators = require("./util/decorators");
- var _assertions = require("./util/assertions");
- var _class;
- const CHARCODE_LOWECASE_A = 97;
- let Cell = (_class = class Cell {
- // Private properties
- constructor(board, x, y, z) {
- this._board = board;
- this._x = x;
- this._y = y;
- this._z = z;
- }
- get position() {
- return [this.number, this.letter];
- }
- get number() {
- const {
- _y,
- _z
- } = this;
- if (_z === 0) return _y + 1;
- if (_z === 1) return 8 - _y;
- if (_z === 2) return 12 - _y;
- return (0, _assertions.never)();
- }
- get letter() {
- const {
- _x,
- _z
- } = this;
- let c;
- if (_z === 0) c = _x;
- else if (_z === 1 && _x >= 4) c = 7 - _x;
- else if (_z === 1 && _x <= 3) c = 12 - _x;
- else if (_z === 2 && _x >= 4) c = 4 + _x;
- else if (_z === 2 && _x <= 3) c = 7 - _x;
- else (0, _assertions.never)();
- return String.fromCharCode(c + CHARCODE_LOWECASE_A);
- }
- get up() {
- const {
- _x,
- _y,
- _z
- } = this;
- if (_y === 3 && _x <= 3) return this._board.cells[(_z + 1) % 3][7 - _x][3];
- if (_y === 3 && _x >= 4) return this._board.cells[(_z + 2) % 3][7 - _x][3];
- return this._board.cells[_z][_x][_y + 1];
- }
- get down() {
- const {
- _x,
- _y,
- _z
- } = this;
- if (_y === 0) return null;
- return this._board.cells[_z][_x][_y - 1];
- }
- get right() {
- const {
- _x,
- _y,
- _z
- } = this;
- if (_x === 7) return null;
- return this._board.cells[_z][_x + 1][_y];
- }
- get left() {
- const {
- _x,
- _y,
- _z
- } = this;
- if (_x === 0) return null;
- return this._board.cells[_z][_x - 1][_y];
- }
- relativeTo(base, dir) {
- if (this._z === base._z) return this[dir];
- switch (dir) {
- case "up":
- return this.down;
- case "down":
- return this.up;
- case "left":
- return this.right;
- case "right":
- return this.left;
- }
- }
- sequence(steps, base = this) {
- let result = this;
- for (const step of steps) {
- if (!result) return null;
- result = result.relativeTo(base, step);
- }
- return result;
- }
- }, ((0, _applyDecoratedDescriptor2.default)(_class.prototype, "position", [_decorators.memoizeGetter], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "position"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "number", [_decorators.memoizeGetter], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "number"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "letter", [_decorators.memoizeGetter], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "letter"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "up", [_decorators.memoizeGetter], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "up"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "down", [_decorators.memoizeGetter], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "down"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "right", [_decorators.memoizeGetter], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "right"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "left", [_decorators.memoizeGetter], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "left"), _class.prototype)), _class);
- exports.default = Cell;
Add Comment
Please, Sign In to add comment