text: !function(n){var e={};function t(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=n,t.c=e,t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:r})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)t.d(r,o,function(e){return n[e]}.bind(null,o));return r},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=4)}([function(n,e,t){var r=t(1);"string"==typeof r&&(r=[[n.i,r,""]]);var o={insert:"head",singleton:!1};t(3)(r,o);r.locals&&(n.exports=r.locals)},function(n,e,t){(e=t(2)(!1)).push([n.i,".alert {\n    max-width: 60%;\n}\n\nbody,\nhtml {\n    background-image: url(\"/assets/Battleships.jpg\");\n    background-size: 100vw 100vh;\n    background-attachment: fixed;\n    height: 100%;\n}\n\nbody {\n    background-color: black;\n}\n\n.computer .hover:hover {\n    background-color: aliceblue;\n    border: darkgreen dotted 3px;\n}\n\n.empty {\n    border: none;\n}\n\n.hit {\n    background:\n        linear-gradient(to top left,\n            rgba(0, 0, 0, 0) 0%,\n            rgba(0, 0, 0, 0) calc(50% - 0.8px),\n            red 50%,\n            rgba(0, 0, 0, 0) calc(50% + 0.8px),\n            rgba(0, 0, 0, 0) 100%),\n        linear-gradient(to top right,\n            rgba(0, 0, 0, 0) 0%,\n            rgba(0, 0, 0, 0) calc(50% - 0.8px),\n            red 50%,\n            rgba(0, 0, 0, 0) calc(50% + 0.8px),\n            rgba(0, 0, 0, 0) 100%);\n    border: 2px solid red;\n}\n\n.main {\n    height: 100%;\n}\n\n.miss {\n    background-color: rgb(203, 236, 203);\n}\n\n.miss,\n.hit {\n    pointer-events: none;\n}\n\n.player .ship {\n    background-color: #2f70a5;\n    border: none;\n}\n\n.randomize {\n    border-left: #2f70a5 solid 0.1em;\n    color: #4682b4;\n    cursor: pointer;\n    padding-left: 5px;\n}\n\n.randomize:active {\n    border-bottom: 2px dotted red;\n}\n\n.randomize:hover {\n    border-bottom: 2px dotted;\n}\n\n.randomize .material-icons {\n    font-size: 12px;\n}\n\n.resetBtn {\n    border-left: #2f70a5 solid 0.1em;\n\n}\n\ntable {\n    margin: 0 auto;\n    width: 90%;\n}\n\ntd {\n    border: 1px solid rgb(213, 213, 213);\n    position: relative;\n    width: calc(100/11%);\n}\n\ntd:after {\n    content: '';\n    display: block;\n    margin-top: 100%;\n}\n\ntd .content {\n    bottom: 0;\n    left: 0;\n    position: absolute;\n    right: 0;\n    top: 0;\n}\n\n.td:hover {\n    background-color: aliceblue;\n}\n\nth {\n    color: #4682b4;\n    font-size: 13px;\n    font-weight: 100;\n}\n\nthead th {\n    padding-bottom: 10px;\n}\n\n.vertical-center {\n    align-items: center;\n    display: flex;\n    justify-content: center;\n    padding: 2em;\n}",""]),n.exports=e},function(n,e,t){"use strict";n.exports=function(n){var e=[];return e.toString=function(){return this.map((function(e){var t=function(n,e){var t=n[1]||"",r=n[3];if(!r)return t;if(e&&"function"==typeof btoa){var o=(i=r,c=btoa(unescape(encodeURIComponent(JSON.stringify(i)))),s="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(c),"/*# ".concat(s," */")),a=r.sources.map((function(n){return"/*# sourceURL=".concat(r.sourceRoot||"").concat(n," */")}));return[t].concat(a).concat([o]).join("\n")}var i,c,s;return[t].join("\n")}(e,n);return e[2]?"@media ".concat(e[2]," {").concat(t,"}"):t})).join("")},e.i=function(n,t,r){"string"==typeof n&&(n=[[null,n,""]]);var o={};if(r)for(var a=0;a<this.length;a++){var i=this[a][0];null!=i&&(o[i]=!0)}for(var c=0;c<n.length;c++){var s=[].concat(n[c]);r&&o[s[0]]||(t&&(s[2]?s[2]="".concat(t," and ").concat(s[2]):s[2]=t),e.push(s))}},e}},function(n,e,t){"use strict";var r,o={},a=function(){return void 0===r&&(r=Boolean(window&&document&&document.all&&!window.atob)),r},i=function(){var n={};return function(e){if(void 0===n[e]){var t=document.querySelector(e);if(window.HTMLIFrameElement&&t instanceof window.HTMLIFrameElement)try{t=t.contentDocument.head}catch(n){t=null}n[e]=t}return n[e]}}();function c(n,e){for(var t=[],r={},o=0;o<n.length;o++){var a=n[o],i=e.base?a[0]+e.base:a[0],c={css:a[1],media:a[2],sourceMap:a[3]};r[i]?r[i].parts.push(c):t.push(r[i]={id:i,parts:[c]})}return t}function s(n,e){for(var t=0;t<n.length;t++){var r=n[t],a=o[r.id],i=0;if(a){for(a.refs++;i<a.parts.length;i++)a.parts[i](r.parts[i]);for(;i<r.parts.length;i++)a.parts.push(v(r.parts[i],e))}else{for(var c=[];i<r.parts.length;i++)c.push(v(r.parts[i],e));o[r.id]={id:r.id,refs:1,parts:c}}}}function u(n){var e=document.createElement("style");if(void 0===n.attributes.nonce){var r=t.nc;r&&(n.attributes.nonce=r)}if(Object.keys(n.attributes).forEach((function(t){e.setAttribute(t,n.attributes[t])})),"function"==typeof n.insert)n.insert(e);else{var o=i(n.insert||"head");if(!o)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");o.appendChild(e)}return e}var d,l=(d=[],function(n,e){return d[n]=e,d.filter(Boolean).join("\n")});function f(n,e,t,r){var o=t?"":r.css;if(n.styleSheet)n.styleSheet.cssText=l(e,o);else{var a=document.createTextNode(o),i=n.childNodes;i[e]&&n.removeChild(i[e]),i.length?n.insertBefore(a,i[e]):n.appendChild(a)}}function p(n,e,t){var r=t.css,o=t.media,a=t.sourceMap;if(o&&n.setAttribute("media",o),a&&btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(a))))," */")),n.styleSheet)n.styleSheet.cssText=r;else{for(;n.firstChild;)n.removeChild(n.firstChild);n.appendChild(document.createTextNode(r))}}var h=null,m=0;function v(n,e){var t,r,o;if(e.singleton){var a=m++;t=h||(h=u(e)),r=f.bind(null,t,a,!1),o=f.bind(null,t,a,!0)}else t=u(e),r=p.bind(null,t,e),o=function(){!function(n){if(null===n.parentNode)return!1;n.parentNode.removeChild(n)}(t)};return r(n),function(e){if(e){if(e.css===n.css&&e.media===n.media&&e.sourceMap===n.sourceMap)return;r(n=e)}else o()}}n.exports=function(n,e){(e=e||{}).attributes="object"==typeof e.attributes?e.attributes:{},e.singleton||"boolean"==typeof e.singleton||(e.singleton=a());var t=c(n,e);return s(t,e),function(n){for(var r=[],a=0;a<t.length;a++){var i=t[a],u=o[i.id];u&&(u.refs--,r.push(u))}n&&s(c(n,e),e);for(var d=0;d<r.length;d++){var l=r[d];if(0===l.refs){for(var f=0;f<l.parts.length;f++)l.parts[f]();delete o[l.id]}}}}},function(n,e,t){"use strict";t.r(e);t(0);var r=function(n){var e=[];return{size:n,hit:function(n,t){return e.push([n,t])},hits:e,isSunk:function(){return n===e.length},coordinates:[]}},o=function(n,e){return Math.floor(Math.random()*(e-n+1))+n},a=function(n){var e=Array.from(Array(10),(function(){return Array(10).fill(0)})),t=0,r=1,a=2,i=3;return{board:e,placeShips:function(){var t=function(n,t,r){if(r-n<0||1===e[t][r-n]||t+1<=9&&1===e[t+1][r-n]||t-1>=0&&1===e[t-1][r-n]||r+1<=9&&1===e[t][r+1]||r+1<=9&&t-1>=0&&1===e[t-1][r+1]||r+1<=9&&t+1<=9&&1===e[t+1][r+1]||t-1>=0&&1===e[t-1][r]||t+1<=9&&1===e[t+1][r])return!1;for(var o=0;o<n;o++)if(1===e[t][r-o]||t-1>=0&&1===e[t-1][r-o]||t+1<=9&&1===e[t+1][r-o])return!1;return!0},r=function(n,t,r){if(r+n>9||1===e[t][r+n]||t-1>=0&&1===e[t-1][r+n]||t+1<=9&&1===e[t+1][r+n]||r-1>=0&&1===e[t][r-1]||r+1<=9&&t-1>=0&&1===e[t-1][r-1]||r+1<=9&&t+1<=9&&1===e[t+1][r-1]||t-1>=0&&1===e[t-1][r]||t+1<=9&&1===e[t+1][r])return!1;for(var o=0;o<n;o++)if(1===e[t][r+o]||t-1>=0&&1===e[t-1][r+o]||t+1<=9&&1===e[t+1][r+o])return!1;return!0},a=function(n,t,r){if(t-n<0||1===e[t-n][r]||r+1<=9&&1===e[t-n][r+1]||r-1>=0&&1===e[t-n][r-1]||t+1<=9&&1===e[t+1][r]||t+1<=9&&r+1<=9&&1===e[t+1][r+1]||t+1<=9&&r-1>=0&&1===e[t+1][r-1]||r-1>=0&&1===e[t][r-1]||r+1<=9&&1===e[t][r+1])return!1;for(var o=0;o<n;o++)if(1===e[t-o][r]||r-1>=0&&1===e[t-o][r-1]||r+1<=9&&1===e[t-o][r+1])return!1;return!0},i=function(n,t,r){if(t+n>9||1===e[t+n][r]||r-1>=0&&1===e[t+n][r-1]||r+1<=9&&1===e[t+n][r+1]||t-1>=0&&1===e[t-1][r]||t-1>=0&&r+1<=9&&1===e[t-1][r+1]||t-1>=0&&r-1>=0&&1===e[t-1][r-1]||r-1>=0&&1===e[t][r-1]||r+1<=9&&1===e[t][r+1])return!1;for(var o=0;o<n;o++)if(1===e[t+o][r]||r-1>=0&&1===e[t+o][r-1]||r+1<=9&&1===e[t+o][r+1])return!1;return!0},c=function(n,t,r){for(var o=0;o<n.size;o++)e[t][r-o]=1,n.coordinates.push([t,r-o])},s=function(n,t,r){for(var o=0;o<n.size;o++)e[t][r+o]=1,n.coordinates.push([t,r+o])},u=function(n,t,r){for(var o=0;o<n.size;o++)e[t-o][r]=1,n.coordinates.push([t-o,r])},d=function(n,t,r){for(var o=0;o<n.size;o++)n.coordinates.push([t+o,r]),e[t+o][r]=1};n.forEach((function(n){for(var e=o(0,9),l=o(0,9),f=!0,p=!0;f;)p?(e>5&&t(n.size,e,l)?(c(n,e,l),f=!1):e<=5&&r(n.size,e,l)?(s(n,e,l),f=!1):(e=o(0,9),l=o(0,9)),p=!1):p||(l>5&&a(n.size,e,l)?(u(n,e,l),f=!1):l<=5&&i(n.size,e,l)?(d(n,e,l),f=!1):(e=o(0,9),l=o(0,9)),p=!0)}))},receiveAttack:function(o,c){e[o][c]===t?e[o][c]=i:e[o][c]===r&&(e[o][c]=a,n.forEach((function(n){n.coordinates.forEach((function(e){e[0]===o&&e[1]===c&&n.hit(o,c)}))})))},allShipsSunk:function(){var t=0;return e.forEach((function(n){t+=n.filter((function(n){return 2===n})).length})),t===function(){var e=0;return n.forEach((function(n){e+=n.size})),e}()}}},i=function(n){return n},c=function(n){var e=["A","B","C","D","E","F","G","H","I","J"],t=document.createElement("div"),r=document.createElement("table"),o=document.createElement("thead"),a=document.createElement("tbody"),i=document.createElement("div");i.classList.add("text-center","mb-3","icons");var c=document.createElement("tr");r.classList.add("text-center","mb-3"),["",0,1,2,3,4,5,6,7,8,9].forEach((function(n){var e=document.createElement("th");""===n&&e.classList.add("empty"),e.innerText=n,c.appendChild(e)})),o.appendChild(c);for(var s=0;s<n.length;s++){var u=document.createElement("i");u.classList.add("material-icons"),u.innerText="directions_boat",i.appendChild(u);var d=document.createElement("tr"),l=document.createElement("th");d.appendChild(l),l.innerText=e[s];for(var f=0;f<n[s].length;f++){var p=document.createElement("td");1===n[s][f]?(p.classList.add("ship"),p.classList.add("hover")):2===n[s][f]?p.classList.add("hit"):3===n[s][f]?p.classList.add("miss"):p.classList.add("hover"),p.id="".concat(s).concat(f),d.appendChild(p)}a.appendChild(d)}return r.appendChild(o),r.appendChild(a),t.appendChild(r),t.innerHTML},s=function(n){var e=document.getElementById("alert"),t=document.createElement("i"),r=document.createElement("span");t.classList.add("material-icons"),t.innerText="autorenew",r.classList.add("randomize","resetBtn","ml-1","pl-1"),r.innerText="Reset Game",r.setAttribute("onclick","location.reload()"),r.appendChild(t),e.classList.add("alert","alert-success","text-center"),e.innerHTML="".concat(n," Wins!"),e.appendChild(r)},u=i("Human"),d=i("Computer"),l=[r(4),r(3),r(3),r(2),r(2),r(2),r(1),r(1),r(1),r(1)],f=[r(4),r(3),r(3),r(2),r(2),r(2),r(1),r(1),r(1),r(1)],p=a(l),h=a(f);p.placeShips(),h.placeShips();var m,v,b,g,y=function(){!function(){var n=document.getElementById("player"),e=document.getElementById("computer");n.innerHTML="",e.innerHTML=""}();var n=document.getElementById("player"),e=document.getElementById("computer");n.innerHTML=c(p.board),e.innerHTML=c(h.board)};y(),m=h,v=document.getElementById("computer"),b=[],g=[],v.addEventListener("click",(function n(e){p.allShipsSunk()&&v.removeEventListener("click",n),g.includes(e.target.id)||p.allShipsSunk()||(g.push("".concat(e.target.id)),m.receiveAttack(e.target.id[0],e.target.id[1]),y(),m.allShipsSunk(h.board)&&(s(u),v.removeEventListener("click",n)),function(n,e){for(var t=o(0,9),r=o(0,9);e.includes("".concat(t).concat(r));)t=o(0,9),r=o(0,9);n.receiveAttack(t,r),e.push("".concat(t).concat(r)),y(),n.allShipsSunk()&&s(d)}(p,b))}))}]);