From 73395ddc23dbc77a99934226e301bb8896bbe03a Mon Sep 17 00:00:00 2001 From: denagyantal Date: Fri, 3 May 2019 09:51:34 +0200 Subject: [PATCH 1/9] for presentation --- __pycache__/alone_2048.cpython-36.pyc | Bin 0 -> 1875 bytes __pycache__/game.cpython-36.pyc | Bin 0 -> 5736 bytes alone_2048.py | 15 +- app/__init__.pyc | Bin 0 -> 318 bytes app/__pycache__/__init__.cpython-36.pyc | Bin 0 -> 269 bytes app/__pycache__/db.cpython-36.pyc | Bin 0 -> 671 bytes app/db.pyc | Bin 0 -> 857 bytes app/static/arc/animframe_polyfill.js | 28 +++ app/static/arc/application.js | 6 + app/static/arc/bind_polyfill.js | 9 + app/static/arc/classlist_polyfill.js | 71 ++++++ app/static/arc/game_manager.js | 272 +++++++++++++++++++++++ app/static/arc/grid.js | 117 ++++++++++ app/static/arc/html_actuator.js | 137 ++++++++++++ app/static/arc/keyboard_input_manager.js | 147 ++++++++++++ app/static/arc/local_storage_manager.js | 63 ++++++ app/static/arc/tile.js | 28 +++ app/static/js/game_engine.js | 158 ++++++------- app/static/js/html_actuator.js | 39 ++-- app/static/js/keyboard_input_manager.js | 14 ++ app/templates/index.html | 3 + game.py | 3 + scores.db | Bin 8192 -> 8192 bytes try.py | 5 + 24 files changed, 996 insertions(+), 119 deletions(-) create mode 100644 __pycache__/alone_2048.cpython-36.pyc create mode 100644 __pycache__/game.cpython-36.pyc create mode 100644 app/__init__.pyc create mode 100644 app/__pycache__/__init__.cpython-36.pyc create mode 100644 app/__pycache__/db.cpython-36.pyc create mode 100644 app/db.pyc create mode 100644 app/static/arc/animframe_polyfill.js create mode 100644 app/static/arc/application.js create mode 100644 app/static/arc/bind_polyfill.js create mode 100644 app/static/arc/classlist_polyfill.js create mode 100644 app/static/arc/game_manager.js create mode 100644 app/static/arc/grid.js create mode 100644 app/static/arc/html_actuator.js create mode 100644 app/static/arc/keyboard_input_manager.js create mode 100644 app/static/arc/local_storage_manager.js create mode 100644 app/static/arc/tile.js create mode 100644 try.py diff --git a/__pycache__/alone_2048.cpython-36.pyc b/__pycache__/alone_2048.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fa15c6131cc34a547710855d863163cac9f5079d GIT binary patch literal 1875 zcma)6OK&4Z5bo~jd3a*y;beEo@?0K5MyoX}2!XU(At6|C35eu0LK;onz4kcsFx~Bt zSmTqqAi;$*e}F3|egeOtPe`2j3pr8M6DQdfhqX1;)zw{(uKKDz?DgWGPX7At*O-uh z$c-Nd{xkUWA3y{Vv>-{l(uBgE6|7_lE4{>{DEA6}gex!nGDw0lOu{lsqOy~8D9K3@ zOE%pQ{)&n~gg=rMO}b7JiH?ZJOlQz_>BC`G)Rj!}^k_3~S&4`%sA` z1&-~LB{SZX8~;-3HQqE>a-dhH!^Kf^9wLH$oW$8W3%B@J)F zh6*nH-}o{z-6jJ44p{Fs-io4!N2KW-643wih3~$o&GugKtZ(!-2oJ0`|4P`7$dw!! zD6pcCkuL!h{&AftVZ%|XN41h_8|1cw`AzFnsg4Gl3bSaVu{0^d#CqB&8_e?2Ng=IY z)S1u<>t*R#(w(V#1Q1F~P)@cgd1g{=)#i zR4PO(zL=LYJ%}w=QqNpGYR8#BR(;g>(Y8qZLXLCeOkTz-GLx;@d}OX+s5Vf)_Y8V^ zAkrTLAznngG-8`xKw}!wz~giq)=l?u*j;jbEx}d20h){0p%RmIjXN~?T)UXIT_`lA zx(&y6V_ek7S&@oo!*qS)V)dQPPvP#m3*H2N(R2PP`GaeKE2v}JT|xZ-HikH$Q^Tfg zbqVyT=KxBkd9xht%?gWStV5G{j1y^1{I?S|>saQixvt0B@>FIvC) zF&t_H0$~9bjt1~=OQYTf>0)oFvs0PQHB7ikKAt#SU*!tNy9b{e3-^IpkA-$9+!zUL z3fX}Hz+lXKkS)(;!UprS!q?)%7QrF7689iGn16K(30hBL7lWx&7{6S-g7SBepqBMY zJ%0XuyZ;mPw{ThG_#-TWhayfnRqw)nu%q6BrOhd#t@X+gHr9VyWcs9y2%*uYACs=` z0kOWS=SI4@>R_x8TP}Cb_KnD{0U13iYcVh6W1Jf<{oAffUV{GU`*-j6{r=v6T4k6_ literal 0 HcmV?d00001 diff --git a/__pycache__/game.cpython-36.pyc b/__pycache__/game.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..efa06ce47256b96c5a569524ab9fa4834a2b6aa7 GIT binary patch literal 5736 zcmd^DTW=f36`t8$UPMvX$g<@)j^a3O=s1?6xM&IpMvw+hp9nN5;($oHU^pAycoAnQ znPSMG0M(bE4bY$ueJc9e{*wNNeeIL}LZ144Gt1?YrWz&iL(r1gnc1D&neTk(oSAuh zVWIH#;lDm@Eer8)k@~qPzl$flgG31>>!KkmQnKvSMMZodl&icmp}e6}ag_6sC}qyk zR+MCv)77ThZ+6Nxei;3dA^(Oifv89&&`~PqOa!iShw^xD)I&Of?7kqsII7W2a&945AP=V?v1Uz zRwLM|Hape&mI_X`wjVrv$0YvIX=kt1^iQ_8b|LBgqtovSJN5mrQ)@Mj9_2V2h0coJ zb*|+8xGq&Z=S)yo1`68^N{;3lBdNy{XpW@wNYXctay37!wR8{_YOSMF`yIl1VNm~KO2R1b z`}@uPj_)sE&M=Ea$b!tv-hvTzR9mA+{4wX^jd)Z`NAxAh_$P-PrwYpvp>czzB0@(R zga$%v8_95b{-UXe4E6nHu!=SYeIa`*X8v^T1Vp5UkzviqV9f!*7-JYpBS+GKLQ_MA zOKBE@e};$sxLeFDXQC&UYkFQo!SHu^AhBq1=x9&LQ6HnmbE?m*F(!p3q*IGFv{=XY z5z`)+wbok4&5qv-bSntKwN|ZK4B=<(lhm`esAVk6ovPL7=*KpG^D@LRlqvG(umX1J^aP--X#G;U{z7;)(7 zZ#r=A@w<0T44r}7{kY>HemFzteev0^2VVER)ceCh2CXxFZ$tDm8yv&YANDZ@@~`?F zIj-9g`0BkQ25$SqC!+n{6KlDd@;NPK?3DCXyq2<2mT{@oh_bc4)_yI}1XG))1(pn1 zvW6^`dAd@+^@ZO&ZbYt0j#^SZ zWzV|Jaq9$CB1&Y9C-^H0N)BZA8-^7GMq>2)fz$1!-s=Om?*O+uec*T~bQ!2fgP04% z93WLjjrR*N@Y;8uh`!f%4qd$&x89s=?Z7Rgw*$OgV494yBNTMn-UPPG7=zv@TYhXD zgawzl{uUe?!A@N z4A;I+ajOrmotSs*?ZCY~a4q47VHcT{`eMr}b5)Q*8w@C$Dw}SxHo-7O8wTG-J;1Zv z6wmT8&(7&?$7Itt@R~5r;OANIK84>Dbn}QZ{_&APZU;k{otTi8Zrkz(EEH5*HdISB zoekPQN1**Z1=_a&?T;zYzIxuE0kRl23-VP!>SN=5X(;vUv!Hax#;X_6pmZrbvlgVs zgp#|RG?eQW%=r|U$+nA*E(sqRFCd@O-Rp=B=rBa!0Np;JYa@;N5=2@x>&EFoiVkV$ zaSwTrF)7Nss2O-{10-Ao7amc}!35v3JW&9pTpxS#_A0_d#<;M^ds+>ZVO65xiM`eI z4oQhWz&Vcg>t$n;aior1-FiA@sb*vJ3061S7}-tBk#5z3F!UR(lbON#aVc+<5xMoC ziD1?0R69ZBR-31qE>hoR!XTy7j)S%wWjJPN{fDuHDgI-7I-dJC=#glR#4pI}2v-PF zT7FyW3ngq}4QJL&%i0RVlvZl=?APb+n!l&Yvq}_>31&jUF);OopABV&WDZwhcGxEg|K6C z1R#?mq?p_r%3VA>BqMBO%8`5;$*SgAF_H?lZ&vtoyrRr|0lSHtBHdCm=yv?D6JYnT z7t{`q(J;QCpx5oK8L6ilB{EN(IPapXy&-@jjW5g)-i)-|3_xmkD5O~xB=*Y5Fyt{g z{LIb4bGyGXwid_43oi@47-oCuxv$ec`7F0J!cs)@@t-;WAD!oE7L zvt0E3_HngtYf{s4`(;AAUSWwhEB1)WQ>Br|?gPd)MM7wv1T@2nH9PWA|B?yCOu0bA zO9pVwJvG@7(&qBcs^j6G&*WY6pU?AOFljEIL!L1`O0Is1y{SL*Vb<7De#fr!5t$ou J&Z5k_{{i{|GNu3k literal 0 HcmV?d00001 diff --git a/alone_2048.py b/alone_2048.py index bb4cf1d..ea15dd6 100644 --- a/alone_2048.py +++ b/alone_2048.py @@ -12,14 +12,20 @@ def main(): @app.route('/api/play_the_game', methods=['POST', 'GET']) def play_the_game(): + # get the move from front-end resp = request.get_json() uId = str(resp['uId']) direction = resp['direction'] + # loads the board from session b = pickle.loads(session['uId']) + + # moves with the board board = b.x moved = b.process_move(direction) legit = b.next_step_check() c_score = b.c_score + + # if game is on if legit: if moved and b.count_zeroes() != 0: b.add_number() @@ -27,19 +33,24 @@ def play_the_game(): game_dict = jsonify(game_data) session['uId'] = pickle.dumps(b) return game_dict + + # why this 2 exists?? elif moved: game_data = {"board": board, "c_score": c_score, "uId": uId, "game_over": False} game_dict = jsonify(game_data) session['uId'] = pickle.dumps(b) return game_dict + + # cant move else: game_data = {"board": board, "c_score": c_score, "uId": uId, "game_over": False} game_dict = jsonify(game_data) session['uId'] = pickle.dumps(b) return game_dict + + # game is over game_data = {"board": board, "c_score": c_score, "uId": uId, "game_over": True} game_dict = jsonify(game_data) - # session['uId'] = pickle.dumps(b) return game_dict @@ -55,7 +66,7 @@ def new_game(): b.add_number() board = b.x c_score = b.c_score - game_data = {"board": board, "c_score": c_score, "uId": uId} + game_data = {"board": board, "c_score": c_score, "uId": uId, "game_over" : False} game_dict = jsonify(game_data) session['uId'] = pickle.dumps(b) return game_dict diff --git a/app/__init__.pyc b/app/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4704093315aed47b85cdbd297d27add61a307a2d GIT binary patch literal 318 zcmYLE%SuBr5S=u=BE^E>4|I7~Myd;iB7$5uf{WHoi!g+nw2kI*F|km${+EB@m-qoX zQ!Eb2$vKlbGl~2j4&dwasfE9gbl%X;R|JNZ01prZECdKE!1mySgap$AE8)2hM#6*( z``{~BR7_@dMQ-;)Q43;)<(=30C7%$>X{3XGcX8#nqiow(Tgrg)v*vc%JmP&bf2a@k zwk6x9q@WxUAVwW5V&RACt}9&Frnq#gT@US3v^YMyxUA^{{vn@}RO=M1(y?f-jNK@% o+W~glvQ7~H2pPC_zo-d^)(GEY2~M`9>{0o1@m;Q#;t literal 0 HcmV?d00001 diff --git a/app/__pycache__/__init__.cpython-36.pyc b/app/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b89cdad39ee76adb4ffd61f6fa6726b9c47bb2b0 GIT binary patch literal 269 zcmX|(y-ve06h`ehj-rT8yg=75VAOVCs1Ong3lalmsfBc9)ovT`PZWnr>B`8H@D@yc z2(L`M0uxS$UgF6rU}`~*>%0)h0x9_m|V@SzfhY+^N7DG+d89|u$|CMsvR4QBcSQK jt+TM3uvo+ZYFl>zmrWn?xpDGcs~a49{7`mAa$JyqF7HK4 literal 0 HcmV?d00001 diff --git a/app/__pycache__/db.cpython-36.pyc b/app/__pycache__/db.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..20d826f179b5f09c6f22d3644cd0339933514147 GIT binary patch literal 671 zcmZ{i&2G~`5XWcNj^hL>`T!h!;807Yt{Q|mpq5biP^k)16F5{zmb1GwiTn}Po2aea zlX(RmqEFB>ud!E7yaEyuGY&%Gz)16-^~`!a^OFZVJN;h|-#&h20N-KDIG*32S5HwS zNS47RNG_c(aLJ@AI~ciSV+g$;cmqa)l#JdaKSi$&Q4B1YWDUE68Wy~PJ65xWBYDFZ zW!whZ*r6x^J36D=UL{JcsslN_9h_do!$}-WhHuZ~U^c&+C7WWfSERWLjJh`aL7NKZ zg;7^ZhoNV?)#q$()WCK{Srkeb>xq@FN^QI9T8WiWm?-mnZfr+nWu-!HUAk(SxChSy?3OqbOZ2BRM@--q@bdDm5yRQJ{5Z;wA4l(;mP)^bgdFo t;?A_+*3P@Qw|;`T(Aj*C>TP1HN87D!T@9l!tl8Cg)dBNp!)&qX!m( za^DFLp<%ej%Zgw83|tCq$2j9*PT5$ZYu+R1UeF!Uf~Owc6Ws|~2)g!>mqP-9H3Xbm zcZ$moL!Xlj%qH?>x>05?ADcs-oyoX2ii1(_^LZRhimOS|#)Gg#6AV|H0Z6J4n&t!-LHxtd1@`$r$0Nv1#SMAymuAWEmxC?D^!1J}zMm0FeLW8^g* zHYDDPuGkVCk)a^`7>;e9#R^-G7TzDWJ}vwuTjt7~FB!7OXnDmFGOHILzvl}5!7!Gi zpg$OWSz-LGcm6dVh9^70NlR7oVv+zMaa4(}NgP%Jn)^!}$ytK#wA|Zu+xS1}jIaaR2}S literal 0 HcmV?d00001 diff --git a/app/static/arc/animframe_polyfill.js b/app/static/arc/animframe_polyfill.js new file mode 100644 index 0000000..c524a99 --- /dev/null +++ b/app/static/arc/animframe_polyfill.js @@ -0,0 +1,28 @@ +(function () { + var lastTime = 0; + var vendors = ['webkit', 'moz']; + for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { + window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; + window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || + window[vendors[x] + 'CancelRequestAnimationFrame']; + } + + if (!window.requestAnimationFrame) { + window.requestAnimationFrame = function (callback) { + var currTime = new Date().getTime(); + var timeToCall = Math.max(0, 16 - (currTime - lastTime)); + var id = window.setTimeout(function () { + callback(currTime + timeToCall); + }, + timeToCall); + lastTime = currTime + timeToCall; + return id; + }; + } + + if (!window.cancelAnimationFrame) { + window.cancelAnimationFrame = function (id) { + clearTimeout(id); + }; + } +}()); diff --git a/app/static/arc/application.js b/app/static/arc/application.js new file mode 100644 index 0000000..c82a2d2 --- /dev/null +++ b/app/static/arc/application.js @@ -0,0 +1,6 @@ +// Wait till the browser is ready to render the game (avoids glitches) +// window.requestAnimationFrame(), tells the browser to perform +// an animation, take a callback as an arg to invoke before repaint +window.requestAnimationFrame(function () { / + new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager); +}); diff --git a/app/static/arc/bind_polyfill.js b/app/static/arc/bind_polyfill.js new file mode 100644 index 0000000..8d9c4a4 --- /dev/null +++ b/app/static/arc/bind_polyfill.js @@ -0,0 +1,9 @@ +Function.prototype.bind = Function.prototype.bind || function (target) { + var self = this; + return function (args) { + if (!(args instanceof Array)) { + args = [args]; + } + self.apply(target, args); + }; +}; diff --git a/app/static/arc/classlist_polyfill.js b/app/static/arc/classlist_polyfill.js new file mode 100644 index 0000000..1789ae7 --- /dev/null +++ b/app/static/arc/classlist_polyfill.js @@ -0,0 +1,71 @@ +(function () { + if (typeof window.Element === "undefined" || + "classList" in document.documentElement) { + return; + } + + var prototype = Array.prototype, + push = prototype.push, + splice = prototype.splice, + join = prototype.join; + + function DOMTokenList(el) { + this.el = el; + // The className needs to be trimmed and split on whitespace + // to retrieve a list of classes. + var classes = el.className.replace(/^\s+|\s+$/g, '').split(/\s+/); + for (var i = 0; i < classes.length; i++) { + push.call(this, classes[i]); + } + } + + DOMTokenList.prototype = { + add: function (token) { + if (this.contains(token)) return; + push.call(this, token); + this.el.className = this.toString(); + }, + contains: function (token) { + return this.el.className.indexOf(token) != -1; + }, + item: function (index) { + return this[index] || null; + }, + remove: function (token) { + if (!this.contains(token)) return; + for (var i = 0; i < this.length; i++) { + if (this[i] == token) break; + } + splice.call(this, i, 1); + this.el.className = this.toString(); + }, + toString: function () { + return join.call(this, ' '); + }, + toggle: function (token) { + if (!this.contains(token)) { + this.add(token); + } else { + this.remove(token); + } + + return this.contains(token); + } + }; + + window.DOMTokenList = DOMTokenList; + + function defineElementGetter(obj, prop, getter) { + if (Object.defineProperty) { + Object.defineProperty(obj, prop, { + get: getter + }); + } else { + obj.__defineGetter__(prop, getter); + } + } + + defineElementGetter(HTMLElement.prototype, 'classList', function () { + return new DOMTokenList(this); + }); +})(); diff --git a/app/static/arc/game_manager.js b/app/static/arc/game_manager.js new file mode 100644 index 0000000..692e4c8 --- /dev/null +++ b/app/static/arc/game_manager.js @@ -0,0 +1,272 @@ +function GameManager(size, InputManager, Actuator, StorageManager) { + this.size = size; // Size of the grid + this.inputManager = new InputManager; + this.storageManager = new StorageManager; + this.actuator = new Actuator; + + this.startTiles = 2; + + this.inputManager.on("move", this.move.bind(this)); + this.inputManager.on("restart", this.restart.bind(this)); + this.inputManager.on("keepPlaying", this.keepPlaying.bind(this)); + + this.setup(); +} + +// Restart the game +GameManager.prototype.restart = function () { + this.storageManager.clearGameState(); + this.actuator.continueGame(); // Clear the game won/lost message + this.setup(); +}; + +// Keep playing after winning (allows going over 2048) +GameManager.prototype.keepPlaying = function () { + this.keepPlaying = true; + this.actuator.continueGame(); // Clear the game won/lost message +}; + +// Return true if the game is lost, or has won and the user hasn't kept playing +GameManager.prototype.isGameTerminated = function () { + return this.over || (this.won && !this.keepPlaying); +}; + +// Set up the game +GameManager.prototype.setup = function () { + var previousState = this.storageManager.getGameState(); + + // Reload the game from a previous game if present + if (previousState) { + this.grid = new Grid(previousState.grid.size, + previousState.grid.cells); // Reload grid + this.score = previousState.score; + this.over = previousState.over; + this.won = previousState.won; + this.keepPlaying = previousState.keepPlaying; + } else { + this.grid = new Grid(this.size); + this.score = 0; + this.over = false; + this.won = false; + this.keepPlaying = false; + + // Add the initial tiles + this.addStartTiles(); + } + + // Update the actuator + this.actuate(); +}; + +// Set up the initial tiles to start the game with +GameManager.prototype.addStartTiles = function () { + for (var i = 0; i < this.startTiles; i++) { + this.addRandomTile(); + } +}; + +// Adds a tile in a random position +GameManager.prototype.addRandomTile = function () { + if (this.grid.cellsAvailable()) { + var value = Math.random() < 0.9 ? 2 : 4; + var tile = new Tile(this.grid.randomAvailableCell(), value); + + this.grid.insertTile(tile); + } +}; + +// Sends the updated grid to the actuator +GameManager.prototype.actuate = function () { + if (this.storageManager.getBestScore() < this.score) { + this.storageManager.setBestScore(this.score); + } + + // Clear the state when the game is over (game over only, not win) + if (this.over) { + this.storageManager.clearGameState(); + } else { + this.storageManager.setGameState(this.serialize()); + } + + this.actuator.actuate(this.grid, { + score: this.score, + over: this.over, + won: this.won, + bestScore: this.storageManager.getBestScore(), + terminated: this.isGameTerminated() + }); +}; + +// Represent the current game as an object +GameManager.prototype.serialize = function () { + return { + grid: this.grid.serialize(), + score: this.score, + over: this.over, + won: this.won, + keepPlaying: this.keepPlaying + }; +}; + +// Save all tile positions and remove merger info +GameManager.prototype.prepareTiles = function () { + this.grid.eachCell(function (x, y, tile) { + if (tile) { + // console.log(tile) + tile.mergedFrom = null; + tile.savePosition(); + } + }); +}; + +// Move a tile and its representation +GameManager.prototype.moveTile = function (tile, cell) { + this.grid.cells[tile.x][tile.y] = null; + this.grid.cells[cell.x][cell.y] = tile; + tile.updatePosition(cell); +}; + +// Move tiles on the grid in the specified direction +GameManager.prototype.move = function (direction) { + // 0: up, 1: right, 2: down, 3: left + var self = this; + + if (this.isGameTerminated()) return; // Don't do anything if the game's over + + var cell, tile; + + var vector = this.getVector(direction); + var traversals = this.buildTraversals(vector); + var moved = false; + + // Save the current tile positions and remove merger information + this.prepareTiles(); + + // Traverse the grid in the right direction and move tiles + traversals.x.forEach(function (x) { + traversals.y.forEach(function (y) { + cell = { x: x, y: y }; + tile = self.grid.cellContent(cell); + + if (tile) { + var positions = self.findFarthestPosition(cell, vector); + var next = self.grid.cellContent(positions.next); + + // Only one merger per row traversal? + if (next && next.value === tile.value && !next.mergedFrom) { + var merged = new Tile(positions.next, tile.value * 2); + merged.mergedFrom = [tile, next]; + + self.grid.insertTile(merged); + self.grid.removeTile(tile); + + // Converge the two tiles' positions + tile.updatePosition(positions.next); + + // Update the score + self.score += merged.value; + + // The mighty 2048 tile + if (merged.value === 2048) self.won = true; + } else { + self.moveTile(tile, positions.farthest); + } + + if (!self.positionsEqual(cell, tile)) { + moved = true; // The tile moved from its original cell! + } + } + }); + }); + + if (moved) { + this.addRandomTile(); + + if (!this.movesAvailable()) { + this.over = true; // Game over! + } + + this.actuate(); + } +}; + +// Get the vector representing the chosen direction +GameManager.prototype.getVector = function (direction) { + // Vectors representing tile movement + var map = { + 0: { x: 0, y: -1 }, // Up + 1: { x: 1, y: 0 }, // Right + 2: { x: 0, y: 1 }, // Down + 3: { x: -1, y: 0 } // Left + }; + + return map[direction]; +}; + +// Build a list of positions to traverse in the right order +GameManager.prototype.buildTraversals = function (vector) { + var traversals = { x: [], y: [] }; + + for (var pos = 0; pos < this.size; pos++) { + traversals.x.push(pos); + traversals.y.push(pos); + } + + // Always traverse from the farthest cell in the chosen direction + if (vector.x === 1) traversals.x = traversals.x.reverse(); + if (vector.y === 1) traversals.y = traversals.y.reverse(); + + return traversals; +}; + +GameManager.prototype.findFarthestPosition = function (cell, vector) { + var previous; + + // Progress towards the vector direction until an obstacle is found + do { + previous = cell; + cell = { x: previous.x + vector.x, y: previous.y + vector.y }; + } while (this.grid.withinBounds(cell) && + this.grid.cellAvailable(cell)); + + return { + farthest: previous, + next: cell // Used to check if a merge is required + }; +}; + +GameManager.prototype.movesAvailable = function () { + return this.grid.cellsAvailable() || this.tileMatchesAvailable(); +}; + +// Check for available matches between tiles (more expensive check) +GameManager.prototype.tileMatchesAvailable = function () { + var self = this; + + var tile; + + for (var x = 0; x < this.size; x++) { + for (var y = 0; y < this.size; y++) { + tile = this.grid.cellContent({ x: x, y: y }); + + if (tile) { + for (var direction = 0; direction < 4; direction++) { + var vector = self.getVector(direction); + var cell = { x: x + vector.x, y: y + vector.y }; + + var other = self.grid.cellContent(cell); + + if (other && other.value === tile.value) { + return true; // These two tiles can be merged + } + } + } + } + } + + return false; +}; + +GameManager.prototype.positionsEqual = function (first, second) { + return first.x === second.x && first.y === second.y; +}; diff --git a/app/static/arc/grid.js b/app/static/arc/grid.js new file mode 100644 index 0000000..29f0821 --- /dev/null +++ b/app/static/arc/grid.js @@ -0,0 +1,117 @@ +function Grid(size, previousState) { + this.size = size; + this.cells = previousState ? this.fromState(previousState) : this.empty(); +} + +// Build a grid of the specified size +Grid.prototype.empty = function () { + var cells = []; + + for (var x = 0; x < this.size; x++) { + var row = cells[x] = []; + + for (var y = 0; y < this.size; y++) { + row.push(null); + } + } + + return cells; +}; + +Grid.prototype.fromState = function (state) { + var cells = []; + + for (var x = 0; x < this.size; x++) { + var row = cells[x] = []; + + for (var y = 0; y < this.size; y++) { + var tile = state[x][y]; + row.push(tile ? new Tile(tile.position, tile.value) : null); + } + } + + return cells; +}; + +// Find the first available random position +Grid.prototype.randomAvailableCell = function () { + var cells = this.availableCells(); + + if (cells.length) { + return cells[Math.floor(Math.random() * cells.length)]; + } +}; + +Grid.prototype.availableCells = function () { + var cells = []; + + this.eachCell(function (x, y, tile) { + if (!tile) { + cells.push({ x: x, y: y }); + } + }); + + return cells; +}; + +// Call callback for every cell +Grid.prototype.eachCell = function (callback) { + for (var x = 0; x < this.size; x++) { + for (var y = 0; y < this.size; y++) { + callback(x, y, this.cells[x][y]); + } + } +}; + +// Check if there are any cells available +Grid.prototype.cellsAvailable = function () { + return !!this.availableCells().length; +}; + +// Check if the specified cell is taken +Grid.prototype.cellAvailable = function (cell) { + return !this.cellOccupied(cell); +}; + +Grid.prototype.cellOccupied = function (cell) { + return !!this.cellContent(cell); +}; + +Grid.prototype.cellContent = function (cell) { + if (this.withinBounds(cell)) { + return this.cells[cell.x][cell.y]; + } else { + return null; + } +}; + +// Inserts a tile at its position +Grid.prototype.insertTile = function (tile) { + this.cells[tile.x][tile.y] = tile; +}; + +Grid.prototype.removeTile = function (tile) { + this.cells[tile.x][tile.y] = null; +}; + +Grid.prototype.withinBounds = function (position) { + return position.x >= 0 && position.x < this.size && + position.y >= 0 && position.y < this.size; +}; + +Grid.prototype.serialize = function () { + var cellState = []; + + for (var x = 0; x < this.size; x++) { + var row = cellState[x] = []; + + for (var y = 0; y < this.size; y++) { + row.push(this.cells[x][y] ? this.cells[x][y].serialize() : null); + } + } + + return { + size: this.size, + cells: cellState + }; +}; diff --git a/app/static/arc/html_actuator.js b/app/static/arc/html_actuator.js new file mode 100644 index 0000000..ceaaa89 --- /dev/null +++ b/app/static/arc/html_actuator.js @@ -0,0 +1,137 @@ +function HTMLActuator() { + this.tileContainer = document.querySelector(".tile-container"); + this.scoreContainer = document.querySelector(".score-container"); + this.bestContainer = document.querySelector(".best-container"); + this.messageContainer = document.querySelector(".game-message"); + this.score = 0; +} + +HTMLActuator.prototype.actuate = function (grid, metadata) { + var self = this; + + window.requestAnimationFrame(function () { + self.clearContainer(self.tileContainer); + + grid.cells.forEach(function (column) { + column.forEach(function (cell) { + if (cell) { + self.addTile(cell); + } + }); + }); + + self.updateScore(metadata.score); + self.updateBestScore(metadata.bestScore); + + if (metadata.terminated) { + if (metadata.over) { + self.message(false); // You lose + } else if (metadata.won) { + self.message(true); // You win! + } + } + }); +}; + +// Continues the game (both restart and keep playing) +HTMLActuator.prototype.continueGame = function () { + this.clearMessage(); +}; + +HTMLActuator.prototype.clearContainer = function (container) { + while (container.firstChild) { + container.removeChild(container.firstChild); + } +}; + +HTMLActuator.prototype.addTile = function (tile) { + var self = this; + + var wrapper = document.createElement("div"); + var inner = document.createElement("div"); + var position = tile.previousPosition || { x: tile.x, y: tile.y }; + var positionClass = this.positionClass(position); + + // We can't use classlist because it somehow glitches when replacing classes + var classes = ["tile", "tile-" + tile.value, positionClass]; + + if (tile.value > 2048) classes.push("tile-super"); + + this.applyClasses(wrapper, classes); + + inner.classList.add("tile-inner"); + inner.textContent = tile.value; + + if (tile.previousPosition) { + // Make sure that the tile gets rendered in the previous position first + window.requestAnimationFrame(function () { + classes[2] = self.positionClass({ x: tile.x, y: tile.y }); + self.applyClasses(wrapper, classes); // Update the position + }); + } else if (tile.mergedFrom) { + classes.push("tile-merged"); + this.applyClasses(wrapper, classes); + + // Render the tiles that merged + tile.mergedFrom.forEach(function (merged) { + self.addTile(merged); + }); + } else { + classes.push("tile-new"); + this.applyClasses(wrapper, classes); + } + + // Add the inner part of the tile to the wrapper + wrapper.appendChild(inner); + + // Put the tile on the board + this.tileContainer.appendChild(wrapper); +}; + +HTMLActuator.prototype.applyClasses = function (element, classes) { + element.setAttribute("class", classes.join(" ")); +}; + +HTMLActuator.prototype.normalizePosition = function (position) { + return { x: position.x + 1, y: position.y + 1 }; +}; + +HTMLActuator.prototype.positionClass = function (position) { + position = this.normalizePosition(position); + return "tile-position-" + position.x + "-" + position.y; +}; + +HTMLActuator.prototype.updateScore = function (score) { + this.clearContainer(this.scoreContainer); + + var difference = score - this.score; + this.score = score; + + this.scoreContainer.textContent = this.score; + + if (difference > 0) { + var addition = document.createElement("div"); + addition.classList.add("score-addition"); + addition.textContent = "+" + difference; + + this.scoreContainer.appendChild(addition); + } +}; + +HTMLActuator.prototype.updateBestScore = function (bestScore) { + this.bestContainer.textContent = bestScore; +}; + +HTMLActuator.prototype.message = function (won) { + var type = won ? "game-won" : "game-over"; + var message = won ? "You win!" : "Game over!"; + + this.messageContainer.classList.add(type); + this.messageContainer.getElementsByTagName("p")[0].textContent = message; +}; + +HTMLActuator.prototype.clearMessage = function () { + // IE only takes one value to remove at a time. + this.messageContainer.classList.remove("game-won"); + this.messageContainer.classList.remove("game-over"); +}; diff --git a/app/static/arc/keyboard_input_manager.js b/app/static/arc/keyboard_input_manager.js new file mode 100644 index 0000000..11ba808 --- /dev/null +++ b/app/static/arc/keyboard_input_manager.js @@ -0,0 +1,147 @@ +function KeyboardInputManager() { + this.events = {}; + + if (window.navigator.msPointerEnabled) { + //Internet Explorer 10 style + this.eventTouchstart = "MSPointerDown"; + this.eventTouchmove = "MSPointerMove"; + this.eventTouchend = "MSPointerUp"; + } else { + this.eventTouchstart = "touchstart"; + this.eventTouchmove = "touchmove"; + this.eventTouchend = "touchend"; + } + + this.listen(); +} + +KeyboardInputManager.prototype.on = function (event, callback) { + if (!this.events[event]) { + this.events[event] = []; + } + this.events[event].push(callback); +}; + + +// emit events +KeyboardInputManager.prototype.emit = function (event, data) { + var callbacks = this.events[event]; + if (callbacks) { + callbacks.forEach(function (callback) { + callback(data); + }); + } +}; + +// Sets the input types +KeyboardInputManager.prototype.listen = function () { + var self = this; + + var map = { + 38: 0, // Up + 39: 1, // Right + 40: 2, // Down + 37: 3, // Left + 75: 0, // Vim up + 76: 1, // Vim right + 74: 2, // Vim down + 72: 3, // Vim left + 87: 0, // W + 68: 1, // D + 83: 2, // S + 65: 3 // A + }; + + // Respond to direction keys + document.addEventListener("keydown", function (event) { + var modifiers = event.altKey || event.ctrlKey || event.metaKey || + event.shiftKey; + var mapped = map[event.which]; + + if (!modifiers) { + if (mapped !== undefined) { + event.preventDefault(); + self.emit("move", mapped); + } + } + + // R key restarts the game + if (!modifiers && event.which === 82) { + self.restart.call(self, event); + } + }); + + // Respond to button presses + this.bindButtonPress(".retry-button", this.restart); + this.bindButtonPress(".restart-button", this.restart); + this.bindButtonPress(".keep-playing-button", this.keepPlaying); + + // Respond to swipe events + var touchStartClientX, touchStartClientY; + var gameContainer = document.getElementsByClassName("game-container")[0]; + + gameContainer.addEventListener(this.eventTouchstart, function (event) { + if ((!window.navigator.msPointerEnabled && event.touches.length > 1) || + event.targetTouches.length > 1) { + return; // Ignore if touching with more than 1 finger + } + + if (window.navigator.msPointerEnabled) { + touchStartClientX = event.pageX; + touchStartClientY = event.pageY; + } else { + touchStartClientX = event.touches[0].clientX; + touchStartClientY = event.touches[0].clientY; + } + + event.preventDefault(); + }); + + gameContainer.addEventListener(this.eventTouchmove, function (event) { + event.preventDefault(); + }); + + gameContainer.addEventListener(this.eventTouchend, function (event) { + if ((!window.navigator.msPointerEnabled && event.touches.length > 0) || + event.targetTouches.length > 0) { + return; // Ignore if still touching with one or more fingers + } + + var touchEndClientX, touchEndClientY; + + if (window.navigator.msPointerEnabled) { + touchEndClientX = event.pageX; + touchEndClientY = event.pageY; + } else { + touchEndClientX = event.changedTouches[0].clientX; + touchEndClientY = event.changedTouches[0].clientY; + } + + var dx = touchEndClientX - touchStartClientX; + var absDx = Math.abs(dx); + + var dy = touchEndClientY - touchStartClientY; + var absDy = Math.abs(dy); + + if (Math.max(absDx, absDy) > 10) { + // (right : left) : (down : up) + self.emit("move", absDx > absDy ? (dx > 0 ? 1 : 3) : (dy > 0 ? 2 : 0)); + } + }); +}; + +KeyboardInputManager.prototype.restart = function (event) { + event.preventDefault(); + this.emit("restart"); +}; + +KeyboardInputManager.prototype.keepPlaying = function (event) { + event.preventDefault(); + this.emit("keepPlaying"); +}; + +KeyboardInputManager.prototype.bindButtonPress = function (selector, fn) { + var button = document.querySelector(selector); + button.addEventListener("click", fn.bind(this)); + button.addEventListener(this.eventTouchend, fn.bind(this)); +}; diff --git a/app/static/arc/local_storage_manager.js b/app/static/arc/local_storage_manager.js new file mode 100644 index 0000000..2ca9cc3 --- /dev/null +++ b/app/static/arc/local_storage_manager.js @@ -0,0 +1,63 @@ +window.fakeStorage = { + _data: {}, + + setItem: function (id, val) { + return this._data[id] = String(val); + }, + + getItem: function (id) { + return this._data.hasOwnProperty(id) ? this._data[id] : undefined; + }, + + removeItem: function (id) { + return delete this._data[id]; + }, + + clear: function () { + return this._data = {}; + } +}; + +function LocalStorageManager() { + this.bestScoreKey = "bestScore"; + this.gameStateKey = "gameState"; + + var supported = this.localStorageSupported(); + this.storage = supported ? window.localStorage : window.fakeStorage; +} + +LocalStorageManager.prototype.localStorageSupported = function () { + var testKey = "test"; + + try { + var storage = window.localStorage; + storage.setItem(testKey, "1"); + storage.removeItem(testKey); + return true; + } catch (error) { + return false; + } +}; + +// Best score getters/setters +LocalStorageManager.prototype.getBestScore = function () { + return this.storage.getItem(this.bestScoreKey) || 0; +}; + +LocalStorageManager.prototype.setBestScore = function (score) { + this.storage.setItem(this.bestScoreKey, score); +}; + +// Game state getters/setters and clearing +LocalStorageManager.prototype.getGameState = function () { + var stateJSON = this.storage.getItem(this.gameStateKey); + return stateJSON ? JSON.parse(stateJSON) : null; +}; + +LocalStorageManager.prototype.setGameState = function (gameState) { + this.storage.setItem(this.gameStateKey, JSON.stringify(gameState)); +}; + +LocalStorageManager.prototype.clearGameState = function () { + this.storage.removeItem(this.gameStateKey); +}; diff --git a/app/static/arc/tile.js b/app/static/arc/tile.js new file mode 100644 index 0000000..a791a95 --- /dev/null +++ b/app/static/arc/tile.js @@ -0,0 +1,28 @@ +function Tile(position, value) { + this.x = position.x; + this.y = position.y; + this.value = value; + + this.previousPosition = null; + this.mergedFrom = null; // Tracks tiles that merged together +} + +Tile.prototype.savePosition = function () { + this.previousPosition = { x: this.x, y: this.y }; +}; + +Tile.prototype.updatePosition = function (position) { + this.x = position.x; + this.y = position.y; +}; + +Tile.prototype.serialize = function () { + return { + position: { + x: this.x, + y: this.y + }, + value: this.value + }; + +}; diff --git a/app/static/js/game_engine.js b/app/static/js/game_engine.js index 57f4ceb..10e2141 100644 --- a/app/static/js/game_engine.js +++ b/app/static/js/game_engine.js @@ -8,10 +8,19 @@ function GameManager(size) { //creates a Grid this.grid = new Grid(this.size); - // bind the move function to the inputManager + // create metaData + this.metaData = { + c_score : 0, + game_over : false, + won : false + }; + + // bind the move and button functions to the inputManager this.inputManager.on("move", this.move.bind(this)); - this.inputManager.on("restart", this.restart.bind(this)); - // this.inputManager.on("keepPlaying", this.keepPlaying.bind(this)); + this.inputManager.on("restart", this.restart.bind(this)); // restart button + this.inputManager.on("keepPlaying", this.keepPlaying.bind(this)); // keepPlaying button + this.inputManager.on("save", this.save.bind(this)); // Save button + // initialize a new board with "gameID" console.log("start a new game" + this.grid.cells) @@ -22,6 +31,7 @@ function GameManager(size) { // Initialize a new game and ask for a new "gameId" GameManager.prototype.setup = function(){ + var self = this; // get the gameId and the initial map var request = new XMLHttpRequest(); @@ -30,7 +40,12 @@ GameManager.prototype.setup = function(){ request.onload = () => { // gameId and highScore this.gameId = request.response['uId']; - this.highScore = request.response['c_score']; + this.metaData.c_score = request.response['c_score']; + console.log("start game:") + console.log(this.metaData) + + // game canno be end at the first run + // this.metaData.game_over = request.response['game_over']; // initialize the map updatedCells = request.response['board']; @@ -46,8 +61,8 @@ GameManager.prototype.setup = function(){ } } // "print" the tiles to the grid - this.actuator.actuate(this.grid, this.highScore) - } + this.actuator.actuate(this.grid, this.metaData) + } request.send(); }; @@ -97,116 +112,71 @@ GameManager.prototype.move = function (direction) { // RECIEVE the updated board due to "currentMove" fom the server request.onreadystatechange = function () { if (request.readyState === 4 && request.status === 200) { - // console.log(this.grid.cells[0][1]); + var json = JSON.parse(request.responseText); - console.log(json); // get the new cells in 2D array var updatedCells = json['board']; - // get the scores - var metaData = json['c_score']; + // console.log(self.metaData); + self.metaData.c_score = request.response; + + self.metaData.c_score = json["c_score"]; + self.metaData.game_over = json["game_over"]; // // DEBUG // console.log("recieved 2D array is: "); // console.log(updatedCells); - // console.log("the actual score is : "); - // console.log(metaData); // fill the grid with new values for(var i = 0; i < updatedCells.length; i++) { for(var j = 0; j < updatedCells.length; j++) { + // get the fresh value for var tile = updatedCells[i][j] + + // check if the game is won, HOW TO CHECK? + if (tile == 2048){ + self.metaData.won = True; + }; + // either create a new tile or set to null var position = ({ x : j, y : i}); - // update the grid position + // update the tile position self.grid.cells[i][j] = (tile ? new Tile(position, tile) : null); } } // console.log("recieved 2D array converted to the grid:") // console.log(this.grid.cells) - self.actuator.actuate(self.grid, metaData); + self.actuator.actuate(self.grid, self.metaData); } }; - console.log(this.grid); - - console.log(currentMove) + // console.log(this.grid); + // + // console.log(currentMove) request.send(currentMove); }; -// // Move tiles on the grid in the specified direction -// GameManager.prototype.move = function (direction) { -// // 0: up, 1: right, 2: down, 3: left -// var self = this; -// console.log(direction) -// -// // if (this.isGameTerminated()) return; // Don't do anything if the game's over -// -// var cell, tile; -// -// // var vector = this.getVector(direction); -// // var traversals = this.buildTraversals(vector); -// var moved = false; -// -// // Save the current tile positions and remove merger information -// // this.prepareTiles(); -// -// // Traverse the grid in the right direction and move tiles -// traversals.x.forEach(function (x) { -// traversals.y.forEach(function (y) { -// cell = { x: x, y: y }; -// tile = self.grid.cellContent(cell); -// -// if (tile) { -// var positions = self.findFarthestPosition(cell, vector); -// var next = self.grid.cellContent(positions.next); -// -// // Only one merger per row traversal? -// if (next && next.value === tile.value && !next.mergedFrom) { -// var merged = new Tile(positions.next, tile.value * 2); -// merged.mergedFrom = [tile, next]; -// -// self.grid.insertTile(merged); -// self.grid.removeTile(tile); -// -// // Converge the two tiles' positions -// tile.updatePosition(positions.next); -// -// // Update the score -// self.score += merged.value; -// -// // The mighty 2048 tile -// if (merged.value === 2048) self.won = true; -// } else { -// self.moveTile(tile, positions.farthest); -// } -// -// if (!self.positionsEqual(cell, tile)) { -// moved = true; // The tile moved from its original cell! -// } -// } -// }); -// }); -// -// if (moved) { -// this.addRandomTile(); -// -// if (!this.movesAvailable()) { -// this.over = true; // Game over! -// } -// -// this.actuate(); -// } -// }; - - -// // // FOR TEST ING -// // create a GameManager -// var testGame = new GameManager(); -// -// -// // console.log(test.getGrid()); -// var updateGrid = testGame.move(); - - - -// console.log(GameManager); +// Keep playing after winning (allows going over 2048) +GameManager.prototype.keepPlaying = function () { + this.actuator.continueGame(); // Clear the game won/lost message +}; + + +// Save username and current score +GameManager.prototype.save = function () { + // ask for usernam + var name = prompt("Please enter your nickname!") + + // Save current move with gameId + var userData = JSON.stringify({"c_score" : this.metaData.c_score, "u_name" : name }); + + // create object for request OR USE FETCH API https://scotch.io/tutorials/how-to-use-the-javascript-fetch-api-to-get-data + var request = new XMLHttpRequest(); + + // SEND "currentMove" to the server + request.open("POST", "/save_user_highscore"); + request.setRequestHeader("Content-Type", "application/json"); + + request.send(userData); + + this.restart(); // Clear the game won/lost message +}; diff --git a/app/static/js/html_actuator.js b/app/static/js/html_actuator.js index 5464afa..997b881 100644 --- a/app/static/js/html_actuator.js +++ b/app/static/js/html_actuator.js @@ -11,7 +11,7 @@ HTMLActuator.prototype.actuate = function (grid, metaData) { window.requestAnimationFrame(function () { self.clearContainer(self.tileContainer); - // console.log(grid) + // update grid grid.cells.forEach(function (column) { column.forEach(function (cell) { if (cell) { @@ -20,32 +20,23 @@ HTMLActuator.prototype.actuate = function (grid, metaData) { } }); }); - }); - - - // // go over the grid and update tiles if needed - // for (let i of grid) { - // for (let j of i) { - // if (j > 0) { - // // console.log(j + ".tile added ") - // self.addTile(j); - // }; - // }; - // }; - // }); - self.updateScore(metaData); - self.updateBestScore(metaData); + // update scores + self.updateScore(metaData.c_score); + self.updateBestScore(metaData.c_score); // console.log("The score is updated"); - // if (metadata.terminated) { - // if (metadata.over) { - // self.message(false); // You lose - // } else if (metadata.won) { - // self.message(true); // You win! - // } - // } + // + console.log("game_over: " + metaData.game_over); + console.log("won: " + metaData.won); + if (metaData.game_over) { + self.message(false); // You lose + } + if (metaData.won) { + self.message(true); // You win! + } + }); }; // Continues the game (both restart and keep playing) @@ -142,12 +133,14 @@ HTMLActuator.prototype.updateBestScore = function (bestScore) { this.bestContainer.textContent = bestScore; }; +// write out the game ending mesage if WON or not HTMLActuator.prototype.message = function (won) { var type = won ? "game-won" : "game-over"; var message = won ? "You win!" : "Game over!"; this.messageContainer.classList.add(type); this.messageContainer.getElementsByTagName("p")[0].textContent = message; + }; HTMLActuator.prototype.clearMessage = function () { diff --git a/app/static/js/keyboard_input_manager.js b/app/static/js/keyboard_input_manager.js index fcd75ff..15e6d33 100644 --- a/app/static/js/keyboard_input_manager.js +++ b/app/static/js/keyboard_input_manager.js @@ -84,6 +84,7 @@ KeyboardInputManager.prototype.listen = function () { this.bindButtonPress(".retry-button", this.restart); this.bindButtonPress(".restart-button", this.restart); this.bindButtonPress(".keep-playing-button", this.keepPlaying); + this.bindButtonPress(".save-button", this.save); // Respond to swipe events var touchStartClientX, touchStartClientY; @@ -139,17 +140,30 @@ KeyboardInputManager.prototype.listen = function () { }); }; + +// handles "restart" button at the end KeyboardInputManager.prototype.restart = function (event) { event.preventDefault(); console.log("restart was pressed") this.emit("restart"); }; + +// handles "keep Playing" button at the end KeyboardInputManager.prototype.keepPlaying = function (event) { event.preventDefault(); this.emit("keepPlaying"); }; + +// handles "save" button at the end +KeyboardInputManager.prototype.save = function (event) { + event.preventDefault(); + this.emit("save"); +}; + + +// KeyboardInputManager.prototype.bindButtonPress = function (selector, fn) { var button = document.querySelector(selector); button.addEventListener("click", fn.bind(this)); diff --git a/app/templates/index.html b/app/templates/index.html index f3016e6..809d3df 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -37,9 +37,12 @@

