├── test ├── config.json └── classes │ └── game.test.js ├── index.js ├── src ├── client │ ├── favicon.ico │ ├── img │ │ ├── ptwulogo.png │ │ └── pokerBanner.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── mstile-150x150.png │ ├── apple-touch-icon.png │ ├── android-chrome-192x192.png │ ├── android-chrome-384x384.png │ ├── css │ │ ├── font │ │ │ ├── Metropolis-Bold.otf │ │ │ ├── Metropolis-Thin.otf │ │ │ ├── CircularStd-Bold.otf │ │ │ ├── CircularStd-Bold.woff │ │ │ ├── CircularStd-Book.woff │ │ │ ├── CircularStd-Medium.otf │ │ │ ├── Metropolis-Black.otf │ │ │ ├── Metropolis-Light.otf │ │ │ ├── Metropolis-Medium.otf │ │ │ ├── Metropolis-Regular.otf │ │ │ ├── roboto │ │ │ │ ├── Roboto-Bold.eot │ │ │ │ ├── Roboto-Bold.ttf │ │ │ │ ├── Roboto-Thin.eot │ │ │ │ ├── Roboto-Thin.ttf │ │ │ │ ├── Roboto-Bold.woff │ │ │ │ ├── Roboto-Bold.woff2 │ │ │ │ ├── Roboto-Light.eot │ │ │ │ ├── Roboto-Light.ttf │ │ │ │ ├── Roboto-Light.woff │ │ │ │ ├── Roboto-Medium.eot │ │ │ │ ├── Roboto-Medium.ttf │ │ │ │ ├── Roboto-Thin.woff │ │ │ │ ├── Roboto-Thin.woff2 │ │ │ │ ├── Roboto-Light.woff2 │ │ │ │ ├── Roboto-Medium.woff │ │ │ │ ├── Roboto-Medium.woff2 │ │ │ │ ├── Roboto-Regular.eot │ │ │ │ ├── Roboto-Regular.ttf │ │ │ │ ├── Roboto-Regular.woff │ │ │ │ └── Roboto-Regular.woff2 │ │ │ ├── CircularStd-Medium.woff │ │ │ ├── Metropolis-ExtraBold.otf │ │ │ ├── Metropolis-SemiBold.otf │ │ │ ├── Metropolis-BlackItalic.otf │ │ │ ├── Metropolis-BoldItalic.otf │ │ │ ├── Metropolis-ExtraLight.otf │ │ │ ├── Metropolis-LightItalic.otf │ │ │ ├── Metropolis-MediumItalic.otf │ │ │ ├── Metropolis-ThinItalic.otf │ │ │ ├── Metropolis-RegularItalic.otf │ │ │ ├── Metropolis-SemiBoldItalic.otf │ │ │ ├── Metropolis-ExtraBoldItalic.otf │ │ │ ├── Metropolis-ExtraLightItalic.otf │ │ │ └── SIL Open Font License.txt │ │ └── index.css │ ├── font │ │ └── roboto │ │ │ ├── Roboto-Bold.eot │ │ │ ├── Roboto-Bold.ttf │ │ │ ├── Roboto-Bold.woff │ │ │ ├── Roboto-Light.eot │ │ │ ├── Roboto-Light.ttf │ │ │ ├── Roboto-Thin.eot │ │ │ ├── Roboto-Thin.ttf │ │ │ ├── Roboto-Thin.woff │ │ │ ├── Roboto-Bold.woff2 │ │ │ ├── Roboto-Light.woff │ │ │ ├── Roboto-Light.woff2 │ │ │ ├── Roboto-Medium.eot │ │ │ ├── Roboto-Medium.ttf │ │ │ ├── Roboto-Medium.woff │ │ │ ├── Roboto-Medium.woff2 │ │ │ ├── Roboto-Regular.eot │ │ │ ├── Roboto-Regular.ttf │ │ │ ├── Roboto-Regular.woff │ │ │ ├── Roboto-Thin.woff2 │ │ │ └── Roboto-Regular.woff2 │ ├── browserconfig.xml │ ├── site.webmanifest │ ├── safari-pinned-tab.svg │ ├── index.html │ ├── main.js │ └── js │ │ └── jquery-2.1.4.min.js ├── classes │ ├── card.js │ ├── player.js │ ├── deck.js │ └── game.js └── app.js ├── .gitignore ├── package.json ├── .github └── workflows │ └── main.yml ├── LICENSE └── README.md /test/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": false 3 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | exports.Game = require('./src/classes/game.js'); -------------------------------------------------------------------------------- /src/client/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/favicon.ico -------------------------------------------------------------------------------- /src/client/img/ptwulogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/img/ptwulogo.png -------------------------------------------------------------------------------- /src/client/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/favicon-16x16.png -------------------------------------------------------------------------------- /src/client/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/favicon-32x32.png -------------------------------------------------------------------------------- /src/client/mstile-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/mstile-150x150.png -------------------------------------------------------------------------------- /src/client/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/apple-touch-icon.png -------------------------------------------------------------------------------- /src/client/img/pokerBanner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/img/pokerBanner.png -------------------------------------------------------------------------------- /src/client/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/android-chrome-192x192.png -------------------------------------------------------------------------------- /src/client/android-chrome-384x384.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/android-chrome-384x384.png -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-Bold.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-Thin.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-Thin.otf -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Bold.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Bold.eot -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Bold.ttf -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Bold.woff -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Light.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Light.eot -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Light.ttf -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Thin.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Thin.eot -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Thin.ttf -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Thin.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Thin.woff -------------------------------------------------------------------------------- /src/client/css/font/CircularStd-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/CircularStd-Bold.otf -------------------------------------------------------------------------------- /src/client/css/font/CircularStd-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/CircularStd-Bold.woff -------------------------------------------------------------------------------- /src/client/css/font/CircularStd-Book.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/CircularStd-Book.woff -------------------------------------------------------------------------------- /src/client/css/font/CircularStd-Medium.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/CircularStd-Medium.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-Black.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-Black.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-Light.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-Light.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-Medium.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-Medium.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-Regular.otf -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Bold.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Bold.eot -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Bold.ttf -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Thin.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Thin.eot -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Thin.ttf -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Bold.woff2 -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Light.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Light.woff -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Light.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Light.woff2 -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Medium.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Medium.eot -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Medium.ttf -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Medium.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Medium.woff -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Medium.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Medium.woff2 -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Regular.eot -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Regular.ttf -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Regular.woff -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Thin.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Thin.woff2 -------------------------------------------------------------------------------- /src/client/css/font/CircularStd-Medium.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/CircularStd-Medium.woff -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-ExtraBold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-ExtraBold.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-SemiBold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-SemiBold.otf -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Bold.woff -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Bold.woff2 -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Light.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Light.eot -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Light.ttf -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Light.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Light.woff -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Medium.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Medium.eot -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Medium.ttf -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Thin.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Thin.woff -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Thin.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Thin.woff2 -------------------------------------------------------------------------------- /src/client/font/roboto/Roboto-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/font/roboto/Roboto-Regular.woff2 -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-BlackItalic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-BlackItalic.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-BoldItalic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-BoldItalic.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-ExtraLight.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-ExtraLight.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-LightItalic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-LightItalic.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-MediumItalic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-MediumItalic.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-ThinItalic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-ThinItalic.otf -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Light.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Light.woff2 -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Medium.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Medium.woff -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Medium.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Medium.woff2 -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Regular.eot -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Regular.ttf -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Regular.woff -------------------------------------------------------------------------------- /src/client/css/font/roboto/Roboto-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/roboto/Roboto-Regular.woff2 -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-RegularItalic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-RegularItalic.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-SemiBoldItalic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-SemiBoldItalic.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-ExtraBoldItalic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-ExtraBoldItalic.otf -------------------------------------------------------------------------------- /src/client/css/font/Metropolis-ExtraLightItalic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptwu/distributed-texasholdem/HEAD/src/client/css/font/Metropolis-ExtraLightItalic.otf -------------------------------------------------------------------------------- /src/client/browserconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #da532c 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | **/node_modules 3 | **/bower_components 4 | 5 | # Cache & History 6 | .npm 7 | .eslintcache 8 | .firebase/ 9 | .node_repl_history 10 | .mypy_cache/ 11 | *.tgz 12 | 13 | # Logs 14 | logs 15 | *.log 16 | firebase-debug.log* 17 | npm-debug.log* 18 | yarn-debug.log* 19 | yarn-error.log* 20 | 21 | # IDE Configs 22 | **/.vs 23 | **/.vscode 24 | *.code-workspace 25 | **/.idea 26 | 27 | # Misc 28 | .DS_Store 29 | /*.env 30 | 31 | .prettierrc -------------------------------------------------------------------------------- /src/client/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "short_name": "", 4 | "icons": [ 5 | { 6 | "src": "/android-chrome-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | }, 10 | { 11 | "src": "/android-chrome-384x384.png", 12 | "sizes": "384x384", 13 | "type": "image/png" 14 | } 15 | ], 16 | "theme_color": "#ffffff", 17 | "background_color": "#ffffff", 18 | "display": "standalone" 19 | } 20 | -------------------------------------------------------------------------------- /src/client/safari-pinned-tab.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | Created by potrace 1.11, written by Peter Selinger 2001-2013 9 | 10 | 12 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/classes/card.js: -------------------------------------------------------------------------------- 1 | //representation of a card in a standard 52 deck 2 | const Card = function (value, suit) { 3 | this.value = value; 4 | this.suit = suit; 5 | 6 | const constructor = (function () {})(this); 7 | 8 | this.compare = (card) => { 9 | if (this.value < card.getValue()) return -1; 10 | if (this.value == card.getValue()) return 0; 11 | return 1; 12 | }; 13 | 14 | this.isGreater = (card) => { 15 | return this.value > card.getValue() ? true : false; 16 | }; 17 | 18 | this.getValue = () => { 19 | return this.value; 20 | }; 21 | 22 | this.getSuit = () => { 23 | return this.suit; 24 | }; 25 | 26 | this.print = () => console.log(this.getValue() + ' of ' + this.getSuit()); 27 | }; 28 | 29 | module.exports = Card; 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "distributed-texasholdem", 3 | "version": "1.0.0", 4 | "description": "distributed texas hold 'em poker made using socket.io, Node, and express", 5 | "main": "index.js", 6 | "repository": "https://github.com/ptwu/distributed-texasholdem.git", 7 | "author": "Peter Wu ", 8 | "license": "MIT", 9 | "scripts": { 10 | "start": "node ./src/app.js", 11 | "dev": "nodemon ./src/app.js", 12 | "test": "jest --config=test/config.json" 13 | }, 14 | "dependencies": { 15 | "cluster": "^0.7.7", 16 | "express": "^4.17.1", 17 | "heroku": "^7.39.3", 18 | "jshint": "^2.9.3", 19 | "pokersolver": "^2.1.3", 20 | "socket.io": "^2.3.0" 21 | }, 22 | "devDependencies": { 23 | "jest": "^26.0.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: CI 4 | 5 | # Controls when the action will run. Triggers the workflow on push or pull request 6 | # events but only for the master branch 7 | on: 8 | push: 9 | branches: [ master ] 10 | pull_request: 11 | branches: [ master ] 12 | 13 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 14 | jobs: 15 | # This workflow contains a single job called "build" 16 | build: 17 | # The type of runner that the job will run on 18 | runs-on: ubuntu-latest 19 | 20 | # Steps represent a sequence of tasks that will be executed as part of the job 21 | steps: 22 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 23 | - uses: actions/checkout@v2 24 | 25 | - name: Set up Node 26 | uses: actions/setup-node@v1 27 | 28 | - name: Yarn Install 29 | run: yarn install 30 | 31 | - name: Run Tests 32 | run: yarn test 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Peter Wu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Multiplayer Texas Hold 'Em 2 | [![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/ptwu/distributed-texasholdem/blob/master/LICENSE) 3 | ![1.0.0](https://img.shields.io/badge/version-1.0.0-blue.svg) 4 | ![CI](https://github.com/ptwu/distributed-texasholdem/workflows/CI/badge.svg) 5 | 6 | Play at https://distributed-texasholdem.onrender.com. Note that the site has to cold start because I'm a 7 | college student who doesn't want to pay for anything beyond the free plan. 8 | 9 | Using `socket.io`, `Node.js`, and `express` to make a distributed poker game. Allows for multiple 10 | gameplay rooms simultaneously across different devices. 11 | 12 | ![Image of Distributed Texas Hold Em Gameplay](https://i.imgur.com/eGj6iHU.png) 13 | ![Image of Distributed Texas Hold Em Lobby](https://i.imgur.com/TCusHG0.png) 14 | 15 | ## Commands 16 | `yarn install` installs all the dependencies required to run the webapp. 17 | 18 | `yarn dev` starts the game with hot reloading provided by `nodemon`. 19 | - The game will be viewable by navigating to `localhost:3000`. 20 | 21 | `yarn start` runs the Node server without hot reloading. Intended for deployment use. 22 | 23 | `yarn test` evaluates the unit tests located in test/classes/. 24 | -------------------------------------------------------------------------------- /src/classes/player.js: -------------------------------------------------------------------------------- 1 | const Player = function (playerName, socket, debug) { 2 | this.username = playerName; 3 | this.cards = []; 4 | this.socket = socket; 5 | this.currentCard = null; 6 | this.money = 100; 7 | this.buyIns = 0; 8 | this.status = ''; 9 | this.blindValue = ''; 10 | this.dealer = false; 11 | this.allIn = false; 12 | this.goAgainStatus = false; 13 | this.debug = debug || false; 14 | 15 | this.addCard = (card) => { 16 | this.cards.push(card); 17 | }; 18 | 19 | this.log = () => { 20 | if (this.debug) { 21 | console.log(...arguments); 22 | } 23 | }; 24 | 25 | this.setStatus = (data) => (this.status = data); 26 | this.setBlind = (data) => (this.blindValue = data); 27 | this.setDealer = (data) => (this.dealer = data); 28 | this.getUsername = () => { 29 | return this.username; 30 | }; 31 | this.getBuyIns = () => { 32 | return this.buyIns; 33 | }; 34 | this.getMoney = () => { 35 | return this.money; 36 | }; 37 | this.getStatus = () => { 38 | return this.status; 39 | }; 40 | this.getBlind = () => { 41 | return this.blindValue; 42 | }; 43 | this.getDealer = () => { 44 | return this.dealer; 45 | }; 46 | 47 | this.emit = (eventName, payload) => { 48 | this.socket.emit(eventName, payload); 49 | }; 50 | }; 51 | 52 | module.exports = Player; 53 | -------------------------------------------------------------------------------- /src/classes/deck.js: -------------------------------------------------------------------------------- 1 | const Card = require('./card'); 2 | 3 | // representation of a deck of standard (52) playing cards 4 | const Deck = function () { 5 | this.cards = []; 6 | 7 | const constructor = (function (deck) { 8 | const suits = ['♠', '♥', '♦', '♣']; 9 | for (let i = 0; i < suits.length; i++) { 10 | for (let j = 1; j <= 13; j++) { 11 | if (j === 1) { 12 | deck.cards.push(new Card('A', suits[i])); 13 | } else if (j === 11) { 14 | deck.cards.push(new Card('J', suits[i])); 15 | } else if (j === 12) { 16 | deck.cards.push(new Card('Q', suits[i])); 17 | } else if (j === 13) { 18 | deck.cards.push(new Card('K', suits[i])); 19 | } else { 20 | deck.cards.push(new Card(j, suits[i])); 21 | } 22 | } 23 | } 24 | })(this); 25 | 26 | this.shuffle = () => { 27 | this.cards = []; 28 | const suits = ['♠', '♥', '♦', '♣']; 29 | for (let i = 0; i < suits.length; i++) { 30 | for (let j = 1; j <= 13; j++) { 31 | if (j === 1) { 32 | this.cards.push(new Card('A', suits[i])); 33 | } else if (j === 11) { 34 | this.cards.push(new Card('J', suits[i])); 35 | } else if (j === 12) { 36 | this.cards.push(new Card('Q', suits[i])); 37 | } else if (j === 13) { 38 | this.cards.push(new Card('K', suits[i])); 39 | } else { 40 | this.cards.push(new Card(j, suits[i])); 41 | } 42 | } 43 | } 44 | }; 45 | 46 | this.dealRandomCard = () => { 47 | const index = Math.floor(Math.random() * this.cards.length); 48 | value = this.cards[index]; 49 | this.cards.splice(index, 1); 50 | return value; 51 | }; 52 | }; 53 | 54 | module.exports = Deck; 55 | -------------------------------------------------------------------------------- /src/client/css/index.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: Metropolis-Medium; 3 | src: url("font/Metropolis-Medium.otf"), 4 | url("font/Metropolis-Medium.otf") format("opentype"); 5 | } 6 | 7 | @font-face { 8 | font-family: Metropolis-Bold; 9 | font-weight: bold; 10 | src: url("font/Metropolis-Bold.otf"), 11 | url("font/Metropolis-Bold.otf") format("opentype"); 12 | } 13 | 14 | #mainContent { 15 | height: 100%; 16 | margin-left: 10px; 17 | margin-right: 10px; 18 | } 19 | 20 | #gameDiv { 21 | margin-left: 10px; 22 | margin-right: 10px; 23 | min-height: 95vh; 24 | } 25 | 26 | html, 27 | body, 28 | .login-box { 29 | background: #2e64bc; 30 | height: 95%; 31 | } 32 | 33 | .card { 34 | margin-right: auto !important; 35 | margin-left: auto !important; 36 | } 37 | 38 | body { 39 | font-family: Metropolis-Medium; 40 | } 41 | 42 | code { 43 | font-size: 24px; 44 | background-color: #ebebeb; 45 | } 46 | 47 | .playingCard_black { 48 | float: left; 49 | border: 5px solid black; 50 | background-color: white; 51 | border-radius: 5px; 52 | height: 135px; 53 | width: 90px; 54 | color: black; 55 | padding: 5px; 56 | margin: 8px; 57 | font-size: 28px; 58 | } 59 | 60 | #usernamesMoney { 61 | font-size: 30px; 62 | min-height: 219px; 63 | } 64 | 65 | .playingCard_red { 66 | float: left; 67 | border: 5px solid black; 68 | background-color: white; 69 | border-radius: 5px; 70 | height: 135px; 71 | width: 90px; 72 | color: red; 73 | padding: 5px; 74 | margin: 8px; 75 | font-size: 28px; 76 | } 77 | 78 | .menuButtons { 79 | zoom: 0.8; 80 | margin: 2px; 81 | } 82 | 83 | .card-content { 84 | font-size: 16px; 85 | } 86 | 87 | .theirTurn { 88 | border: 5px solid yellow; 89 | } 90 | 91 | .playingCard_red_opponent { 92 | float: left; 93 | border: 5px solid black; 94 | background-color: white; 95 | border-radius: 5px; 96 | height: 84px; 97 | width: 60px; 98 | color: red; 99 | padding: 5px; 100 | margin: 4px; 101 | font-size: 18px; 102 | } 103 | 104 | .playingCard_black_opponent { 105 | float: left; 106 | border: 5px solid black; 107 | background-color: white; 108 | border-radius: 5px; 109 | height: 84px; 110 | width: 60px; 111 | color: black; 112 | padding: 5px; 113 | margin: 4px; 114 | font-size: 18px; 115 | } 116 | 117 | .blankCard { 118 | float: left; 119 | background: repeating-linear-gradient( 120 | 45deg, 121 | #606dbc, 122 | #606dbc 10px, 123 | #465298 10px, 124 | #465298 20px 125 | ); 126 | border: 5px solid black; 127 | border-radius: 5px; 128 | height: 84px; 129 | width: 60px; 130 | padding: 10px; 131 | margin: 4px; 132 | } 133 | 134 | .selected { 135 | background: grey; 136 | border: 2px solid red; 137 | } 138 | 139 | #divStart { 140 | text-align: center; 141 | } 142 | 143 | .modal { 144 | position: absolute; 145 | } 146 | 147 | .toast { 148 | position: relative; 149 | z-index: -1 !important; 150 | } 151 | -------------------------------------------------------------------------------- /src/client/css/font/SIL Open Font License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Chris Simpson, with Reserved Font Name: "Metropolis". 2 | 3 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 4 | This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL 5 | 6 | ----------------------------------------------------------- 7 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 8 | ----------------------------------------------------------- 9 | 10 | PREAMBLE 11 | The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others. 12 | 13 | The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives. 14 | 15 | DEFINITIONS 16 | "Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation. 17 | 18 | "Reserved Font Name" refers to any names specified as such after the copyright statement(s). 19 | 20 | "Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s). 21 | 22 | "Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment. 23 | 24 | "Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software. 25 | 26 | PERMISSION & CONDITIONS 27 | Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions: 28 | 29 | 1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself. 30 | 31 | 2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user. 32 | 33 | 3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users. 34 | 35 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission. 36 | 37 | 5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software. 38 | 39 | TERMINATION 40 | This license becomes null and void if any of the above conditions are not met. 41 | 42 | DISCLAIMER 43 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. -------------------------------------------------------------------------------- /src/app.js: -------------------------------------------------------------------------------- 1 | // server-side socket.io backend event handling 2 | const express = require('express'); 3 | const http = require('http'); 4 | const socketio = require('socket.io'); 5 | const Game = require('./classes/game.js'); 6 | 7 | const app = express(); 8 | const server = http.createServer(app); 9 | const io = socketio(server); 10 | 11 | const PORT = process.env.PORT || 3000; 12 | 13 | app.use('/', express.static(__dirname + '/client')); 14 | 15 | let rooms = []; 16 | 17 | io.on('connection', (socket) => { 18 | console.log('new connection ', socket.id); 19 | socket.on('host', (data) => { 20 | if (data.username == '' || data.username.length > 12) { 21 | socket.emit('hostRoom', undefined); 22 | } else { 23 | let code; 24 | do { 25 | code = 26 | '' + 27 | Math.floor(Math.random() * 10) + 28 | Math.floor(Math.random() * 10) + 29 | Math.floor(Math.random() * 10) + 30 | Math.floor(Math.random() * 10); 31 | } while (rooms.length != 0 && rooms.some((r) => r.getCode() === code)); 32 | const game = new Game(code, data.username); 33 | rooms.push(game); 34 | game.addPlayer(data.username, socket); 35 | game.emitPlayers('hostRoom', { 36 | code: code, 37 | players: game.getPlayersArray(), 38 | }); 39 | } 40 | }); 41 | 42 | socket.on('join', (data) => { 43 | const game = rooms.find((r) => r.getCode() === data.code); 44 | if ( 45 | game == undefined || 46 | game.getPlayersArray().some((p) => p == data.username) || 47 | data.username == undefined || 48 | data.username.length > 12 49 | ) { 50 | socket.emit('joinRoom', undefined); 51 | } else { 52 | game.addPlayer(data.username, socket); 53 | rooms = rooms.map((r) => (r.getCode() === data.code ? game : r)); 54 | game.emitPlayers('joinRoom', { 55 | host: game.getHostName(), 56 | players: game.getPlayersArray(), 57 | }); 58 | game.emitPlayers('hostRoom', { 59 | code: data.code, 60 | players: game.getPlayersArray(), 61 | }); 62 | } 63 | }); 64 | 65 | socket.on('startGame', (data) => { 66 | const game = rooms.find((r) => r.getCode() == data.code); 67 | if (game == undefined) { 68 | socket.emit('gameBegin', undefined); 69 | } else { 70 | game.emitPlayers('gameBegin', { code: data.code }); 71 | game.startGame(); 72 | } 73 | }); 74 | 75 | socket.on('evaluatePossibleMoves', () => { 76 | const game = rooms.find( 77 | (r) => r.findPlayer(socket.id).socket.id === socket.id 78 | ); 79 | if (game.roundInProgress) { 80 | const possibleMoves = game.getPossibleMoves(socket); 81 | socket.emit('displayPossibleMoves', possibleMoves); 82 | } 83 | }); 84 | 85 | socket.on('raiseModalData', () => { 86 | const game = rooms.find( 87 | (r) => r.findPlayer(socket.id).socket.id === socket.id 88 | ); 89 | if (game != undefined) { 90 | socket.emit('updateRaiseModal', { 91 | topBet: game.getCurrentTopBet(), 92 | usernameMoney: 93 | game.getPlayerBetInStage(game.findPlayer(socket.id)) + 94 | game.findPlayer(socket.id).getMoney(), 95 | }); 96 | } 97 | }); 98 | 99 | socket.on('startNextRound', () => { 100 | const game = rooms.find( 101 | (r) => r.findPlayer(socket.id).socket.id === socket.id 102 | ); 103 | if (game != undefined) { 104 | if (game.roundInProgress === false) { 105 | game.startNewRound(); 106 | } 107 | } 108 | }); 109 | 110 | // precondition: user must be able to make the move in the first place. 111 | socket.on('moveMade', (data) => { 112 | // worst case complexity O(num_rooms * num_players_in_room) 113 | const game = rooms.find( 114 | (r) => r.findPlayer(socket.id).socket.id === socket.id 115 | ); 116 | 117 | if (game != undefined) { 118 | if (data.move == 'fold') { 119 | game.fold(socket); 120 | } else if (data.move == 'check') { 121 | game.check(socket); 122 | } else if (data.move == 'bet') { 123 | game.bet(socket, data.bet); 124 | } else if (data.move == 'call') { 125 | game.call(socket); 126 | } else if (data.move == 'raise') { 127 | game.raise(socket, data.bet); 128 | } 129 | } else { 130 | console.log("ERROR: can't find game!!!"); 131 | } 132 | }); 133 | 134 | socket.on('disconnect', () => { 135 | const game = rooms.find( 136 | (r) => r.findPlayer(socket.id).socket.id === socket.id 137 | ); 138 | if (game != undefined) { 139 | const player = game.findPlayer(socket.id); 140 | game.disconnectPlayer(player); 141 | if (game.players.length == 0) { 142 | if (this.rooms != undefined && this.rooms.length !== 0) { 143 | this.rooms = this.rooms.filter((a) => a != game); 144 | } 145 | } 146 | } 147 | }); 148 | }); 149 | 150 | server.listen(PORT, () => console.log(`hosting on port ${PORT}`)); 151 | -------------------------------------------------------------------------------- /src/client/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Texas Hold 'Em - Distributed 15 | 16 | 17 | 18 |
19 | 25 |
26 |
27 |

