diff --git a/.babelrc b/.babelrc index 8a87b4d..234f419 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,7 @@ { - "presets": ["es2015"] + "presets": ["es2015"], + "plugins": [ + "add-module-exports", + "transform-es2015-modules-umd" + ] } \ No newline at end of file diff --git a/dist/SudokuMaker.js b/dist/SudokuMaker.js index 619c77d..37b253b 100644 --- a/dist/SudokuMaker.js +++ b/dist/SudokuMaker.js @@ -1,5 +1,14 @@ -var SudokuMaker = -/******/ (function(modules) { // webpackBootstrap +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else if(typeof exports === 'object') + exports["SudokuMaker"] = factory(); + else + root["SudokuMaker"] = factory(); +})(this, function() { +return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; @@ -52,9 +61,9 @@ var SudokuMaker = /* 1 */ /***/ function(module, exports, __webpack_require__) { - var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { if (true) { - !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, exports, __webpack_require__(2), __webpack_require__(3)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, exports, __webpack_require__(3), __webpack_require__(2)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else if (typeof exports !== "undefined") { factory(module, exports, require('./Pattern'), require('./Constants')); } else { @@ -64,297 +73,320 @@ var SudokuMaker = factory(mod, mod.exports, global.Pattern, global.Constants); global.index = mod.exports; } - })(this, function (module, exports, _Pattern, _Constants) { - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - 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; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } + })(this, function (module, exports) { + (function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, exports, __webpack_require__(3), __webpack_require__(2)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(module, exports); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.Pattern, global.Constants); + global.index = mod.exports; } + })(this, function (module, exports, _Pattern, _Constants) { + 'use strict'; - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; - }(); - - var sudokuMaker = function () { - function sudokuMaker(type) { - _classCallCheck(this, sudokuMaker); + Object.defineProperty(exports, "__esModule", { + value: true + }); - this.createType = type || _Constants.CreateTypes.RANDOM; + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } } - _createClass(sudokuMaker, [{ - key: 'initRndNum', - value: function initRndNum() { - var baseData = []; - var number = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - for (var i = 0; i < 3; i++) { - for (var j = 0; j < 3; j++) { - if (!baseData[j]) { - baseData[j] = []; - } - baseData[j][i] = []; - baseData[j][i] = number.splice(Math.floor(Math.random() * number.length), 1)[0]; - } + 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; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); } - return baseData; } - }, { - key: 'createGame', - value: function createGame() { - var baseData = this.initRndNum(); - var number = Math.floor(Math.random() * _Pattern.GamePattern.length); - var type = _Pattern.GamePattern[number]; - var gameData = []; - - gameData = type.map(function (data, index) { - return moveCard(baseData, _Pattern.TilePattern[data]); - }); - - if (this.createType === _Constants.CreateTypes.RANDOM) { - var end = 40; - var start = 25; - var pick_cnt = Math.floor(Math.random() * (end - start + 1) + start); - var randomGamePattern = objectClone(gameData); - var value = ['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']; - - for (var i = 0; i < pick_cnt; i++) { - var pick_idx = Math.floor(Math.random() * value.length); - var coord = getCoordByCount(value[pick_idx]); - randomGamePattern[coord.i][coord.j][coord.k] = undefined; - value.splice(pick_idx, 1); - } - gameData = { - org: gameData, - data: randomGamePattern - }; - } + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + var sudokuMaker = function () { + function sudokuMaker() { + _classCallCheck(this, sudokuMaker); - return gameData; + this.createType = _Constants.CreateTypes.RANDOM; } - }, { - key: 'gameDataCheck', - value: function gameDataCheck(gameData) { - var checkData = { - state: _Constants.PlayTypes.COMPLETE, - box: {}, - rows: {}, - cols: {} - }; - - var isSolving = false; - var isFail = false; - - var _loop = function _loop(i) { - var duplicate = []; - gameData[i].forEach(function (items, _j) { - items.forEach(function (item, _k) { - var prev_item_idx = duplicate.indexOf(item); - if (prev_item_idx >= 0 && item) { - isFail = true; - var key = '' + i + _j + _k; - checkData.box[key] = { - _i: i, - _j: _j, - _k: _k - }; - - var p_j = Math.floor(prev_item_idx / 3); - var p_k = prev_item_idx % 3; - var prev_key = '' + i + p_j + p_k; - - checkData.box[prev_key] = { - _i: i, - _j: p_j, - _k: p_k - }; - } else if (!item) { - isSolving = true; - } - duplicate.push(item); - }); - }); - }; - for (var i = 0; i < 9; i++) { - _loop(i); + _createClass(sudokuMaker, [{ + key: 'setType', + value: function setType(type) { + this.createType = type || _Constants.CreateTypes.RANDOM; } + }, { + key: 'getType', + value: function getType() { + var createType = this.createType || _Constants.CreateTypes.RANDOM; + return createType; + } + }, { + key: 'createGame', + value: function createGame() { + var baseData = initRndNum(); + var number = Math.floor(Math.random() * _Pattern.GamePattern.length); + var type = _Pattern.GamePattern[number]; + var gameData = []; + + gameData = type.map(function (data, index) { + return moveCard(baseData, _Pattern.TilePattern[data]); + }); - var _loop2 = function _loop2(_i2) { - var _loop4 = function _loop4(j) { - var duplicate = []; - var rows = gameData[_i2][j].concat(gameData[_i2 + 1][j], gameData[_i2 + 2][j]); - rows.forEach(function (item, idx) { - var _i = _i2 + Math.floor(idx / 3); - var _k = idx % 3; - var prev_item_idx = duplicate.indexOf(item); - if (prev_item_idx >= 0 && item) { - isFail = true; - var key = '' + _i + j + _k; - checkData.rows[key] = { - _i: _i, - _j: j, - _k: _k - }; - - var p_i = _i2 + Math.floor(prev_item_idx / 3); - var p_k = prev_item_idx % 3; - - var prev_key = '' + p_i + j + p_k; - - checkData.rows[prev_key] = { - _i: p_i, - _j: j, - _k: p_k - }; - } else if (!item) { - isSolving = true; - } - duplicate.push(item); - }); - }; + if (this.createType === _Constants.CreateTypes.RANDOM) { + var end = 40; + var start = 25; + var pick_cnt = Math.floor(Math.random() * (end - start + 1) + start); + var randomGamePattern = objectClone(gameData); + var value = ['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']; + + for (var i = 0; i < pick_cnt; i++) { + var pick_idx = Math.floor(Math.random() * value.length); + var coord = getCoordByCount(value[pick_idx]); + randomGamePattern[coord.i][coord.j][coord.k] = undefined; + value.splice(pick_idx, 1); + } - for (var j = 0; j < 3; j++) { - _loop4(j); + gameData = { + correctData: gameData, + data: randomGamePattern + }; } - }; - for (var _i2 = 0; _i2 < 9; _i2 = _i2 + 3) { - _loop2(_i2); + return gameData; } + }, { + key: 'gameDataCheck', + value: function gameDataCheck(gameData) { + var checkData = { + state: _Constants.PlayTypes.COMPLETE, + box: {}, + rows: {}, + cols: {} + }; + + var isSolving = false; + var isFail = false; - var _loop3 = function _loop3(_i3) { - var _loop5 = function _loop5(k) { + var _loop = function _loop(i) { var duplicate = []; - var j = 0; - - var cols = []; - - cols.push(gameData[_i3][j][k]); - cols.push(gameData[_i3][j + 1][k]); - cols.push(gameData[_i3][j + 2][k]); - cols.push(gameData[_i3 + 3][j][k]); - cols.push(gameData[_i3 + 3][j + 1][k]); - cols.push(gameData[_i3 + 3][j + 2][k]); - cols.push(gameData[_i3 + 6][j][k]); - cols.push(gameData[_i3 + 6][j + 1][k]); - cols.push(gameData[_i3 + 6][j + 2][k]); - - cols.forEach(function (item, idx) { - var _i = Math.floor(idx / 3) * 3 + _i3; - var _j = idx % 3; - var prev_item_idx = duplicate.indexOf(item); - if (prev_item_idx >= 0 && item) { - isFail = true; - var key = '' + _i + _j + k; - checkData.cols[key] = { - _i: _i, - _j: _j, - _k: k - }; - - var p_i = Math.floor(prev_item_idx / 3) * 3 + _i3; - var p_j = prev_item_idx % 3; - var prev_key = '' + p_i + p_j + k; - checkData.cols[prev_key] = { - _i: p_i, - _j: p_j, - _k: k - }; - } else if (!item) { - isSolving = true; - } - duplicate.push(item); + gameData[i].forEach(function (items, _j) { + items.forEach(function (item, _k) { + var prev_item_idx = duplicate.indexOf(item); + if (prev_item_idx >= 0 && item) { + isFail = true; + var key = '' + i + _j + _k; + checkData.box[key] = { + _i: i, + _j: _j, + _k: _k + }; + + var p_j = Math.floor(prev_item_idx / 3); + var p_k = prev_item_idx % 3; + var prev_key = '' + i + p_j + p_k; + + checkData.box[prev_key] = { + _i: i, + _j: p_j, + _k: p_k + }; + } else if (!item) { + isSolving = true; + } + duplicate.push(item); + }); }); }; - for (var k = 0; k < 3; k++) { - _loop5(k); + for (var i = 0; i < 9; i++) { + _loop(i); } - }; - for (var _i3 = 0; _i3 < 3; _i3++) { - _loop3(_i3); - } + var _loop2 = function _loop2(_i2) { + var _loop4 = function _loop4(j) { + var duplicate = []; + var rows = gameData[_i2][j].concat(gameData[_i2 + 1][j], gameData[_i2 + 2][j]); + rows.forEach(function (item, idx) { + var _i = _i2 + Math.floor(idx / 3); + var _k = idx % 3; + var prev_item_idx = duplicate.indexOf(item); + if (prev_item_idx >= 0 && item) { + isFail = true; + var key = '' + _i + j + _k; + checkData.rows[key] = { + _i: _i, + _j: j, + _k: _k + }; + + var p_i = _i2 + Math.floor(prev_item_idx / 3); + var p_k = prev_item_idx % 3; + + var prev_key = '' + p_i + j + p_k; + + checkData.rows[prev_key] = { + _i: p_i, + _j: j, + _k: p_k + }; + } else if (!item) { + isSolving = true; + } + duplicate.push(item); + }); + }; + + for (var j = 0; j < 3; j++) { + _loop4(j); + } + }; - if (isFail) { - checkData.state = _Constants.PlayTypes.FAIL; - } else if (isSolving) { - checkData.state = _Constants.PlayTypes.SOLVING; - } + for (var _i2 = 0; _i2 < 9; _i2 = _i2 + 3) { + _loop2(_i2); + } - return checkData; - } - }]); + var _loop3 = function _loop3(_i3) { + var _loop5 = function _loop5(k) { + var duplicate = []; + var j = 0; + + var cols = []; + + cols.push(gameData[_i3][j][k]); + cols.push(gameData[_i3][j + 1][k]); + cols.push(gameData[_i3][j + 2][k]); + cols.push(gameData[_i3 + 3][j][k]); + cols.push(gameData[_i3 + 3][j + 1][k]); + cols.push(gameData[_i3 + 3][j + 2][k]); + cols.push(gameData[_i3 + 6][j][k]); + cols.push(gameData[_i3 + 6][j + 1][k]); + cols.push(gameData[_i3 + 6][j + 2][k]); + + cols.forEach(function (item, idx) { + var _i = Math.floor(idx / 3) * 3 + _i3; + var _j = idx % 3; + var prev_item_idx = duplicate.indexOf(item); + if (prev_item_idx >= 0 && item) { + isFail = true; + var key = '' + _i + _j + k; + checkData.cols[key] = { + _i: _i, + _j: _j, + _k: k + }; + + var p_i = Math.floor(prev_item_idx / 3) * 3 + _i3; + var p_j = prev_item_idx % 3; + var prev_key = '' + p_i + p_j + k; + checkData.cols[prev_key] = { + _i: p_i, + _j: p_j, + _k: k + }; + } else if (!item) { + isSolving = true; + } + duplicate.push(item); + }); + }; + + for (var k = 0; k < 3; k++) { + _loop5(k); + } + }; - return sudokuMaker; - }(); + for (var _i3 = 0; _i3 < 3; _i3++) { + _loop3(_i3); + } - exports.default = sudokuMaker; + if (isFail) { + checkData.state = _Constants.PlayTypes.FAIL; + } else if (isSolving) { + checkData.state = _Constants.PlayTypes.SOLVING; + } + return checkData; + } + }]); + + return sudokuMaker; + }(); + + function initRndNum() { + var baseData = []; + var number = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + for (var i = 0; i < 3; i++) { + for (var j = 0; j < 3; j++) { + if (!baseData[j]) { + baseData[j] = []; + } + baseData[j][i] = []; + baseData[j][i] = number.splice(Math.floor(Math.random() * number.length), 1)[0]; + } + } + return baseData; + } - function searchXY(data, value) { - var temp = []; - for (var i = 0; i < 3; i++) { - temp = temp.concat(data[i]); + function searchXY(data, value) { + var temp = []; + for (var i = 0; i < 3; i++) { + temp = temp.concat(data[i]); + } + return temp[value]; } - return temp[value]; - } - function moveCard(data, pattern) { - var result = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]; - var getTable = []; - for (var i = 0; i < 3; i++) { - for (var j = 0; j < 3; j++) { - result[i][j] = searchXY(data, pattern[i][j]); + function moveCard(data, pattern) { + var result = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]; + var getTable = []; + for (var i = 0; i < 3; i++) { + for (var j = 0; j < 3; j++) { + result[i][j] = searchXY(data, pattern[i][j]); + } } + return result; } - return result; - } - function objectClone(object) { - return JSON.parse(JSON.stringify(object)); - } + function objectClone(object) { + return JSON.parse(JSON.stringify(object)); + } - function getCoordByCount(count) { - var _i = Math.floor((count - 1) / 9); - var _j = Math.floor(count % 9 / 3); - var _k = Math.floor(count % 9 % 3); + function getCoordByCount(count) { + var _i = Math.floor((count - 1) / 9); + var _j = Math.floor(count % 9 / 3); + var _k = Math.floor(count % 9 % 3); - return { - i: _i, - j: _j, - k: _k - }; - } - module.exports = exports['default']; + return { + i: _i, + j: _j, + k: _k + }; + } + + exports.default = new sudokuMaker(); + module.exports = exports['default']; + }); }); /***/ }, /* 2 */ /***/ function(module, exports, __webpack_require__) { - var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { if (true) { !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else if (typeof exports !== "undefined") { @@ -364,69 +396,48 @@ var SudokuMaker = exports: {} }; factory(mod.exports); - global.Pattern = mod.exports; + global.Constants = mod.exports; } })(this, function (exports) { - "use strict"; - 'use strict;'; + (function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(exports); + } else { + var mod = { + exports: {} + }; + factory(mod.exports); + global.Constants = mod.exports; + } + })(this, function (exports) { + 'use strict'; + 'use strict;'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + var PlayTypes = { + SUCCESS: 'SUCCESS', + FAIL: 'FAIL', + SOLVING: 'SOLVING' + }; - Object.defineProperty(exports, "__esModule", { - value: true + var CreateTypes = { + RANDOM: 'RANDOM' + }; + + exports.PlayTypes = PlayTypes; + exports.CreateTypes = CreateTypes; }); - var TilePattern = {}; - TilePattern["A"] = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]; - TilePattern["B"] = [[1, 2, 0], [4, 5, 3], [7, 8, 6]]; - TilePattern["C"] = [[2, 0, 1], [5, 3, 4], [8, 6, 7]]; - TilePattern["D"] = [[3, 4, 5], [6, 7, 8], [0, 1, 2]]; - TilePattern["E"] = [[4, 5, 3], [7, 8, 6], [1, 2, 0]]; - TilePattern["F"] = [[5, 3, 4], [8, 6, 7], [2, 0, 1]]; - TilePattern["G"] = [[6, 7, 8], [0, 1, 2], [3, 4, 5]]; - TilePattern["H"] = [[7, 8, 6], [1, 2, 0], [4, 5, 3]]; - TilePattern["I"] = [[8, 6, 7], [2, 0, 1], [5, 3, 4]]; - TilePattern["J"] = [[8, 7, 6], [2, 1, 0], [5, 4, 3]]; - TilePattern["K"] = [[4, 3, 5], [7, 6, 8], [1, 0, 2]]; - TilePattern["L"] = [[6, 8, 7], [0, 2, 1], [3, 5, 4]]; - TilePattern["M"] = [[4, 8, 1], [7, 5, 6], [2, 0, 3]]; - TilePattern["N"] = [[8, 2, 4], [5, 6, 7], [1, 3, 0]]; - TilePattern["O"] = [[6, 5, 8], [0, 7, 2], [3, 4, 1]]; - TilePattern["P"] = [[7, 2, 6], [4, 3, 0], [8, 1, 5]]; - TilePattern["Q"] = [[5, 6, 7], [1, 0, 3], [2, 8, 4]]; - TilePattern["R"] = [[7, 4, 3], [6, 1, 8], [0, 5, 2]]; - TilePattern["S"] = [[3, 0, 5], [2, 8, 1], [4, 6, 7]]; - TilePattern["T"] = [[1, 3, 0], [8, 2, 4], [5, 7, 6]]; - TilePattern["U"] = [[4, 2, 0], [5, 3, 1], [8, 6, 7]]; - TilePattern["V"] = [[7, 5, 4], [1, 8, 3], [2, 0, 6]]; - TilePattern["W"] = [[8, 5, 3], [7, 0, 6], [2, 4, 1]]; - TilePattern["X"] = [[6, 1, 7], [0, 2, 8], [4, 3, 5]]; - TilePattern["Y"] = [[1, 8, 2], [5, 6, 0], [3, 7, 4]]; - TilePattern["Z"] = [[6, 4, 7], [2, 1, 8], [0, 3, 5]]; - TilePattern["AA"] = [[5, 8, 3], [7, 6, 4], [1, 2, 0]]; - TilePattern["AB"] = [[3, 0, 6], [4, 7, 2], [8, 5, 1]]; - - var GamePattern = []; - GamePattern[0] = ["A", "D", "G", "B", "E", "H", "C", "F", "I"]; - GamePattern[1] = ["A", "G", "D", "B", "H", "E", "C", "I", "F"]; - GamePattern[2] = ["A", "G", "D", "C", "I", "F", "B", "H", "E"]; - GamePattern[3] = ["A", "J", "F", "I", "K", "A", "B", "L", "E"]; - GamePattern[4] = ["A", "G", "D", "F", "C", "I", "E", "B", "H"]; - GamePattern[5] = ["A", "O", "R", "M", "P", "S", "N", "Q", "T"]; - GamePattern[6] = ["A", "R", "O", "M", "S", "P", "N", "T", "Q"]; - GamePattern[7] = ["A", "R", "O", "N", "T", "Q", "M", "S", "P"]; - GamePattern[8] = ["A", "O", "R", "N", "Q", "T", "M", "P", "S"]; - GamePattern[9] = ["A", "W", "Z", "U", "X", "AA", "V", "Y", "AB"]; - GamePattern[10] = ["A", "Z", "W", "U", "AA", "X", "V", "AB", "Y"]; - GamePattern[11] = ["A", "Z", "W", "V", "AB", "Y", "U", "AA", "X"]; - GamePattern[12] = ["A", "W", "Z", "V", "Y", "AB", "U", "X", "AA"]; - - exports.TilePattern = TilePattern; - exports.GamePattern = GamePattern; }); /***/ }, /* 3 */ /***/ function(module, exports, __webpack_require__) { - var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { if (true) { !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else if (typeof exports !== "undefined") { @@ -436,27 +447,79 @@ var SudokuMaker = exports: {} }; factory(mod.exports); - global.Constants = mod.exports; + global.Pattern = mod.exports; } })(this, function (exports) { - 'use strict'; - 'use strict;'; - - Object.defineProperty(exports, "__esModule", { - value: true + (function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof exports !== "undefined") { + factory(exports); + } else { + var mod = { + exports: {} + }; + factory(mod.exports); + global.Pattern = mod.exports; + } + })(this, function (exports) { + "use strict"; + 'use strict;'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + var TilePattern = {}; + TilePattern["A"] = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]; + TilePattern["B"] = [[1, 2, 0], [4, 5, 3], [7, 8, 6]]; + TilePattern["C"] = [[2, 0, 1], [5, 3, 4], [8, 6, 7]]; + TilePattern["D"] = [[3, 4, 5], [6, 7, 8], [0, 1, 2]]; + TilePattern["E"] = [[4, 5, 3], [7, 8, 6], [1, 2, 0]]; + TilePattern["F"] = [[5, 3, 4], [8, 6, 7], [2, 0, 1]]; + TilePattern["G"] = [[6, 7, 8], [0, 1, 2], [3, 4, 5]]; + TilePattern["H"] = [[7, 8, 6], [1, 2, 0], [4, 5, 3]]; + TilePattern["I"] = [[8, 6, 7], [2, 0, 1], [5, 3, 4]]; + TilePattern["J"] = [[8, 7, 6], [2, 1, 0], [5, 4, 3]]; + TilePattern["K"] = [[4, 3, 5], [7, 6, 8], [1, 0, 2]]; + TilePattern["L"] = [[6, 8, 7], [0, 2, 1], [3, 5, 4]]; + TilePattern["M"] = [[4, 8, 1], [7, 5, 6], [2, 0, 3]]; + TilePattern["N"] = [[8, 2, 4], [5, 6, 7], [1, 3, 0]]; + TilePattern["O"] = [[6, 5, 8], [0, 7, 2], [3, 4, 1]]; + TilePattern["P"] = [[7, 2, 6], [4, 3, 0], [8, 1, 5]]; + TilePattern["Q"] = [[5, 6, 7], [1, 0, 3], [2, 8, 4]]; + TilePattern["R"] = [[7, 4, 3], [6, 1, 8], [0, 5, 2]]; + TilePattern["S"] = [[3, 0, 5], [2, 8, 1], [4, 6, 7]]; + TilePattern["T"] = [[1, 3, 0], [8, 2, 4], [5, 7, 6]]; + TilePattern["U"] = [[4, 2, 0], [5, 3, 1], [8, 6, 7]]; + TilePattern["V"] = [[7, 5, 4], [1, 8, 3], [2, 0, 6]]; + TilePattern["W"] = [[8, 5, 3], [7, 0, 6], [2, 4, 1]]; + TilePattern["X"] = [[6, 1, 7], [0, 2, 8], [4, 3, 5]]; + TilePattern["Y"] = [[1, 8, 2], [5, 6, 0], [3, 7, 4]]; + TilePattern["Z"] = [[6, 4, 7], [2, 1, 8], [0, 3, 5]]; + TilePattern["AA"] = [[5, 8, 3], [7, 6, 4], [1, 2, 0]]; + TilePattern["AB"] = [[3, 0, 6], [4, 7, 2], [8, 5, 1]]; + + var GamePattern = []; + GamePattern[0] = ["A", "D", "G", "B", "E", "H", "C", "F", "I"]; + GamePattern[1] = ["A", "G", "D", "B", "H", "E", "C", "I", "F"]; + GamePattern[2] = ["A", "G", "D", "C", "I", "F", "B", "H", "E"]; + GamePattern[3] = ["A", "J", "F", "I", "K", "A", "B", "L", "E"]; + GamePattern[4] = ["A", "G", "D", "F", "C", "I", "E", "B", "H"]; + GamePattern[5] = ["A", "O", "R", "M", "P", "S", "N", "Q", "T"]; + GamePattern[6] = ["A", "R", "O", "M", "S", "P", "N", "T", "Q"]; + GamePattern[7] = ["A", "R", "O", "N", "T", "Q", "M", "S", "P"]; + GamePattern[8] = ["A", "O", "R", "N", "Q", "T", "M", "P", "S"]; + GamePattern[9] = ["A", "W", "Z", "U", "X", "AA", "V", "Y", "AB"]; + GamePattern[10] = ["A", "Z", "W", "U", "AA", "X", "V", "AB", "Y"]; + GamePattern[11] = ["A", "Z", "W", "V", "AB", "Y", "U", "AA", "X"]; + GamePattern[12] = ["A", "W", "Z", "V", "Y", "AB", "U", "X", "AA"]; + + exports.TilePattern = TilePattern; + exports.GamePattern = GamePattern; }); - var PlayTypes = { - SUCCESS: 'SUCCESS', - FAIL: 'FAIL', - SOLVING: 'SOLVING' - }; - - var CreateTypes = { - RANDOM: 'RANDOM' - }; - - exports.PlayTypes = PlayTypes; }); /***/ } -/******/ ]); \ No newline at end of file +/******/ ]) +}); +; \ No newline at end of file diff --git a/dist/SudokuMaker.min.js b/dist/SudokuMaker.min.js index 4b1592a..e73109b 100644 --- a/dist/SudokuMaker.min.js +++ b/dist/SudokuMaker.min.js @@ -1 +1 @@ -var SudokuMaker=function(r){function t(o){if(e[o])return e[o].exports;var n=e[o]={exports:{},id:o,loaded:!1};return r[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var e={};return t.m=r,t.c=e,t.p="/",t(0)}([function(r,t,e){r.exports=e(1)},function(r,t,e){var o,n,a;!function(i,u){n=[r,t,e(2),e(3)],o=u,a="function"==typeof o?o.apply(t,n):o,!(void 0!==a&&(r.exports=a))}(this,function(r,t,e,o){"use strict";function n(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}function a(r,t){for(var e=[],o=0;o<3;o++)e=e.concat(r[o]);return e[t]}function i(r,t){for(var e=[[0,0,0],[0,0,0],[0,0,0]],o=0;o<3;o++)for(var n=0;n<3;n++)e[o][n]=a(r,t[o][n]);return e}function u(r){return JSON.parse(JSON.stringify(r))}function f(r){var t=Math.floor((r-1)/9),e=Math.floor(r%9/3),o=Math.floor(r%9%3);return{i:t,j:e,k:o}}Object.defineProperty(t,"__esModule",{value:!0});var c=function(){function r(r,t){for(var e=0;e=0&&r){n=!0;var c=""+o+i+u;t.box[c]={_i:o,_j:i,_k:u};var s=Math.floor(f/3),l=f%3,p=""+o+s+l;t.box[p]={_i:o,_j:s,_k:l}}else r||(e=!0);a.push(r)})})},i=0;i<9;i++)a(i);for(var u=function(o){for(var a=function(a){var i=[],u=r[o][a].concat(r[o+1][a],r[o+2][a]);u.forEach(function(r,u){var f=o+Math.floor(u/3),c=u%3,s=i.indexOf(r);if(s>=0&&r){n=!0;var l=""+f+a+c;t.rows[l]={_i:f,_j:a,_k:c};var p=o+Math.floor(s/3),v=s%3,h=""+p+a+v;t.rows[h]={_i:p,_j:a,_k:v}}else r||(e=!0);i.push(r)})},i=0;i<3;i++)a(i)},f=0;f<9;f+=3)u(f);for(var c=function(o){for(var a=function(a){var i=[],u=0,f=[];f.push(r[o][u][a]),f.push(r[o][u+1][a]),f.push(r[o][u+2][a]),f.push(r[o+3][u][a]),f.push(r[o+3][u+1][a]),f.push(r[o+3][u+2][a]),f.push(r[o+6][u][a]),f.push(r[o+6][u+1][a]),f.push(r[o+6][u+2][a]),f.forEach(function(r,u){var f=3*Math.floor(u/3)+o,c=u%3,s=i.indexOf(r);if(s>=0&&r){n=!0;var l=""+f+c+a;t.cols[l]={_i:f,_j:c,_k:a};var p=3*Math.floor(s/3)+o,v=s%3,h=""+p+v+a;t.cols[h]={_i:p,_j:v,_k:a}}else r||(e=!0);i.push(r)})},i=0;i<3;i++)a(i)},s=0;s<3;s++)c(s);return n?t.state=o.PlayTypes.FAIL:e&&(t.state=o.PlayTypes.SOLVING),t}}]),r}();t["default"]=s,r.exports=t["default"]})},function(r,t,e){var o,n,a;!function(e,i){n=[t],o=i,a="function"==typeof o?o.apply(t,n):o,!(void 0!==a&&(r.exports=a))}(this,function(r){"use strict";"use strict;";Object.defineProperty(r,"__esModule",{value:!0});var t={};t.A=[[0,1,2],[3,4,5],[6,7,8]],t.B=[[1,2,0],[4,5,3],[7,8,6]],t.C=[[2,0,1],[5,3,4],[8,6,7]],t.D=[[3,4,5],[6,7,8],[0,1,2]],t.E=[[4,5,3],[7,8,6],[1,2,0]],t.F=[[5,3,4],[8,6,7],[2,0,1]],t.G=[[6,7,8],[0,1,2],[3,4,5]],t.H=[[7,8,6],[1,2,0],[4,5,3]],t.I=[[8,6,7],[2,0,1],[5,3,4]],t.J=[[8,7,6],[2,1,0],[5,4,3]],t.K=[[4,3,5],[7,6,8],[1,0,2]],t.L=[[6,8,7],[0,2,1],[3,5,4]],t.M=[[4,8,1],[7,5,6],[2,0,3]],t.N=[[8,2,4],[5,6,7],[1,3,0]],t.O=[[6,5,8],[0,7,2],[3,4,1]],t.P=[[7,2,6],[4,3,0],[8,1,5]],t.Q=[[5,6,7],[1,0,3],[2,8,4]],t.R=[[7,4,3],[6,1,8],[0,5,2]],t.S=[[3,0,5],[2,8,1],[4,6,7]],t.T=[[1,3,0],[8,2,4],[5,7,6]],t.U=[[4,2,0],[5,3,1],[8,6,7]],t.V=[[7,5,4],[1,8,3],[2,0,6]],t.W=[[8,5,3],[7,0,6],[2,4,1]],t.X=[[6,1,7],[0,2,8],[4,3,5]],t.Y=[[1,8,2],[5,6,0],[3,7,4]],t.Z=[[6,4,7],[2,1,8],[0,3,5]],t.AA=[[5,8,3],[7,6,4],[1,2,0]],t.AB=[[3,0,6],[4,7,2],[8,5,1]];var e=[];e[0]=["A","D","G","B","E","H","C","F","I"],e[1]=["A","G","D","B","H","E","C","I","F"],e[2]=["A","G","D","C","I","F","B","H","E"],e[3]=["A","J","F","I","K","A","B","L","E"],e[4]=["A","G","D","F","C","I","E","B","H"],e[5]=["A","O","R","M","P","S","N","Q","T"],e[6]=["A","R","O","M","S","P","N","T","Q"],e[7]=["A","R","O","N","T","Q","M","S","P"],e[8]=["A","O","R","N","Q","T","M","P","S"],e[9]=["A","W","Z","U","X","AA","V","Y","AB"],e[10]=["A","Z","W","U","AA","X","V","AB","Y"],e[11]=["A","Z","W","V","AB","Y","U","AA","X"],e[12]=["A","W","Z","V","Y","AB","U","X","AA"],r.TilePattern=t,r.GamePattern=e})},function(r,t,e){var o,n,a;!function(e,i){n=[t],o=i,a="function"==typeof o?o.apply(t,n):o,!(void 0!==a&&(r.exports=a))}(this,function(r){"use strict";"use strict;";Object.defineProperty(r,"__esModule",{value:!0});var t={SUCCESS:"SUCCESS",FAIL:"FAIL",SOLVING:"SOLVING"};r.PlayTypes=t})}]); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.SudokuMaker=e():t.SudokuMaker=e()}(this,function(){return function(t){function e(r){if(o[r])return o[r].exports;var n=o[r]={exports:{},id:r,loaded:!1};return t[r].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var o={};return e.m=t,e.c=o,e.p="/",e(0)}([function(t,e,o){t.exports=o(1)},function(t,e,o){var r,n,a,r,n,a;!function(f,i){n=[t,e,o(3),o(2)],r=i,a="function"==typeof r?r.apply(e,n):r,!(void 0!==a&&(t.exports=a))}(this,function(t,e){!function(f,i){n=[t,e,o(3),o(2)],r=i,a="function"==typeof r?r.apply(e,n):r,!(void 0!==a&&(t.exports=a))}(this,function(t,e,o,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(){for(var t=[],e=[1,2,3,4,5,6,7,8,9],o=0;o<3;o++)for(var r=0;r<3;r++)t[r]||(t[r]=[]),t[r][o]=[],t[r][o]=e.splice(Math.floor(Math.random()*e.length),1)[0];return t}function f(t,e){for(var o=[],r=0;r<3;r++)o=o.concat(t[r]);return o[e]}function i(t,e){for(var o=[[0,0,0],[0,0,0],[0,0,0]],r=0;r<3;r++)for(var n=0;n<3;n++)o[r][n]=f(t,e[r][n]);return o}function u(t){return JSON.parse(JSON.stringify(t))}function c(t){var e=Math.floor((t-1)/9),o=Math.floor(t%9/3),r=Math.floor(t%9%3);return{i:e,j:o,k:r}}Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(t,e){for(var o=0;o=0&&t){n=!0;var c=""+r+f+i;e.box[c]={_i:r,_j:f,_k:i};var s=Math.floor(u/3),p=u%3,l=""+r+s+p;e.box[l]={_i:r,_j:s,_k:p}}else t||(o=!0);a.push(t)})})},f=0;f<9;f++)a(f);for(var i=function(r){for(var a=function(a){var f=[],i=t[r][a].concat(t[r+1][a],t[r+2][a]);i.forEach(function(t,i){var u=r+Math.floor(i/3),c=i%3,s=f.indexOf(t);if(s>=0&&t){n=!0;var p=""+u+a+c;e.rows[p]={_i:u,_j:a,_k:c};var l=r+Math.floor(s/3),v=s%3,h=""+l+a+v;e.rows[h]={_i:l,_j:a,_k:v}}else t||(o=!0);f.push(t)})},f=0;f<3;f++)a(f)},u=0;u<9;u+=3)i(u);for(var c=function(r){for(var a=function(a){var f=[],i=0,u=[];u.push(t[r][i][a]),u.push(t[r][i+1][a]),u.push(t[r][i+2][a]),u.push(t[r+3][i][a]),u.push(t[r+3][i+1][a]),u.push(t[r+3][i+2][a]),u.push(t[r+6][i][a]),u.push(t[r+6][i+1][a]),u.push(t[r+6][i+2][a]),u.forEach(function(t,i){var u=3*Math.floor(i/3)+r,c=i%3,s=f.indexOf(t);if(s>=0&&t){n=!0;var p=""+u+c+a;e.cols[p]={_i:u,_j:c,_k:a};var l=3*Math.floor(s/3)+r,v=s%3,h=""+l+v+a;e.cols[h]={_i:l,_j:v,_k:a}}else t||(o=!0);f.push(t)})},f=0;f<3;f++)a(f)},s=0;s<3;s++)c(s);return n?e.state=r.PlayTypes.FAIL:o&&(e.state=r.PlayTypes.SOLVING),e}}]),t}();e["default"]=new p,t.exports=e["default"]})})},function(t,e,o){var r,n,a,r,n,a;!function(o,f){n=[e],r=f,a="function"==typeof r?r.apply(e,n):r,!(void 0!==a&&(t.exports=a))}(this,function(e){!function(o,f){n=[e],r=f,a="function"==typeof r?r.apply(e,n):r,!(void 0!==a&&(t.exports=a))}(this,function(t){"use strict";"use strict;";Object.defineProperty(t,"__esModule",{value:!0});var e={SUCCESS:"SUCCESS",FAIL:"FAIL",SOLVING:"SOLVING"},o={RANDOM:"RANDOM"};t.PlayTypes=e,t.CreateTypes=o})})},function(t,e,o){var r,n,a,r,n,a;!function(o,f){n=[e],r=f,a="function"==typeof r?r.apply(e,n):r,!(void 0!==a&&(t.exports=a))}(this,function(e){!function(o,f){n=[e],r=f,a="function"==typeof r?r.apply(e,n):r,!(void 0!==a&&(t.exports=a))}(this,function(t){"use strict";"use strict;";Object.defineProperty(t,"__esModule",{value:!0});var e={};e.A=[[0,1,2],[3,4,5],[6,7,8]],e.B=[[1,2,0],[4,5,3],[7,8,6]],e.C=[[2,0,1],[5,3,4],[8,6,7]],e.D=[[3,4,5],[6,7,8],[0,1,2]],e.E=[[4,5,3],[7,8,6],[1,2,0]],e.F=[[5,3,4],[8,6,7],[2,0,1]],e.G=[[6,7,8],[0,1,2],[3,4,5]],e.H=[[7,8,6],[1,2,0],[4,5,3]],e.I=[[8,6,7],[2,0,1],[5,3,4]],e.J=[[8,7,6],[2,1,0],[5,4,3]],e.K=[[4,3,5],[7,6,8],[1,0,2]],e.L=[[6,8,7],[0,2,1],[3,5,4]],e.M=[[4,8,1],[7,5,6],[2,0,3]],e.N=[[8,2,4],[5,6,7],[1,3,0]],e.O=[[6,5,8],[0,7,2],[3,4,1]],e.P=[[7,2,6],[4,3,0],[8,1,5]],e.Q=[[5,6,7],[1,0,3],[2,8,4]],e.R=[[7,4,3],[6,1,8],[0,5,2]],e.S=[[3,0,5],[2,8,1],[4,6,7]],e.T=[[1,3,0],[8,2,4],[5,7,6]],e.U=[[4,2,0],[5,3,1],[8,6,7]],e.V=[[7,5,4],[1,8,3],[2,0,6]],e.W=[[8,5,3],[7,0,6],[2,4,1]],e.X=[[6,1,7],[0,2,8],[4,3,5]],e.Y=[[1,8,2],[5,6,0],[3,7,4]],e.Z=[[6,4,7],[2,1,8],[0,3,5]],e.AA=[[5,8,3],[7,6,4],[1,2,0]],e.AB=[[3,0,6],[4,7,2],[8,5,1]];var o=[];o[0]=["A","D","G","B","E","H","C","F","I"],o[1]=["A","G","D","B","H","E","C","I","F"],o[2]=["A","G","D","C","I","F","B","H","E"],o[3]=["A","J","F","I","K","A","B","L","E"],o[4]=["A","G","D","F","C","I","E","B","H"],o[5]=["A","O","R","M","P","S","N","Q","T"],o[6]=["A","R","O","M","S","P","N","T","Q"],o[7]=["A","R","O","N","T","Q","M","S","P"],o[8]=["A","O","R","N","Q","T","M","P","S"],o[9]=["A","W","Z","U","X","AA","V","Y","AB"],o[10]=["A","Z","W","U","AA","X","V","AB","Y"],o[11]=["A","Z","W","V","AB","Y","U","AA","X"],o[12]=["A","W","Z","V","Y","AB","U","X","AA"],t.TilePattern=e,t.GamePattern=o})})}])}); \ No newline at end of file diff --git a/example/sudoku.html b/example/example.html similarity index 100% rename from example/sudoku.html rename to example/example.html diff --git a/example/image.png b/example/image.png deleted file mode 100644 index 19d53d6..0000000 Binary files a/example/image.png and /dev/null differ diff --git a/package.json b/package.json index 4eb86d5..7989bfe 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "sudokuMaker", "version": "v1.0.6", "description": "sudokuMaker", - "main": "./src/sdm.js", + "main": "./dist/SudoKuMaker.min.js", "directories": { "example": "example" }, diff --git a/src/constants.js b/src/constants.js index 5228d28..b60da82 100644 --- a/src/constants.js +++ b/src/constants.js @@ -11,5 +11,6 @@ const CreateTypes = { } export { - PlayTypes + PlayTypes, + CreateTypes } \ No newline at end of file diff --git a/src/index.js b/src/index.js index 3b1f7fe..a3a5cda 100644 --- a/src/index.js +++ b/src/index.js @@ -3,28 +3,22 @@ import { TilePattern, GamePattern } from './Pattern'; import { PlayTypes, CreateTypes } from './Constants'; -export default class sudokuMaker { - constructor(type) { - this.createType = type || CreateTypes.RANDOM; +class sudokuMaker { + constructor() { + this.createType = CreateTypes.RANDOM; } - initRndNum() { - let baseData = []; - const number = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; - for ( let i = 0; i < 3; i++) { - for ( let j = 0; j < 3; j++) { - if(!baseData[j]) { - baseData[j] = []; - } - baseData[j][i] = []; - baseData[j][i] = (number.splice(Math.floor(Math.random() * number.length), 1))[0]; - } - } - return baseData; + setType(type) { + this.createType = type || CreateTypes.RANDOM; + } + + getType() { + const createType = this.createType || CreateTypes.RANDOM; + return createType; } createGame() { - const baseData = this.initRndNum(); + const baseData = initRndNum(); let number = Math.floor((Math.random() * GamePattern.length)); let type = GamePattern[number]; let gameData = []; @@ -48,7 +42,7 @@ export default class sudokuMaker { } gameData = { - org : gameData, + correctData : gameData, data: randomGamePattern } } @@ -190,6 +184,21 @@ export default class sudokuMaker { } } +function initRndNum() { + let baseData = []; + const number = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; + for ( let i = 0; i < 3; i++) { + for ( let j = 0; j < 3; j++) { + if(!baseData[j]) { + baseData[j] = []; + } + baseData[j][i] = []; + baseData[j][i] = (number.splice(Math.floor(Math.random() * number.length), 1))[0]; + } + } + return baseData; +} + function searchXY(data, value) { let temp = []; for ( let i = 0; i < 3; i++) { @@ -223,4 +232,6 @@ function getCoordByCount(count) { j: _j, k: _k } -} \ No newline at end of file +} + +export default new sudokuMaker; \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 9862661..56994a0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,10 +3,10 @@ var webpack = require('webpack'); module.exports = { entry: { - SudokuMaker: [ + sudokuMaker: [ './src/index.js', ], - 'SudokuMaker.min': [ + 'sudokuMaker.min': [ './src/index.js', ], }, @@ -14,8 +14,8 @@ module.exports = { path: path.join(__dirname, 'dist'), publicPath: '/', filename: '[name].js', - library: 'SudokuMaker', - libraryTarget: 'var', + library: 'sudokuMaker', + libraryTarget: 'umd', }, // devtool: 'source-map', module: {