2048

diff --git a/game.py b/game.py index d6f4d80..ca0a682 100644 --- a/game.py +++ b/game.py @@ -3,8 +3,11 @@ class Game: + x = [[0 for c in range(4)] for r in range(4)] + c_score = 0 + copy_board = [] def __init__(self): diff --git a/scores.db b/scores.db index 15392376ef2d066c34319f8a75cf0bb15f3687b0..39c7fdd0ed97e7618460048a653b7933cd719d9a 100644 GIT binary patch delta 95 zcmZp0XmFSy%_uNY#+hG$K~H7_F9QPuBmYVU{*{{r1+4ieujG&BVd1~Q!2g5)J^w@g y8$i(${2J^m%%U8J7apC+!^|wtVQgq*Vr*n+Y{Je26watJGi76B=4UcsbOZo=N){FX delta 89 zcmZp0XmFSy&B!xR#+jdoLH8LOF9QPuBmYVU{*{{r1+4ieujG&BVh~_p;Q!2jhyM;x Y>^T3#04_xppfVVcfH4>tK)N9S09=X=kN^Mx diff --git a/try.py b/try.py new file mode 100644 index 0000000..3386623 --- /dev/null +++ b/try.py @@ -0,0 +1,5 @@ + game_data = {"board": + {[]}, + "c_score": c_score, + "uId": uId, + "game_over": True} From c78a218add0b5e259c8059835b8658926b416f2c Mon Sep 17 00:00:00 2001 From: denagyantal Date: Fri, 3 May 2019 15:20:47 +0200 Subject: [PATCH 2/9] fixed game end error --- __pycache__/game.cpython-36.pyc | Bin 5736 -> 5736 bytes app/static/js/game_engine.js | 4 ++++ scores.db | Bin 8192 -> 8192 bytes 3 files changed, 4 insertions(+) diff --git a/__pycache__/game.cpython-36.pyc b/__pycache__/game.cpython-36.pyc index efa06ce47256b96c5a569524ab9fa4834a2b6aa7..bec0227bdb9f766fc8281bc2d7fb8be42ed007a1 100644 GIT binary patch delta 25 gcmaE%^FoK$n3tDJ#o Date: Wed, 8 May 2019 12:40:14 +0200 Subject: [PATCH 3/9] tests folder created, basic flask route tests added --- __pycache__/alone_2048.cpython-37.pyc | Bin 0 -> 1881 bytes __pycache__/game.cpython-37.pyc | Bin 0 -> 5742 bytes app/__pycache__/__init__.cpython-37.pyc | Bin 0 -> 275 bytes app/__pycache__/db.cpython-37.pyc | Bin 0 -> 677 bytes app/__pycache__/models.cpython-37.pyc | Bin 0 -> 3026 bytes tests/test_alone.py | 29 ++++++++++++++++++++++++ 6 files changed, 29 insertions(+) create mode 100644 __pycache__/alone_2048.cpython-37.pyc create mode 100644 __pycache__/game.cpython-37.pyc create mode 100644 app/__pycache__/__init__.cpython-37.pyc create mode 100644 app/__pycache__/db.cpython-37.pyc create mode 100644 app/__pycache__/models.cpython-37.pyc create mode 100644 tests/test_alone.py diff --git a/__pycache__/alone_2048.cpython-37.pyc b/__pycache__/alone_2048.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..780c8383d1ffc54c0b5758d56b2d1a0ef19136df GIT binary patch literal 1881 zcma)6OK&4Z5T5SodH9uwlielDb9o3Et=4Ek2&B~t0n3U@KqRLT(rE1NwI`W}>28O_ z8lS=uE}TKKk6bzNH@Nl*i4%VzC#rg4Cs}b=TT@+K-Cb4v^;h*-r_*%c_vE*~zWW8V ze{iz;F;G5*PyGRcJDg-rRF5PgFsB*KX+(23atYeqj2+_0GB5WdKM$fH52G+|L=EDk zPSg~1(c<2caGwW1I_D&63wqSzA#d>Ji1OCYl(%`uu5|3)4cNQMx2$EuTDHN`bNf(sdIkx#Nj z3lkivvPhqunLr7p(z3W9{UN$p{U|7(!>2+J8bCS6P;`IROu^IXgR#!D9+5t*{_aQw z*NTe|`r|Se{ZTR~W#0dy98PmlXw`rC{)ZpOlQTUoi}>VWKgr5M#AtjlIWsIz(gFi1 z4C_$Y2082YlS$f#e9vM%7V#*_g<;=(eQ;>pr%w*yjzKQKA6M(dF%1tsoA?DN+F6jL zGj}wt;0k;27IOj`-E-zty9=g0v@Xfqt=uDj&MJ2iR21eOXd#^R!QPk$l`sFUJoyt? zn@eE8v1|3#(jiX8s-PmAaqm|)4|Tf=AxZNBIVvoHZ>g z5v(iTq08qAM%M*Hpe*HWST?OuRt}OZ<~P%{m1A@Dtj|wi@2U#k1bx=A@e1*SEr2!E zvGCSZ--n5I&XMRu(*<2#5`E!Xf;vZR4h3-J0nKUU0$B;CKvt&xiUC)6v-SdW{t} zc>HWzxDU#zE!0inT1%h{KnEHCg+}jUQ?N)Fe;OBfTfErJKY&pD9-xEx%UdX15K+_S zpvxE-cmD&-h@Zy* literal 0 HcmV?d00001 diff --git a/__pycache__/game.cpython-37.pyc b/__pycache__/game.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..af9b8e51c29ec8178832ad2674b1b32f6ab333f0 GIT binary patch literal 5742 zcmd^DO>Y~=8J^i)eu$zzBg>NGIEv%Ap=(>J>Y^zi7=ddzJrQV9#DS1>L31{eERrkD zQnJL7K>@j!q7BfXhn@=Q*!JJ#xYwTa7jo+J%q*8nnrhX;hoU91^RYW0?>z7GzVFOD znwlyJ{MP>V?dRdF5PxT-|8r6J5KnX)i4saSL{n}`$+FWBo8lv(T;;tK$~$p39p!u? zD!FsC6%`p5bgiX!TJ36`FZ#c9$UoyvAU35E=qQ!*QUtDYPvm29A~!wdZRWPbW?tn~ z{-xL~sDdgYFRBSuLO!7;RT+6nO{r<*lWIoIA}^~sHIIBsy`dJ6Ppd0x5&4X|s+N$? zs%3Qz`J8%FT}M8z-cmP^zoFh%E65krJL)F#E9zY=W(QE_7D{#q>S+C$wW z-`!i?4x7R1R_$4+o2!q*`av^jwWHPbwFe*gd&lkVu;m}F<9jo>zjypyX``_dwd-MX z?_q)SQS7|vT;p2q558rJ=bQ^F%RyyZLB-KrWi0hT2F;Ol5lME)nUNv&1Y2<->B?E5 z04Zi&aVpM$n=iZKxq}?fa~HX*08d3$D_%U&3SRin!kSjGJczf|0=*1b{K- za3YNyX$J~T4H-6Nc?bp?CU%o<3Adb~o?Nc!xrBmY@N7?F(PG!po|64OMvdoGpIKu< z3Qb5y7Hw#;i1&S_t(mpf!-H1a?*uvwB5*CN*Ba5o4CyjO;u{?_`*TcQVvhGNH3vrI zDmB?qkw$4F!pG&ToLBm*NHv!In!-p_{%wt=xKqUj_i|5?ZYK%m7H2@wtR4L;D3<$z z!mw`|DA372tThg3;;&$h;jW>_Kf_@n9e{}SX*)eUc8UOLkh;QePyu7@-`UD>S*M`X zne4&1Pn|PFiCs^B-G+lt>fVw#aeD62r)>`r#5r*ui!XlG^Nt>6>JNH3SU|4pEsJh$ znPWKm<1WTP{#BQ5Bl)%=@Yef4^xXZApNjoQPp#$Vs^_$nfm6~~QLW_TJR?)sjPv#F zaHk$UDz#$P(Br$X5ZWkFEEmq15k>gVG%s zubxJO%BAqkTaca*O73>DP%c_9Co^EC+pZx;r_m4ObB?y#q76EnAR>ZppV76EMqLRa z%`3AVFG6X25PnF1&ky4aQP&m%nKj0=ms z7qv(kR;3yq+FOn8kd*ihoMV5-UNttEMC#bp;foPVH5;SPhz&h}}leLa++kwRRA@wbrqwi_~|Ra7UxFj)S%w=Qw6${fDuH5&mO)I+*+C z=#grT#4pKf2v-PFgYD{|^^or9hfI)qj>3@w-x2POllZg;4Jh}eF?8aNApar1^N0wo zu0zjvGxZzLnri|U!%pH%6axE_*bw_02swB0l#`I2uMVFs{!?w~yO4XFwth)W5^cS0 zm}}u5x2dx3h}JYN^vRY{LoAO?+#8+jKDvF*$rv+*33uEfbga49N&i0}4~Rkn`K=7( z#z|ie_pBYPV>oL7KV<19lMySJwD6h<>YRN<2iE^*8&N#|{yY4Z{ys!`J#OnlL)ga@ zeXZOvTFJVO3w6`?UHTqHe86Ot$@iF4n2dE?dX1mVwr8B%ntNq#`kjk>*W!3_hg^K> zz~~5Y2*Y_r;k;sUC&>|POx-(^TOJ%4TpYqit{Tf1v8-vH6=SJj`(}kdLKS7+3)oHE z2}4r&Coc zi@cR;;quM*d(9wH+EdyueEQ{_x02eAc!~g&Q literal 0 HcmV?d00001 diff --git a/app/__pycache__/__init__.cpython-37.pyc b/app/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c03998a690b3431b02334fe2c4fb94ac10a241d6 GIT binary patch literal 275 zcmXwxzfQw25XS8|j-rT8yg=75U{ry`P$2|_1*rq=f`xQ4v6}|`CyG;~bY%fCn%E<^dFU=m5Jk-;2eq_B$KFefrn zk)0E@HnIZRu}~^5YaR|DV<%{70-lrR>AD#^!yXGG?0I`KVutb6syFOYYn?`<<==Bfr}*MzH_@ literal 0 HcmV?d00001 diff --git a/app/__pycache__/db.cpython-37.pyc b/app/__pycache__/db.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..60ca0569afee18efcd4d2fe3d8d18ffd744bf59d GIT binary patch literal 677 zcmZ{iv2NQi5Qa%gmSwj=`v4s@bclc;3X-DeP$YE{4FLiNh}{lB0YN5N+khpyBo!oq zvgH*z7O=)XPFAj&`U;(LC$~j9^nm-1I#Q>*k2>7g=o7H?`~Bx{l#mB}_+tzfAHdBk z5J3c8kP9N1@b1V36~5>|WP*-J9Q=e6WXMs`@J$c=2;A&|ShAvmHuRR%WW^eCOKZCF z1Zyb8jNgzpb}$M86}{n2&v2!s*%p(Vy`%GVFixZK;P5n!X7lMRTW?02WnRe0$}77S zwW(-cS~-?E_aiBxlF`ldwK18T+7_bOiX;7 zzQs%XG;Cczha5*dXn3Fl-eP(Si@%sy&00)e?IEU`)btB$7(imbVX@W!V7)#Wj?(jS zbTS;D{ln_h;PhiU+C12b4uFovE;Qbf#y&JQq63sJNbI|y$`CHVTf^2NZuU@csI@$U zmFt`QQf5}c%sAhZnP0-(`UT`-Z~Z;oZxc^ywAI=|;rl{~Y9aUGS0o183cWCV1hQ_K A(EtDd literal 0 HcmV?d00001 diff --git a/app/__pycache__/models.cpython-37.pyc b/app/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8951cf216ec1f5f29af7d55535e5ade0e11752d1 GIT binary patch literal 3026 zcmai0OOM+&5GJXIW!X-gZJJku!hInzT6oiBffm7H(KZVN0h&dD4SEn-C|Z&6dLzkR zie6+5=j1JtOAq}41-!@poL+hDDSsiS&QS6*DJp;zC6U9KZ@zED9~upxz;*M_zki8b zLjJ*r+2z3CJ81bKbewRSkdy|L;+Q2YwF1kGt;9~9z)9V}rQ{*uHh0blcZ55!f(ksl zyaLY^;RtVH2UU3E@hZHj3hT&+IW=KT>*oY)`TL|@djq?XHr4)5z4&<|o}3N@JTZRI zX1eltsG@^J=vq10?Zqm_1+&X42l;In2og|E0>)`zy&}&jXWTmT0=sZAa9$Cc1TJjq z>Pt%oA7wxGaGIV2dL}U~DDK%LkMOdtGxDp>mSy%8jl}H`gn0FU&bP+mywQ%D4yH3nZR1lRc zN<|oIKMWz1VS?j&7#9X&8^AmrF`>^y3-x^2=B z!{hwIoZ^)~f$smfQqVYX3-SgP;c=hW&d7uYRbJ23Nn&DL)U~A5aii{d< zecwvp-crEnmO6}7tCtQEVRGBLZ_ue|eI7;%J&U{VVk{&FR$T*YSHY@m4 zgBN8gXM38ABD1eTGaC^)y8OP4R1b9Zis%ral_G(PHaoUppg=#k=a@_x7Kn4GmN2%ArqBmA+S(OL#Hxjcdi^Yt zr>$J5mN-GNx1x-u-Iify1I(x+~^9Ns3a2{t}TPZ(11JVY$>#oLAJaO^Rx>!N@RS=y`?;_dv+66 zdtsstsHcs7v0pyq|$Z>w#jM#+9n~ILv1khI2)P`KJbG8q&_Te8^ zu)xuNFYjf!in3S~Y(&2$8rE*y7cv%5v8_1CwF~J=oF`E<>p-Jo zzlJtb?U&0ihhbMJ07OA4exGuw$?Qy=tMwmC_hL0BWv16_|Fy*m$q;rECPKPi)n4Pt zgZ##}i|nnTgQf8U+z_MgmiWx7+aK)M-Y;MP$5AUFd;?EeZx;VDQ{4P*R9M_k2RmD6 z6RVp`MqjN40YZ5fr};tydRbrKD1d+#ugX6sZiIL(teDb_TS0wW!)r0A-H=U~AunNv z#L<;7 Date: Wed, 8 May 2019 13:06:14 +0200 Subject: [PATCH 4/9] python game engine tests added --- tests/test_game.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/test_game.py diff --git a/tests/test_game.py b/tests/test_game.py new file mode 100644 index 0000000..0462bbc --- /dev/null +++ b/tests/test_game.py @@ -0,0 +1,89 @@ +import os,sys,inspect +current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) +parent_dir = os.path.dirname(current_dir) +sys.path.insert(0, parent_dir) +from game import * + +import copy + +def empty_game(): + game = Game() + game.x = copy.deepcopy(Game.x) + game.copy_board = game.x[:] + game.c_score = Game.c_score + return game + +import unittest + + + +class TestEmptyBoard(unittest.TestCase): + def setUp(self): + self.game = empty_game() + + + def test_board_size(self): + self.assertEqual(len(self.game.x), 4) + self.assertEqual(len(self.game.x[0]), 4) + + + def test_board_rotate(self): + self.game.x[0][0] = 8 + self.game.rotate(2) + self.assertEqual(self.game.x[3][3],8) + + def test_move(self): + self.game.x[0][0] = 8 + self.game.process_move("d") + self.assertEqual(self.game.x[0][3],8) + self.game.process_move("s") + self.assertEqual(self.game.x[3][3],8) + self.game.process_move("a") + self.assertEqual(self.game.x[3][0],8) + self.game.process_move("w") + self.assertEqual(self.game.x[0][0],8) + + def test_sum_up(self): + self.game.x[2][0] = 4 + self.game.x[3][0] = 4 + self.game.sum_up() + self.assertEqual(self.game.x[2][0],8) + self.assertEqual(self.game.x[3][0],0) + + def test_count_score(self): + self.game.x[2][0] = 4 + self.game.x[3][0] = 4 + #print(self.game.x) + self.game.sum_up() + #print(self.game.x) + self.assertEqual(self.game.c_score,8) + + def test_gravity(self): + # move elements to the bottom on the Y-axis + + self.game.x[0][2] = 8 + self.game.x[1][3] = 32 + self.game.x[3][2] = 8 + + # printing just to see what happens in CLI + # and making the display behave like 'gravity' in CLI + """ + print() + for p in self.game.x[::-1]: + print(p) + print() + """ + self.game.gravity() + """ + for p in self.game.x[::-1]: + print(p) + print() + """ + + self.assertEqual(self.game.x[0][3],32) + self.assertEqual(self.game.x[1][2],8) + + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From a99565f5541638cd7ddf7c0be94930594384d218 Mon Sep 17 00:00:00 2001 From: gabor-marton Date: Wed, 8 May 2019 15:24:38 +0200 Subject: [PATCH 5/9] test_new_board added --- tests/test_game.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_game.py b/tests/test_game.py index 0462bbc..99de11a 100644 --- a/tests/test_game.py +++ b/tests/test_game.py @@ -5,10 +5,11 @@ from game import * import copy +import itertools def empty_game(): game = Game() - game.x = copy.deepcopy(Game.x) + game.x = copy.deepcopy(Game.x) #using deepcopy to not reflect any other child of this object game.copy_board = game.x[:] game.c_score = Game.c_score return game @@ -83,6 +84,10 @@ def test_gravity(self): self.assertEqual(self.game.x[0][3],32) self.assertEqual(self.game.x[1][2],8) + def test_new_board(self): + self.game.new_board() + matrix_list = list(itertools.chain.from_iterable(self.game.x)) #making a list from the matrix to use assertIn + self.assertIn(2 or 4,matrix_list) if __name__ == '__main__': From d7f6ad3608e67895a224700f9fb4924a9a3072d1 Mon Sep 17 00:00:00 2001 From: gabor-marton Date: Wed, 8 May 2019 17:08:41 +0200 Subject: [PATCH 6/9] bugfix: test_new_board method + random-board-gravity test added --- tests/test_game.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/test_game.py b/tests/test_game.py index 99de11a..315205d 100644 --- a/tests/test_game.py +++ b/tests/test_game.py @@ -84,10 +84,22 @@ def test_gravity(self): self.assertEqual(self.game.x[0][3],32) self.assertEqual(self.game.x[1][2],8) + + ##### TESTING WITH RANDOMLY ADDED NUMBER(S) ##### + + def test_new_board(self): self.game.new_board() - matrix_list = list(itertools.chain.from_iterable(self.game.x)) #making a list from the matrix to use assertIn - self.assertIn(2 or 4,matrix_list) + matrix_list = list(itertools.chain.from_iterable(self.game.x)) #making a list from the matrix to use assertion + self.assertTrue(2 in matrix_list or 4 in matrix_list) + + def test_randomboard_gravity(self): + self.game.new_board() + self.game.gravity() + #print(self.game.x[0]) + self.assertTrue(2 in self.game.x[0] or 4 in self.game.x[0]) + + if __name__ == '__main__': From b5d224916b3ff2bed6de09e50d57dd6dbed7a964 Mon Sep 17 00:00:00 2001 From: gabor-marton Date: Thu, 9 May 2019 15:46:06 +0200 Subject: [PATCH 7/9] bugfix: game.py + additional tests + coverage:94% on game.py --- .coverage | 1 + __pycache__/game.cpython-37.pyc | Bin 5742 -> 5567 bytes game.py | 4 +- tests/.coverage | 1 + ...borm_Documents_2048_python_v2_game_py.html | 341 ++++++++++ tests/htmlcov/coverage_html.js | 584 ++++++++++++++++++ tests/htmlcov/index.html | 113 ++++ .../jquery.ba-throttle-debounce.min.js | 9 + tests/htmlcov/jquery.hotkeys.js | 99 +++ tests/htmlcov/jquery.isonscreen.js | 53 ++ tests/htmlcov/jquery.min.js | 4 + tests/htmlcov/jquery.tablesorter.min.js | 2 + tests/htmlcov/keybd_closed.png | Bin 0 -> 112 bytes tests/htmlcov/keybd_open.png | Bin 0 -> 112 bytes tests/htmlcov/status.json | 1 + tests/htmlcov/style.css | 375 +++++++++++ tests/htmlcov/test_game_py.html | 399 ++++++++++++ tests/test_game.py | 49 ++ 18 files changed, 2033 insertions(+), 2 deletions(-) create mode 100644 .coverage create mode 100644 tests/.coverage create mode 100644 tests/htmlcov/_home_gaborm_Documents_2048_python_v2_game_py.html create mode 100644 tests/htmlcov/coverage_html.js create mode 100644 tests/htmlcov/index.html create mode 100644 tests/htmlcov/jquery.ba-throttle-debounce.min.js create mode 100644 tests/htmlcov/jquery.hotkeys.js create mode 100644 tests/htmlcov/jquery.isonscreen.js create mode 100644 tests/htmlcov/jquery.min.js create mode 100644 tests/htmlcov/jquery.tablesorter.min.js create mode 100644 tests/htmlcov/keybd_closed.png create mode 100644 tests/htmlcov/keybd_open.png create mode 100644 tests/htmlcov/status.json create mode 100644 tests/htmlcov/style.css create mode 100644 tests/htmlcov/test_game_py.html diff --git a/.coverage b/.coverage new file mode 100644 index 0000000..5d49699 --- /dev/null +++ b/.coverage @@ -0,0 +1 @@ +!coverage.py: This is a private format, don't read it directly!{"lines":{"/home/gaborm/Documents/2048_python_v2/run.py":[1,3,4],"/home/gaborm/Documents/2048_python_v2/app/__init__.py":[1,4,5,8],"/home/gaborm/Documents/2048_python_v2/alone_2048.py":[1,2,3,4,7,8,13,57,62,82],"/home/gaborm/Documents/2048_python_v2/app/db.py":[1,4,12],"/home/gaborm/Documents/2048_python_v2/game.py":[1,2,5,7,9,11,13,18,21,24,27,38,49,60,70,81,92,99,106,117,122,129,130,132,139,143,144,148,153,158,169,176,184,213,218,227]}} \ No newline at end of file diff --git a/__pycache__/game.cpython-37.pyc b/__pycache__/game.cpython-37.pyc index af9b8e51c29ec8178832ad2674b1b32f6ab333f0..d8a27ce821004eaf9121cea3cccb70e32b917e0b 100644 GIT binary patch delta 487 zcmaE-vtOIriIf~ZX_9?pvdO;Tr7-?YLmZk>!3*qZ?@wpU}RGP>DQQ?D3pT(QCfT%w7Wk delta 489 zcmYjNyG{Z@6y*|kc&@v!7__i}T@;ped8jeQ#6qL|gb6W(5?O|X1WRpAG~Um!GHYRM z{0GaeF@24%OnE5^ + + + + + + + Coverage for /home/gaborm/Documents/2048_python_v2/game.py: 94% + + + + + + + + + + + + +
+ Hide keyboard shortcuts +

