Guest User

Untitled

a guest
Jan 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. "use strict";
  2.  
  3. var _interopRequireDefault =
  4. require("@babel/runtime/helpers/interopRequireDefault");
  5.  
  6. exports.__esModule = true;
  7. exports.default = void 0;
  8.  
  9. var _getOwnPropertyDescriptor =
  10. _interopRequireDefault(require("@babel/runtime/core-js/object/get-own-
  11. property-descriptor"));
  12.  
  13. var _applyDecoratedDescriptor2 =
  14.  
  15. `_interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));`
  16.  
  17. var _decorators = require("./util/decorators");
  18.  
  19. var _assertions = require("./util/assertions");
  20.  
  21. var _class;
  22.  
  23. const CHARCODE_LOWECASE_A = 97;
  24. let Cell = (_class = class Cell {
  25. // Private properties
  26. constructor(board, x, y, z) {
  27. this._board = board;
  28. this._x = x;
  29. this._y = y;
  30. this._z = z;
  31. }
  32.  
  33. get position() {
  34. return [this.number, this.letter];
  35. }
  36.  
  37. get number() {
  38. const {
  39. _y,
  40. _z
  41. } = this;
  42. if (_z === 0) return _y + 1;
  43. if (_z === 1) return 8 - _y;
  44. if (_z === 2) return 12 - _y;
  45. return (0, _assertions.never)();
  46. }
  47.  
  48. get letter() {
  49. const {
  50. _x,
  51. _z
  52. } = this;
  53. let c;
  54. if (_z === 0) c = _x;
  55. else if (_z === 1 && _x >= 4) c = 7 - _x;
  56. else if (_z === 1 && _x <= 3) c = 12 - _x;
  57. else if (_z === 2 && _x >= 4) c = 4 + _x;
  58. else if (_z === 2 && _x <= 3) c = 7 - _x;
  59. else (0, _assertions.never)();
  60. return String.fromCharCode(c + CHARCODE_LOWECASE_A);
  61. }
  62.  
  63. get up() {
  64. const {
  65. _x,
  66. _y,
  67. _z
  68. } = this;
  69. if (_y === 3 && _x <= 3) return this._board.cells[(_z + 1) % 3][7 - _x][3];
  70. if (_y === 3 && _x >= 4) return this._board.cells[(_z + 2) % 3][7 - _x][3];
  71. return this._board.cells[_z][_x][_y + 1];
  72. }
  73.  
  74. get down() {
  75. const {
  76. _x,
  77. _y,
  78. _z
  79. } = this;
  80. if (_y === 0) return null;
  81. return this._board.cells[_z][_x][_y - 1];
  82. }
  83.  
  84. get right() {
  85. const {
  86. _x,
  87. _y,
  88. _z
  89. } = this;
  90. if (_x === 7) return null;
  91. return this._board.cells[_z][_x + 1][_y];
  92. }
  93.  
  94. get left() {
  95. const {
  96. _x,
  97. _y,
  98. _z
  99. } = this;
  100. if (_x === 0) return null;
  101. return this._board.cells[_z][_x - 1][_y];
  102. }
  103.  
  104. relativeTo(base, dir) {
  105. if (this._z === base._z) return this[dir];
  106.  
  107. switch (dir) {
  108. case "up":
  109. return this.down;
  110.  
  111. case "down":
  112. return this.up;
  113.  
  114. case "left":
  115. return this.right;
  116.  
  117. case "right":
  118. return this.left;
  119. }
  120. }
  121.  
  122. sequence(steps, base = this) {
  123. let result = this;
  124.  
  125. for (const step of steps) {
  126. if (!result) return null;
  127. result = result.relativeTo(base, step);
  128. }
  129.  
  130. return result;
  131. }
  132.  
  133. }, ((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);
  134. exports.default = Cell;
Add Comment
Please, Sign In to add comment