all files / src/ PlayerActions.js

91.75% Statements 89/97
67.74% Branches 21/31
94.29% Functions 33/35
98.48% Lines 65/66
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211    1×       6×   1×   17×   26×                 1× 1× 26×     1×                 1× 4× 8× 8×   4×       4×           1× 4×     1×                     1× 4× 8× 8×   4×       4×           1× 4×     1×                       1× 3× 6× 6×   3×       3×           1× 3×     1×                     1× 4× 8× 8×   4×       4×           1× 4×     1×                       1× 2× 2× 4× 4×   2×     2×   2× 6×         2×           1× 2×     1×                       2×   2× 169×   15× 2×       1×     1×  
'use strict';
 
Object.defineProperty(exports, "__esModule", {
	value: true
});
 
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
require('regenerator-runtime/runtime');
 
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } Eif (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
 
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
/**
 * These are actions done by a player
 * every method should return a Promise
 *
 * this refers to the player the actions are being called on
 * @abstract
 */
var PlayerActions = function () {
	function PlayerActions() {
		_classCallCheck(this, PlayerActions);
	}
 
	_createClass(PlayerActions, [{
		key: 'add2ToRoll',
 
		/**
   * If I can, do it!
   * @param dice
   * @return {Promise.<boolean>}
   */
		value: function () {
			var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(dice) {
				return regeneratorRuntime.wrap(function _callee$(_context) {
					while (1) {
						switch (_context.prev = _context.next) {
							case 0:
								return _context.abrupt('return', this.canAdd2ToRoll(dice));
 
							case 1:
							case 'end':
								return _context.stop();
						}
					}
				}, _callee, this);
			}));
 
			function add2ToRoll(_x) {
				return _ref.apply(this, arguments);
			}
 
			return add2ToRoll;
		}()
 
		/**
   * If I can, do it!
   * @return {Promise.<boolean>}
   */
 
	}, {
		key: 'rollAgain',
		value: function () {
			var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2() {
				return regeneratorRuntime.wrap(function _callee2$(_context2) {
					while (1) {
						switch (_context2.prev = _context2.next) {
							case 0:
								return _context2.abrupt('return', this.canRollAgain());
 
							case 1:
							case 'end':
								return _context2.stop();
						}
					}
				}, _callee2, this);
			}));
 
			function rollAgain() {
				return _ref2.apply(this, arguments);
			}
 
			return rollAgain;
		}()
 
		/**
   * If I can, do it!
   * @param {number[]} dice
   * @return {Promise.<boolean>}
   */
 
	}, {
		key: 'turnAgain',
		value: function () {
			var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(dice) {
				return regeneratorRuntime.wrap(function _callee3$(_context3) {
					while (1) {
						switch (_context3.prev = _context3.next) {
							case 0:
								return _context3.abrupt('return', this.canTurnAgain(dice));
 
							case 1:
							case 'end':
								return _context3.stop();
						}
					}
				}, _callee3, this);
			}));
 
			function turnAgain(_x2) {
				return _ref3.apply(this, arguments);
			}
 
			return turnAgain;
		}()
 
		/**
   * If I can, do it!
   * @return {Promise.<boolean>}
   */
 
	}, {
		key: 'roll2Dice',
		value: function () {
			var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4() {
				return regeneratorRuntime.wrap(function _callee4$(_context4) {
					while (1) {
						switch (_context4.prev = _context4.next) {
							case 0:
								return _context4.abrupt('return', this.canRoll2Dice());
 
							case 1:
							case 'end':
								return _context4.stop();
						}
					}
				}, _callee4, this);
			}));
 
			function roll2Dice() {
				return _ref4.apply(this, arguments);
			}
 
			return roll2Dice;
		}()
 
		/**
   * Can I buy landmarks?
   * By default this will buy anything it can spend money on. (Not good strategy)
   * @return {Promise.<string[]>}
   */
 
	}, {
		key: 'buyLandmarks',
		value: function () {
			var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5() {
				var ret;
				return regeneratorRuntime.wrap(function _callee5$(_context5) {
					while (1) {
						switch (_context5.prev = _context5.next) {
							case 0:
								ret = this.possibleLandmarks();
 
 
								while (ret.length && !this.canBuyLandmarks(ret)) {
									ret.pop();
								}return _context5.abrupt('return', ret.map(function (lm) {
									return lm.name;
								}));
 
							case 3:
							case 'end':
								return _context5.stop();
						}
					}
				}, _callee5, this);
			}));
 
			function buyLandmarks() {
				return _ref5.apply(this, arguments);
			}
 
			return buyLandmarks;
		}()
 
		/**
   * Can I buy from market?
   * By default this will buy anything it can spend money on. (Not good strategy)
   * @return {Promise.<number[]>}
   */
 
	}, {
		key: 'buyFromMarket',
		value: function buyFromMarket(market) {
			var ret = this.possibleCards(market);
 
			while (ret.length && !this.canBuyCards(ret.map(function (i) {
				return market[i];
			}))) {
				ret.pop();
			}return ret;
		}
	}]);
 
	return PlayerActions;
}();
 
exports.default = PlayerActions;
//# sourceMappingURL=PlayerActions.js.map