Hot-keys on this page

+
+

+ r + m + x + p   toggle line displays +

+

+ j + k   next/prev highlighted chunk +

+

+ 0   (zero) top of page +

+

+ 1   (one) first highlighted chunk +

+
+
+ +
+ + + + + +
+

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

+ +
+

from random import randint 

+

import random 

+

 

+

 

+

class Game: 

+

 

+

x = [[0 for c in range(4)] for r in range(4)] 

+

 

+

c_score = 0 

+

 

+

copy_board = [] 

+

 

+

def __init__(self): 

+

self.x = self.new_board() 

+

self.c_score = self.c_score 

+

self.copy_board = self.copy_board 

+

 

+

def print_inline(self, s): 

+

print(s, end='') 

+

 

+

def count_zeroes(self): 

+

return sum([sum([1 for c in r if c == 0]) for r in self.x]) 

+

 

+

def max_value(self): 

+

return max([max(r) for r in self.x]) 

+

 

+

def add_number(self): 

+

list_of_num = [2, 2, 2, 2, 4] 

+

num = random.choice(list_of_num) 

+

if self.count_zeroes() > 0: 

+

pos = randint(0, self.count_zeroes() - 1) 

+

for i in range(0, 4): 

+

for j in range(0, 4): 

+

if self.x[i][j] == 0: 