Texas Hold 'Em Game

28 |
29 |
30 |
31 |
32 | 33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | 41 |
42 |
43 |
44 |
45 | 46 |
47 | 48 |
49 | 51 |
52 | 53 |
54 | 56 |
57 |
58 |
59 |
60 |
61 |
62 | 63 | 64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | 93 |
94 | 114 | 115 | 116 | 140 | 141 | 162 | 163 | 183 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | -------------------------------------------------------------------------------- /test/classes/game.test.js: -------------------------------------------------------------------------------- 1 | const Game = require('../../src/classes/game.js'); 2 | const events = require('events'); 3 | 4 | test('Test call until fold then check', () => { 5 | const game = new Game('best-game', '1'); 6 | game.smallBlind = 5; 7 | game.bigBlind = 10; 8 | 9 | // Mock socket 10 | const sock1 = new events.EventEmitter(); 11 | sock1.id = 1; 12 | const sock2 = new events.EventEmitter(); 13 | sock2.id = 2; 14 | 15 | const p1 = game.addPlayer("1", sock1); 16 | expect(p1.money).toBe(100); 17 | const p2 = game.addPlayer("2", sock2); 18 | expect(p2.money).toBe(100); 19 | 20 | expect(game.findPlayer(1)).toBe(p1); 21 | expect(game.findPlayer(2)).toBe(p2); 22 | 23 | expect(game.players.length).toBe(2); 24 | 25 | expect(game.roundNum).toBe(0); 26 | expect(game.roundData.bets.length).toBe(0); 27 | game.startGame(); 28 | expect(game.roundNum).toBe(1); 29 | expect(game.roundData.bets.length).toBeGreaterThan(0); 30 | 31 | const smallPlayer = game.players[game.roundData.smallBlind]; 32 | const bigPlayer = game.players[game.roundData.bigBlind]; 33 | 34 | // Test parametable small/big blind 35 | expect(smallPlayer.money).toBe(95); 36 | expect(bigPlayer.money).toBe(90); 37 | 38 | expect(smallPlayer.status).toBe('Their Turn'); 39 | 40 | // Pre-Flop 41 | game.call(smallPlayer.socket); 42 | expect(game.roundNum).toBe(1); 43 | expect(game.roundData.bets.length).toBe(1); 44 | 45 | // Flop 46 | game.check(bigPlayer.socket); 47 | game.check(smallPlayer.socket); 48 | expect(game.roundNum).toBe(1); 49 | expect(game.roundData.bets.length).toBe(2); 50 | 51 | // Turn 52 | game.check(bigPlayer.socket); 53 | game.check(smallPlayer.socket); 54 | expect(game.roundNum).toBe(1); 55 | expect(game.roundData.bets.length).toBe(3); 56 | 57 | // River 58 | game.check(bigPlayer.socket); 59 | game.check(smallPlayer.socket); 60 | expect(game.roundNum).toBe(1); 61 | expect(game.roundData.bets.length).toBe(4); 62 | 63 | // End of game 64 | game.check(bigPlayer.socket); 65 | game.check(smallPlayer.socket); 66 | expect(game.roundNum).toBe(1); 67 | }); 68 | 69 | test('Test raise more than possessed', () => { 70 | const game = new Game('best-game', '1'); 71 | game.smallBlind = 5; 72 | game.bigBlind = 10; 73 | 74 | // Mock socket 75 | const sock1 = new events.EventEmitter(); 76 | sock1.id = 1; 77 | const sock2 = new events.EventEmitter(); 78 | sock2.id = 2; 79 | 80 | const p1 = game.addPlayer("1", sock1); 81 | expect(p1.money).toBe(100); 82 | const p2 = game.addPlayer("2", sock2); 83 | expect(p2.money).toBe(100); 84 | 85 | expect(game.findPlayer(1)).toBe(p1); 86 | expect(game.findPlayer(2)).toBe(p2); 87 | 88 | expect(game.players.length).toBe(2); 89 | 90 | expect(game.roundNum).toBe(0); 91 | expect(game.roundData.bets.length).toBe(0); 92 | game.startGame(); 93 | expect(game.roundNum).toBe(1); 94 | expect(game.roundData.bets.length).toBeGreaterThan(0); 95 | 96 | const smallPlayer = game.players[game.roundData.smallBlind]; 97 | const bigPlayer = game.players[game.roundData.bigBlind]; 98 | 99 | // Test parametable small/big blind 100 | expect(smallPlayer.money).toBe(95); 101 | expect(bigPlayer.money).toBe(90); 102 | 103 | expect(smallPlayer.status).toBe('Their Turn'); 104 | 105 | // Pre-Flop 106 | expect(game.call(smallPlayer.socket)).toBe(true); 107 | expect(game.roundNum).toBe(1); 108 | expect(game.roundData.bets.length).toBe(1); 109 | 110 | // Flop 111 | expect(game.raise(bigPlayer.socket, 1000)).not.toBe(true); 112 | }); 113 | 114 | test('Test bet more than possessed', () => { 115 | const game = new Game('best-game', '1'); 116 | game.smallBlind = 5; 117 | game.bigBlind = 10; 118 | 119 | // Mock socket 120 | const sock1 = new events.EventEmitter(); 121 | sock1.id = 1; 122 | const sock2 = new events.EventEmitter(); 123 | sock2.id = 2; 124 | 125 | const p1 = game.addPlayer("1", sock1); 126 | expect(p1.money).toBe(100); 127 | const p2 = game.addPlayer("2", sock2); 128 | expect(p2.money).toBe(100); 129 | 130 | expect(game.findPlayer(1)).toBe(p1); 131 | expect(game.findPlayer(2)).toBe(p2); 132 | 133 | expect(game.players.length).toBe(2); 134 | 135 | expect(game.roundNum).toBe(0); 136 | expect(game.roundData.bets.length).toBe(0); 137 | game.startGame(); 138 | expect(game.roundNum).toBe(1); 139 | expect(game.roundData.bets.length).toBeGreaterThan(0); 140 | 141 | const smallPlayer = game.players[game.roundData.smallBlind]; 142 | const bigPlayer = game.players[game.roundData.bigBlind]; 143 | 144 | // Test parametable small/big blind 145 | expect(smallPlayer.money).toBe(95); 146 | expect(bigPlayer.money).toBe(90); 147 | 148 | expect(smallPlayer.status).toBe('Their Turn'); 149 | 150 | // Pre-Flop 151 | expect(game.call(smallPlayer.socket)).toBe(true); 152 | expect(game.roundNum).toBe(1); 153 | expect(game.roundData.bets.length).toBe(1); 154 | 155 | // Flop 156 | game.check(bigPlayer.socket); 157 | game.check(smallPlayer.socket); 158 | expect(game.roundNum).toBe(1); 159 | expect(game.roundData.bets.length).toBe(2); 160 | 161 | // Turn 162 | expect(game.bet(bigPlayer.socket, 1000)).not.toBe(true); 163 | }); 164 | 165 | test('Test all-in / call', () => { 166 | const game = new Game('best-game', '1'); 167 | game.smallBlind = 5; 168 | game.bigBlind = 10; 169 | 170 | // Mock socket 171 | const sock1 = new events.EventEmitter(); 172 | sock1.id = 1; 173 | const sock2 = new events.EventEmitter(); 174 | sock2.id = 2; 175 | 176 | const p1 = game.addPlayer("1", sock1); 177 | p1.money = 50; 178 | expect(p1.money).toBe(50); 179 | const p2 = game.addPlayer("2", sock2); 180 | expect(p2.money).toBe(100); 181 | 182 | expect(game.findPlayer(1)).toBe(p1); 183 | expect(game.findPlayer(2)).toBe(p2); 184 | 185 | expect(game.players.length).toBe(2); 186 | 187 | expect(game.roundNum).toBe(0); 188 | expect(game.roundData.bets.length).toBe(0); 189 | game.startGame(); 190 | expect(game.roundNum).toBe(1); 191 | expect(game.roundData.bets.length).toBeGreaterThan(0); 192 | 193 | const smallPlayer = game.players[game.roundData.smallBlind]; 194 | const bigPlayer = game.players[game.roundData.bigBlind]; 195 | 196 | expect(smallPlayer.status).toBe('Their Turn'); 197 | 198 | // Pre-Flop 199 | expect(game.call(smallPlayer.socket)).toBe(true); 200 | expect(game.roundNum).toBe(1); 201 | expect(game.roundData.bets.length).toBe(1); 202 | 203 | // Flop 204 | game.check(bigPlayer.socket); 205 | game.check(smallPlayer.socket); 206 | expect(game.roundNum).toBe(1); 207 | expect(game.roundData.bets.length).toBe(2); 208 | 209 | // Turn 210 | expect(game.bet(bigPlayer.socket, bigPlayer.money)).toBe(true); 211 | 212 | expect(game.call(smallPlayer.socket)).toBe(true); 213 | 214 | expect(smallPlayer.money + bigPlayer.money).toBe(150); 215 | }); 216 | 217 | test('Test all-in 3 players', () => { 218 | const game = new Game('best-game', '1'); 219 | game.smallBlind = 5; 220 | game.bigBlind = 10; 221 | 222 | // Mock socket 223 | const sock1 = new events.EventEmitter(); 224 | sock1.id = 1; 225 | const sock2 = new events.EventEmitter(); 226 | sock2.id = 2; 227 | const sock3 = new events.EventEmitter(); 228 | sock3.id = 3; 229 | 230 | const p1 = game.addPlayer("1", sock1); 231 | expect(p1.money).toBe(100); 232 | const p2 = game.addPlayer("2", sock2); 233 | p2.money = 50; 234 | expect(p2.money).toBe(50); 235 | const p3 = game.addPlayer("3", sock3); 236 | expect(p3.money).toBe(100); 237 | 238 | expect(game.findPlayer(1)).toBe(p1); 239 | expect(game.findPlayer(2)).toBe(p2); 240 | expect(game.findPlayer(3)).toBe(p3); 241 | 242 | expect(game.players.length).toBe(3); 243 | 244 | expect(game.roundNum).toBe(0); 245 | expect(game.roundData.bets.length).toBe(0); 246 | game.startGame(); 247 | expect(game.roundNum).toBe(1); 248 | expect(game.roundData.bets.length).toBeGreaterThan(0); 249 | 250 | const smallPlayer = game.players[game.roundData.smallBlind]; 251 | const bigPlayer = game.players[game.roundData.bigBlind]; 252 | const thirdPlayer = game.players.filter((p) => [smallPlayer, bigPlayer].indexOf(p) === -1)[0]; 253 | 254 | let currentPlayer; 255 | 256 | // Pre-Flop 257 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 258 | expect(game.call(currentPlayer.socket)).toBe(true); 259 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 260 | expect(game.call(currentPlayer.socket)).toBe(true); 261 | expect(game.roundNum).toBe(1); 262 | expect(game.roundData.bets.length).toBe(1); 263 | 264 | // Flop 265 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 266 | game.check(currentPlayer.socket); 267 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 268 | game.check(currentPlayer.socket); 269 | expect(game.roundNum).toBe(1); 270 | expect(game.roundData.bets.length).toBe(2); 271 | 272 | // Turn 273 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 274 | expect(game.bet(currentPlayer.socket, currentPlayer.money)).toBe(true); 275 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 276 | expect(game.call(currentPlayer.socket)).toBe(true); 277 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 278 | expect(game.call(currentPlayer.socket)).toBe(true); 279 | 280 | expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(250); 281 | expect(game.roundData.bets.length).toBe(4); 282 | }); 283 | 284 | test('Test disconnected', () => { 285 | const game = new Game('best-game', '1'); 286 | game.smallBlind = 5; 287 | game.bigBlind = 10; 288 | 289 | // Mock socket 290 | const sock1 = new events.EventEmitter(); 291 | sock1.id = 1; 292 | const sock2 = new events.EventEmitter(); 293 | sock2.id = 2; 294 | 295 | const p1 = game.addPlayer("1", sock1); 296 | p1.money = 50; 297 | expect(p1.money).toBe(50); 298 | const p2 = game.addPlayer("2", sock2); 299 | expect(p2.money).toBe(100); 300 | 301 | expect(game.findPlayer(1)).toBe(p1); 302 | expect(game.findPlayer(2)).toBe(p2); 303 | 304 | expect(game.players.length).toBe(2); 305 | 306 | expect(game.roundNum).toBe(0); 307 | expect(game.roundData.bets.length).toBe(0); 308 | game.startGame(); 309 | expect(game.roundNum).toBe(1); 310 | expect(game.roundData.bets.length).toBeGreaterThan(0); 311 | 312 | const smallPlayer = game.players[game.roundData.smallBlind]; 313 | const bigPlayer = game.players[game.roundData.bigBlind]; 314 | 315 | expect(smallPlayer.status).toBe('Their Turn'); 316 | 317 | // Pre-Flop 318 | expect(game.call(smallPlayer.socket)).toBe(true); 319 | expect(game.roundNum).toBe(1); 320 | expect(game.roundData.bets.length).toBe(1); 321 | 322 | // Flop 323 | game.check(bigPlayer.socket); 324 | game.check(smallPlayer.socket); 325 | expect(game.roundNum).toBe(1); 326 | expect(game.roundData.bets.length).toBe(2); 327 | 328 | // Turn 329 | game.disconnectPlayer(bigPlayer); 330 | 331 | expect(game.players.length).toBe(1); 332 | }); 333 | 334 | test('Test init blind and dealer', () => { 335 | const game = new Game('best-game', '1'); 336 | game.smallBlind = 5; 337 | game.bigBlind = 10; 338 | 339 | // Mock socket 340 | const sock1 = new events.EventEmitter(); 341 | sock1.id = 1; 342 | const sock2 = new events.EventEmitter(); 343 | sock2.id = 2; 344 | const sock3 = new events.EventEmitter(); 345 | sock3.id = 3; 346 | 347 | const p1 = game.addPlayer("1", sock1); 348 | const p2 = game.addPlayer("2", sock2); 349 | const p3 = game.addPlayer("3", sock3); 350 | 351 | expect(game.findPlayer(1)).toBe(p1); 352 | expect(game.findPlayer(2)).toBe(p2); 353 | expect(game.findPlayer(3)).toBe(p3); 354 | 355 | expect(game.players.length).toBe(3); 356 | 357 | expect(game.roundNum).toBe(0); 358 | game.startGame(); 359 | expect(game.roundNum).toBe(1); 360 | 361 | expect(p1.dealer).toBe(true); 362 | expect(p2.dealer).toBe(false); 363 | expect(p3.dealer).toBe(false); 364 | expect(p1.blindValue).toBe(''); 365 | expect(p2.blindValue).toBe('Small Blind'); 366 | expect(p3.blindValue).toBe('Big Blind'); 367 | 368 | game.startNewRound(); 369 | expect(game.roundNum).toBe(2); 370 | 371 | expect(p1.dealer).toBe(false); 372 | expect(p2.dealer).toBe(true); 373 | expect(p3.dealer).toBe(false); 374 | expect(p1.blindValue).toBe('Big Blind'); 375 | expect(p2.blindValue).toBe(''); 376 | expect(p3.blindValue).toBe('Small Blind'); 377 | 378 | game.startNewRound(); 379 | expect(game.roundNum).toBe(3); 380 | 381 | expect(p1.dealer).toBe(false); 382 | expect(p2.dealer).toBe(false); 383 | expect(p3.dealer).toBe(true); 384 | expect(p1.blindValue).toBe('Small Blind'); 385 | expect(p2.blindValue).toBe('Big Blind'); 386 | expect(p3.blindValue).toBe(''); 387 | 388 | game.startNewRound(); 389 | expect(game.roundNum).toBe(4); 390 | 391 | expect(p1.dealer).toBe(true); 392 | expect(p2.dealer).toBe(false); 393 | expect(p3.dealer).toBe(false); 394 | expect(p1.blindValue).toBe(''); 395 | expect(p2.blindValue).toBe('Small Blind'); 396 | expect(p3.blindValue).toBe('Big Blind'); 397 | }); 398 | 399 | test('Test raise', () => { 400 | const game = new Game('best-game', '1'); 401 | game.smallBlind = 5; 402 | game.bigBlind = 10; 403 | 404 | // Mock socket 405 | const sock1 = new events.EventEmitter(); 406 | sock1.id = 1; 407 | const sock2 = new events.EventEmitter(); 408 | sock2.id = 2; 409 | 410 | const p1 = game.addPlayer("1", sock1); 411 | expect(p1.money).toBe(100); 412 | const p2 = game.addPlayer("2", sock2); 413 | expect(p2.money).toBe(100); 414 | 415 | expect(game.findPlayer(1)).toBe(p1); 416 | expect(game.findPlayer(2)).toBe(p2); 417 | 418 | expect(game.players.length).toBe(2); 419 | 420 | expect(game.roundNum).toBe(0); 421 | expect(game.roundData.bets.length).toBe(0); 422 | game.startGame(); 423 | expect(game.roundNum).toBe(1); 424 | expect(game.roundData.bets.length).toBeGreaterThan(0); 425 | 426 | let currentPlayer; 427 | 428 | // Pre-Flop 429 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 430 | expect(game.bet(currentPlayer.socket, 30)).toBe(true); 431 | 432 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 433 | // Check can't raise under topBet 434 | expect(game.raise(currentPlayer.socket, 20)).not.toBe(true); 435 | expect(game.roundNum).toBe(1); 436 | expect(game.roundData.bets.length).toBe(1); 437 | 438 | // Raise correct value 439 | expect(game.raise(currentPlayer.socket, 30)).toBe(true); 440 | expect(game.roundNum).toBe(1); 441 | expect(game.roundData.bets.length).toBe(2); 442 | }); 443 | 444 | test('Test all-in 3 players low credits win', () => { 445 | const game = new Game('best-game', '1'); 446 | game.smallBlind = 5; 447 | game.bigBlind = 10; 448 | 449 | // Mock socket 450 | const sock1 = new events.EventEmitter(); 451 | sock1.id = 1; 452 | const sock2 = new events.EventEmitter(); 453 | sock2.id = 2; 454 | const sock3 = new events.EventEmitter(); 455 | sock3.id = 3; 456 | 457 | const p1 = game.addPlayer("1", sock1); 458 | expect(p1.money).toBe(100); 459 | 460 | const p2 = game.addPlayer("2", sock2); 461 | expect(p2.money).toBe(100); 462 | 463 | const p3 = game.addPlayer("3", sock3); 464 | p3.money = 50; 465 | expect(p3.money).toBe(50); 466 | 467 | expect(game.findPlayer(1)).toBe(p1); 468 | expect(game.findPlayer(2)).toBe(p2); 469 | expect(game.findPlayer(3)).toBe(p3); 470 | 471 | expect(game.players.length).toBe(3); 472 | 473 | expect(game.roundNum).toBe(0); 474 | expect(game.roundData.bets.length).toBe(0); 475 | game.startGame(); 476 | 477 | 478 | p1.cards[0].value = 7; 479 | p1.cards[0].suit = '♠'; 480 | p1.cards[1].value = 7; 481 | p1.cards[1].suit = '♥'; 482 | 483 | p2.cards[0].value = 8; 484 | p2.cards[0].suit = '♠'; 485 | p2.cards[1].value = 8; 486 | p2.cards[1].suit = '♥'; 487 | 488 | p3.cards[0].value = 1; 489 | p3.cards[0].suit = '♠'; 490 | p3.cards[1].value = 1; 491 | p3.cards[1].suit = '♥'; 492 | 493 | 494 | expect(game.roundNum).toBe(1); 495 | expect(game.roundData.bets.length).toBeGreaterThan(0); 496 | 497 | let currentPlayer; 498 | 499 | // Pre-Flop 500 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 501 | expect(game.call(currentPlayer.socket)).toBe(true); 502 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 503 | expect(game.call(currentPlayer.socket)).toBe(true); 504 | expect(game.roundNum).toBe(1); 505 | expect(game.roundData.bets.length).toBe(1); 506 | 507 | // Flop 508 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 509 | game.check(currentPlayer.socket); 510 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 511 | game.check(currentPlayer.socket); 512 | expect(game.roundNum).toBe(1); 513 | expect(game.roundData.bets.length).toBe(2); 514 | 515 | game.community[0].value = 1; 516 | game.community[0].suit = '♦'; 517 | game.community[1].value = 1; 518 | game.community[1].suit = '♣'; 519 | game.community[2].value = 'K'; 520 | game.community[2].suit = '♣'; 521 | 522 | // Turn 523 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 524 | expect(currentPlayer.money).toBe(90); 525 | expect(game.bet(currentPlayer.socket, currentPlayer.money)).toBe(true); 526 | expect(currentPlayer.money).toBe(0); 527 | 528 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 529 | expect(currentPlayer.money).toBe(40); 530 | expect(game.call(currentPlayer.socket)).toBe(true); 531 | expect(currentPlayer.money).toBe(0); 532 | 533 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 534 | expect(currentPlayer.money).toBe(90); 535 | expect(game.call(currentPlayer.socket)).toBe(true); 536 | 537 | // Winner has to be p3 with 4 as 538 | expect(p1.money).toBe(50); 539 | expect(p2.money).toBe(50); 540 | expect(p3.money).toBe(150); 541 | 542 | expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(250); 543 | expect(game.roundData.bets.length).toBe(4); 544 | }); 545 | 546 | test('Test all-in 3 players high credits win', () => { 547 | const game = new Game('best-game', '1'); 548 | game.smallBlind = 5; 549 | game.bigBlind = 10; 550 | 551 | // Mock socket 552 | const sock1 = new events.EventEmitter(); 553 | sock1.id = 1; 554 | const sock2 = new events.EventEmitter(); 555 | sock2.id = 2; 556 | const sock3 = new events.EventEmitter(); 557 | sock3.id = 3; 558 | 559 | const p1 = game.addPlayer("1", sock1); 560 | expect(p1.money).toBe(100); 561 | 562 | const p2 = game.addPlayer("2", sock2); 563 | expect(p2.money).toBe(100); 564 | 565 | const p3 = game.addPlayer("3", sock3); 566 | p3.money = 50; 567 | expect(p3.money).toBe(50); 568 | 569 | expect(game.findPlayer(1)).toBe(p1); 570 | expect(game.findPlayer(2)).toBe(p2); 571 | expect(game.findPlayer(3)).toBe(p3); 572 | 573 | expect(game.players.length).toBe(3); 574 | 575 | expect(game.roundNum).toBe(0); 576 | expect(game.roundData.bets.length).toBe(0); 577 | game.startGame(); 578 | 579 | 580 | p1.cards[0].value = 7; 581 | p1.cards[0].suit = '♠'; 582 | p1.cards[1].value = 7; 583 | p1.cards[1].suit = '♥'; 584 | 585 | p2.cards[0].value = 1; 586 | p2.cards[0].suit = '♠'; 587 | p2.cards[1].value = 1; 588 | p2.cards[1].suit = '♥'; 589 | 590 | p3.cards[0].value = 8; 591 | p3.cards[0].suit = '♠'; 592 | p3.cards[1].value = 8; 593 | p3.cards[1].suit = '♥'; 594 | 595 | 596 | expect(game.roundNum).toBe(1); 597 | expect(game.roundData.bets.length).toBeGreaterThan(0); 598 | 599 | let currentPlayer; 600 | 601 | // Pre-Flop 602 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 603 | expect(game.call(currentPlayer.socket)).toBe(true); 604 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 605 | expect(game.call(currentPlayer.socket)).toBe(true); 606 | expect(game.roundNum).toBe(1); 607 | expect(game.roundData.bets.length).toBe(1); 608 | 609 | // Flop 610 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 611 | game.check(currentPlayer.socket); 612 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 613 | game.check(currentPlayer.socket); 614 | expect(game.roundNum).toBe(1); 615 | expect(game.roundData.bets.length).toBe(2); 616 | 617 | game.community[0].value = 1; 618 | game.community[0].suit = '♦'; 619 | game.community[1].value = 1; 620 | game.community[1].suit = '♣'; 621 | game.community[2].value = 'K'; 622 | game.community[2].suit = '♣'; 623 | 624 | // Turn 625 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 626 | expect(currentPlayer.money).toBe(90); 627 | expect(game.bet(currentPlayer.socket, currentPlayer.money)).toBe(true); 628 | expect(currentPlayer.money).toBe(0); 629 | 630 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 631 | expect(currentPlayer.money).toBe(40); 632 | expect(game.call(currentPlayer.socket)).toBe(true); 633 | expect(currentPlayer.money).toBe(0); 634 | 635 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 636 | expect(currentPlayer.money).toBe(90); 637 | expect(game.call(currentPlayer.socket)).toBe(true); 638 | 639 | // Winner has to be p2 with 4 as 640 | expect(p1.money).toBe(0); 641 | expect(p2.money).toBe(250); 642 | expect(p3.money).toBe(0); 643 | 644 | expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(250); 645 | expect(game.roundData.bets.length).toBe(4); 646 | }); 647 | 648 | function getCurrentPlayer(players) { 649 | const currentTurnArr = players.filter((p) => p.status === 'Their Turn'); 650 | expect(currentTurnArr.length).toBe(1); 651 | return currentTurnArr[0]; 652 | } 653 | 654 | test('Test fold', () => { 655 | const game = new Game('best-game', '1'); 656 | game.smallBlind = 5; 657 | game.bigBlind = 10; 658 | 659 | // Mock socket 660 | const sock1 = new events.EventEmitter(); 661 | sock1.id = 1; 662 | const sock2 = new events.EventEmitter(); 663 | sock2.id = 2; 664 | const sock3 = new events.EventEmitter(); 665 | sock3.id = 3; 666 | 667 | const p1 = game.addPlayer("1", sock1); 668 | expect(p1.money).toBe(100); 669 | 670 | const p2 = game.addPlayer("2", sock2); 671 | expect(p2.money).toBe(100); 672 | 673 | const p3 = game.addPlayer("3", sock3); 674 | expect(p3.money).toBe(100); 675 | 676 | expect(game.findPlayer(1)).toBe(p1); 677 | expect(game.findPlayer(2)).toBe(p2); 678 | expect(game.findPlayer(3)).toBe(p3); 679 | 680 | expect(game.players.length).toBe(3); 681 | 682 | expect(game.roundNum).toBe(0); 683 | expect(game.roundData.bets.length).toBe(0); 684 | game.startGame(); 685 | 686 | expect(game.roundNum).toBe(1); 687 | expect(game.roundData.bets.length).toBeGreaterThan(0); 688 | 689 | let currentPlayer; 690 | 691 | // Pre-Flop 692 | currentPlayer = getCurrentPlayer(game.players); 693 | expect(game.raise(currentPlayer.socket, 30)).toBe(true); 694 | currentPlayer = getCurrentPlayer(game.players); 695 | expect(game.call(currentPlayer.socket)).toBe(true); 696 | currentPlayer = getCurrentPlayer(game.players); 697 | expect(game.call(currentPlayer.socket)).toBe(true); 698 | expect(game.roundNum).toBe(1); 699 | expect(game.roundData.bets.length).toBe(2); 700 | 701 | // Flop 702 | currentPlayer = getCurrentPlayer(game.players); 703 | game.fold(currentPlayer.socket); 704 | currentPlayer = getCurrentPlayer(game.players); 705 | game.check(currentPlayer.socket); 706 | currentPlayer = getCurrentPlayer(game.players); 707 | game.check(currentPlayer.socket); 708 | expect(game.roundNum).toBe(1); 709 | expect(game.roundData.bets.length).toBe(3); 710 | 711 | // Turn 712 | currentPlayer = getCurrentPlayer(game.players); 713 | game.check(currentPlayer.socket); 714 | currentPlayer = getCurrentPlayer(game.players); 715 | game.check(currentPlayer.socket); 716 | expect(game.roundNum).toBe(1); 717 | expect(game.roundData.bets.length).toBe(4); 718 | 719 | // River 720 | currentPlayer = getCurrentPlayer(game.players); 721 | game.check(currentPlayer.socket); 722 | currentPlayer = getCurrentPlayer(game.players); 723 | game.check(currentPlayer.socket); 724 | expect(game.roundNum).toBe(1); 725 | expect(game.roundData.bets.length).toBe(4); 726 | expect(game.roundInProgress).toBe(false); 727 | 728 | expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(300); 729 | }); 730 | 731 | test('Test all fold', () => { 732 | const game = new Game('best-game', '1'); 733 | game.smallBlind = 5; 734 | game.bigBlind = 10; 735 | 736 | // Mock socket 737 | const sock1 = new events.EventEmitter(); 738 | sock1.id = 1; 739 | const sock2 = new events.EventEmitter(); 740 | sock2.id = 2; 741 | const sock3 = new events.EventEmitter(); 742 | sock3.id = 3; 743 | 744 | const p1 = game.addPlayer("1", sock1); 745 | expect(p1.money).toBe(100); 746 | 747 | const p2 = game.addPlayer("2", sock2); 748 | expect(p2.money).toBe(100); 749 | 750 | const p3 = game.addPlayer("3", sock3); 751 | expect(p3.money).toBe(100); 752 | 753 | expect(game.findPlayer(1)).toBe(p1); 754 | expect(game.findPlayer(2)).toBe(p2); 755 | expect(game.findPlayer(3)).toBe(p3); 756 | 757 | expect(game.players.length).toBe(3); 758 | 759 | expect(game.roundNum).toBe(0); 760 | expect(game.roundData.bets.length).toBe(0); 761 | game.startGame(); 762 | 763 | expect(game.roundNum).toBe(1); 764 | expect(game.roundData.bets.length).toBeGreaterThan(0); 765 | 766 | let currentPlayer; 767 | 768 | // Pre-Flop 769 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 770 | expect(game.raise(currentPlayer.socket, 30)).toBe(true); 771 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 772 | expect(game.call(currentPlayer.socket)).toBe(true); 773 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 774 | expect(game.call(currentPlayer.socket)).toBe(true); 775 | expect(game.roundNum).toBe(1); 776 | expect(game.roundData.bets.length).toBe(2); 777 | expect(game.roundInProgress).toBe(true); 778 | 779 | // Flop 780 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 781 | game.fold(currentPlayer.socket); 782 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 783 | game.fold(currentPlayer.socket); 784 | 785 | expect(game.roundNum).toBe(1); 786 | expect(game.roundData.bets.length).toBe(2); 787 | expect(game.roundInProgress).toBe(false); 788 | 789 | expect(game.players.reduce((a, c) => a + c.money, 0)).toBe(300); 790 | }); 791 | 792 | test('Test _distributeMoney', () => { 793 | const game = new Game('best-game', '1'); 794 | const pot = 100; 795 | const players = [ 796 | { live: true, invested: 20, handStrength: 100, result: 0 }, 797 | { live: true, invested: 50, handStrength: 200, result: 0 }, 798 | { live: true, invested: 80, handStrength: 90, result: 0 }, 799 | { live: true, invested: 80, handStrength: 100, result: 0 }, 800 | { live: true, invested: 1000, handStrength: 0, result: 0 }, 801 | ]; 802 | 803 | game.calculateMoney(pot, players); 804 | 805 | expect(players[0].result).toBe(0); 806 | expect(players[1].result).toBe(320); 807 | expect(players[2].result).toBe(0); 808 | expect(players[3].result).toBe(90); 809 | expect(players[4].result).toBe(920); 810 | }); 811 | 812 | 813 | 814 | test('Test infinite loop issue', () => { 815 | // Log data retreive before infinite loop crash 816 | const playersData = [{ 817 | "username": "$2a$11$sN3yXEe38GKcnCfxIO2GCe8/rGoSkZ5AtWba6p1cq5NQXQ4HZUYPS", 818 | "cards": [{ 819 | "value": "A", 820 | "suit": "♣" 821 | }, { 822 | "value": 3, 823 | "suit": "♠" 824 | }], 825 | "money": 5, 826 | }, { 827 | "username": "$2a$11$Um0VU8I.gNaKNi6LeFFUG.n7yvlTcCd0CNIozbfofFoP82IcMmri2", 828 | "cards": [{ 829 | "value": "Q", 830 | "suit": "♠" 831 | }, { 832 | "value": 2, 833 | "suit": "♣" 834 | }], 835 | "money": 5, 836 | }, { 837 | "username": "$2a$11$EFSkbqmMr9.xSzEWOWXcEuu85NypJpg3XUdMrT3oO1FmMjB1wF4JO", 838 | "cards": [{ 839 | "value": 10, 840 | "suit": "♥" 841 | }, { 842 | "value": "A", 843 | "suit": "♥" 844 | }], 845 | "money": 5, 846 | }]; 847 | 848 | const game = new Game('best-game', '1'); 849 | game.smallBlind = 5; 850 | game.bigBlind = 10; 851 | 852 | // Mock socket 853 | const sockets = []; 854 | const players = []; 855 | for (const pl of playersData) { 856 | const sock = new events.EventEmitter(); 857 | sock.id = pl.username; 858 | sockets.push(sock); 859 | 860 | const p = game.addPlayer(pl.username, sock); 861 | p.money = pl.money; 862 | players.push(p); 863 | } 864 | 865 | expect(game.players.length).toBe(playersData.length); 866 | 867 | expect(game.roundNum).toBe(0); 868 | expect(game.roundData.bets.length).toBe(0); 869 | 870 | game.startGame(); 871 | 872 | for (const [index, pl] of Object.entries(playersData)) { 873 | const p = players[Number(index)]; 874 | p.cards = [...pl.cards]; 875 | } 876 | 877 | expect(game.roundNum).toBe(1); 878 | expect(game.roundData.bets.length).toBeGreaterThan(0); 879 | 880 | let currentPlayer; 881 | 882 | // Pre-Flop 883 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 884 | expect(game.call(currentPlayer.socket)).toBe(true); 885 | 886 | currentPlayer = game.players.filter((p) => p.status === 'Their Turn')[0]; 887 | expect(game.call(currentPlayer.socket)).toBe(true); // This call made an infinite loop 888 | }); -------------------------------------------------------------------------------- /src/client/main.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function () { 2 | $('#gameDiv').hide(); 3 | $('.modal-trigger').leanModal(); 4 | $('.tooltipped').tooltip({ delay: 50 }); 5 | }); 6 | 7 | var socket = io(); 8 | var gameInfo = null; 9 | 10 | socket.on('playerDisconnected', function (data) { 11 | Materialize.toast(data.player + ' disconnected.', 4000); 12 | }); 13 | 14 | socket.on('hostRoom', function (data) { 15 | if (data != undefined) { 16 | if (data.players.length >= 11) { 17 | $('#hostModalContent').html( 18 | '
Code:
' + 19 | data.code + 20 | '
Warning: you have too many players in your room. Max is 11.
Players Currently in My Room
' 21 | ); 22 | $('#playersNames').html( 23 | data.players.map(function (p) { 24 | return '' + p + '
'; 25 | }) 26 | ); 27 | } else if (data.players.length > 1) { 28 | $('#hostModalContent').html( 29 | '
Code:
' + 30 | data.code + 31 | '
Players Currently in My Room
' 32 | ); 33 | $('#playersNames').html( 34 | data.players.map(function (p) { 35 | return '' + p + '
'; 36 | }) 37 | ); 38 | $('#startGameArea').html( 39 | '
' 42 | ); 43 | } else { 44 | $('#hostModalContent').html( 45 | '
Code:
' + 46 | data.code + 47 | '
Players Currently in My Room
' 48 | ); 49 | $('#playersNames').html( 50 | data.players.map(function (p) { 51 | return '' + p + '
'; 52 | }) 53 | ); 54 | } 55 | } else { 56 | Materialize.toast( 57 | 'Enter a valid name! (max length of name is 12 characters)', 58 | 4000 59 | ); 60 | $('#joinButton').removeClass('disabled'); 61 | } 62 | }); 63 | 64 | socket.on('hostRoomUpdate', function (data) { 65 | $('#playersNames').html( 66 | data.players.map(function (p) { 67 | return '' + p + '
'; 68 | }) 69 | ); 70 | if (data.players.length == 1) { 71 | $('#startGameArea').empty(); 72 | } 73 | }); 74 | 75 | socket.on('joinRoomUpdate', function (data) { 76 | $('#startGameAreaDisconnectSituation').html( 77 | '
' 80 | ); 81 | $('#joinModalContent').html( 82 | '
' + 83 | data.host + 84 | "'s room

Players Currently in Room

You are now a host of this game.

" 85 | ); 86 | 87 | $('#playersNamesJoined').html( 88 | data.players.map(function (p) { 89 | return '' + p + '
'; 90 | }) 91 | ); 92 | }); 93 | 94 | socket.on('joinRoom', function (data) { 95 | if (data == undefined) { 96 | $('#joinModal').closeModal(); 97 | Materialize.toast( 98 | "Enter a valid name/code! (max length of name is 12 characters & cannot be the same as someone else's)", 99 | 4000 100 | ); 101 | $('#hostButton').removeClass('disabled'); 102 | } else { 103 | $('#joinModalContent').html( 104 | '
' + 105 | data.host + 106 | "'s room

Players Currently in Room

Please wait until your host starts the game. Leaving the page, refreshing, or going back will disconnect you from the game.

" 107 | ); 108 | $('#playersNamesJoined').html( 109 | data.players.map(function (p) { 110 | return '' + p + '
'; 111 | }) 112 | ); 113 | } 114 | }); 115 | 116 | socket.on('dealt', function (data) { 117 | $('#mycards').html( 118 | data.cards.map(function (c) { 119 | return renderCard(c); 120 | }) 121 | ); 122 | $('#usernamesCards').text(data.username + ' - My Cards'); 123 | $('#mainContent').remove(); 124 | }); 125 | 126 | socket.on('rerender', function (data) { 127 | if (data.myBet == 0) { 128 | $('#usernamesCards').text(data.username + ' - My Cards'); 129 | } else { 130 | $('#usernamesCards').text(data.username + ' - My Bet: $' + data.myBet); 131 | } 132 | if (data.community != undefined) 133 | $('#communityCards').html( 134 | data.community.map(function (c) { 135 | return renderCard(c); 136 | }) 137 | ); 138 | else $('#communityCards').html('

'); 139 | if (data.currBet == undefined) data.currBet = 0; 140 | $('#table-title').text( 141 | 'Game ' + 142 | data.round + 143 | ' | ' + 144 | data.stage + 145 | ' | Current Top Bet: $' + 146 | data.topBet + 147 | ' | Pot: $' + 148 | data.pot 149 | ); 150 | $('#opponentCards').html( 151 | data.players.map(function (p) { 152 | return renderOpponent(p.username, { 153 | text: p.status, 154 | money: p.money, 155 | blind: p.blind, 156 | bets: data.bets, 157 | buyIns: p.buyIns, 158 | isChecked: p.isChecked, 159 | }); 160 | }) 161 | ); 162 | renderSelf({ 163 | money: data.myMoney, 164 | text: data.myStatus, 165 | blind: data.myBlind, 166 | bets: data.bets, 167 | buyIns: data.buyIns, 168 | }); 169 | if (!data.roundInProgress) { 170 | $('#usernameFold').hide(); 171 | $('#usernameCheck').hide(); 172 | $('#usernameBet').hide(); 173 | $('#usernameCall').hide(); 174 | $('#usernameRaise').hide(); 175 | } 176 | }); 177 | 178 | socket.on('gameBegin', function (data) { 179 | $('#navbar-ptwu').hide(); 180 | $('#joinModal').closeModal(); 181 | $('#hostModal').closeModal(); 182 | if (data == undefined) { 183 | alert('Error - invalid game.'); 184 | } else { 185 | $('#gameDiv').show(); 186 | } 187 | }); 188 | 189 | function playNext() { 190 | socket.emit('startNextRound', {}); 191 | } 192 | 193 | socket.on('reveal', function (data) { 194 | $('#usernameFold').hide(); 195 | $('#usernameCheck').hide(); 196 | $('#usernameBet').hide(); 197 | $('#usernameCall').hide(); 198 | $('#usernameRaise').hide(); 199 | 200 | for (var i = 0; i < data.winners.length; i++) { 201 | if (data.winners[i] == data.username) { 202 | Materialize.toast('You won the hand!', 4000); 203 | break; 204 | } 205 | } 206 | $('#table-title').text('Hand Winner(s): ' + data.winners); 207 | $('#playNext').html( 208 | '' 209 | ); 210 | $('#blindStatus').text(data.hand); 211 | $('#usernamesMoney').text('$' + data.money); 212 | $('#opponentCards').html( 213 | data.cards.map(function (p) { 214 | return renderOpponentCards(p.username, { 215 | cards: p.cards, 216 | folded: p.folded, 217 | money: p.money, 218 | endHand: p.hand, 219 | buyIns: p.buyIns, 220 | }); 221 | }) 222 | ); 223 | }); 224 | 225 | socket.on('endHand', function (data) { 226 | $('#usernameFold').hide(); 227 | $('#usernameCheck').hide(); 228 | $('#usernameBet').hide(); 229 | $('#usernameCall').hide(); 230 | $('#usernameRaise').hide(); 231 | $('#table-title').text(data.winner + ' takes the pot of $' + data.pot); 232 | $('#playNext').html( 233 | '' 234 | ); 235 | $('#blindStatus').text(''); 236 | if (data.folded == 'Fold') { 237 | $('#status').text('You Folded'); 238 | $('#playerInformationCard').removeClass('theirTurn'); 239 | $('#playerInformationCard').removeClass('green'); 240 | $('#playerInformationCard').addClass('grey'); 241 | $('#usernameFold').hide(); 242 | $('#usernameCheck').hide(); 243 | $('#usernameBet').hide(); 244 | $('#usernameCall').hide(); 245 | $('#usernameRaise').hide(); 246 | } 247 | $('#usernamesMoney').text('$' + data.money); 248 | $('#opponentCards').html( 249 | data.cards.map(function (p) { 250 | return renderOpponent(p.username, { 251 | text: p.text, 252 | money: p.money, 253 | blind: '', 254 | bets: data.bets, 255 | }); 256 | }) 257 | ); 258 | }); 259 | 260 | var beginHost = function () { 261 | if ($('#hostName-field').val() == '') { 262 | $('.toast').hide(); 263 | $('#hostModal').closeModal(); 264 | Materialize.toast( 265 | 'Enter a valid name! (max length of name is 12 characters)', 266 | 4000 267 | ); 268 | $('#joinButton').removeClass('disabled'); 269 | } else { 270 | socket.emit('host', { username: $('#hostName-field').val() }); 271 | $('#joinButton').addClass('disabled'); 272 | $('#joinButton').off('click'); 273 | } 274 | }; 275 | 276 | var joinRoom = function () { 277 | // yes, i know this is client-side. 278 | if ( 279 | $('#joinName-field').val() == '' || 280 | $('#code-field').val() == '' || 281 | $('#joinName-field').val().length > 12 282 | ) { 283 | $('.toast').hide(); 284 | Materialize.toast( 285 | 'Enter a valid name/code! (max length of name is 12 characters.)', 286 | 4000 287 | ); 288 | $('#joinModal').closeModal(); 289 | $('#hostButton').removeClass('disabled'); 290 | $('#hostButton').on('click'); 291 | } else { 292 | socket.emit('join', { 293 | code: $('#code-field').val(), 294 | username: $('#joinName-field').val(), 295 | }); 296 | $('#hostButton').addClass('disabled'); 297 | $('#hostButton').off('click'); 298 | } 299 | }; 300 | 301 | var startGame = function (gameCode) { 302 | socket.emit('startGame', { code: gameCode }); 303 | }; 304 | 305 | var fold = function () { 306 | socket.emit('moveMade', { move: 'fold', bet: 'Fold' }); 307 | }; 308 | 309 | var bet = function () { 310 | if (parseInt($('#betRangeSlider').val()) == 0) { 311 | Materialize.toast('You must bet more than $0! Try again.', 4000); 312 | } else if (parseInt($('#betRangeSlider').val()) < 2) { 313 | Materialize.toast('The minimum bet is $2.', 4000); 314 | } else { 315 | socket.emit('moveMade', { 316 | move: 'bet', 317 | bet: parseInt($('#betRangeSlider').val()), 318 | }); 319 | } 320 | }; 321 | 322 | function call() { 323 | socket.emit('moveMade', { move: 'call', bet: 'Call' }); 324 | } 325 | 326 | var check = function () { 327 | socket.emit('moveMade', { move: 'check', bet: 'Check' }); 328 | }; 329 | 330 | var raise = function () { 331 | if ( 332 | parseInt($('#raiseRangeSlider').val()) == $('#raiseRangeSlider').prop('min') 333 | ) { 334 | Materialize.toast( 335 | 'You must raise higher than the current top bet! Try again.', 336 | 4000 337 | ); 338 | } else { 339 | socket.emit('moveMade', { 340 | move: 'raise', 341 | bet: parseInt($('#raiseRangeSlider').val()), 342 | }); 343 | } 344 | }; 345 | 346 | function renderCard(card) { 347 | if (card.suit == '♠' || card.suit == '♣') 348 | return ( 349 | '
' + 357 | card.value + 358 | ' ' + 359 | card.suit + 360 | '
' 361 | ); 362 | else 363 | return ( 364 | '
' + 372 | card.value + 373 | ' ' + 374 | card.suit + 375 | '
' 376 | ); 377 | } 378 | 379 | function renderOpponent(name, data) { 380 | var bet = 0; 381 | if (data.bets != undefined) { 382 | var arr = data.bets[data.bets.length - 1]; 383 | for (var pn = 0; pn < arr.length; pn++) { 384 | if (arr[pn].player == name) bet = arr[pn].bet; 385 | } 386 | } 387 | var buyInsText = 388 | data.buyIns > 0 ? (data.buyIns > 1 ? 'buy-ins' : 'buy-in') : ''; 389 | if (data.buyIns > 0) { 390 | if (data.text == 'Fold') { 391 | return ( 392 | '
' + 393 | name + 394 | ' (Fold)






' + 395 | data.blind + 396 | '
' + 397 | data.text + 398 | '

$' + 399 | data.money + 400 | ' (' + 401 | data.buyIns + 402 | ' ' + 403 | buyInsText + 404 | ')' + 405 | '
' 406 | ); 407 | } else { 408 | if (data.text == 'Their Turn') { 409 | if (data.isChecked) 410 | return ( 411 | '
' + 412 | name + 413 | '
Check






' + 414 | data.blind + 415 | '
' + 416 | data.text + 417 | '

$' + 418 | data.money + 419 | ' (' + 420 | data.buyIns + 421 | ' ' + 422 | buyInsText + 423 | ')' + 424 | '
' 425 | ); 426 | else if (bet == 0) { 427 | return ( 428 | '
' + 429 | name + 430 | '






' + 431 | data.blind + 432 | '
' + 433 | data.text + 434 | '

$' + 435 | data.money + 436 | ' (' + 437 | data.buyIns + 438 | ' ' + 439 | buyInsText + 440 | ')' + 441 | '
' 442 | ); 443 | } else { 444 | return ( 445 | '
' + 446 | name + 447 | '
Bet: $' + 448 | bet + 449 | '






' + 450 | data.blind + 451 | '

' + 452 | data.text + 453 | '

$' + 454 | data.money + 455 | ' (' + 456 | data.buyIns + 457 | ' ' + 458 | buyInsText + 459 | ')' + 460 | '
' 461 | ); 462 | } 463 | } else { 464 | if (data.isChecked) 465 | return ( 466 | '
' + 467 | name + 468 | '
Check






' + 469 | data.blind + 470 | '
' + 471 | data.text + 472 | '

$' + 473 | data.money + 474 | ' (' + 475 | data.buyIns + 476 | ' ' + 477 | buyInsText + 478 | ')' + 479 | '
' 480 | ); 481 | else if (bet == 0) { 482 | return ( 483 | '
' + 484 | name + 485 | '






' + 486 | data.blind + 487 | '
' + 488 | data.text + 489 | '

$' + 490 | data.money + 491 | ' (' + 492 | data.buyIns + 493 | ' ' + 494 | buyInsText + 495 | ')' + 496 | '
' 497 | ); 498 | } else { 499 | return ( 500 | '
' + 501 | name + 502 | '
Bet: $' + 503 | bet + 504 | '






' + 505 | data.blind + 506 | '
' + 507 | data.text + 508 | '

$' + 509 | data.money + 510 | ' (' + 511 | data.buyIns + 512 | ' ' + 513 | buyInsText + 514 | ')' + 515 | '
' 516 | ); 517 | } 518 | } 519 | } 520 | } 521 | // buy-ins rendering 522 | else { 523 | if (data.text == 'Fold') { 524 | return ( 525 | '
' + 526 | name + 527 | ' (Fold)






' + 528 | data.blind + 529 | '
' + 530 | data.text + 531 | '

$' + 532 | data.money + 533 | '
' 534 | ); 535 | } else { 536 | if (data.text == 'Their Turn') { 537 | if (data.isChecked) 538 | return ( 539 | '
' + 540 | name + 541 | '
Check






' + 542 | data.blind + 543 | '
' + 544 | data.text + 545 | '

$' + 546 | data.money + 547 | '
' 548 | ); 549 | else if (bet == 0) { 550 | return ( 551 | '
' + 552 | name + 553 | '






' + 554 | data.blind + 555 | '
' + 556 | data.text + 557 | '

$' + 558 | data.money + 559 | '
' 560 | ); 561 | } else { 562 | return ( 563 | '
' + 564 | name + 565 | '
Bet: $' + 566 | bet + 567 | '






' + 568 | data.blind + 569 | '

' + 570 | data.text + 571 | '

$' + 572 | data.money + 573 | '
' 574 | ); 575 | } 576 | } else { 577 | if (data.isChecked) 578 | return ( 579 | '
' + 580 | name + 581 | '
Check






' + 582 | data.blind + 583 | '
' + 584 | data.text + 585 | '

$' + 586 | data.money + 587 | '
' 588 | ); 589 | else if (bet == 0) { 590 | return ( 591 | '
' + 592 | name + 593 | '






' + 594 | data.blind + 595 | '
' + 596 | data.text + 597 | '

$' + 598 | data.money + 599 | '
' 600 | ); 601 | } else { 602 | return ( 603 | '
' + 604 | name + 605 | '
Bet: $' + 606 | bet + 607 | '






' + 608 | data.blind + 609 | '
' + 610 | data.text + 611 | '

$' + 612 | data.money + 613 | '
' 614 | ); 615 | } 616 | } 617 | } 618 | } 619 | } 620 | 621 | function renderOpponentCards(name, data) { 622 | var bet = 0; 623 | if (data.bets != undefined) { 624 | var arr = data.bets[data.bets.length - 1].reverse(); 625 | for (var pn = 0; pn < arr.length; pn++) { 626 | if (arr[pn].player == name) bet = arr[pn].bet; 627 | } 628 | } 629 | var buyInsText2 = 630 | data.buyIns > 0 ? (data.buyIns > 1 ? 'buy-ins' : 'buy-in') : ''; 631 | if (data.buyIns > 0) { 632 | if (data.folded) 633 | return ( 634 | '
' + 635 | name + 636 | ' | Bet: $' + 637 | bet + 638 | '







$' + 639 | data.money + 640 | ' (' + 641 | data.buyIns + 642 | ' ' + 643 | buyInsText2 + 644 | ')' + 645 | '
' 646 | ); 647 | else 648 | return ( 649 | '
' + 650 | name + 651 | ' | Bet: $' + 652 | bet + 653 | '

' + 654 | renderOpponentCard(data.cards[0]) + 655 | renderOpponentCard(data.cards[1]) + 656 | '





' + 657 | data.endHand + 658 | '

$' + 659 | data.money + 660 | ' (' + 661 | data.buyIns + 662 | ' ' + 663 | buyInsText2 + 664 | ')' + 665 | '
' 666 | ); 667 | } else { 668 | if (data.folded) 669 | return ( 670 | '
' + 671 | name + 672 | ' | Bet: $' + 673 | bet + 674 | '







$' + 675 | data.money + 676 | '
' 677 | ); 678 | else 679 | return ( 680 | '
' + 681 | name + 682 | ' | Bet: $' + 683 | bet + 684 | '

' + 685 | renderOpponentCard(data.cards[0]) + 686 | renderOpponentCard(data.cards[1]) + 687 | '





' + 688 | data.endHand + 689 | '

$' + 690 | data.money + 691 | '
' 692 | ); 693 | } 694 | } 695 | 696 | function renderOpponentCard(card) { 697 | if (card.suit == '♠' || card.suit == '♣') 698 | return ( 699 | '
' + 707 | card.value + 708 | ' ' + 709 | card.suit + 710 | '
' 711 | ); 712 | else 713 | return ( 714 | '
' + 722 | card.value + 723 | ' ' + 724 | card.suit + 725 | '
' 726 | ); 727 | } 728 | 729 | function updateBetDisplay() { 730 | if ($('#betRangeSlider').val() == $('#usernamesMoney').text()) { 731 | $('#betDisplay').html( 732 | '

All-In $' + 733 | $('#betRangeSlider').val() + 734 | '' 735 | ); 736 | } else { 737 | $('#betDisplay').html( 738 | '

$' + $('#betRangeSlider').val() + '' 739 | ); 740 | } 741 | } 742 | 743 | function updateBetModal() { 744 | $('#betDisplay').html('

$0

'); 745 | document.getElementById('betRangeSlider').value = 0; 746 | var usernamesMoneyStr = $('#usernamesMoney').text().replace('$', ''); 747 | var usernamesMoneyNum = parseInt(usernamesMoneyStr); 748 | $('#betRangeSlider').attr({ 749 | max: usernamesMoneyNum, 750 | min: 0, 751 | }); 752 | } 753 | 754 | function updateRaiseDisplay() { 755 | $('#raiseDisplay').html( 756 | '

Raise top bet to $' + 757 | $('#raiseRangeSlider').val() + 758 | '

' 759 | ); 760 | } 761 | 762 | socket.on('updateRaiseModal', function (data) { 763 | $('#raiseRangeSlider').attr({ 764 | max: data.usernameMoney, 765 | min: data.topBet, 766 | }); 767 | }); 768 | 769 | function updateRaiseModal() { 770 | document.getElementById('raiseRangeSlider').value = 0; 771 | socket.emit('raiseModalData', {}); 772 | } 773 | 774 | socket.on('displayPossibleMoves', function (data) { 775 | if (data.fold == 'yes') $('#usernameFold').show(); 776 | else $('#usernameHide').hide(); 777 | if (data.check == 'yes') $('#usernameCheck').show(); 778 | else $('#usernameCheck').hide(); 779 | if (data.bet == 'yes') $('#usernameBet').show(); 780 | else $('#usernameBet').hide(); 781 | if (data.call != 'no' || data.call == 'all-in') { 782 | $('#usernameCall').show(); 783 | if (data.call == 'all-in') $('#usernameCall').text('Call All-In'); 784 | else $('#usernameCall').text('Call $' + data.call); 785 | } else $('#usernameCall').hide(); 786 | if (data.raise == 'yes') $('#usernameRaise').show(); 787 | else $('#usernameRaise').hide(); 788 | }); 789 | 790 | function renderSelf(data) { 791 | $('#playNext').empty(); 792 | $('#usernamesMoney').text('$' + data.money); 793 | if (data.text == 'Their Turn') { 794 | $('#playerInformationCard').removeClass('grey'); 795 | $('#playerInformationCard').removeClass('grey'); 796 | $('#playerInformationCard').addClass('yellow'); 797 | $('#playerInformationCard').addClass('darken-2'); 798 | $('#usernamesCards').removeClass('white-text'); 799 | $('#usernamesCards').addClass('black-text'); 800 | $('#status').text('My Turn'); 801 | Materialize.toast('My Turn', 4000); 802 | socket.emit('evaluatePossibleMoves', {}); 803 | } else if (data.text == 'Fold') { 804 | $('#status').text('You Folded'); 805 | $('#playerInformationCard').removeClass('green'); 806 | $('#playerInformationCard').removeClass('yellow'); 807 | $('#playerInformationCard').removeClass('darken-2'); 808 | $('#playerInformationCard').addClass('grey'); 809 | $('#usernamesCards').removeClass('black-text'); 810 | $('#usernamesCards').addClass('white-text'); 811 | Materialize.toast('You folded', 3000); 812 | $('#usernameFold').hide(); 813 | $('#usernameCheck').hide(); 814 | $('#usernameBet').hide(); 815 | $('#usernameCall').hide(); 816 | $('#usernameRaise').hide(); 817 | } else { 818 | $('#status').text(''); 819 | $('#usernamesCards').removeClass('black-text'); 820 | $('#usernamesCards').addClass('white-text'); 821 | $('#playerInformationCard').removeClass('grey'); 822 | $('#playerInformationCard').removeClass('yellow'); 823 | $('#playerInformationCard').removeClass('darken-2'); 824 | $('#playerInformationCard').addClass('green'); 825 | $('#playerInformationCard').removeClass('theirTurn'); 826 | $('#usernameFold').hide(); 827 | $('#usernameCheck').hide(); 828 | $('#usernameBet').hide(); 829 | $('#usernameCall').hide(); 830 | $('#usernameRaise').hide(); 831 | } 832 | $('#blindStatus').text(data.blind); 833 | } 834 | -------------------------------------------------------------------------------- /src/classes/game.js: -------------------------------------------------------------------------------- 1 | // server-side game logic for a texas hold 'em game 2 | const Deck = require('./deck.js'); 3 | const Player = require('./player.js'); 4 | const Hand = require('pokersolver').Hand; 5 | 6 | const Game = function (name, host) { 7 | this.deck = new Deck(); 8 | this.host = host; 9 | this.players = []; 10 | this.status = 0; 11 | this.cardsPerPlayer = 2; 12 | this.currentlyPlayed = 0; 13 | this.gameWinner = null; 14 | this.gameName = name; 15 | this.roundNum = 0; 16 | this.roundData = { 17 | dealer: 0, 18 | bigBlind: '', 19 | smallBlind: '', 20 | turn: '', 21 | bets: [], 22 | }; 23 | this.community = []; 24 | this.foldPot = 0; 25 | this.bigBlindWent = false; 26 | this.lastMoveParsed = { move: '', player: '' }; 27 | this.roundInProgress = false; 28 | this.disconnectedPlayers = []; 29 | this.autoBuyIns = true; 30 | this.debug = false; 31 | this.smallBlind = 1; 32 | this.bigBlind = 2; 33 | 34 | const constructor = (function () {})(this); 35 | 36 | this.log = () => { 37 | if (this.debug) { 38 | console.log(...arguments); 39 | } 40 | }; 41 | 42 | this.assignBlind = () => { 43 | this.roundData.smallBlind = 44 | this.roundData.dealer + 1 < this.players.length 45 | ? this.roundData.dealer + 1 46 | : 0; 47 | this.roundData.bigBlind = 48 | this.roundData.smallBlind + 1 < this.players.length 49 | ? this.roundData.smallBlind + 1 50 | : 0; 51 | 52 | this.log('smallBlind: ' + this.roundData.smallBlind); 53 | this.log('bigBlind: ' + this.roundData.bigBlind); 54 | 55 | for (let i = 0; i < this.players.length; i++) { 56 | this.players[i].setDealer(i === this.roundData.dealer); 57 | if (i === this.roundData.bigBlind) { 58 | this.players[i].setBlind('Big Blind'); 59 | } else if (i === this.roundData.smallBlind) { 60 | this.players[i].setBlind('Small Blind'); 61 | } else { 62 | this.players[i].setBlind(''); 63 | } 64 | this.players[i].setStatus(''); 65 | } 66 | 67 | const goFirstIndex = 68 | this.roundData.bigBlind - 1 < 0 69 | ? this.players.length - 1 70 | : this.roundData.bigBlind - 1; 71 | this.roundData.turn = this.players[goFirstIndex].getUsername(); 72 | this.players[goFirstIndex].setStatus('Their Turn'); 73 | }; 74 | 75 | this.startNewRound = () => { 76 | this.lastMoveParsed = { move: '', player: '' }; 77 | this.roundInProgress = true; 78 | this.foldPot = 0; 79 | this.bigBlindWent = false; 80 | this.community = []; 81 | this.roundData.turn = ''; 82 | this.roundData.bets = []; 83 | this.dealCards(); 84 | this.log('deck len' + this.deck.cards.length); 85 | for (pn of this.players) { 86 | pn.allIn = false; 87 | } 88 | 89 | // Init dealer 90 | if (this.roundNum == 0) { 91 | this.roundData.dealer = 0; 92 | } else { 93 | this.roundData.dealer = 94 | this.roundData.dealer + 1 < this.players.length 95 | ? this.roundData.dealer + 1 96 | : 0; 97 | } 98 | // Init blind and first player 99 | this.assignBlind(); 100 | 101 | if (this.autoBuyIns) { 102 | for (player of this.players) { 103 | if (player.getMoney() == 0) { 104 | player.money = 100; 105 | player.buyIns = player.buyIns + 1; 106 | } 107 | } 108 | } 109 | 110 | // handle big and small blind initial forced bets 111 | 112 | if (this.players[this.roundData.bigBlind].money < this.bigBlind) { 113 | this.players[this.roundData.bigBlind].money = 0; 114 | this.players[this.roundData.bigBlind].allIn = true; 115 | this.roundData.bets.push([ 116 | { 117 | player: this.players[this.roundData.bigBlind].getUsername(), 118 | bet: this.bigBlind - this.players[this.roundData.bigBlind].money, 119 | }, 120 | ]); 121 | } else { 122 | this.players[this.roundData.bigBlind].money = 123 | this.players[this.roundData.bigBlind].money - this.bigBlind; 124 | this.roundData.bets.push([ 125 | { 126 | player: this.players[this.roundData.bigBlind].getUsername(), 127 | bet: this.bigBlind, 128 | }, 129 | ]); 130 | } 131 | 132 | if (this.players[this.roundData.smallBlind].money == this.smallBlind) { 133 | this.players[this.roundData.smallBlind].money = 0; 134 | this.roundData.bets[0].push({ 135 | player: this.players[this.roundData.smallBlind].getUsername(), 136 | bet: this.smallBlind - this.players[this.roundData.bigBlind].money, 137 | }); 138 | this.players[this.roundData.smallBlind].allIn = true; 139 | } else { 140 | this.players[this.roundData.smallBlind].money = 141 | this.players[this.roundData.smallBlind].money - this.smallBlind; 142 | this.roundData.bets[0].push({ 143 | player: this.players[this.roundData.smallBlind].getUsername(), 144 | bet: this.smallBlind, 145 | }); 146 | } 147 | 148 | this.roundNum++; 149 | this.rerender(); 150 | }; 151 | 152 | this.rerender = () => { 153 | let playersData = []; 154 | for (let pn = 0; pn < this.getNumPlayers(); pn++) { 155 | playersData.push({ 156 | username: this.players[pn].getUsername(), 157 | status: this.players[pn].getStatus(), 158 | blind: this.players[pn].getBlind(), 159 | money: this.players[pn].getMoney(), 160 | buyIns: this.players[pn].buyIns, 161 | isChecked: this.playerIsChecked(this.players[pn]), 162 | }); 163 | } 164 | for (let pn = 0; pn < this.getNumPlayers(); pn++) { 165 | this.players[pn].emit('rerender', { 166 | community: this.community, 167 | topBet: this.getCurrentTopBet(), 168 | bets: this.roundData.bets, 169 | username: this.players[pn].getUsername(), 170 | round: this.roundNum, 171 | stage: this.getStageName(), 172 | pot: this.getCurrentPot(), 173 | players: playersData, 174 | myMoney: this.players[pn].getMoney(), 175 | myBet: this.getPlayerBetInStage(this.players[pn]), 176 | myStatus: this.players[pn].getStatus(), 177 | myBlind: this.players[pn].getBlind(), 178 | roundInProgress: this.roundInProgress, 179 | buyIns: this.players[pn].buyIns, 180 | }); 181 | } 182 | }; 183 | 184 | this.getCurrentPot = () => { 185 | if (this.roundData.bets == undefined || this.roundData.bets.length == 0) 186 | return 0; 187 | else { 188 | let sum = 0; 189 | for (let i = 0; i < this.roundData.bets.length; i++) { 190 | sum += this.roundData.bets[i].reduce( 191 | (acc, curr) => 192 | curr.bet != 'Buy-in' && curr.bet != 'Fold' 193 | ? acc + curr.bet 194 | : acc + 0, 195 | 0 196 | ); 197 | } 198 | return this.foldPot + sum; 199 | } 200 | }; 201 | 202 | this.getPlayerBetInStage = (player) => { 203 | if ( 204 | this.roundData.bets == undefined || 205 | this.roundData.bets.length == 0 || 206 | this.getCurrentRoundBets() == undefined 207 | ) 208 | return 0; 209 | const stageData = this.getCurrentRoundBets(); 210 | let totalBetInStage = 0; 211 | 212 | for (let j = 0; j < stageData.length; j++) { 213 | if ( 214 | stageData[j].player == player.getUsername() && 215 | stageData[j].bet != 'Buy-in' && 216 | stageData[j].bet != 'Fold' 217 | ) { 218 | totalBetInStage += stageData[j].bet; 219 | break; 220 | } 221 | } 222 | return totalBetInStage; 223 | }; 224 | 225 | this.getCurrentTopBet = () => { 226 | if (this.roundData.bets == undefined || this.roundData.bets.length == 0) 227 | return 0; 228 | else { 229 | let maxBet = 0; 230 | for (let i = 0; i < this.players.length; i++) { 231 | maxBet = Math.max(maxBet, this.getPlayerBetInStage(this.players[i])); 232 | } 233 | return maxBet; 234 | } 235 | }; 236 | 237 | this.getStageName = () => { 238 | if (this.roundData.bets.length == 1) { 239 | return 'Pre-Flop'; 240 | } else if (this.roundData.bets.length == 2) { 241 | return 'Flop'; 242 | } else if (this.roundData.bets.length == 3) { 243 | return 'Turn'; 244 | } else if (this.roundData.bets.length == 4) { 245 | return 'River'; 246 | } else { 247 | return 'Error'; 248 | } 249 | }; 250 | 251 | this.playerIsChecked = (playr) => { 252 | if (this.roundData.bets) { 253 | const bets = this.getCurrentRoundBets() || []; 254 | return bets.some((a) => a.player == playr.getUsername() && a.bet == 0); 255 | } 256 | }; 257 | 258 | this.findFirstToGoPlayer = () => { 259 | if ( 260 | !this.players[this.roundData.smallBlind] || 261 | this.players[this.roundData.smallBlind].getStatus() == 'Fold' || 262 | this.players[this.roundData.smallBlind].allIn 263 | ) { 264 | let index = this.roundData.smallBlind; 265 | do { 266 | index = index - 1 < 0 ? this.players.length - 1 : index - 1; 267 | } while ( 268 | this.players[index].getStatus() == 'Fold' || 269 | this.players[index].allIn 270 | ); 271 | return index; 272 | } else { 273 | return this.roundData.smallBlind; 274 | } 275 | }; 276 | 277 | this.getNonFoldedPlayer = () => { 278 | let numNonFolds = 0; 279 | let nonFolderPlayer; 280 | for (let i = 0; i < this.getNumPlayers(); i++) { 281 | if (this.players[i].getStatus() != 'Fold') { 282 | numNonFolds++; 283 | nonFolderPlayer = this.players[i]; 284 | } 285 | } 286 | return [numNonFolds, nonFolderPlayer]; 287 | }; 288 | 289 | this.updateStage = () => { 290 | for (let i = 0; i < this.players.length; i++) { 291 | if ( 292 | i === this.findFirstToGoPlayer() && 293 | this.players[i].getStatus() !== 'Fold' 294 | ) { 295 | this.players[i].setStatus('Their Turn'); 296 | } else if (this.players[i].getStatus() !== 'Fold') { 297 | this.players[i].setStatus(''); 298 | } 299 | } 300 | this.roundData.bets.push([]); 301 | }; 302 | 303 | this.moveOntoNextPlayer = () => { 304 | let handOver = false; 305 | if (this.isStageComplete()) { 306 | this.log('stage complete'); 307 | if (this.allPlayersAllIn()) { 308 | this.log(' all players all in'); 309 | if (this.roundData.bets.length == 1) { 310 | this.community.push(this.deck.dealRandomCard()); 311 | this.community.push(this.deck.dealRandomCard()); 312 | this.community.push(this.deck.dealRandomCard()); 313 | this.roundData.bets.push([]); 314 | } 315 | if (this.roundData.bets.length == 2) { 316 | this.community.push(this.deck.dealRandomCard()); 317 | this.roundData.bets.push([]); 318 | } 319 | if (this.roundData.bets.length == 3) { 320 | this.community.push(this.deck.dealRandomCard()); 321 | this.roundData.bets.push([]); 322 | } 323 | this.rerender(); 324 | } 325 | // stage-by-stage logic. 326 | // check if everyone folded but one 327 | const [numNonFolds, nonFolderPlayer] = this.getNonFoldedPlayer(); 328 | if (numNonFolds == 1) { 329 | // everyone folded, start new round, give pot to player 330 | this.log('everyone folded except one'); 331 | nonFolderPlayer.money = this.getCurrentPot() + nonFolderPlayer.money; 332 | this.endHandAllFold(nonFolderPlayer.getUsername()); 333 | handOver = true; 334 | } else { 335 | if (this.roundData.bets.length == 1) { 336 | this.community.push(this.deck.dealRandomCard()); 337 | this.community.push(this.deck.dealRandomCard()); 338 | this.community.push(this.deck.dealRandomCard()); 339 | this.updateStage(); 340 | } else if (this.roundData.bets.length == 2) { 341 | this.community.push(this.deck.dealRandomCard()); 342 | this.updateStage(); 343 | } else if (this.roundData.bets.length == 3) { 344 | this.community.push(this.deck.dealRandomCard()); 345 | this.updateStage(); 346 | } else if (this.roundData.bets.length == 4) { 347 | handOver = true; 348 | const roundResults = this.evaluateWinners(); 349 | for (playerResult of roundResults.playersData) { 350 | playerResult.player.setStatus(playerResult.hand.name); 351 | } 352 | const winningData = this.distributeMoney(roundResults); 353 | this.revealCards(winningData.filter((a) => a.winner)); 354 | } else { 355 | this.log('This stage of the round is INVALID!!'); 356 | } 357 | } 358 | } else { 359 | this.log('stage not complete'); 360 | //check if everyone folded except one player 361 | const [numNonFolds, nonFolderPlayer] = this.getNonFoldedPlayer(); 362 | if (!handOver && numNonFolds == 1) { 363 | // everyone folded, start new round, give pot to player 364 | this.log('everyone folded except one'); 365 | nonFolderPlayer.money = this.getCurrentPot() + nonFolderPlayer.money; 366 | this.endHandAllFold(nonFolderPlayer.getUsername()); 367 | handOver = true; 368 | } else { 369 | let currTurnIndex = 0; 370 | //check if move just made was a fold 371 | if (this.lastMoveParsed.move == 'Fold') { 372 | currTurnIndex = this.players.findIndex( 373 | (p) => p === this.lastMoveParsed.player 374 | ); 375 | this.lastMoveParsed = { move: '', player: '' }; 376 | } else { 377 | currTurnIndex = this.players.findIndex( 378 | (p) => p.getStatus() === 'Their Turn' 379 | ); 380 | this.players[currTurnIndex].setStatus(''); 381 | } 382 | let count = 0; 383 | do { 384 | currTurnIndex = currTurnIndex - 1 < 0 ? this.players.length - 1 : currTurnIndex - 1; 385 | count ++; 386 | } while ( 387 | (this.players[currTurnIndex].getStatus() == 'Fold' 388 | || this.players[currTurnIndex].allIn) 389 | && count < Object.keys(this.players).length * 2 // Avoid infinite loop, allow search twice on all players 390 | ); 391 | this.players[currTurnIndex].setStatus('Their Turn'); 392 | } 393 | } 394 | if (!handOver) { 395 | this.log('RERENDERING'); 396 | this.rerender(); 397 | } 398 | }; 399 | 400 | this.getPlayerBetInStageNum = (player, stageNum) => { 401 | if ( 402 | this.roundData.bets == undefined || 403 | this.roundData.bets.length == 0 || 404 | this.roundData.bets[stageNum - 1] == undefined 405 | ) 406 | return 0; 407 | const stageData = this.roundData.bets[stageNum - 1]; 408 | let totalBetInStage = 0; 409 | 410 | for (let j = 0; j < stageData.length; j++) { 411 | if ( 412 | stageData[j].player == player.getUsername() && 413 | stageData[j].bet != 'Buy-in' && 414 | stageData[j].bet != 'Fold' 415 | ) 416 | totalBetInStage += stageData[j].bet; 417 | } 418 | return totalBetInStage; 419 | }; 420 | 421 | this.getTotalBetsInStageNum = (stageNum) => { 422 | if ( 423 | this.roundData.bets == undefined || 424 | this.roundData.bets.length == 0 || 425 | this.roundData.bets[stageNum - 1] == undefined 426 | ) 427 | return 0; 428 | const stageData = this.roundData.bets[stageNum - 1]; 429 | let totalBetInStage = 0; 430 | 431 | for (let j = 0; j < stageData.length; j++) { 432 | if (stageData[j].bet != 'Buy-in' && stageData[j].bet != 'Fold') 433 | totalBetInStage += stageData[j].bet; 434 | } 435 | return totalBetInStage; 436 | }; 437 | 438 | this.getTotalInvested = (player) => { 439 | return ( 440 | this.getPlayerBetInStageNum(player, 1) + 441 | this.getPlayerBetInStageNum(player, 2) + 442 | this.getPlayerBetInStageNum(player, 3) + 443 | this.getPlayerBetInStageNum(player, 4) 444 | ); 445 | }; 446 | 447 | this.calculateMoney = (winnerPot, players) => { 448 | let playerInvestments = [...players]; 449 | while (playerInvestments.length > 1) { 450 | const sortedByInvested = playerInvestments.sort((a, b) => 451 | a.invested < b.invested ? -1 : 1 452 | ); 453 | const minStack = sortedByInvested[0].invested; 454 | winnerPot += minStack * playerInvestments.length; 455 | for (p of playerInvestments) { 456 | p.invested -= minStack; 457 | } 458 | const sortedByHandStrength = playerInvestments.sort((a, b) => 459 | a.handStrength > b.handStrength ? -1 : 1 460 | ); 461 | const maxHand = sortedByHandStrength[0].handStrength; 462 | const winners = playerInvestments.filter( 463 | (p) => p.handStrength === maxHand && p.live 464 | ); 465 | for (p of winners) { 466 | p.result += winnerPot / winners.length; 467 | } 468 | playerInvestments = playerInvestments.filter((p) => p.invested > 0); 469 | winnerPot = 0; 470 | } 471 | 472 | if (playerInvestments.length === 1) { 473 | let p = playerInvestments[0]; 474 | p.result += winnerPot + p.invested; 475 | } 476 | }; 477 | 478 | this.distributeMoney = (result) => { 479 | let playerInvestments = this.players.map((p) => { 480 | const winData = result.winnerData.find((w) => w.player === p); 481 | const invested = this.getTotalInvested(p); 482 | return { 483 | player: p, 484 | invested: invested, 485 | originalInvested: invested, 486 | handStrength: winData ? winData.rank : -1, 487 | result: -invested, 488 | live: p.getStatus() !== 'Fold', 489 | winner: false, 490 | gain: 0, 491 | }; 492 | }); 493 | let pot = this.foldPot; 494 | this.calculateMoney(pot, playerInvestments); 495 | 496 | for (p of playerInvestments) { 497 | p.gain = p.originalInvested + p.result; 498 | p.player.money += p.gain; 499 | if (p.gain > 0) { 500 | p.winner = true; 501 | } 502 | } 503 | return playerInvestments; 504 | }; 505 | 506 | this.evaluateWinners = () => { 507 | let handArray = []; 508 | let playerArray = []; 509 | for (let i = 0; i < this.players.length; i++) { 510 | if (this.players[i].getStatus() != 'Fold') { 511 | let h = Hand.solve( 512 | this.convertCardsFormat(this.players[i].cards.concat(this.community)) 513 | ); 514 | handArray.push(h); 515 | playerArray.push({ player: this.players[i], hand: h }); 516 | } 517 | } 518 | const winners = Hand.winners(handArray); 519 | 520 | let winnerData = []; 521 | if (Array.isArray(winners)) { 522 | for (playerHand of playerArray) { 523 | for (winner of winners) { 524 | let winnerArray = winner.toString().split(', '); 525 | if ( 526 | this.arraysEqual(playerHand.hand.cards.sort(), winnerArray.sort()) 527 | ) { 528 | winnerData.push({ 529 | player: playerHand.player, 530 | rank: playerHand.hand.rank, 531 | handTitle: playerHand.hand.name, 532 | }); 533 | break; 534 | } 535 | } 536 | } 537 | } else { 538 | this.log('fatal error: winner cannot be calculated'); 539 | } 540 | const res = { winnerData: winnerData, playersData: playerArray }; 541 | return res; 542 | }; 543 | 544 | this.arraysEqual = (a, b) => { 545 | if (a === b) return true; 546 | if (a == null || b == null) return false; 547 | if (a.length != b.length) return false; 548 | 549 | for (let i = 0; i < a.length; ++i) { 550 | if (a[i] != b[i]) return false; 551 | } 552 | return true; 553 | }; 554 | 555 | this.convertCardsFormat = (arr) => { 556 | let res = []; 557 | for (let i = 0; i < arr.length; i++) { 558 | let str = ''; 559 | let value = arr[i].getValue(); 560 | let suit = arr[i].getSuit(); 561 | if (value == 10) { 562 | str += 'T'; 563 | } else { 564 | str += value.toString(); 565 | } 566 | if (suit == '♠') str += 's'; 567 | else if (suit == '♥') str += 'h'; 568 | else if (suit == '♦') str += 'd'; 569 | else if (suit == '♣') str += 'c'; 570 | res.push(str); 571 | } 572 | return res; 573 | }; 574 | 575 | this.endHandAllFold = (username) => { 576 | this.log('endhandallfold' + this.players); 577 | this.roundInProgress = false; 578 | let cardData = []; 579 | for (let i = 0; i < this.players.length; i++) { 580 | cardData.push({ 581 | username: this.players[i].getUsername(), 582 | money: this.players[i].getMoney(), 583 | text: this.players[i].getStatus(), 584 | }); 585 | } 586 | for (let pn = 0; pn < this.getNumPlayers(); pn++) { 587 | this.players[pn].emit('endHand', { 588 | winner: username, 589 | folded: this.players[pn].getUsername() != username ? 'Fold' : '', 590 | username: this.players[pn].getUsername(), 591 | pot: this.getCurrentPot(), 592 | money: this.players[pn].getMoney(), 593 | cards: cardData, 594 | bets: this.roundData.bets, 595 | }); 596 | } 597 | }; 598 | 599 | this.revealCards = (winners) => { 600 | this.log('revealllllll'); 601 | this.roundInProgress = false; 602 | let cardData = []; 603 | for (let i = 0; i < this.players.length; i++) { 604 | const winData = winners.find((w) => w.player === this.players[i]); 605 | cardData.push({ 606 | username: this.players[i].getUsername(), 607 | cards: this.players[i].cards, 608 | hand: this.players[i].getStatus(), 609 | folded: this.players[i].getStatus() == 'Fold', 610 | money: this.players[i].getMoney(), 611 | buyIns: this.players[i].buyIns, 612 | gain: winData ? winData.gain : null, 613 | }); 614 | } 615 | const winnersUsernames = winners 616 | .map((a) => a.player.getUsername()) 617 | .toString(); 618 | for (let pn = 0; pn < this.getNumPlayers(); pn++) { 619 | this.players[pn].emit('reveal', { 620 | username: this.players[pn].getUsername(), 621 | money: this.players[pn].getMoney(), 622 | cards: cardData, 623 | bets: this.roundData.bets, 624 | winners: winnersUsernames, 625 | hand: this.players[pn].getStatus(), 626 | }); 627 | } 628 | }; 629 | 630 | this.allPlayersAllIn = () => { 631 | let participatingPlayers = 0; 632 | for (player of this.players) { 633 | if (!player.allIn && player.getStatus() != 'Fold') participatingPlayers++; 634 | } 635 | return participatingPlayers <= 1; 636 | }; 637 | 638 | this.isStageComplete = () => { 639 | let allPlayersPresent = false; 640 | let numUnfolded = 0; 641 | for (let i = 0; i < this.players.length; i++) { 642 | if (this.players[i].status != 'Fold' && !this.players[i].allIn) 643 | numUnfolded++; 644 | } 645 | const currRound = this.getCurrentRoundBets(); 646 | if (this.roundData.bets.length == 1) { 647 | allPlayersPresent = 648 | currRound.filter((a) => a.bet != 'Fold').length >= numUnfolded && 649 | this.bigBlindWent; 650 | } else { 651 | allPlayersPresent = 652 | currRound.filter((a) => a.bet != 'Fold').length >= numUnfolded; 653 | } 654 | this.log('all players present ' + allPlayersPresent); 655 | let allPlayersCall = true; 656 | for (player of this.players) { 657 | if ( 658 | player.getStatus() != 'Fold' && 659 | this.getPlayerBetInStage(player) != this.getCurrentTopBet() && 660 | !player.allIn 661 | ) { 662 | allPlayersCall = false; 663 | break; 664 | } 665 | } 666 | this.log('all players call ' + allPlayersCall); 667 | return allPlayersPresent && allPlayersCall; 668 | }; 669 | 670 | this.setCardsPerPlayer = (numCards) => { 671 | this.cardsPerPlayer = numCards; 672 | }; 673 | 674 | this.getHostName = () => { 675 | return this.host; 676 | }; 677 | 678 | this.getPlayersArray = () => { 679 | return this.players.map((p) => { 680 | return p.getUsername(); 681 | }); 682 | }; 683 | 684 | this.getCode = () => { 685 | return this.gameName; 686 | }; 687 | 688 | this.addPlayer = (playerName, socket) => { 689 | const player = new Player(playerName, socket, this.debug); 690 | this.players.push(player); 691 | return player; 692 | }; 693 | 694 | this.getNumPlayers = () => { 695 | return this.players.length; 696 | }; 697 | 698 | this.startGame = () => { 699 | this.dealCards(); 700 | this.emitPlayers('startGame', { 701 | players: this.players.map((p) => { 702 | return p.username; 703 | }), 704 | }); 705 | this.startNewRound(); 706 | }; 707 | 708 | this.dealCards = () => { 709 | this.deck.shuffle(); 710 | for (let pn = 0; pn < this.getNumPlayers(); pn++) { 711 | this.players[pn].cards = []; 712 | for (let i = 0; i < this.cardsPerPlayer; i++) { 713 | this.players[pn].addCard(this.deck.dealRandomCard()); 714 | } 715 | } 716 | 717 | this.refreshCards(); 718 | }; 719 | 720 | this.refreshCards = function () { 721 | for (let pn = 0; pn < this.getNumPlayers(); pn++) { 722 | this.players[pn].cards.sort((a, b) => { 723 | return a.compare(b); 724 | }); 725 | 726 | this.players[pn].emit('dealt', { 727 | currBet: this.getCurrentTopBet(), 728 | username: this.players[pn].getUsername(), 729 | cards: this.players[pn].cards, 730 | players: this.players.map((p) => { 731 | return p.username; 732 | }), 733 | }); 734 | } 735 | }; 736 | 737 | this.emitPlayers = (eventName, payload) => { 738 | for (let pn = 0; pn < this.getNumPlayers(); pn++) { 739 | this.players[pn].emit(eventName, payload); 740 | } 741 | }; 742 | 743 | this.findPlayer = (socketId) => { 744 | for (let pn = 0; pn < this.getNumPlayers(); pn++) { 745 | if (this.players[pn].socket.id === socketId) { 746 | return this.players[pn]; 747 | } 748 | } 749 | return { socket: { id: 0 } }; 750 | }; 751 | 752 | this.disconnectPlayer = (player) => { 753 | this.disconnectedPlayers.push(player); 754 | if (player.getStatus() == 'Their Turn') { 755 | this.moveOntoNextPlayer(); 756 | } 757 | this.players = this.players.filter((a) => a !== player); 758 | if (player.getUsername() == this.host) { 759 | if (this.players.length > 0) { 760 | this.host = this.players[0].getUsername(); 761 | } 762 | } 763 | this.emitPlayers('playerDisconnected', { player: player.getUsername() }); 764 | this.emitPlayers('joinRoomUpdate', { 765 | players: this.getPlayersArray(), 766 | code: this.getCode(), 767 | }); 768 | this.emitPlayers('hostRoomUpdate', { players: this.getPlayersArray() }); 769 | this.rerender(); 770 | }; 771 | 772 | this.checkBigBlindWent = (socket) => { 773 | if ( 774 | this.findPlayer(socket.id).blindValue == 'Big Blind' && 775 | this.roundData.bets.length == 1 776 | ) { 777 | this.bigBlindWent = true; 778 | } 779 | }; 780 | 781 | this.getCurrentRoundBets = () => { 782 | return this.roundData.bets[this.roundData.bets.length - 1]; 783 | }; 784 | 785 | this.setCurrentRoundBets = (bets) => { 786 | return (this.roundData.bets[this.roundData.bets.length - 1] = bets); 787 | }; 788 | 789 | this.fold = (socket) => { 790 | this.checkBigBlindWent(socket); 791 | const player = this.findPlayer(socket.id); 792 | let preFoldBetAmount = 0; 793 | 794 | let roundDataStage = this.getCurrentRoundBets().find( 795 | (a) => a.player == player.getUsername() 796 | ); 797 | if (roundDataStage != undefined && roundDataStage.bet != 'Fold') { 798 | preFoldBetAmount += roundDataStage.bet; 799 | } 800 | player.setStatus('Fold'); 801 | this.foldPot = this.foldPot + preFoldBetAmount; 802 | if ( 803 | this.getCurrentRoundBets().some((a) => a.player == player.getUsername()) 804 | ) { 805 | this.setCurrentRoundBets( 806 | this.getCurrentRoundBets().map((a) => 807 | a.player == player.getUsername() 808 | ? { player: player.getUsername(), bet: 'Fold' } 809 | : a 810 | ) 811 | ); 812 | } else { 813 | this.getCurrentRoundBets().push({ 814 | player: player.getUsername(), 815 | bet: 'Fold', 816 | }); 817 | } 818 | this.lastMoveParsed = { move: 'Fold', player: player }; 819 | this.moveOntoNextPlayer(); 820 | return true; 821 | }; 822 | 823 | this.call = (socket) => { 824 | this.checkBigBlindWent(socket); 825 | const player = this.findPlayer(socket.id); 826 | let currBet = this.getPlayerBetInStage(player); 827 | const topBet = this.getCurrentTopBet(); 828 | if (currBet === 0) { 829 | if ( 830 | this.getCurrentRoundBets().some((a) => a.player == player.getUsername()) 831 | ) { 832 | if (player.getMoney() - topBet <= 0) { 833 | this.setCurrentRoundBets( 834 | this.getCurrentRoundBets().map((a) => 835 | a.player == player.username 836 | ? { player: player.getUsername(), bet: player.getMoney() } 837 | : a 838 | ) 839 | ); 840 | player.money = 0; 841 | player.allIn = true; 842 | } else { 843 | this.setCurrentRoundBets( 844 | this.getCurrentRoundBets().map((a) => 845 | a.player == player.username 846 | ? { player: player.getUsername(), bet: topBet } 847 | : a 848 | ) 849 | ); 850 | player.money = player.money - topBet; 851 | } 852 | } else { 853 | if (player.getMoney() - topBet <= 0) { 854 | this.getCurrentRoundBets().push({ 855 | player: player.getUsername(), 856 | bet: player.getMoney(), 857 | }); 858 | player.money = 0; 859 | player.allIn = true; 860 | } else { 861 | this.getCurrentRoundBets().push({ 862 | player: player.getUsername(), 863 | bet: topBet, 864 | }); 865 | player.money = player.money - topBet; 866 | } 867 | } 868 | this.moveOntoNextPlayer(); 869 | return true; 870 | } else { 871 | if ( 872 | this.getCurrentRoundBets().some((a) => a.player == player.getUsername()) 873 | ) { 874 | if (player.getMoney() + currBet - topBet <= 0) { 875 | this.setCurrentRoundBets( 876 | this.getCurrentRoundBets().map((a) => 877 | a.player == player.username 878 | ? { 879 | player: player.getUsername(), 880 | bet: player.getMoney() + currBet, 881 | } 882 | : a 883 | ) 884 | ); 885 | player.money = 0; 886 | player.allIn = true; 887 | this.moveOntoNextPlayer(); 888 | } else { 889 | this.setCurrentRoundBets( 890 | this.getCurrentRoundBets().map((a) => 891 | a.player == player.username 892 | ? { player: player.getUsername(), bet: topBet } 893 | : a 894 | ) 895 | ); 896 | player.money = player.money - (topBet - currBet); 897 | this.moveOntoNextPlayer(); 898 | } 899 | return true; 900 | } else { 901 | this.log('this should not happen'); 902 | } 903 | } 904 | }; 905 | 906 | this.bet = (socket, bet) => { 907 | this.checkBigBlindWent(socket); 908 | if (bet >= this.bigBlind) { 909 | const player = this.findPlayer(socket.id); 910 | if (player.getMoney() - bet >= 0) { 911 | this.setCurrentRoundBets( 912 | this.getCurrentRoundBets().filter( 913 | (a) => a.player != player.getUsername() 914 | ) 915 | ); 916 | this.getCurrentRoundBets().push({ 917 | player: player.getUsername(), 918 | bet: bet, 919 | }); 920 | player.money = player.money - bet; 921 | if (player.money == 0) player.allIn = true; 922 | this.moveOntoNextPlayer(); 923 | return true; 924 | } 925 | } 926 | }; 927 | 928 | this.check = (socket) => { 929 | this.checkBigBlindWent(socket); 930 | let currBet = 0; 931 | const player = this.findPlayer(socket.id); 932 | if ( 933 | this.getCurrentRoundBets().find( 934 | (a) => a.player == player.getUsername() 935 | ) != undefined 936 | ) { 937 | currBet = this.getCurrentRoundBets().find( 938 | (a) => a.player == player.getUsername() 939 | ).bet; 940 | this.setCurrentRoundBets( 941 | this.getCurrentRoundBets().map((a) => 942 | a.player == player.getUsername() 943 | ? { player: player.getUsername(), bet: currBet } 944 | : a 945 | ) 946 | ); 947 | } else { 948 | this.getCurrentRoundBets().push({ 949 | player: player.getUsername(), 950 | bet: currBet, 951 | }); 952 | } 953 | this.moveOntoNextPlayer(); 954 | return true; 955 | }; 956 | 957 | this.raise = (socket, bet) => { 958 | this.checkBigBlindWent(socket); 959 | const topBet = this.getCurrentTopBet(); 960 | const player = this.findPlayer(socket.id); 961 | const currBet = this.getPlayerBetInStage(player); 962 | const moneyToRemove = bet - currBet; 963 | if ( 964 | moneyToRemove > 0 && 965 | bet >= topBet && 966 | player.getMoney() - moneyToRemove >= 0 967 | ) { 968 | if (currBet === 0) { 969 | this.setCurrentRoundBets( 970 | this.getCurrentRoundBets().filter( 971 | (a) => a.player != player.getUsername() 972 | ) 973 | ); 974 | this.getCurrentRoundBets().push({ 975 | player: player.getUsername(), 976 | bet: bet, 977 | }); 978 | } else { 979 | this.setCurrentRoundBets( 980 | this.getCurrentRoundBets().map((a) => 981 | a.player == player.getUsername() 982 | ? { player: player.getUsername(), bet: bet } 983 | : a 984 | ) 985 | ); 986 | } 987 | player.money -= moneyToRemove; 988 | if (player.money == 0) player.allIn = true; 989 | this.moveOntoNextPlayer(); 990 | return true; 991 | } 992 | }; 993 | 994 | this.getPossibleMoves = (socket) => { 995 | const player = this.findPlayer(socket.id); 996 | const playerBet = this.getPlayerBetInStage(player); 997 | const topBet = this.getCurrentTopBet(); 998 | let possibleMoves = { 999 | fold: 'yes', 1000 | check: 'yes', 1001 | bet: 'yes', 1002 | call: topBet, 1003 | raise: 'yes', 1004 | }; 1005 | if (player.getStatus() == 'Fold') { 1006 | this.log('Error: Folded players should not be able to move.'); 1007 | } 1008 | if (topBet != 0) { 1009 | possibleMoves.bet = 'no'; 1010 | possibleMoves.check = 'no'; 1011 | if ( 1012 | player.blindValue == 'Big Blind' && 1013 | !this.bigBlindWent && 1014 | topBet == this.bigBlind 1015 | ) 1016 | possibleMoves.check = 'yes'; 1017 | } else { 1018 | possibleMoves.raise = 'no'; 1019 | } 1020 | if (topBet <= playerBet) { 1021 | possibleMoves.call = 'no'; 1022 | } 1023 | if (topBet >= player.getMoney() + playerBet) { 1024 | possibleMoves.raise = 'no'; 1025 | possibleMoves.call = 'all-in'; 1026 | } 1027 | return possibleMoves; 1028 | }; 1029 | }; 1030 | 1031 | module.exports = Game; 1032 | -------------------------------------------------------------------------------- /src/client/js/jquery-2.1.4.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v2.1.4 | (c) 2005, 2015 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=a.document,m="2.1.4",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,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=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.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},n.extend=n.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||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)+1>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},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=s(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(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;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=s(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&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b="length"in a&&a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+1*new Date,v=a.document,w=0,x=0,y=ha(),z=ha(),A=ha(),B=function(a,b){return a===b&&(l=!0),0},C=1<<31,D={}.hasOwnProperty,E=[],F=E.pop,G=E.push,H=E.push,I=E.slice,J=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},K="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",L="[\\x20\\t\\r\\n\\f]",M="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",N=M.replace("w","w#"),O="\\["+L+"*("+M+")(?:"+L+"*([*^$|!~]?=)"+L+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+N+"))|)"+L+"*\\]",P=":("+M+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+O+")*)|.*)\\)|)",Q=new RegExp(L+"+","g"),R=new RegExp("^"+L+"+|((?:^|[^\\\\])(?:\\\\.)*)"+L+"+$","g"),S=new RegExp("^"+L+"*,"+L+"*"),T=new RegExp("^"+L+"*([>+~]|"+L+")"+L+"*"),U=new RegExp("="+L+"*([^\\]'\"]*?)"+L+"*\\]","g"),V=new RegExp(P),W=new RegExp("^"+N+"$"),X={ID:new RegExp("^#("+M+")"),CLASS:new RegExp("^\\.("+M+")"),TAG:new RegExp("^("+M.replace("w","w*")+")"),ATTR:new RegExp("^"+O),PSEUDO:new RegExp("^"+P),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+L+"*(even|odd|(([+-]|)(\\d*)n|)"+L+"*(?:([+-]|)"+L+"*(\\d+)|))"+L+"*\\)|)","i"),bool:new RegExp("^(?:"+K+")$","i"),needsContext:new RegExp("^"+L+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+L+"*((?:-\\d)?\\d*)"+L+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,aa=/[+~]/,ba=/'|\\/g,ca=new RegExp("\\\\([\\da-f]{1,6}"+L+"?|("+L+")|.)","ig"),da=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)},ea=function(){m()};try{H.apply(E=I.call(v.childNodes),v.childNodes),E[v.childNodes.length].nodeType}catch(fa){H={apply:E.length?function(a,b){G.apply(a,I.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function ga(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||[],k=b.nodeType,"string"!=typeof a||!a||1!==k&&9!==k&&11!==k)return d;if(!e&&p){if(11!==k&&(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 H.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName)return H.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=1!==k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(ba,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+ra(o[l]);w=aa.test(a)&&pa(b.parentNode)||b,x=o.join(",")}if(x)try{return H.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function ha(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function ia(a){return a[u]=!0,a}function ja(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function ka(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function la(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||C)-(~a.sourceIndex||C);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function ma(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function na(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function oa(a){return ia(function(b){return b=+b,ia(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 pa(a){return a&&"undefined"!=typeof a.getElementsByTagName&&a}c=ga.support={},f=ga.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=ga.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=g.documentElement,e=g.defaultView,e&&e!==e.top&&(e.addEventListener?e.addEventListener("unload",ea,!1):e.attachEvent&&e.attachEvent("onunload",ea)),p=!f(g),c.attributes=ja(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ja(function(a){return a.appendChild(g.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(g.getElementsByClassName),c.getById=ja(function(a){return o.appendChild(a).id=u,!g.getElementsByName||!g.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(ca,da);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(ca,da);return function(a){var c="undefined"!=typeof a.getAttributeNode&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return"undefined"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(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 p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(g.querySelectorAll))&&(ja(function(a){o.appendChild(a).innerHTML="",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+L+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+L+"*(?:value|"+K+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),ja(function(a){var b=g.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+L+"*[*^$|!~]?="),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))&&ja(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",P)}),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===g||a.ownerDocument===v&&t(v,a)?-1:b===g||b.ownerDocument===v&&t(v,b)?1:k?J(k,a)-J(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,h=[a],i=[b];if(!e||!f)return a===g?-1:b===g?1:e?-1:f?1:k?J(k,a)-J(k,b):0;if(e===f)return la(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?la(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},g):n},ga.matches=function(a,b){return ga(a,null,null,b)},ga.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 ga(b,n,null,[a]).length>0},ga.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},ga.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&D.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},ga.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},ga.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=ga.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=ga.selectors={cacheLength:50,createPseudo:ia,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(ca,da),a[3]=(a[3]||a[4]||a[5]||"").replace(ca,da),"~="===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]||ga.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]&&ga.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(ca,da).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("(^|"+L+")"+a+"("+L+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||"undefined"!=typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=ga.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.replace(Q," ")+" ").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()]||ga.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ia(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=J(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ia(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?ia(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),b[0]=null,!c.pop()}}),has:ia(function(a){return function(b){return ga(a,b).length>0}}),contains:ia(function(a){return a=a.replace(ca,da),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ia(function(a){return W.test(a||"")||ga.error("unsupported lang: "+a),a=a.replace(ca,da).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:oa(function(){return[0]}),last:oa(function(a,b){return[b-1]}),eq:oa(function(a,b,c){return[0>c?c+b:c]}),even:oa(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:oa(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:oa(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:oa(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function sa(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 ta(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 ua(a,b,c){for(var d=0,e=b.length;e>d;d++)ga(a,b[d],c);return c}function va(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 wa(a,b,c,d,e,f){return d&&!d[u]&&(d=wa(d)),e&&!e[u]&&(e=wa(e,f)),ia(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||ua(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:va(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=va(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?J(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=va(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):H.apply(g,r)})}function xa(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=sa(function(a){return a===b},h,!0),l=sa(function(a){return J(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];f>i;i++)if(c=d.relative[a[i].type])m=[sa(ta(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 wa(i>1&&ta(m),i>1&&ra(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&xa(a.slice(i,e)),f>e&&xa(a=a.slice(e)),f>e&&ra(a))}m.push(c)}return ta(m)}function ya(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]=F.call(i));s=va(s)}H.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&ga.uniqueSort(i)}return k&&(w=v,j=t),r};return c?ia(f):f}return h=ga.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=xa(b[c]),f[u]?d.push(f):e.push(f);f=A(a,ya(e,d)),f.selector=a}return f},i=ga.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(ca,da),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(ca,da),aa.test(j[0].type)&&pa(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&ra(j),!a)return H.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,aa.test(a)&&pa(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ja(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ja(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||ka("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ja(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||ka("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ja(function(a){return null==a.getAttribute("disabled")})||ka(K,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),ga}(a);n.find=t,n.expr=t.selectors,n.expr[":"]=n.expr.pseudos,n.unique=t.uniqueSort,n.text=t.getText,n.isXMLDoc=t.isXML,n.contains=t.contains;var u=n.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(n.isFunction(b))return n.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return n.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return n.filter(b,a,c);b=n.filter(b,a)}return n.grep(a,function(a){return g.call(b,a)>=0!==c})}n.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?n.find.matchesSelector(d,a)?[d]:[]:n.find.matches(a,n.grep(b,function(a){return 1===a.nodeType}))},n.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(n(a).filter(function(){for(b=0;c>b;b++)if(n.contains(e[b],this))return!0}));for(b=0;c>b;b++)n.find(a,e[b],d);return d=this.pushStack(c>1?n.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?n(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=n.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof n?b[0]:b,n.merge(this,n.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:l,!0)),v.test(c[1])&&n.isPlainObject(b))for(c in b)n.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=l.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=l,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):n.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(n):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),n.makeArray(a,this))};A.prototype=n.fn,y=n(l);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};n.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&n(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),n.fn.extend({has:function(a){var b=n(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(n.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?n(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&&n.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?n.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(n(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(n.unique(n.merge(this.get(),n(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}n.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return n.dir(a,"parentNode")},parentsUntil:function(a,b,c){return n.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return n.dir(a,"nextSibling")},prevAll:function(a){return n.dir(a,"previousSibling")},nextUntil:function(a,b,c){return n.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return n.dir(a,"previousSibling",c)},siblings:function(a){return n.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return n.sibling(a.firstChild)},contents:function(a){return a.contentDocument||n.merge([],a.childNodes)}},function(a,b){n.fn[a]=function(c,d){var e=n.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=n.filter(d,e)),this.length>1&&(C[a]||n.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return n.each(a.match(E)||[],function(a,c){b[c]=!0}),b}n.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):n.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&n.each(arguments,function(a,b){var c;while((c=n.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?n.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},n.extend({Deferred:function(a){var b=[["resolve","done",n.Callbacks("once memory"),"resolved"],["reject","fail",n.Callbacks("once memory"),"rejected"],["notify","progress",n.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.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?n.extend(a,d):d}},e={};return d.pipe=d.then,n.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&&n.isFunction(a.promise)?e:0,g=1===f?a:n.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]&&n.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;n.fn.ready=function(a){return n.ready.promise().done(a),this},n.extend({isReady:!1,readyWait:1,holdReady:function(a){a?n.readyWait++:n.ready(!0)},ready:function(a){(a===!0?--n.readyWait:n.isReady)||(n.isReady=!0,a!==!0&&--n.readyWait>0||(H.resolveWith(l,[n]),n.fn.triggerHandler&&(n(l).triggerHandler("ready"),n(l).off("ready"))))}});function I(){l.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),n.ready()}n.ready.promise=function(b){return H||(H=n.Deferred(),"complete"===l.readyState?setTimeout(n.ready):(l.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},n.ready.promise();var J=n.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===n.type(c)){e=!0;for(h in c)n.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,n.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(n(a),c)})),b))for(;i>h;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};n.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=n.expando+K.uid++}K.uid=1,K.accepts=n.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,n.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(n.isEmptyObject(f))n.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,n.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{n.isArray(b)?d=b.concat(b.map(n.camelCase)):(e=n.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!n.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?n.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}n.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){return M.access(a,b,c)},removeData:function(a,b){M.remove(a,b)},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.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.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.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 L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.lengthx",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=i[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete i[o])}else for(o in i)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,m,o,p=[d||l],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||l,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+n.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:n.makeArray(c,[b]),o=n.event.special[q]||{},e||!o.trigger||o.trigger.apply(d,c)!==!1)){if(!e&&!o.noBubble&&!n.isWindow(d)){for(i=o.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||l)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:o.bindType||q,m=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),m&&m.apply(g,c),m=k&&g[k],m&&m.apply&&n.acceptData(g)&&(b.result=m.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||o._default&&o._default.apply(p.pop(),c)!==!1||!n.acceptData(d)||k&&n.isFunction(d[q])&&!n.isWindow(d)&&(h=d[k],h&&(d[k]=null),n.event.triggered=q,d[q](),n.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!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(i.disabled!==!0||"click"!==a.type){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?n(e,this).index(i)>=0:n.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h]*)\/>/gi,ba=/<([\w:]+)/,ca=/<|&#?\w+;/,da=/<(?:script|style|link)/i,ea=/checked\s*(?:[^=]|=\s*.checked.)/i,fa=/^$|\/(?:java|ecma)script/i,ga=/^true\/(.*)/,ha=/^\s*\s*$/g,ia={option:[1,""],thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};ia.optgroup=ia.option,ia.tbody=ia.tfoot=ia.colgroup=ia.caption=ia.thead,ia.th=ia.td;function ja(a,b){return n.nodeName(a,"table")&&n.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function ka(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function la(a){var b=ga.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function ma(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function na(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)n.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=n.extend({},h),M.set(b,i))}}function oa(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&n.nodeName(a,b)?n.merge([a],c):c}function pa(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}n.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=n.contains(a.ownerDocument,a);if(!(k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||n.isXMLDoc(a)))for(g=oa(h),f=oa(a),d=0,e=f.length;e>d;d++)pa(f[d],g[d]);if(b)if(c)for(f=f||oa(a),g=g||oa(h),d=0,e=f.length;e>d;d++)na(f[d],g[d]);else na(a,h);return g=oa(h,"script"),g.length>0&&ma(g,!i&&oa(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,o=a.length;o>m;m++)if(e=a[m],e||0===e)if("object"===n.type(e))n.merge(l,e.nodeType?[e]:e);else if(ca.test(e)){f=f||k.appendChild(b.createElement("div")),g=(ba.exec(e)||["",""])[1].toLowerCase(),h=ia[g]||ia._default,f.innerHTML=h[1]+e.replace(aa,"<$1>")+h[2],j=h[0];while(j--)f=f.lastChild;n.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===n.inArray(e,d))&&(i=n.contains(e.ownerDocument,e),f=oa(k.appendChild(e),"script"),i&&ma(f),c)){j=0;while(e=f[j++])fa.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f=n.event.special,g=0;void 0!==(c=a[g]);g++){if(n.acceptData(c)&&(e=c[L.expando],e&&(b=L.cache[e]))){if(b.events)for(d in b.events)f[d]?n.event.remove(c,d):n.removeEvent(c,d,b.handle);L.cache[e]&&delete L.cache[e]}delete M.cache[c[M.expando]]}}}),n.fn.extend({text:function(a){return J(this,function(a){return void 0===a?n.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=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=ja(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=ja(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?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(oa(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&ma(oa(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(n.cleanData(oa(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return n.clone(this,a,b)})},html:function(a){return J(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!da.test(a)&&!ia[(ba.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(aa,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(oa(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,n.cleanData(oa(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,m=this,o=l-1,p=a[0],q=n.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&ea.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(c=n.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=n.map(oa(c,"script"),ka),g=f.length;l>j;j++)h=c,j!==o&&(h=n.clone(h,!0,!0),g&&n.merge(f,oa(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,n.map(f,la),j=0;g>j;j++)h=f[j],fa.test(h.type||"")&&!L.access(h,"globalEval")&&n.contains(i,h)&&(h.src?n._evalUrl&&n._evalUrl(h.src):n.globalEval(h.textContent.replace(ha,"")))}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=[],e=n(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),n(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qa,ra={};function sa(b,c){var d,e=n(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:n.css(e[0],"display");return e.detach(),f}function ta(a){var b=l,c=ra[a];return c||(c=sa(a,b),"none"!==c&&c||(qa=(qa||n("