+

if pos == 0: self.x[i][j] = num 

+

pos -= 1 

+

 

+

def gravity(self): 

+

changed = False 

+

for i in range(0, 4): 

+

for j in range(0, 4): 

+

k = i 

+

while k < 4 and self.x[k][j] == 0: k += 1 

+

if k != i and k < 4: 

+

self.x[i][j], self.x[k][j] = self.x[k][j], 0 

+

changed = True 

+

return changed 

+

 

+

def gravity_copy(self): 

+

changed = False 

+

for i in range(0, 4): 

+

for j in range(0, 4): 

+

k = i 

+

while k < 4 and self.copy_board[k][j] == 0: k += 1 

+

if k != i and k < 4: 

+

self.copy_board[i][j], self.copy_board[k][j] = self.copy_board[k][j], 0 

+

changed = True 

+

return changed 

+

 

+

def sum_up_copy(self): 

+

changed = False 

+

for i in range(0, 3): 

+

for j in range(0, 4): 

+

if self.copy_board[i][j] != 0 and self.copy_board[i][j] == self.copy_board[i + 1][j]: 

+

self.copy_board[i][j] = 2 * self.copy_board[i][j] 

+

self.copy_board[i + 1][j] = 0 

+

changed = True 

+

return changed 

+

 

+

def sum_up(self): 

+

changed = False 

+

for i in range(0, 3): 

+

for j in range(0, 4): 

+

if self.x[i][j] != 0 and self.x[i][j] == self.x[i + 1][j]: 

+

self.x[i][j] = 2 * self.x[i][j] 

+

self.c_score = self.c_score + self.x[i][j] 

+

self.x[i + 1][j] = 0 

+

changed = True 

+

return changed 

+

 

+

def process_move(self, c): 

+

moves = "wasd" # up, left, down, right 

+

for i in range(len(moves)): 

+

if moves[i] == c: 

+

self.rotate(i) 

+

changed = any([self.gravity(), self.sum_up(), self.gravity()]) 

+

self.rotate(4 - i) 

+

self.copy_board = [row[:] for row in self.x] 

+

return changed 

+

return False 

+

 

+

def rotate(self, n): # rotate 90 degrees n times 

+

for i in range(0, n): 

+

y = [row[:] for row in self.x] # clone x 

+

for i in range(0, 4): 

+

for j in range(0, 4): 

+

self.x[i][3 - j] = y[j][i] 

+

 

+

def rotate_copy(self, n): # rotate 90 degrees n times 

+

for i in range(0, n): 

+

y = [row[:] for row in self.copy_board] # clone x 

+

for i in range(0, 4): 

+

for j in range(0, 4): 

+

self.copy_board[i][3 - j] = y[j][i] 

+

 

+

def process_move_copy(self, c): 

+

moves = "wasd" # up, left, down, right 

+

for i in range(len(moves)): 

+

if moves[i] == c: 

+

self.rotate_copy(i) 

+

changed = any([self.gravity_copy(), self.sum_up_copy(), self.gravity_copy()]) 

+

self.rotate_copy(4 - i) 

+

#self.copy_board = [row[:] for row in self.x] 

+

return changed 

+

return False 

+

 

+

def next_step_check(self): 

+

changed = any([self.process_move_copy("w"), self.process_move_copy("a"), self.process_move_copy("s"), 

+

self.process_move_copy("d")]) 

+

return changed 

+

 

+

def new_board(self): 

+

self.x = [[0 for c in range(4)] for r in range(4)] 

+

self.copy_board = self.x 

+

self.add_number() 

+

return self.x 

+ +
+
+ + + + + diff --git a/tests/htmlcov/coverage_html.js b/tests/htmlcov/coverage_html.js new file mode 100644 index 0000000..f6f5de2 --- /dev/null +++ b/tests/htmlcov/coverage_html.js @@ -0,0 +1,584 @@ +// Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +// For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt + +// Coverage.py HTML report browser code. +/*jslint browser: true, sloppy: true, vars: true, plusplus: true, maxerr: 50, indent: 4 */ +/*global coverage: true, document, window, $ */ + +coverage = {}; + +// Find all the elements with shortkey_* class, and use them to assign a shortcut key. +coverage.assign_shortkeys = function () { + $("*[class*='shortkey_']").each(function (i, e) { + $.each($(e).attr("class").split(" "), function (i, c) { + if (/^shortkey_/.test(c)) { + $(document).bind('keydown', c.substr(9), function () { + $(e).click(); + }); + } + }); + }); +}; + +// Create the events for the help panel. +coverage.wire_up_help_panel = function () { + $("#keyboard_icon").click(function () { + // Show the help panel, and position it so the keyboard icon in the + // panel is in the same place as the keyboard icon in the header. + $(".help_panel").show(); + var koff = $("#keyboard_icon").offset(); + var poff = $("#panel_icon").position(); + $(".help_panel").offset({ + top: koff.top-poff.top, + left: koff.left-poff.left + }); + }); + $("#panel_icon").click(function () { + $(".help_panel").hide(); + }); +}; + +// Create the events for the filter box. +coverage.wire_up_filter = function () { + // Cache elements. + var table = $("table.index"); + var table_rows = table.find("tbody tr"); + var table_row_names = table_rows.find("td.name a"); + var no_rows = $("#no_rows"); + + // Create a duplicate table footer that we can modify with dynamic summed values. + var table_footer = $("table.index tfoot tr"); + var table_dynamic_footer = table_footer.clone(); + table_dynamic_footer.attr('class', 'total_dynamic hidden'); + table_footer.after(table_dynamic_footer); + + // Observe filter keyevents. + $("#filter").on("keyup change", $.debounce(150, function (event) { + var filter_value = $(this).val(); + + if (filter_value === "") { + // Filter box is empty, remove all filtering. + table_rows.removeClass("hidden"); + + // Show standard footer, hide dynamic footer. + table_footer.removeClass("hidden"); + table_dynamic_footer.addClass("hidden"); + + // Hide placeholder, show table. + if (no_rows.length > 0) { + no_rows.hide(); + } + table.show(); + + } + else { + // Filter table items by value. + var hidden = 0; + var shown = 0; + + // Hide / show elements. + $.each(table_row_names, function () { + var element = $(this).parents("tr"); + + if ($(this).text().indexOf(filter_value) === -1) { + // hide + element.addClass("hidden"); + hidden++; + } + else { + // show + element.removeClass("hidden"); + shown++; + } + }); + + // Show placeholder if no rows will be displayed. + if (no_rows.length > 0) { + if (shown === 0) { + // Show placeholder, hide table. + no_rows.show(); + table.hide(); + } + else { + // Hide placeholder, show table. + no_rows.hide(); + table.show(); + } + } + + // Manage dynamic header: + if (hidden > 0) { + // Calculate new dynamic sum values based on visible rows. + for (var column = 2; column < 20; column++) { + // Calculate summed value. + var cells = table_rows.find('td:nth-child(' + column + ')'); + if (!cells.length) { + // No more columns...! + break; + } + + var sum = 0, numer = 0, denom = 0; + $.each(cells.filter(':visible'), function () { + var ratio = $(this).data("ratio"); + if (ratio) { + var splitted = ratio.split(" "); + numer += parseInt(splitted[0], 10); + denom += parseInt(splitted[1], 10); + } + else { + sum += parseInt(this.innerHTML, 10); + } + }); + + // Get footer cell element. + var footer_cell = table_dynamic_footer.find('td:nth-child(' + column + ')'); + + // Set value into dynamic footer cell element. + if (cells[0].innerHTML.indexOf('%') > -1) { + // Percentage columns use the numerator and denominator, + // and adapt to the number of decimal places. + var match = /\.([0-9]+)/.exec(cells[0].innerHTML); + var places = 0; + if (match) { + places = match[1].length; + } + var pct = numer * 100 / denom; + footer_cell.text(pct.toFixed(places) + '%'); + } + else { + footer_cell.text(sum); + } + } + + // Hide standard footer, show dynamic footer. + table_footer.addClass("hidden"); + table_dynamic_footer.removeClass("hidden"); + } + else { + // Show standard footer, hide dynamic footer. + table_footer.removeClass("hidden"); + table_dynamic_footer.addClass("hidden"); + } + } + })); + + // Trigger change event on setup, to force filter on page refresh + // (filter value may still be present). + $("#filter").trigger("change"); +}; + +// Loaded on index.html +coverage.index_ready = function ($) { + // Look for a cookie containing previous sort settings: + var sort_list = []; + var cookie_name = "COVERAGE_INDEX_SORT"; + var i; + + // This almost makes it worth installing the jQuery cookie plugin: + if (document.cookie.indexOf(cookie_name) > -1) { + var cookies = document.cookie.split(";"); + for (i = 0; i < cookies.length; i++) { + var parts = cookies[i].split("="); + + if ($.trim(parts[0]) === cookie_name && parts[1]) { + sort_list = eval("[[" + parts[1] + "]]"); + break; + } + } + } + + // Create a new widget which exists only to save and restore + // the sort order: + $.tablesorter.addWidget({ + id: "persistentSort", + + // Format is called by the widget before displaying: + format: function (table) { + if (table.config.sortList.length === 0 && sort_list.length > 0) { + // This table hasn't been sorted before - we'll use + // our stored settings: + $(table).trigger('sorton', [sort_list]); + } + else { + // This is not the first load - something has + // already defined sorting so we'll just update + // our stored value to match: + sort_list = table.config.sortList; + } + } + }); + + // Configure our tablesorter to handle the variable number of + // columns produced depending on report options: + var headers = []; + var col_count = $("table.index > thead > tr > th").length; + + headers[0] = { sorter: 'text' }; + for (i = 1; i < col_count-1; i++) { + headers[i] = { sorter: 'digit' }; + } + headers[col_count-1] = { sorter: 'percent' }; + + // Enable the table sorter: + $("table.index").tablesorter({ + widgets: ['persistentSort'], + headers: headers + }); + + coverage.assign_shortkeys(); + coverage.wire_up_help_panel(); + coverage.wire_up_filter(); + + // Watch for page unload events so we can save the final sort settings: + $(window).unload(function () { + document.cookie = cookie_name + "=" + sort_list.toString() + "; path=/"; + }); +}; + +// -- pyfile stuff -- + +coverage.pyfile_ready = function ($) { + // If we're directed to a particular line number, highlight the line. + var frag = location.hash; + if (frag.length > 2 && frag[1] === 'n') { + $(frag).addClass('highlight'); + coverage.set_sel(parseInt(frag.substr(2), 10)); + } + else { + coverage.set_sel(0); + } + + $(document) + .bind('keydown', 'j', coverage.to_next_chunk_nicely) + .bind('keydown', 'k', coverage.to_prev_chunk_nicely) + .bind('keydown', '0', coverage.to_top) + .bind('keydown', '1', coverage.to_first_chunk) + ; + + $(".button_toggle_run").click(function (evt) {coverage.toggle_lines(evt.target, "run");}); + $(".button_toggle_exc").click(function (evt) {coverage.toggle_lines(evt.target, "exc");}); + $(".button_toggle_mis").click(function (evt) {coverage.toggle_lines(evt.target, "mis");}); + $(".button_toggle_par").click(function (evt) {coverage.toggle_lines(evt.target, "par");}); + + coverage.assign_shortkeys(); + coverage.wire_up_help_panel(); + + coverage.init_scroll_markers(); + + // Rebuild scroll markers after window high changing + $(window).resize(coverage.resize_scroll_markers); +}; + +coverage.toggle_lines = function (btn, cls) { + btn = $(btn); + var hide = "hide_"+cls; + if (btn.hasClass(hide)) { + $("#source ."+cls).removeClass(hide); + btn.removeClass(hide); + } + else { + $("#source ."+cls).addClass(hide); + btn.addClass(hide); + } +}; + +// Return the nth line div. +coverage.line_elt = function (n) { + return $("#t" + n); +}; + +// Return the nth line number div. +coverage.num_elt = function (n) { + return $("#n" + n); +}; + +// Return the container of all the code. +coverage.code_container = function () { + return $(".linenos"); +}; + +// Set the selection. b and e are line numbers. +coverage.set_sel = function (b, e) { + // The first line selected. + coverage.sel_begin = b; + // The next line not selected. + coverage.sel_end = (e === undefined) ? b+1 : e; +}; + +coverage.to_top = function () { + coverage.set_sel(0, 1); + coverage.scroll_window(0); +}; + +coverage.to_first_chunk = function () { + coverage.set_sel(0, 1); + coverage.to_next_chunk(); +}; + +coverage.is_transparent = function (color) { + // Different browsers return different colors for "none". + return color === "transparent" || color === "rgba(0, 0, 0, 0)"; +}; + +coverage.to_next_chunk = function () { + var c = coverage; + + // Find the start of the next colored chunk. + var probe = c.sel_end; + var color, probe_line; + while (true) { + probe_line = c.line_elt(probe); + if (probe_line.length === 0) { + return; + } + color = probe_line.css("background-color"); + if (!c.is_transparent(color)) { + break; + } + probe++; + } + + // There's a next chunk, `probe` points to it. + var begin = probe; + + // Find the end of this chunk. + var next_color = color; + while (next_color === color) { + probe++; + probe_line = c.line_elt(probe); + next_color = probe_line.css("background-color"); + } + c.set_sel(begin, probe); + c.show_selection(); +}; + +coverage.to_prev_chunk = function () { + var c = coverage; + + // Find the end of the prev colored chunk. + var probe = c.sel_begin-1; + var probe_line = c.line_elt(probe); + if (probe_line.length === 0) { + return; + } + var color = probe_line.css("background-color"); + while (probe > 0 && c.is_transparent(color)) { + probe--; + probe_line = c.line_elt(probe); + if (probe_line.length === 0) { + return; + } + color = probe_line.css("background-color"); + } + + // There's a prev chunk, `probe` points to its last line. + var end = probe+1; + + // Find the beginning of this chunk. + var prev_color = color; + while (prev_color === color) { + probe--; + probe_line = c.line_elt(probe); + prev_color = probe_line.css("background-color"); + } + c.set_sel(probe+1, end); + c.show_selection(); +}; + +// Return the line number of the line nearest pixel position pos +coverage.line_at_pos = function (pos) { + var l1 = coverage.line_elt(1), + l2 = coverage.line_elt(2), + result; + if (l1.length && l2.length) { + var l1_top = l1.offset().top, + line_height = l2.offset().top - l1_top, + nlines = (pos - l1_top) / line_height; + if (nlines < 1) { + result = 1; + } + else { + result = Math.ceil(nlines); + } + } + else { + result = 1; + } + return result; +}; + +// Returns 0, 1, or 2: how many of the two ends of the selection are on +// the screen right now? +coverage.selection_ends_on_screen = function () { + if (coverage.sel_begin === 0) { + return 0; + } + + var top = coverage.line_elt(coverage.sel_begin); + var next = coverage.line_elt(coverage.sel_end-1); + + return ( + (top.isOnScreen() ? 1 : 0) + + (next.isOnScreen() ? 1 : 0) + ); +}; + +coverage.to_next_chunk_nicely = function () { + coverage.finish_scrolling(); + if (coverage.selection_ends_on_screen() === 0) { + // The selection is entirely off the screen: select the top line on + // the screen. + var win = $(window); + coverage.select_line_or_chunk(coverage.line_at_pos(win.scrollTop())); + } + coverage.to_next_chunk(); +}; + +coverage.to_prev_chunk_nicely = function () { + coverage.finish_scrolling(); + if (coverage.selection_ends_on_screen() === 0) { + var win = $(window); + coverage.select_line_or_chunk(coverage.line_at_pos(win.scrollTop() + win.height())); + } + coverage.to_prev_chunk(); +}; + +// Select line number lineno, or if it is in a colored chunk, select the +// entire chunk +coverage.select_line_or_chunk = function (lineno) { + var c = coverage; + var probe_line = c.line_elt(lineno); + if (probe_line.length === 0) { + return; + } + var the_color = probe_line.css("background-color"); + if (!c.is_transparent(the_color)) { + // The line is in a highlighted chunk. + // Search backward for the first line. + var probe = lineno; + var color = the_color; + while (probe > 0 && color === the_color) { + probe--; + probe_line = c.line_elt(probe); + if (probe_line.length === 0) { + break; + } + color = probe_line.css("background-color"); + } + var begin = probe + 1; + + // Search forward for the last line. + probe = lineno; + color = the_color; + while (color === the_color) { + probe++; + probe_line = c.line_elt(probe); + color = probe_line.css("background-color"); + } + + coverage.set_sel(begin, probe); + } + else { + coverage.set_sel(lineno); + } +}; + +coverage.show_selection = function () { + var c = coverage; + + // Highlight the lines in the chunk + c.code_container().find(".highlight").removeClass("highlight"); + for (var probe = c.sel_begin; probe > 0 && probe < c.sel_end; probe++) { + c.num_elt(probe).addClass("highlight"); + } + + c.scroll_to_selection(); +}; + +coverage.scroll_to_selection = function () { + // Scroll the page if the chunk isn't fully visible. + if (coverage.selection_ends_on_screen() < 2) { + // Need to move the page. The html,body trick makes it scroll in all + // browsers, got it from http://stackoverflow.com/questions/3042651 + var top = coverage.line_elt(coverage.sel_begin); + var top_pos = parseInt(top.offset().top, 10); + coverage.scroll_window(top_pos - 30); + } +}; + +coverage.scroll_window = function (to_pos) { + $("html,body").animate({scrollTop: to_pos}, 200); +}; + +coverage.finish_scrolling = function () { + $("html,body").stop(true, true); +}; + +coverage.init_scroll_markers = function () { + var c = coverage; + // Init some variables + c.lines_len = $('td.text p').length; + c.body_h = $('body').height(); + c.header_h = $('div#header').height(); + c.missed_lines = $('td.text p.mis, td.text p.par'); + + // Build html + c.resize_scroll_markers(); +}; + +coverage.resize_scroll_markers = function () { + var c = coverage, + min_line_height = 3, + max_line_height = 10, + visible_window_h = $(window).height(); + + $('#scroll_marker').remove(); + // Don't build markers if the window has no scroll bar. + if (c.body_h <= visible_window_h) { + return; + } + + $("body").append("
 
"); + var scroll_marker = $('#scroll_marker'), + marker_scale = scroll_marker.height() / c.body_h, + line_height = scroll_marker.height() / c.lines_len; + + // Line height must be between the extremes. + if (line_height > min_line_height) { + if (line_height > max_line_height) { + line_height = max_line_height; + } + } + else { + line_height = min_line_height; + } + + var previous_line = -99, + last_mark, + last_top; + + c.missed_lines.each(function () { + var line_top = Math.round($(this).offset().top * marker_scale), + id_name = $(this).attr('id'), + line_number = parseInt(id_name.substring(1, id_name.length)); + + if (line_number === previous_line + 1) { + // If this solid missed block just make previous mark higher. + last_mark.css({ + 'height': line_top + line_height - last_top + }); + } + else { + // Add colored line in scroll_marker block. + scroll_marker.append('
'); + last_mark = $('#m' + line_number); + last_mark.css({ + 'height': line_height, + 'top': line_top + }); + last_top = line_top; + } + + previous_line = line_number; + }); +}; diff --git a/tests/htmlcov/index.html b/tests/htmlcov/index.html new file mode 100644 index 0000000..140235b --- /dev/null +++ b/tests/htmlcov/index.html @@ -0,0 +1,113 @@ + + + + + + + + Coverage report + + + + + + + + + + + + + +
+ Hide keyboard shortcuts +

Hot-keys on this page

+
+

+ n + s + m + x + + c   change column sorting +

+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Modulestatementsmissingexcludedcoverage
Total1936097%
/home/gaborm/Documents/2048_python_v2/game.py1046094%
test_game.py8900100%
+ +

+ No items found using the specified filter. +

+
+ + + + + diff --git a/tests/htmlcov/jquery.ba-throttle-debounce.min.js b/tests/htmlcov/jquery.ba-throttle-debounce.min.js new file mode 100644 index 0000000..648fe5d --- /dev/null +++ b/tests/htmlcov/jquery.ba-throttle-debounce.min.js @@ -0,0 +1,9 @@ +/* + * jQuery throttle / debounce - v1.1 - 3/7/2010 + * http://benalman.com/projects/jquery-throttle-debounce-plugin/ + * + * Copyright (c) 2010 "Cowboy" Ben Alman + * Dual licensed under the MIT and GPL licenses. + * http://benalman.com/about/license/ + */ +(function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this); diff --git a/tests/htmlcov/jquery.hotkeys.js b/tests/htmlcov/jquery.hotkeys.js new file mode 100644 index 0000000..09b21e0 --- /dev/null +++ b/tests/htmlcov/jquery.hotkeys.js @@ -0,0 +1,99 @@ +/* + * jQuery Hotkeys Plugin + * Copyright 2010, John Resig + * Dual licensed under the MIT or GPL Version 2 licenses. + * + * Based upon the plugin by Tzury Bar Yochay: + * http://github.com/tzuryby/hotkeys + * + * Original idea by: + * Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/ +*/ + +(function(jQuery){ + + jQuery.hotkeys = { + version: "0.8", + + specialKeys: { + 8: "backspace", 9: "tab", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause", + 20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home", + 37: "left", 38: "up", 39: "right", 40: "down", 45: "insert", 46: "del", + 96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7", + 104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/", + 112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8", + 120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 191: "/", 224: "meta" + }, + + shiftNums: { + "`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", "6": "^", "7": "&", + "8": "*", "9": "(", "0": ")", "-": "_", "=": "+", ";": ": ", "'": "\"", ",": "<", + ".": ">", "/": "?", "\\": "|" + } + }; + + function keyHandler( handleObj ) { + // Only care when a possible input has been specified + if ( typeof handleObj.data !== "string" ) { + return; + } + + var origHandler = handleObj.handler, + keys = handleObj.data.toLowerCase().split(" "); + + handleObj.handler = function( event ) { + // Don't fire in text-accepting inputs that we didn't directly bind to + if ( this !== event.target && (/textarea|select/i.test( event.target.nodeName ) || + event.target.type === "text") ) { + return; + } + + // Keypress represents characters, not special keys + var special = event.type !== "keypress" && jQuery.hotkeys.specialKeys[ event.which ], + character = String.fromCharCode( event.which ).toLowerCase(), + key, modif = "", possible = {}; + + // check combinations (alt|ctrl|shift+anything) + if ( event.altKey && special !== "alt" ) { + modif += "alt+"; + } + + if ( event.ctrlKey && special !== "ctrl" ) { + modif += "ctrl+"; + } + + // TODO: Need to make sure this works consistently across platforms + if ( event.metaKey && !event.ctrlKey && special !== "meta" ) { + modif += "meta+"; + } + + if ( event.shiftKey && special !== "shift" ) { + modif += "shift+"; + } + + if ( special ) { + possible[ modif + special ] = true; + + } else { + possible[ modif + character ] = true; + possible[ modif + jQuery.hotkeys.shiftNums[ character ] ] = true; + + // "$" can be triggered as "Shift+4" or "Shift+$" or just "$" + if ( modif === "shift+" ) { + possible[ jQuery.hotkeys.shiftNums[ character ] ] = true; + } + } + + for ( var i = 0, l = keys.length; i < l; i++ ) { + if ( possible[ keys[i] ] ) { + return origHandler.apply( this, arguments ); + } + } + }; + } + + jQuery.each([ "keydown", "keyup", "keypress" ], function() { + jQuery.event.special[ this ] = { add: keyHandler }; + }); + +})( jQuery ); diff --git a/tests/htmlcov/jquery.isonscreen.js b/tests/htmlcov/jquery.isonscreen.js new file mode 100644 index 0000000..0182ebd --- /dev/null +++ b/tests/htmlcov/jquery.isonscreen.js @@ -0,0 +1,53 @@ +/* Copyright (c) 2010 + * @author Laurence Wheway + * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) + * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. + * + * @version 1.2.0 + */ +(function($) { + jQuery.extend({ + isOnScreen: function(box, container) { + //ensure numbers come in as intgers (not strings) and remove 'px' is it's there + for(var i in box){box[i] = parseFloat(box[i])}; + for(var i in container){container[i] = parseFloat(container[i])}; + + if(!container){ + container = { + left: $(window).scrollLeft(), + top: $(window).scrollTop(), + width: $(window).width(), + height: $(window).height() + } + } + + if( box.left+box.width-container.left > 0 && + box.left < container.width+container.left && + box.top+box.height-container.top > 0 && + box.top < container.height+container.top + ) return true; + return false; + } + }) + + + jQuery.fn.isOnScreen = function (container) { + for(var i in container){container[i] = parseFloat(container[i])}; + + if(!container){ + container = { + left: $(window).scrollLeft(), + top: $(window).scrollTop(), + width: $(window).width(), + height: $(window).height() + } + } + + if( $(this).offset().left+$(this).width()-container.left > 0 && + $(this).offset().left < container.width+container.left && + $(this).offset().top+$(this).height()-container.top > 0 && + $(this).offset().top < container.height+container.top + ) return true; + return false; + } +})(jQuery); diff --git a/tests/htmlcov/jquery.min.js b/tests/htmlcov/jquery.min.js new file mode 100644 index 0000000..d1608e3 --- /dev/null +++ b/tests/htmlcov/jquery.min.js @@ -0,0 +1,4 @@ +/*! jQuery v1.11.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ +!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l="1.11.1",m=function(a,b){return new m.fn.init(a,b)},n=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,o=/^-ms-/,p=/-([\da-z])/gi,q=function(a,b){return b.toUpperCase()};m.fn=m.prototype={jquery:l,constructor:m,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=m.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return m.each(this,a,b)},map:function(a){return this.pushStack(m.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},m.extend=m.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||m.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(e=arguments[h]))for(d in e)a=g[d],c=e[d],g!==c&&(j&&c&&(m.isPlainObject(c)||(b=m.isArray(c)))?(b?(b=!1,f=a&&m.isArray(a)?a:[]):f=a&&m.isPlainObject(a)?a:{},g[d]=m.extend(j,f,c)):void 0!==c&&(g[d]=c));return g},m.extend({expando:"jQuery"+(l+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===m.type(a)},isArray:Array.isArray||function(a){return"array"===m.type(a)},isWindow:function(a){return null!=a&&a==a.window},isNumeric:function(a){return!m.isArray(a)&&a-parseFloat(a)>=0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},isPlainObject:function(a){var b;if(!a||"object"!==m.type(a)||a.nodeType||m.isWindow(a))return!1;try{if(a.constructor&&!j.call(a,"constructor")&&!j.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}if(k.ownLast)for(b in a)return j.call(a,b);for(b in a);return void 0===b||j.call(a,b)},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(b){b&&m.trim(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(o,"ms-").replace(p,q)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=r(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(n,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(r(Object(a))?m.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){var d;if(b){if(g)return g.call(b,a,c);for(d=b.length,c=c?0>c?Math.max(0,d+c):c:0;d>c;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,b){var c=+b.length,d=0,e=a.length;while(c>d)a[e++]=b[d++];if(c!==c)while(void 0!==b[d])a[e++]=b[d++];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=r(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(f=a[b],b=a,a=f),m.isFunction(a)?(c=d.call(arguments,2),e=function(){return a.apply(b||this,c.concat(d.call(arguments)))},e.guid=a.guid=a.guid||m.guid++,e):void 0},now:function(){return+new Date},support:k}),m.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function r(a){var b=a.length,c=m.type(a);return"function"===c||m.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var s=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+-new Date,v=a.document,w=0,x=0,y=gb(),z=gb(),A=gb(),B=function(a,b){return a===b&&(l=!0),0},C="undefined",D=1<<31,E={}.hasOwnProperty,F=[],G=F.pop,H=F.push,I=F.push,J=F.slice,K=F.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},L="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",N="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=N.replace("w","w#"),P="\\["+M+"*("+N+")(?:"+M+"*([*^$|!~]?=)"+M+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+O+"))|)"+M+"*\\]",Q=":("+N+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+P+")*)|.*)\\)|)",R=new RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),S=new RegExp("^"+M+"*,"+M+"*"),T=new RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),V=new RegExp(Q),W=new RegExp("^"+O+"$"),X={ID:new RegExp("^#("+N+")"),CLASS:new RegExp("^\\.("+N+")"),TAG:new RegExp("^("+N.replace("w","w*")+")"),ATTR:new RegExp("^"+P),PSEUDO:new RegExp("^"+Q),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+L+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)};try{I.apply(F=J.call(v.childNodes),v.childNodes),F[v.childNodes.length].nodeType}catch(eb){I={apply:F.length?function(a,b){H.apply(a,J.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function fb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],!a||"string"!=typeof a)return d;if(1!==(k=b.nodeType)&&9!==k)return[];if(p&&!e){if(f=_.exec(a))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return I.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName&&b.getElementsByClassName)return I.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=9===k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+qb(o[l]);w=ab.test(a)&&ob(b.parentNode)||b,x=o.join(",")}if(x)try{return I.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function gb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function hb(a){return a[u]=!0,a}function ib(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function jb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function kb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||D)-(~a.sourceIndex||D);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function lb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function nb(a){return hb(function(b){return b=+b,hb(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function ob(a){return a&&typeof a.getElementsByTagName!==C&&a}c=fb.support={},f=fb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=fb.setDocument=function(a){var b,e=a?a.ownerDocument||a:v,g=e.defaultView;return e!==n&&9===e.nodeType&&e.documentElement?(n=e,o=e.documentElement,p=!f(e),g&&g!==g.top&&(g.addEventListener?g.addEventListener("unload",function(){m()},!1):g.attachEvent&&g.attachEvent("onunload",function(){m()})),c.attributes=ib(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ib(function(a){return a.appendChild(e.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(e.getElementsByClassName)&&ib(function(a){return a.innerHTML="
",a.firstChild.className="i",2===a.getElementsByClassName("i").length}),c.getById=ib(function(a){return o.appendChild(a).id=u,!e.getElementsByName||!e.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if(typeof b.getElementById!==C&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c=typeof a.getAttributeNode!==C&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return typeof b.getElementsByTagName!==C?b.getElementsByTagName(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return typeof b.getElementsByClassName!==C&&p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(e.querySelectorAll))&&(ib(function(a){a.innerHTML="",a.querySelectorAll("[msallowclip^='']").length&&q.push("[*^$]="+M+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+M+"*(?:value|"+L+")"),a.querySelectorAll(":checked").length||q.push(":checked")}),ib(function(a){var b=e.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+M+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ib(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",Q)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===e||a.ownerDocument===v&&t(v,a)?-1:b===e||b.ownerDocument===v&&t(v,b)?1:k?K.call(k,a)-K.call(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,f=a.parentNode,g=b.parentNode,h=[a],i=[b];if(!f||!g)return a===e?-1:b===e?1:f?-1:g?1:k?K.call(k,a)-K.call(k,b):0;if(f===g)return kb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?kb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},e):n},fb.matches=function(a,b){return fb(a,null,null,b)},fb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return fb(b,n,null,[a]).length>0},fb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},fb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&E.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},fb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},fb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=fb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=fb.selectors={cacheLength:50,createPseudo:hb,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||fb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&fb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+M+")"+a+"("+M+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||typeof a.getAttribute!==C&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=fb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||fb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?hb(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=K.call(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:hb(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?hb(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),!c.pop()}}),has:hb(function(a){return function(b){return fb(a,b).length>0}}),contains:hb(function(a){return function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:hb(function(a){return W.test(a||"")||fb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:nb(function(){return[0]}),last:nb(function(a,b){return[b-1]}),eq:nb(function(a,b,c){return[0>c?c+b:c]}),even:nb(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:nb(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:nb(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:nb(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function rb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function sb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function tb(a,b,c){for(var d=0,e=b.length;e>d;d++)fb(a,b[d],c);return c}function ub(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function vb(a,b,c,d,e,f){return d&&!d[u]&&(d=vb(d)),e&&!e[u]&&(e=vb(e,f)),hb(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||tb(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:ub(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=ub(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?K.call(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=ub(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):I.apply(g,r)})}function wb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=rb(function(a){return a===b},h,!0),l=rb(function(a){return K.call(b,a)>-1},h,!0),m=[function(a,c,d){return!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d))}];f>i;i++)if(c=d.relative[a[i].type])m=[rb(sb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return vb(i>1&&sb(m),i>1&&qb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&wb(a.slice(i,e)),f>e&&wb(a=a.slice(e)),f>e&&qb(a))}m.push(c)}return sb(m)}function xb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=G.call(i));s=ub(s)}I.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&fb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?hb(f):f}return h=fb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=wb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,xb(e,d)),f.selector=a}return f},i=fb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&ob(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&qb(j),!a)return I.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&ob(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ib(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ib(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||jb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ib(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||jb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ib(function(a){return null==a.getAttribute("disabled")})||jb(L,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),fb}(a);m.find=s,m.expr=s.selectors,m.expr[":"]=m.expr.pseudos,m.unique=s.uniqueSort,m.text=s.getText,m.isXMLDoc=s.isXML,m.contains=s.contains;var t=m.expr.match.needsContext,u=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,v=/^.[^:#\[\.,]*$/;function w(a,b,c){if(m.isFunction(b))return m.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return m.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(v.test(b))return m.filter(b,a,c);b=m.filter(b,a)}return m.grep(a,function(a){return m.inArray(a,b)>=0!==c})}m.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?m.find.matchesSelector(d,a)?[d]:[]:m.find.matches(a,m.grep(b,function(a){return 1===a.nodeType}))},m.fn.extend({find:function(a){var b,c=[],d=this,e=d.length;if("string"!=typeof a)return this.pushStack(m(a).filter(function(){for(b=0;e>b;b++)if(m.contains(d[b],this))return!0}));for(b=0;e>b;b++)m.find(a,d[b],c);return c=this.pushStack(e>1?m.unique(c):c),c.selector=this.selector?this.selector+" "+a:a,c},filter:function(a){return this.pushStack(w(this,a||[],!1))},not:function(a){return this.pushStack(w(this,a||[],!0))},is:function(a){return!!w(this,"string"==typeof a&&t.test(a)?m(a):a||[],!1).length}});var x,y=a.document,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=m.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a.charAt(0)&&">"===a.charAt(a.length-1)&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||x).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof m?b[0]:b,m.merge(this,m.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:y,!0)),u.test(c[1])&&m.isPlainObject(b))for(c in b)m.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}if(d=y.getElementById(c[2]),d&&d.parentNode){if(d.id!==c[2])return x.find(a);this.length=1,this[0]=d}return this.context=y,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):m.isFunction(a)?"undefined"!=typeof x.ready?x.ready(a):a(m):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),m.makeArray(a,this))};A.prototype=m.fn,x=m(y);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};m.extend({dir:function(a,b,c){var d=[],e=a[b];while(e&&9!==e.nodeType&&(void 0===c||1!==e.nodeType||!m(e).is(c)))1===e.nodeType&&d.push(e),e=e[b];return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),m.fn.extend({has:function(a){var b,c=m(a,this),d=c.length;return this.filter(function(){for(b=0;d>b;b++)if(m.contains(this,c[b]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=t.test(a)||"string"!=typeof a?m(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&m.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?m.unique(f):f)},index:function(a){return a?"string"==typeof a?m.inArray(this[0],m(a)):m.inArray(a.jquery?a[0]:a,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(m.unique(m.merge(this.get(),m(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){do a=a[b];while(a&&1!==a.nodeType);return a}m.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return m.dir(a,"parentNode")},parentsUntil:function(a,b,c){return m.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return m.dir(a,"nextSibling")},prevAll:function(a){return m.dir(a,"previousSibling")},nextUntil:function(a,b,c){return m.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return m.dir(a,"previousSibling",c)},siblings:function(a){return m.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return m.sibling(a.firstChild)},contents:function(a){return m.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:m.merge([],a.childNodes)}},function(a,b){m.fn[a]=function(c,d){var e=m.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=m.filter(d,e)),this.length>1&&(C[a]||(e=m.unique(e)),B.test(a)&&(e=e.reverse())),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return m.each(a.match(E)||[],function(a,c){b[c]=!0}),b}m.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):m.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(c=a.memory&&l,d=!0,f=g||0,g=0,e=h.length,b=!0;h&&e>f;f++)if(h[f].apply(l[0],l[1])===!1&&a.stopOnFalse){c=!1;break}b=!1,h&&(i?i.length&&j(i.shift()):c?h=[]:k.disable())},k={add:function(){if(h){var d=h.length;!function f(b){m.each(b,function(b,c){var d=m.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=h.length:c&&(g=d,j(c))}return this},remove:function(){return h&&m.each(arguments,function(a,c){var d;while((d=m.inArray(c,h,d))>-1)h.splice(d,1),b&&(e>=d&&e--,f>=d&&f--)}),this},has:function(a){return a?m.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],e=0,this},disable:function(){return h=i=c=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,c||k.disable(),this},locked:function(){return!i},fireWith:function(a,c){return!h||d&&!i||(c=c||[],c=[a,c.slice?c.slice():c],b?i.push(c):j(c)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!d}};return k},m.extend({Deferred:function(a){var b=[["resolve","done",m.Callbacks("once memory"),"resolved"],["reject","fail",m.Callbacks("once memory"),"rejected"],["notify","progress",m.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return m.Deferred(function(c){m.each(b,function(b,f){var g=m.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&m.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?m.extend(a,d):d}},e={};return d.pipe=d.then,m.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&m.isFunction(a.promise)?e:0,g=1===f?a:m.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&m.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;m.fn.ready=function(a){return m.ready.promise().done(a),this},m.extend({isReady:!1,readyWait:1,holdReady:function(a){a?m.readyWait++:m.ready(!0)},ready:function(a){if(a===!0?!--m.readyWait:!m.isReady){if(!y.body)return setTimeout(m.ready);m.isReady=!0,a!==!0&&--m.readyWait>0||(H.resolveWith(y,[m]),m.fn.triggerHandler&&(m(y).triggerHandler("ready"),m(y).off("ready")))}}});function I(){y.addEventListener?(y.removeEventListener("DOMContentLoaded",J,!1),a.removeEventListener("load",J,!1)):(y.detachEvent("onreadystatechange",J),a.detachEvent("onload",J))}function J(){(y.addEventListener||"load"===event.type||"complete"===y.readyState)&&(I(),m.ready())}m.ready.promise=function(b){if(!H)if(H=m.Deferred(),"complete"===y.readyState)setTimeout(m.ready);else if(y.addEventListener)y.addEventListener("DOMContentLoaded",J,!1),a.addEventListener("load",J,!1);else{y.attachEvent("onreadystatechange",J),a.attachEvent("onload",J);var c=!1;try{c=null==a.frameElement&&y.documentElement}catch(d){}c&&c.doScroll&&!function e(){if(!m.isReady){try{c.doScroll("left")}catch(a){return setTimeout(e,50)}I(),m.ready()}}()}return H.promise(b)};var K="undefined",L;for(L in m(k))break;k.ownLast="0"!==L,k.inlineBlockNeedsLayout=!1,m(function(){var a,b,c,d;c=y.getElementsByTagName("body")[0],c&&c.style&&(b=y.createElement("div"),d=y.createElement("div"),d.style.cssText="position:absolute;border:0;width:0;height:0;top:0;left:-9999px",c.appendChild(d).appendChild(b),typeof b.style.zoom!==K&&(b.style.cssText="display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1",k.inlineBlockNeedsLayout=a=3===b.offsetWidth,a&&(c.style.zoom=1)),c.removeChild(d))}),function(){var a=y.createElement("div");if(null==k.deleteExpando){k.deleteExpando=!0;try{delete a.test}catch(b){k.deleteExpando=!1}}a=null}(),m.acceptData=function(a){var b=m.noData[(a.nodeName+" ").toLowerCase()],c=+a.nodeType||1;return 1!==c&&9!==c?!1:!b||b!==!0&&a.getAttribute("classid")===b};var M=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,N=/([A-Z])/g;function O(a,b,c){if(void 0===c&&1===a.nodeType){var d="data-"+b.replace(N,"-$1").toLowerCase();if(c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:M.test(c)?m.parseJSON(c):c}catch(e){}m.data(a,b,c)}else c=void 0}return c}function P(a){var b;for(b in a)if(("data"!==b||!m.isEmptyObject(a[b]))&&"toJSON"!==b)return!1;return!0}function Q(a,b,d,e){if(m.acceptData(a)){var f,g,h=m.expando,i=a.nodeType,j=i?m.cache:a,k=i?a[h]:a[h]&&h; +if(k&&j[k]&&(e||j[k].data)||void 0!==d||"string"!=typeof b)return k||(k=i?a[h]=c.pop()||m.guid++:h),j[k]||(j[k]=i?{}:{toJSON:m.noop}),("object"==typeof b||"function"==typeof b)&&(e?j[k]=m.extend(j[k],b):j[k].data=m.extend(j[k].data,b)),g=j[k],e||(g.data||(g.data={}),g=g.data),void 0!==d&&(g[m.camelCase(b)]=d),"string"==typeof b?(f=g[b],null==f&&(f=g[m.camelCase(b)])):f=g,f}}function R(a,b,c){if(m.acceptData(a)){var d,e,f=a.nodeType,g=f?m.cache:a,h=f?a[m.expando]:m.expando;if(g[h]){if(b&&(d=c?g[h]:g[h].data)){m.isArray(b)?b=b.concat(m.map(b,m.camelCase)):b in d?b=[b]:(b=m.camelCase(b),b=b in d?[b]:b.split(" ")),e=b.length;while(e--)delete d[b[e]];if(c?!P(d):!m.isEmptyObject(d))return}(c||(delete g[h].data,P(g[h])))&&(f?m.cleanData([a],!0):k.deleteExpando||g!=g.window?delete g[h]:g[h]=null)}}}m.extend({cache:{},noData:{"applet ":!0,"embed ":!0,"object ":"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(a){return a=a.nodeType?m.cache[a[m.expando]]:a[m.expando],!!a&&!P(a)},data:function(a,b,c){return Q(a,b,c)},removeData:function(a,b){return R(a,b)},_data:function(a,b,c){return Q(a,b,c,!0)},_removeData:function(a,b){return R(a,b,!0)}}),m.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=m.data(f),1===f.nodeType&&!m._data(f,"parsedAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=m.camelCase(d.slice(5)),O(f,d,e[d])));m._data(f,"parsedAttrs",!0)}return e}return"object"==typeof a?this.each(function(){m.data(this,a)}):arguments.length>1?this.each(function(){m.data(this,a,b)}):f?O(f,a,m.data(f,a)):void 0},removeData:function(a){return this.each(function(){m.removeData(this,a)})}}),m.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=m._data(a,b),c&&(!d||m.isArray(c)?d=m._data(a,b,m.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=m.queue(a,b),d=c.length,e=c.shift(),f=m._queueHooks(a,b),g=function(){m.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return m._data(a,c)||m._data(a,c,{empty:m.Callbacks("once memory").add(function(){m._removeData(a,b+"queue"),m._removeData(a,c)})})}}),m.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.lengthh;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f},W=/^(?:checkbox|radio)$/i;!function(){var a=y.createElement("input"),b=y.createElement("div"),c=y.createDocumentFragment();if(b.innerHTML="
a",k.leadingWhitespace=3===b.firstChild.nodeType,k.tbody=!b.getElementsByTagName("tbody").length,k.htmlSerialize=!!b.getElementsByTagName("link").length,k.html5Clone="<:nav>"!==y.createElement("nav").cloneNode(!0).outerHTML,a.type="checkbox",a.checked=!0,c.appendChild(a),k.appendChecked=a.checked,b.innerHTML="",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue,c.appendChild(b),b.innerHTML="",k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,k.noCloneEvent=!0,b.attachEvent&&(b.attachEvent("onclick",function(){k.noCloneEvent=!1}),b.cloneNode(!0).click()),null==k.deleteExpando){k.deleteExpando=!0;try{delete b.test}catch(d){k.deleteExpando=!1}}}(),function(){var b,c,d=y.createElement("div");for(b in{submit:!0,change:!0,focusin:!0})c="on"+b,(k[b+"Bubbles"]=c in a)||(d.setAttribute(c,"t"),k[b+"Bubbles"]=d.attributes[c].expando===!1);d=null}();var X=/^(?:input|select|textarea)$/i,Y=/^key/,Z=/^(?:mouse|pointer|contextmenu)|click/,$=/^(?:focusinfocus|focusoutblur)$/,_=/^([^.]*)(?:\.(.+)|)$/;function ab(){return!0}function bb(){return!1}function cb(){try{return y.activeElement}catch(a){}}m.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m._data(a);if(r){c.handler&&(i=c,c=i.handler,e=i.selector),c.guid||(c.guid=m.guid++),(g=r.events)||(g=r.events={}),(k=r.handle)||(k=r.handle=function(a){return typeof m===K||a&&m.event.triggered===a.type?void 0:m.event.dispatch.apply(k.elem,arguments)},k.elem=a),b=(b||"").match(E)||[""],h=b.length;while(h--)f=_.exec(b[h])||[],o=q=f[1],p=(f[2]||"").split(".").sort(),o&&(j=m.event.special[o]||{},o=(e?j.delegateType:j.bindType)||o,j=m.event.special[o]||{},l=m.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&m.expr.match.needsContext.test(e),namespace:p.join(".")},i),(n=g[o])||(n=g[o]=[],n.delegateCount=0,j.setup&&j.setup.call(a,d,p,k)!==!1||(a.addEventListener?a.addEventListener(o,k,!1):a.attachEvent&&a.attachEvent("on"+o,k))),j.add&&(j.add.call(a,l),l.handler.guid||(l.handler.guid=c.guid)),e?n.splice(n.delegateCount++,0,l):n.push(l),m.event.global[o]=!0);a=null}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m.hasData(a)&&m._data(a);if(r&&(k=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=_.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=m.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,n=k[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),i=f=n.length;while(f--)g=n[f],!e&&q!==g.origType||c&&c.guid!==g.guid||h&&!h.test(g.namespace)||d&&d!==g.selector&&("**"!==d||!g.selector)||(n.splice(f,1),g.selector&&n.delegateCount--,l.remove&&l.remove.call(a,g));i&&!n.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||m.removeEvent(a,o,r.handle),delete k[o])}else for(o in k)m.event.remove(a,o+b[j],c,d,!0);m.isEmptyObject(k)&&(delete r.handle,m._removeData(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,l,n,o=[d||y],p=j.call(b,"type")?b.type:b,q=j.call(b,"namespace")?b.namespace.split("."):[];if(h=l=d=d||y,3!==d.nodeType&&8!==d.nodeType&&!$.test(p+m.event.triggered)&&(p.indexOf(".")>=0&&(q=p.split("."),p=q.shift(),q.sort()),g=p.indexOf(":")<0&&"on"+p,b=b[m.expando]?b:new m.Event(p,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=q.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+q.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:m.makeArray(c,[b]),k=m.event.special[p]||{},e||!k.trigger||k.trigger.apply(d,c)!==!1)){if(!e&&!k.noBubble&&!m.isWindow(d)){for(i=k.delegateType||p,$.test(i+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),l=h;l===(d.ownerDocument||y)&&o.push(l.defaultView||l.parentWindow||a)}n=0;while((h=o[n++])&&!b.isPropagationStopped())b.type=n>1?i:k.bindType||p,f=(m._data(h,"events")||{})[b.type]&&m._data(h,"handle"),f&&f.apply(h,c),f=g&&h[g],f&&f.apply&&m.acceptData(h)&&(b.result=f.apply(h,c),b.result===!1&&b.preventDefault());if(b.type=p,!e&&!b.isDefaultPrevented()&&(!k._default||k._default.apply(o.pop(),c)===!1)&&m.acceptData(d)&&g&&d[p]&&!m.isWindow(d)){l=d[g],l&&(d[g]=null),m.event.triggered=p;try{d[p]()}catch(r){}m.event.triggered=void 0,l&&(d[g]=l)}return b.result}},dispatch:function(a){a=m.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(m._data(this,"events")||{})[a.type]||[],k=m.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=m.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,g=0;while((e=f.handlers[g++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(e.namespace))&&(a.handleObj=e,a.data=e.data,c=((m.event.special[e.origType]||{}).handle||e.handler).apply(f.elem,i),void 0!==c&&(a.result=c)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!=this;i=i.parentNode||this)if(1===i.nodeType&&(i.disabled!==!0||"click"!==a.type)){for(e=[],f=0;h>f;f++)d=b[f],c=d.selector+" ",void 0===e[c]&&(e[c]=d.needsContext?m(c,this).index(i)>=0:m.find(c,this,null,[i]).length),e[c]&&e.push(d);e.length&&g.push({elem:i,handlers:e})}return h]","i"),hb=/^\s+/,ib=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,jb=/<([\w:]+)/,kb=/\s*$/g,rb={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3,"","
"],_default:k.htmlSerialize?[0,"",""]:[1,"X
","
"]},sb=db(y),tb=sb.appendChild(y.createElement("div"));rb.optgroup=rb.option,rb.tbody=rb.tfoot=rb.colgroup=rb.caption=rb.thead,rb.th=rb.td;function ub(a,b){var c,d,e=0,f=typeof a.getElementsByTagName!==K?a.getElementsByTagName(b||"*"):typeof a.querySelectorAll!==K?a.querySelectorAll(b||"*"):void 0;if(!f)for(f=[],c=a.childNodes||a;null!=(d=c[e]);e++)!b||m.nodeName(d,b)?f.push(d):m.merge(f,ub(d,b));return void 0===b||b&&m.nodeName(a,b)?m.merge([a],f):f}function vb(a){W.test(a.type)&&(a.defaultChecked=a.checked)}function wb(a,b){return m.nodeName(a,"table")&&m.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function xb(a){return a.type=(null!==m.find.attr(a,"type"))+"/"+a.type,a}function yb(a){var b=pb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function zb(a,b){for(var c,d=0;null!=(c=a[d]);d++)m._data(c,"globalEval",!b||m._data(b[d],"globalEval"))}function Ab(a,b){if(1===b.nodeType&&m.hasData(a)){var c,d,e,f=m._data(a),g=m._data(b,f),h=f.events;if(h){delete g.handle,g.events={};for(c in h)for(d=0,e=h[c].length;e>d;d++)m.event.add(b,c,h[c][d])}g.data&&(g.data=m.extend({},g.data))}}function Bb(a,b){var c,d,e;if(1===b.nodeType){if(c=b.nodeName.toLowerCase(),!k.noCloneEvent&&b[m.expando]){e=m._data(b);for(d in e.events)m.removeEvent(b,d,e.handle);b.removeAttribute(m.expando)}"script"===c&&b.text!==a.text?(xb(b).text=a.text,yb(b)):"object"===c?(b.parentNode&&(b.outerHTML=a.outerHTML),k.html5Clone&&a.innerHTML&&!m.trim(b.innerHTML)&&(b.innerHTML=a.innerHTML)):"input"===c&&W.test(a.type)?(b.defaultChecked=b.checked=a.checked,b.value!==a.value&&(b.value=a.value)):"option"===c?b.defaultSelected=b.selected=a.defaultSelected:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}}m.extend({clone:function(a,b,c){var d,e,f,g,h,i=m.contains(a.ownerDocument,a);if(k.html5Clone||m.isXMLDoc(a)||!gb.test("<"+a.nodeName+">")?f=a.cloneNode(!0):(tb.innerHTML=a.outerHTML,tb.removeChild(f=tb.firstChild)),!(k.noCloneEvent&&k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||m.isXMLDoc(a)))for(d=ub(f),h=ub(a),g=0;null!=(e=h[g]);++g)d[g]&&Bb(e,d[g]);if(b)if(c)for(h=h||ub(a),d=d||ub(f),g=0;null!=(e=h[g]);g++)Ab(e,d[g]);else Ab(a,f);return d=ub(f,"script"),d.length>0&&zb(d,!i&&ub(a,"script")),d=h=e=null,f},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,l,n=a.length,o=db(b),p=[],q=0;n>q;q++)if(f=a[q],f||0===f)if("object"===m.type(f))m.merge(p,f.nodeType?[f]:f);else if(lb.test(f)){h=h||o.appendChild(b.createElement("div")),i=(jb.exec(f)||["",""])[1].toLowerCase(),l=rb[i]||rb._default,h.innerHTML=l[1]+f.replace(ib,"<$1>")+l[2],e=l[0];while(e--)h=h.lastChild;if(!k.leadingWhitespace&&hb.test(f)&&p.push(b.createTextNode(hb.exec(f)[0])),!k.tbody){f="table"!==i||kb.test(f)?""!==l[1]||kb.test(f)?0:h:h.firstChild,e=f&&f.childNodes.length;while(e--)m.nodeName(j=f.childNodes[e],"tbody")&&!j.childNodes.length&&f.removeChild(j)}m.merge(p,h.childNodes),h.textContent="";while(h.firstChild)h.removeChild(h.firstChild);h=o.lastChild}else p.push(b.createTextNode(f));h&&o.removeChild(h),k.appendChecked||m.grep(ub(p,"input"),vb),q=0;while(f=p[q++])if((!d||-1===m.inArray(f,d))&&(g=m.contains(f.ownerDocument,f),h=ub(o.appendChild(f),"script"),g&&zb(h),c)){e=0;while(f=h[e++])ob.test(f.type||"")&&c.push(f)}return h=null,o},cleanData:function(a,b){for(var d,e,f,g,h=0,i=m.expando,j=m.cache,l=k.deleteExpando,n=m.event.special;null!=(d=a[h]);h++)if((b||m.acceptData(d))&&(f=d[i],g=f&&j[f])){if(g.events)for(e in g.events)n[e]?m.event.remove(d,e):m.removeEvent(d,e,g.handle);j[f]&&(delete j[f],l?delete d[i]:typeof d.removeAttribute!==K?d.removeAttribute(i):d[i]=null,c.push(f))}}}),m.fn.extend({text:function(a){return V(this,function(a){return void 0===a?m.text(this):this.empty().append((this[0]&&this[0].ownerDocument||y).createTextNode(a))},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?m.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||m.cleanData(ub(c)),c.parentNode&&(b&&m.contains(c.ownerDocument,c)&&zb(ub(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++){1===a.nodeType&&m.cleanData(ub(a,!1));while(a.firstChild)a.removeChild(a.firstChild);a.options&&m.nodeName(a,"select")&&(a.options.length=0)}return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return m.clone(this,a,b)})},html:function(a){return V(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a)return 1===b.nodeType?b.innerHTML.replace(fb,""):void 0;if(!("string"!=typeof a||mb.test(a)||!k.htmlSerialize&&gb.test(a)||!k.leadingWhitespace&&hb.test(a)||rb[(jb.exec(a)||["",""])[1].toLowerCase()])){a=a.replace(ib,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(m.cleanData(ub(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,m.cleanData(ub(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,n=this,o=l-1,p=a[0],q=m.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&nb.test(p))return this.each(function(c){var d=n.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(i=m.buildFragment(a,this[0].ownerDocument,!1,this),c=i.firstChild,1===i.childNodes.length&&(i=c),c)){for(g=m.map(ub(i,"script"),xb),f=g.length;l>j;j++)d=i,j!==o&&(d=m.clone(d,!0,!0),f&&m.merge(g,ub(d,"script"))),b.call(this[j],d,j);if(f)for(h=g[g.length-1].ownerDocument,m.map(g,yb),j=0;f>j;j++)d=g[j],ob.test(d.type||"")&&!m._data(d,"globalEval")&&m.contains(h,d)&&(d.src?m._evalUrl&&m._evalUrl(d.src):m.globalEval((d.text||d.textContent||d.innerHTML||"").replace(qb,"")));i=c=null}return this}}),m.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){m.fn[a]=function(a){for(var c,d=0,e=[],g=m(a),h=g.length-1;h>=d;d++)c=d===h?this:this.clone(!0),m(g[d])[b](c),f.apply(e,c.get());return this.pushStack(e)}});var Cb,Db={};function Eb(b,c){var d,e=m(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:m.css(e[0],"display");return e.detach(),f}function Fb(a){var b=y,c=Db[a];return c||(c=Eb(a,b),"none"!==c&&c||(Cb=(Cb||m("