├── .dockerignore ├── .gitattributes ├── .gitignore ├── .jshintignore ├── .jshintrc ├── .tern-project ├── .travis.yml ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── README.md ├── app.json ├── app ├── browser │ ├── README.md │ ├── bower.json │ ├── design │ │ ├── row2-triangle-dark.pdn │ │ └── row2-triangle-light.pdn │ ├── gulpfile.js │ ├── images │ │ ├── background-photo.jpg │ │ ├── digit-1-black.png │ │ ├── digit-1-white.png │ │ ├── digit-2-black.png │ │ ├── digit-2-white.png │ │ ├── digit-3-black.png │ │ ├── digit-3-white.png │ │ ├── digit-4-black.png │ │ ├── digit-4-white.png │ │ ├── digit-5-black.png │ │ ├── digit-5-white.png │ │ ├── digit-6-black.png │ │ ├── digit-6-white.png │ │ ├── loader.gif │ │ ├── piece-black-2-sh.png │ │ ├── piece-black-2.png │ │ ├── piece-black.png │ │ ├── piece-white-2-sh.png │ │ ├── piece-white-2.png │ │ ├── piece-white.png │ │ ├── row1-triangle-dark.gif │ │ ├── row1-triangle-light.gif │ │ ├── row2-triangle-dark.gif │ │ ├── row2-triangle-light.gif │ │ └── v-line.gif │ ├── index.html │ ├── js │ │ ├── SimpleBoardUI.js │ │ ├── config.js │ │ └── main.js │ ├── package.json │ └── style │ │ ├── backgammon.css │ │ └── ribbons.css └── server │ ├── README.md │ ├── config.js │ ├── package.json │ ├── queue_manager.js │ └── server.js ├── docs ├── Backgammon.js.uml ├── INSTALL.md ├── README.md ├── backgammon.js-lib │ └── 0.0.1 │ │ ├── Client.html │ │ ├── Dice.html │ │ ├── Game.html │ │ ├── Match.html │ │ ├── MoveAction.html │ │ ├── Piece.html │ │ ├── Player.html │ │ ├── PlayerStats.html │ │ ├── Random.html │ │ ├── Rule.html │ │ ├── RuleBgCasual.html │ │ ├── RuleBgGulbara.html │ │ ├── RuleBgTapa.html │ │ ├── State.html │ │ ├── Utils.html │ │ ├── client.js.html │ │ ├── comm.js.html │ │ ├── fonts │ │ ├── OpenSans-Bold-webfont.eot │ │ ├── OpenSans-Bold-webfont.svg │ │ ├── OpenSans-Bold-webfont.woff │ │ ├── OpenSans-BoldItalic-webfont.eot │ │ ├── OpenSans-BoldItalic-webfont.svg │ │ ├── OpenSans-BoldItalic-webfont.woff │ │ ├── OpenSans-Italic-webfont.eot │ │ ├── OpenSans-Italic-webfont.svg │ │ ├── OpenSans-Italic-webfont.woff │ │ ├── OpenSans-Light-webfont.eot │ │ ├── OpenSans-Light-webfont.svg │ │ ├── OpenSans-Light-webfont.woff │ │ ├── OpenSans-LightItalic-webfont.eot │ │ ├── OpenSans-LightItalic-webfont.svg │ │ ├── OpenSans-LightItalic-webfont.woff │ │ ├── OpenSans-Regular-webfont.eot │ │ ├── OpenSans-Regular-webfont.svg │ │ └── OpenSans-Regular-webfont.woff │ │ ├── global.html │ │ ├── index.html │ │ ├── model.js.html │ │ ├── rules_RuleBgCasual.js.html │ │ ├── rules_RuleBgGulbara.js.html │ │ ├── rules_RuleBgTapa.js.html │ │ ├── rules_rule.js.html │ │ ├── scripts │ │ ├── linenumber.js │ │ └── prettify │ │ │ ├── Apache-License-2.0.txt │ │ │ ├── lang-css.js │ │ │ └── prettify.js │ │ └── styles │ │ ├── jsdoc-default.css │ │ ├── prettify-jsdoc.css │ │ └── prettify-tomorrow.css ├── glossary.md ├── images │ ├── architecture.png │ ├── class-diagrams │ │ ├── model.png │ │ └── rules.png │ ├── progress-gameplay-2.jpg │ ├── progress-gameplay.jpg │ ├── progress-landing-page.jpg │ └── use-cases │ │ ├── developer-goals.png │ │ └── player-goals.png └── rules.md ├── lib ├── README.md ├── client.js ├── comm.js ├── model.js ├── package.json └── rules │ ├── RuleBgCasual.js │ ├── RuleBgGulbara.js │ ├── RuleBgTapa.js │ └── rule.js └── package.json /.dockerignore: -------------------------------------------------------------------------------- 1 | .git* 2 | node_modules/* 3 | bower_components/* 4 | npm-debug.log 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files you want to always be normalized and converted 5 | # to native line endings on checkout. 6 | *.css text eol=lf 7 | *.html text eol=lf 8 | *.js text eol=lf 9 | *.md text eol=lf 10 | *.json text eol=lf 11 | 12 | # Denote all files that are truly binary and should not be modified. 13 | *.png binary 14 | *.jpg binary 15 | *.gif binary 16 | *.uml binary 17 | *.pdn binary 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .tmp 4 | .sass-cache 5 | bower_components 6 | /app/browser/js/bundle.js 7 | /nbproject/private/ 8 | .idea 9 | nbproject 10 | /app/server/db 11 | npm-debug.log* 12 | *.*~* 13 | -------------------------------------------------------------------------------- /.jshintignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | app/browser/bower_components/* 3 | app/browser/node_modules/* 4 | app/browser/js/bundle.js 5 | app/server/node_modules/* 6 | lib/node_modules/* 7 | docs/* 8 | dist/* 9 | .tmp/* 10 | .sass-cache/* 11 | nbproject/private/* 12 | .idea/* 13 | nbproject/* 14 | app/server/db/* 15 | npm-debug.log* 16 | *.*~* 17 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "indent" : 2, 3 | "latedef" : true, 4 | "node" : true 5 | } 6 | -------------------------------------------------------------------------------- /.tern-project: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaVersion": 6, 3 | "libs": [ 4 | "browser", 5 | "jquery" 6 | ], 7 | "loadEagerly": [ 8 | "lib/**/*.js", 9 | "app/browser/js/**/*.js", 10 | "app/server/**/*.js" 11 | ], 12 | "plugins": { 13 | "complete_strings": {}, 14 | "node": {"load":true}, 15 | "lint": {}, 16 | "angular": {}, 17 | "requirejs": {}, 18 | "modules": {}, 19 | "es_modules": {}, 20 | "doc_comment": { 21 | "fullDocs": true, 22 | "strong": true 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "node" 4 | install: 5 | - npm install 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | Change log introduced in version 0.4. 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | The format is based on [Keep a Changelog](http://keepachangelog.com/). 7 | 8 | ## [Unreleased] 9 | ### Added 10 | - None 11 | 12 | ### Changed 13 | - None 14 | 15 | ## [0.6] - 2016-01-15 16 | ### Added 17 | - Allow player to resign from game/match; 18 | 19 | ## [0.5] - 2016-12-17 20 | ### Added 21 | - Implement challenge friends functionality - player can send a link for starting a private game with a friend; 22 | 23 | ## [0.4] - 2015-12-17 24 | ### Added 25 | - New rule: Tapa (RuleBgTapa.js); 26 | - Rule selector on front page - player can choose rule before starting a game; 27 | - Show error message to player, if a move request is not valid; 28 | - Show current match standings in an alert box during match (when a new game starts); 29 | - Display alert box, if player undoes a move; 30 | - Add OhSnap.js dependency; 31 | - Allow player to undo moves; 32 | 33 | ### Changed 34 | - Server to use separate waiting queues for each rule (via QueueManager); 35 | - Fixed bug in Gulbara rule preventing player from bearing pieces; 36 | - Changed rule RuleBgCasual to allow playing doubles as four moves, even on first turn. It's more common to play it that way in Bulgaria, instead of playing doubles after the first turn; 37 | - Fixed bug that caused a piece to move several times, if double-clicked; 38 | 39 | 40 | [0.6]: https://github.com/quasoft/backgammonjs/tree/0.6 41 | [0.5]: https://github.com/quasoft/backgammonjs/tree/0.5 42 | [0.4]: https://github.com/quasoft/backgammonjs/tree/0.4 -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Using alpine image, because it is super slim 2 | FROM alpine 3 | 4 | # Install only bash and nodejs, then remove cached package data 5 | RUN apk add --update bash && apk add --update nodejs nodejs-npm && rm -rf /var/cache/apk/* 6 | 7 | # Create app directory. This is where source code will be copied to 8 | RUN mkdir -p /usr/src/app 9 | WORKDIR /usr/src/app 10 | 11 | # Copy source from host to directory in container 12 | COPY . /usr/src/app 13 | 14 | # Install application and all its dependencies 15 | RUN npm install 16 | 17 | # Expose 8080 port. Client should connect at http://IP_OF_CONTAINER:8080 18 | EXPOSE 8080 19 | 20 | # Start application 21 | CMD [ "npm", "start" ] 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 quasoft 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # backgammon.js [![Build Status](https://travis-ci.org/quasoft/backgammonjs.svg?branch=master)](https://travis-ci.org/quasoft/backgammonjs) 2 | 3 | ### Extensible multiplayer backgammon game written in JavaScript 4 | 5 | Current version: 0.6 6 | 7 | See [CHANGELOG](CHANGELOG.md) for recent changes. 8 | 9 | **Volunteer needed to host live DEMO.** 10 | 11 | ## Features: 12 | 13 | - Challenge friends or play with strangers online without registration and game setup process. 14 | - Fair gameplay that is as close to real game as possible: 15 | - no visual hints (eg. for allowed moves); 16 | - no pip counter; 17 | - quality random generator. 18 | - Extensible and modular engine that would allow the open source community to implement different variants of the game as known in different countries and different user interfaces (eg. themes). 19 | - Lightweight - playable on any device, even old ones - anything that can run a modern browser; 20 | - Works in browser @ PC & Mobile; 21 | 22 | If you want to learn more about the project see [Detailed documentation](docs/README.md). 23 | 24 | ## Screenshot 25 | ![Landing page](docs/images/progress-landing-page.jpg) 26 | 27 | You can try the game locally or deploy it to your own server. 28 | 29 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/quasoft/backgammonjs/tree/heroku) 30 | 31 | ## How to install 32 | 33 | To host the game on your own server or test it locally for development, you need to install the main backgammon.js package. 34 | It includes both the backgammon.js server and client. 35 | 36 | There is no need to install the client separately, as it is served automatically from the server via HTTP. 37 | Client should work in *modern* browsers of both desktop PCs and mobile devices. 38 | 39 | The universal way to install the server is: 40 | 41 | 1. Clone repository locally 42 | 2. Change working directory to the local copy of the repository 43 | 3. Run: 44 | 45 | npm install 46 | npm start 47 | 48 | The game server has been tested to work on the following platforms: 49 | 50 | - [Ubuntu](docs/INSTALL.md#ubuntu) 51 | - [Windows](docs/INSTALL.md#windows) 52 | - [Docker](docs/INSTALL.md#docker) 53 | - [Heroku](docs/INSTALL.md#heroku) 54 | - [OpenShift Online](docs/INSTALL.md#openshift-online) 55 | 56 | Follow the links above for more detailed installation instructions on those platforms. 57 | 58 | ## How to change default rule 59 | 60 | Currently three rules have been implemented (as known in Bulgaria): 61 | 62 | - [`RuleBgCasual`](lib/rules/RuleBgCasual.js) - Standard rules, but without doubling cube (Rules: [Standard/Обикновена](https://en.wikipedia.org/wiki/Backgammon#Rules)) 63 | - [`RuleBgGulbara`](lib/rules/RuleBgGulbara.js) - `Gul bara`, also called `Rosespring` or `Crazy Narde` (Rules: [Gul bara/Гюлбара](https://en.wikipedia.org/wiki/Gul_bara)) 64 | - [`RuleBgTapa`](lib/rules/RuleBgTapa.js) - `Tapa` (Rules: [Tapa/Тапа](https://en.wikipedia.org/wiki/Tapa_(game))) 65 | 66 | The player can choose which rule to play before starting a new game. 67 | 68 | ## How to add new rules (variants) 69 | 70 | Short instructions on how to add new rules are available here: [Creating rules for `backgammon.js`](docs/rules.md). 71 | 72 | ## Documentation: 73 | 74 | - [Installation instructions](docs/INSTALL.md) 75 | - [Detailed documentation](docs/README.md) 76 | - [JsDoc documentation of library](https://cdn.rawgit.com/quasoft/backgammonjs/master/docs/backgammon.js-lib/0.0.1/index.html) 77 | 78 | ## Screenshots 79 | ### Classic rule: 80 | ![Classic rule](docs/images/progress-gameplay.jpg) 81 | ### Gul bara rule: 82 | ![Gul-bara rule](docs/images/progress-gameplay-2.jpg) 83 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backgammonjs", 3 | "description": "Extensible multiplayer backgammon game written in JavaScript.", 4 | "repository": "https://github.com/quasoft/backgammonjs", 5 | "website": "https://github.com/quasoft/backgammonjs", 6 | "keywords": ["http", "javascript", "backgammon", "game", "multiplayer", "web", "socket"] 7 | } 8 | -------------------------------------------------------------------------------- /app/browser/README.md: -------------------------------------------------------------------------------- 1 | # backgammon.js-client 2 | 3 | See [`project README`](../../README.md) -------------------------------------------------------------------------------- /app/browser/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backgammon-client", 3 | "version": "0.0.1", 4 | "authors": [ 5 | "quasoft " 6 | ], 7 | "description": "Backgammon Web Client", 8 | "license": "MIT", 9 | "private": true, 10 | "ignore": [ 11 | "**/.*", 12 | "node_modules", 13 | "bower_components", 14 | "test", 15 | "tests" 16 | ], 17 | "dependencies": { 18 | "jquery": "~2.1.3", 19 | "fittext": "*", 20 | "oh-snap": "https://github.com/quasoft/ohSnap.git#modularized", 21 | "bootstrap3-dialog": "^1.35.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/browser/design/row2-triangle-dark.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/design/row2-triangle-dark.pdn -------------------------------------------------------------------------------- /app/browser/design/row2-triangle-light.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/design/row2-triangle-light.pdn -------------------------------------------------------------------------------- /app/browser/gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'), 2 | gutil = require('gulp-util'), 3 | uglify = require('gulp-uglify'), 4 | concat = require('gulp-concat'), 5 | runSequence = require('run-sequence'); 6 | 7 | gulp.task('copy', function () { 8 | return gulp.src('./bower_components/jquery/dist/jquery.js') 9 | .pipe(gulp.dest('./js')); 10 | }); 11 | 12 | gulp.task('compress', function () { 13 | return gulp.src(['./js/*.js', '!./js/all.js']) 14 | .pipe(uglify()) 15 | .pipe(concat('all.js')) 16 | .pipe(gulp.dest('./js')); 17 | }); 18 | 19 | gulp.task('default', function(callback) { 20 | runSequence('copy', 21 | 'compress', 22 | callback); 23 | }); 24 | -------------------------------------------------------------------------------- /app/browser/images/background-photo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/background-photo.jpg -------------------------------------------------------------------------------- /app/browser/images/digit-1-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-1-black.png -------------------------------------------------------------------------------- /app/browser/images/digit-1-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-1-white.png -------------------------------------------------------------------------------- /app/browser/images/digit-2-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-2-black.png -------------------------------------------------------------------------------- /app/browser/images/digit-2-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-2-white.png -------------------------------------------------------------------------------- /app/browser/images/digit-3-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-3-black.png -------------------------------------------------------------------------------- /app/browser/images/digit-3-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-3-white.png -------------------------------------------------------------------------------- /app/browser/images/digit-4-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-4-black.png -------------------------------------------------------------------------------- /app/browser/images/digit-4-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-4-white.png -------------------------------------------------------------------------------- /app/browser/images/digit-5-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-5-black.png -------------------------------------------------------------------------------- /app/browser/images/digit-5-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-5-white.png -------------------------------------------------------------------------------- /app/browser/images/digit-6-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-6-black.png -------------------------------------------------------------------------------- /app/browser/images/digit-6-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/digit-6-white.png -------------------------------------------------------------------------------- /app/browser/images/loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/loader.gif -------------------------------------------------------------------------------- /app/browser/images/piece-black-2-sh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/piece-black-2-sh.png -------------------------------------------------------------------------------- /app/browser/images/piece-black-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/piece-black-2.png -------------------------------------------------------------------------------- /app/browser/images/piece-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/piece-black.png -------------------------------------------------------------------------------- /app/browser/images/piece-white-2-sh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/piece-white-2-sh.png -------------------------------------------------------------------------------- /app/browser/images/piece-white-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/piece-white-2.png -------------------------------------------------------------------------------- /app/browser/images/piece-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/piece-white.png -------------------------------------------------------------------------------- /app/browser/images/row1-triangle-dark.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/row1-triangle-dark.gif -------------------------------------------------------------------------------- /app/browser/images/row1-triangle-light.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/row1-triangle-light.gif -------------------------------------------------------------------------------- /app/browser/images/row2-triangle-dark.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/row2-triangle-dark.gif -------------------------------------------------------------------------------- /app/browser/images/row2-triangle-light.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/row2-triangle-light.gif -------------------------------------------------------------------------------- /app/browser/images/v-line.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/app/browser/images/v-line.gif -------------------------------------------------------------------------------- /app/browser/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 57 | 58 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 97 | 98 |
71 | 72 |
73 |
74 |

Backgammon.js
Extensible multiplayer game

75 |
76 |
77 |
78 |
79 | 82 |
83 |
84 |
85 |
86 |
87 | 88 |
89 |
90 | 91 |
92 |
93 |
94 |
95 |
96 |
99 | 100 | 101 | 119 | 120 | 121 | 122 | 123 | 126 | 127 | 128 | 129 | 133 | 134 | 148 | 149 |
150 |
151 | 152 | -------------------------------------------------------------------------------- /app/browser/js/config.js: -------------------------------------------------------------------------------- 1 | var config = { 2 | 'containerID': 'backgammon', 3 | 'boardUI': '../app/browser/js/SimpleBoardUI.js', 4 | 'defaultRule': 'RuleBgCasual', 5 | 'selectableRules': [ 6 | 'RuleBgCasual', 7 | 'RuleBgGulbara', 8 | 'RuleBgTapa' 9 | ] 10 | }; 11 | 12 | module.exports = config; -------------------------------------------------------------------------------- /app/browser/js/main.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /*jslint browser: true */ 3 | /*global fitText: false */ 4 | /*global ohSnap: false */ 5 | 6 | var $ = require('jquery'); 7 | var fittext = require('jquery-fittext'); 8 | var cookie = require('js-cookie'); 9 | // TODO: Fix this hack. Makes bootstrap happy, but this should not be needed. 10 | window.jQuery = window.$ = $; 11 | 12 | var bootstrap = require('bootstrap/dist/js/bootstrap.bundle.js'); 13 | var clipboard = require('clipboard'); 14 | var cl = require('../../../lib/client'); 15 | var comm = require('../../../lib/comm.js'); 16 | var model = require('../../../lib/model.js'); 17 | require('../../../lib/rules/rule.js'); 18 | require('../../../lib/rules/RuleBgCasual.js'); 19 | require('../../../lib/rules/RuleBgGulbara.js'); 20 | require('../../../lib/rules/RuleBgTapa.js'); 21 | 22 | function App() { 23 | this._config = {}; 24 | this._isWaiting = false; 25 | this._isChallenging = false; 26 | this._currentView = 'index'; 27 | 28 | this.setIsWaiting = function (value) { 29 | this._isWaiting = value; 30 | }; 31 | 32 | this.setIsChallenging = function (value) { 33 | this._isChallenging = value; 34 | }; 35 | 36 | this.setCurrentView = function (name) { 37 | this._currentView = name; 38 | }; 39 | 40 | this.updateView = function () { 41 | if (this._isChallenging) { 42 | $('#waiting-overlay .challenge').show(); 43 | } else { 44 | $('#waiting-overlay .challenge').hide(); 45 | } 46 | 47 | if (this._isWaiting) { 48 | $('#waiting-overlay').show(); 49 | } else { 50 | $('#waiting-overlay').hide(); 51 | } 52 | 53 | $('#game-view').hide(); 54 | $('#index-view').hide(); 55 | $('#github-ribbon').hide(); 56 | if (this._currentView === 'index') { 57 | $('#index-view').show(); 58 | $('#github-ribbon').show(); 59 | } 60 | else if (this._currentView === 'game') { 61 | $('#game-view').show(); 62 | } 63 | }; 64 | 65 | /** 66 | * Get name of rule selected by player 67 | * @returns {string} - Name of selected rule. 68 | */ 69 | this.getSelectedRuleName = function () { 70 | var selected = $('#rule-selector label.active input').val(); 71 | return selected; 72 | }; 73 | 74 | /** 75 | * Load rule module 76 | * @param {string} ruleName - Rule's name, equal to rule's class name (eg. RuleBgCasual) 77 | * @returns {Rule} - Corresponding rule object 78 | */ 79 | this.loadRule = function (ruleName) { 80 | var rulePath = '../../../lib/rules/'; 81 | var fileName = model.Utils.sanitizeName(ruleName); 82 | var file = rulePath + fileName + '.js'; 83 | var rule = require(file); 84 | rule.name = fileName; 85 | return rule; 86 | }; 87 | 88 | /** 89 | * Initialize selector of game rule 90 | */ 91 | this.initRuleSelector = function () { 92 | // Init rule selector 93 | var selector = $('#rule-selector'); 94 | var i; 95 | for (i = 0; i < this._config.selectableRules.length; i++) { 96 | var ruleName = this._config.selectableRules[i]; 97 | var rule = this.loadRule(ruleName); 98 | var isSelected = false; 99 | var isActive = isSelected ? 'active' : ''; 100 | var isChecked = isSelected ? 'checked' : ''; 101 | 102 | var item = $('#tmpl-rule-selector-item').html(); 103 | item = item.replace('{{name}}', rule.name); 104 | item = item.replace('{{title}}', rule.title); 105 | item = item.replace('{{active}}', isActive); 106 | item = item.replace('{{checked}}', isChecked); 107 | 108 | selector.append($(item)); 109 | } 110 | }; 111 | 112 | /** 113 | * Initialize application. Must be called after DOM is ready. 114 | * @param {Object} config - Configuration object 115 | */ 116 | this.init = function (config) { 117 | var self = this; 118 | this._config = config; 119 | 120 | this.initRuleSelector(); 121 | 122 | // Initialize the overlay showing game results 123 | $('#game-result-overlay').click(function () { 124 | $('#game-result-overlay').hide(); 125 | }); 126 | 127 | // Initialize game client 128 | var client = new cl.Client(this._config); 129 | 130 | // Subscribe to events used on landing page 131 | client.subscribe(comm.Message.EVENT_MATCH_START, function (msg, params) { 132 | self.setIsWaiting(false); 133 | self.setCurrentView('game'); 134 | self.updateView(); 135 | client.resizeUI(); 136 | }); 137 | 138 | client.subscribe(comm.Message.EVENT_MATCH_OVER, function (msg, params) { 139 | self.setIsWaiting(false); 140 | self.setCurrentView('index'); 141 | self.updateView(); 142 | }); 143 | 144 | client.subscribe(comm.Message.EVENT_PLAYER_JOINED, function (msg, params) { 145 | self.setIsWaiting(false); 146 | self.setCurrentView('game'); 147 | self.updateView(); 148 | client.resizeUI(); 149 | }); 150 | 151 | client.subscribe(comm.Message.JOIN_MATCH, function (msg, params) { 152 | if (!params.result) { 153 | return; 154 | } 155 | self.setIsWaiting(false); 156 | self.setCurrentView('game'); 157 | self.updateView(); 158 | client.resizeUI(); 159 | }); 160 | 161 | client.subscribe(comm.Message.CREATE_GUEST, function (msg, params) { 162 | if (!params.reconnected) { 163 | // Get matchID from query string (?join=123456) 164 | var matchID = parseInt((location.search.split('join=')[1] || '').split('&')[0], 10); 165 | 166 | // Join game 167 | client.reqJoinMatch(matchID); 168 | 169 | // Remove query string from URL 170 | if (history.pushState) { 171 | history.pushState(null, '', '/'); 172 | } 173 | } 174 | }); 175 | 176 | $('#btn-play-random').click(function (e) { 177 | self.setIsChallenging(false); 178 | self.setIsWaiting(true); 179 | self.updateView(); 180 | // TODO: Store selected rule in cookie 181 | client.reqPlayRandom(self.getSelectedRuleName()); 182 | }); 183 | 184 | $('#btn-challenge-friend').click(function (e) { 185 | self.setIsChallenging(false); 186 | self.setIsWaiting(true); 187 | self.updateView(); 188 | 189 | // TODO: Store selected rule in cookie 190 | client.reqCreateMatch(self.getSelectedRuleName(), function (msg, clientMsgSeq, reply) { 191 | if (!reply.result) { 192 | self.setIsChallenging(false); 193 | self.setIsWaiting(false); 194 | self.updateView(); 195 | return; 196 | } 197 | 198 | var serverURL = self._config.serverURL; 199 | if (!serverURL) { 200 | serverURL = window.location.protocol + '//' + window.location.host + '/'; 201 | } 202 | $('#challenge-link').val(serverURL + '?join=' + reply.matchID); 203 | self.setIsChallenging(true); 204 | self.updateView(); 205 | }); 206 | }); 207 | 208 | $(window).resize(function () { 209 | client.resizeUI(); 210 | }); 211 | }; 212 | } 213 | 214 | var app = new App(); 215 | 216 | $(document).ready(function() { 217 | // Initialize bootstrap and helpers 218 | new clipboard('.btn-copy'); 219 | 220 | // Prepare client config 221 | var config = require('./config'); 222 | 223 | app.init(config); 224 | }); 225 | -------------------------------------------------------------------------------- /app/browser/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backgammon.js-client", 3 | "version": "0.0.1", 4 | "author": "quasoft ", 5 | "description": "Backgammon.js Client", 6 | "license": "MIT", 7 | "main": "index.html", 8 | "dependencies": { 9 | "browserify": "^13.0.1", 10 | "socket.io-client": "^1.4.5", 11 | "bower": "^1.7.9", 12 | "popper.js": "^1.12.3", 13 | "bootstrap": "~>4.3.1", 14 | "clipboard": "^1.5.10", 15 | "jquery": "^3.3.1", 16 | "js-cookie": "^2.1.2" 17 | }, 18 | "devDependencies": { 19 | "watch": "^0.17.1", 20 | "watchify": "^3.7.0" 21 | }, 22 | "scripts": { 23 | "build:js": "browserify ./js/main.js --require socket.io-client -o ./js/bundle.js", 24 | "build": "npm run build:js", 25 | "watch:js": "watchify ./js/main.js --require socket.io-client -o ./js/bundle.js -v", 26 | "watch": "npm run watch:js", 27 | "postinstall": "HOME=$OPENSHIFT_REPO_DIR bower install || bower install" 28 | }, 29 | "browser": { 30 | "jquery-fittext": "./bower_components/fittext/fittext.js" 31 | }, 32 | "browserify": { 33 | "transform": [] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/browser/style/backgammon.css: -------------------------------------------------------------------------------- 1 | /* Reset & compatibility */ 2 | .cf:before, 3 | .cf:after { 4 | content:""; 5 | display:table; 6 | } 7 | 8 | .cf:after { 9 | clear:both; 10 | } 11 | 12 | .cf { 13 | *zoom:1; 14 | } 15 | 16 | /* Layout */ 17 | html, body, 18 | #backgammon, 19 | .board, .pane { 20 | width: 100%; 21 | height: 100%; 22 | } 23 | 24 | .board { 25 | height: 99%; 26 | } 27 | 28 | .pane { 29 | width: 45%; 30 | } 31 | 32 | #pane-left, 33 | #pane-right, 34 | #bar { 35 | float: left; 36 | } 37 | 38 | #pane-left, 39 | #pane-right { 40 | width: 46%; 41 | } 42 | 43 | .field { 44 | height: 50%; 45 | } 46 | 47 | .row0.field { 48 | padding-bottom: 8%; 49 | } 50 | 51 | .row1.field { 52 | padding-top: 8%; 53 | } 54 | 55 | .space { 56 | height: 7%; 57 | } 58 | 59 | .frame { 60 | height: 0.5%; 61 | } 62 | 63 | .bar { 64 | width: 8%; 65 | height: 100%; 66 | } 67 | 68 | .bar td { 69 | position: relative; 70 | } 71 | 72 | .point { 73 | float: left; 74 | width: 16.5%; 75 | height: 100%; 76 | 77 | text-align: center; 78 | position: relative; 79 | } 80 | 81 | #point17, #point6 { 82 | margin-right: 0.5%; 83 | } 84 | 85 | #point18, #point5 { 86 | margin-left: 0.5%; 87 | } 88 | 89 | /* 90 | .piece-out { 91 | position: absolute; 92 | bottom: 0; 93 | } 94 | */ 95 | 96 | .piece { 97 | float: none; 98 | display: inline-block; 99 | position: absolute; 100 | width: 100%; 101 | left: 0; 102 | right: 0; 103 | } 104 | .piece:after { 105 | content: ''; 106 | display: block; 107 | /*margin-top: 56.25%;*/ 108 | padding-top: 100%; 109 | } 110 | .piece .image { 111 | position: absolute; 112 | top: 0; 113 | bottom: 0; 114 | left: 0; 115 | right: 0; 116 | 117 | width: 100%; 118 | height: 100%; 119 | } 120 | 121 | /* Piece text */ 122 | .piece { 123 | vertical-align: middle; 124 | } 125 | 126 | .piece .image:before { 127 | content: ''; 128 | display: inline-block; 129 | height: 100%; 130 | vertical-align: middle; 131 | } 132 | 133 | .piece span { 134 | vertical-align: middle; 135 | } 136 | 137 | .navbar { 138 | min-height: auto; 139 | height: auto; 140 | margin: 0; 141 | border-radius: 0; 142 | border: none; 143 | z-index: 1100; 144 | } 145 | 146 | /* 147 | .action-panel { 148 | margin: auto; 149 | width: 150px; 150 | height: 100%; 151 | } 152 | 153 | .action-panel button.action { 154 | width: 100%; 155 | height: 100%; 156 | } 157 | */ 158 | 159 | /* 160 | .game-menu { 161 | background: hsla(1,0%,100%,.9); 162 | position: absolute; 163 | top: 0; 164 | right: 0; 165 | left: 0; 166 | bottom: 0; 167 | z-index: 1050; 168 | min-height: 100%; 169 | } 170 | 171 | .game-menu td { 172 | text-align: center; 173 | vertical-align: middle; 174 | } 175 | */ 176 | 177 | /* 178 | 179 | #score { 180 | font-family: "Raleway","Helvetica Neue",Helvetica,Arial,sans-serif; 181 | } 182 | 183 | #score .player { 184 | font-size: 36px; 185 | font-weight: 700; 186 | } 187 | 188 | #score .score { 189 | font-size: 36px; 190 | font-weight: 300; 191 | } 192 | 193 | .game-menu .btn { 194 | width: 100%; 195 | height: 100%; 196 | } 197 | 198 | div.menu-toggle .inner { 199 | position: relative; 200 | } 201 | 202 | div.menu-toggle .inner { 203 | margin: auto; 204 | position: absolute; 205 | top: 1%; left: 1%; 206 | z-index: 1100; 207 | width: 40px; 208 | height: 40px; 209 | } 210 | 211 | div.menu-toggle .inner .btn { 212 | width: 100%; 213 | height: 100%; 214 | background-color: red; 215 | opacity: 0.5; 216 | } 217 | */ 218 | 219 | div.action-panel { 220 | margin: auto; 221 | position: absolute; 222 | top: 0; left: 0; bottom: 0; right: 0; 223 | z-index: 1000; 224 | width: 12%; 225 | min-width: 64px; 226 | height: 128px; 227 | } 228 | 229 | div.action-panel button.action { 230 | width: 100%; 231 | height: 50%; 232 | min-width: 64px; 233 | margin-bottom: 10px; 234 | } 235 | 236 | div.dice-panel { 237 | margin: auto; 238 | position: absolute; 239 | top: 0; bottom: 0; 240 | z-index: 1000; 241 | width: 50%; 242 | min-width: 128px; 243 | height: 64px; 244 | } 245 | 246 | div.dice-panel.left { 247 | left: 0; 248 | } 249 | 250 | div.dice-panel.right { 251 | right: 0; 252 | } 253 | 254 | /* Behaviour */ 255 | #backgammon div, #backgammon span { 256 | -webkit-touch-callout: none; 257 | -webkit-user-select: none; 258 | -khtml-user-select: none; 259 | -moz-user-select: none; 260 | -ms-user-select: none; 261 | -o-user-select: none; 262 | user-select: none; 263 | } 264 | 265 | .piece, .piece .image .die { 266 | cursor: pointer; 267 | } 268 | 269 | .collapsing { 270 | -webkit-transition: none; 271 | transition: none; 272 | } 273 | 274 | /* Global style */ 275 | 276 | body { 277 | /* TODO: use smaller image on mobile devices or a css only background */ 278 | background: url('../images/background-photo.jpg') no-repeat center center fixed; 279 | -webkit-background-size: cover; 280 | -moz-background-size: cover; 281 | -o-background-size: cover; 282 | background-size: cover; 283 | background-color:#333; 284 | } 285 | 286 | .glyphicon { 287 | top: 3px; 288 | padding-right: 5px; 289 | } 290 | 291 | /* Index page style */ 292 | #index-view h1, 293 | #index-view h1 small { 294 | font-family: "Raleway","Helvetica Neue",Helvetica,Arial,sans-serif; 295 | color: #ffffff; 296 | } 297 | 298 | #index-view h1 { 299 | font-size: 50px; 300 | font-weight: 700; 301 | padding-right: 1em; 302 | } 303 | 304 | #index-view h1 small { 305 | font-size: 30px; 306 | font-weight: 300; 307 | padding-left: 2em; 308 | } 309 | 310 | #index-view .row .col { 311 | padding-bottom: 20px; 312 | } 313 | 314 | #index-view .input-group { 315 | max-width: 250px; 316 | margin: 0 auto; 317 | } 318 | 319 | #game-result-overlay, 320 | #waiting-overlay { 321 | background-color: rgba(239,239,239,0.9); 322 | position:fixed; 323 | width: 100%; 324 | height: 100%; 325 | z-index: 1000; 326 | top: 0px; 327 | left: 0px; 328 | } 329 | 330 | #waiting-overlay .loader { 331 | width: 100%; 332 | height: 100%; 333 | opacity: 1; 334 | text-align: center; 335 | } 336 | 337 | #waiting-overlay .loader:before { 338 | content: ''; 339 | display: inline-block; 340 | height: 90%; 341 | vertical-align: middle; 342 | margin-right: -0.25em; 343 | } 344 | 345 | #waiting-overlay span { 346 | font-family: "Raleway","Helvetica Neue",Helvetica,Arial,sans-serif; 347 | font-size: 22px; 348 | color: #000000; 349 | } 350 | 351 | #waiting-overlay div.inner { 352 | display: inline-block; 353 | vertical-align: middle; 354 | width: 100%; 355 | } 356 | 357 | #waiting-overlay div.challenge { 358 | width: 60%; 359 | min-width: 250px; 360 | margin: 0 auto; 361 | } 362 | 363 | #waiting-overlay div.challenge span { 364 | font-size: 20px; 365 | } 366 | 367 | .game-result .text { 368 | width: 80%; 369 | height: 40%; 370 | opacity: 1; 371 | display: flex; 372 | justify-content: center; 373 | align-items: center; 374 | margin: 0 auto; 375 | font-weight: 900; 376 | } 377 | 378 | .game-result .message, 379 | .game-result .score { 380 | text-shadow: 0 1px 0 #ccc, 381 | 0 2px 0 #c9c9c9, 382 | 0 3px 0 #bbb, 383 | 0 4px 0 #b9b9b9, 384 | 0 5px 0 #aaa, 385 | 0 6px 1px rgba(0,0,0,.1), 386 | 0 0 5px rgba(0,0,0,.1), 387 | 0 1px 3px rgba(0,0,0,.3), 388 | 0 3px 5px rgba(0,0,0,.2), 389 | 0 5px 10px rgba(0,0,0,.25), 390 | 0 10px 10px rgba(0,0,0,.2), 391 | 0 20px 20px rgba(0,0,0,.15); 392 | } 393 | 394 | .navbar-toggle { 395 | width: 100%; 396 | height: 100%; 397 | max-width: 48px; 398 | max-height: 48px; 399 | display: block !important; 400 | position: inherit; 401 | float: none; 402 | margin: 0 auto; 403 | padding: 0; 404 | background-color: #ffffff; 405 | border: none; 406 | border-radius: 0; 407 | } 408 | 409 | .navbar-toggle .glyphicon { 410 | padding-right: 0; 411 | } 412 | 413 | .navbar .badge { 414 | margin-left: 5px; 415 | } 416 | 417 | .navbar .badge.left { 418 | margin-right: 5px; 419 | } 420 | 421 | /* Board style */ 422 | .board { 423 | /*background-color: #5E4733*/; 424 | /*E8D1A5*/ 425 | /*background-color: #fff1dd;*/ 426 | background-color: #fff1dd; 427 | } 428 | 429 | .frame { 430 | background-color: #5e4733; 431 | } 432 | 433 | .bar { 434 | background: #5e4733 url(../images/v-line.gif) repeat-y center center; 435 | } 436 | 437 | .point.odd, 438 | .point.even { 439 | background-size: 100% 100%; 440 | background-repeat: no-repeat; 441 | } 442 | 443 | .row0 .point.odd { 444 | /*background-color: #D8C3A3;*/ 445 | background-image: url(../images/row1-triangle-light.gif); 446 | } 447 | 448 | .row0 .point.even { 449 | /*background-color: #B58863;*/ 450 | background-image: url(../images/row1-triangle-dark.gif); 451 | } 452 | 453 | .row1 .point.odd { 454 | /*background-color: #D8C3A3;*/ 455 | background-image: url(../images/row2-triangle-light.gif); 456 | } 457 | 458 | .row1 .point.even { 459 | /*background-color: #B58863;*/ 460 | background-image: url(../images/row2-triangle-dark.gif); 461 | } 462 | 463 | .piece { 464 | font-weight: bold; 465 | } 466 | 467 | .piece .image { 468 | overflow: hidden; 469 | background-size: cover; 470 | background-position: center; 471 | background-repeat: no-repeat; 472 | } 473 | 474 | .piece.white .image { 475 | background-image: url(../images/piece-white-2.png); 476 | color: #000000; 477 | } 478 | 479 | .piece.black .image{ 480 | background-image: url(../images/piece-black-2.png); 481 | color: #ffffff; 482 | } 483 | 484 | .dice { 485 | text-align: center; 486 | } 487 | 488 | .die { 489 | margin: 0 auto; 490 | display: inline-block; 491 | width: 64px; 492 | height: 64px; 493 | text-indent: -100px; 494 | overflow: hidden; 495 | background-size: cover; 496 | background-position: center; 497 | background-repeat: no-repeat; 498 | } 499 | 500 | .digit-1-white { 501 | background-image: url(../images/digit-1-white.png); 502 | } 503 | 504 | .digit-2-white { 505 | background-image: url(../images/digit-2-white.png); 506 | } 507 | 508 | .digit-3-white { 509 | background-image: url(../images/digit-3-white.png); 510 | } 511 | 512 | .digit-4-white { 513 | background-image: url(../images/digit-4-white.png); 514 | } 515 | 516 | .digit-5-white { 517 | background-image: url(../images/digit-5-white.png); 518 | } 519 | 520 | .digit-6-white { 521 | background-image: url(../images/digit-6-white.png); 522 | } 523 | 524 | .digit-1-black { 525 | background-image: url(../images/digit-1-black.png); 526 | } 527 | 528 | .digit-2-black { 529 | background-image: url(../images/digit-2-black.png); 530 | } 531 | 532 | .digit-3-black { 533 | background-image: url(../images/digit-3-black.png); 534 | } 535 | 536 | .digit-4-black { 537 | background-image: url(../images/digit-4-black.png); 538 | } 539 | 540 | .digit-5-black { 541 | background-image: url(../images/digit-5-black.png); 542 | } 543 | 544 | .digit-6-black { 545 | background-image: url(../images/digit-6-black.png); 546 | } 547 | 548 | .dice .played { 549 | opacity: 0.5; 550 | } 551 | 552 | /* ohSnap ALERTS */ 553 | /* inspired by Twitter Bootstrap */ 554 | 555 | .alert { 556 | padding: 15px; 557 | margin-bottom: 20px; 558 | border: 1px solid #eed3d7; 559 | border-radius: 4px; 560 | position: absolute; 561 | bottom: 0px; 562 | right: 21px; 563 | /* Each alert has its own width */ 564 | float: right; 565 | clear: right; 566 | background-color: white; 567 | } 568 | 569 | .alert-red { 570 | color: white; 571 | background-color: #DA4453; 572 | } 573 | .alert-green { 574 | color: white; 575 | background-color: #37BC9B; 576 | } 577 | .alert-blue { 578 | color: white; 579 | background-color: #4A89DC; 580 | } 581 | .alert-yellow { 582 | color: white; 583 | background-color: #F6BB42; 584 | } 585 | .alert-orange { 586 | color:white; 587 | background-color: #E9573F; 588 | } 589 | 590 | /* Resign dialog */ 591 | .resign-dialog .modal-body { 592 | display: none 593 | } 594 | 595 | /* Responsive variations */ 596 | @media screen and (min-width: 1024px) { 597 | #index-view h1 { 598 | font-size: 72px; 599 | } 600 | #index-view h1 small { 601 | font-size: 36px; 602 | } 603 | } 604 | 605 | @media screen and (max-width: 768px) { 606 | #index-view h1 { 607 | font-size: 36px; 608 | } 609 | #index-view h1 small { 610 | font-size: 22px; 611 | } 612 | } 613 | 614 | @media screen and (max-width: 544px) { 615 | #index-view h1 { 616 | font-size: 32px; 617 | } 618 | #index-view h1 small { 619 | font-size: 20px; 620 | } 621 | 622 | #index-view .row .col { 623 | text-align: center; 624 | } 625 | } 626 | 627 | @media screen and (max-width: 480px) { 628 | #index-view h1 { 629 | font-size: 26px; 630 | } 631 | #index-view h1 small { 632 | font-size: 14px; 633 | } 634 | 635 | .col-ts-12 { 636 | width: 100%; 637 | float: none; 638 | position: relative; 639 | min-height: 1px; 640 | padding-right: 15px; 641 | padding-left: 15px; 642 | } 643 | 644 | #index-view .row .col { 645 | padding-bottom: 8px; 646 | } 647 | 648 | #index-view .btn-group-lg>.btn, 649 | #index-view .btn-lg { 650 | padding: 10px 16px; 651 | font-size: 14px; 652 | } 653 | 654 | .hidden-ts { 655 | display: none; 656 | } 657 | 658 | div.action-panel { 659 | min-width: 64px; 660 | height: 64px; 661 | } 662 | 663 | div.action-panel button.action { 664 | min-width: 64px; 665 | margin-bottom: 4px; 666 | } 667 | 668 | div.action-panel .btn-group-lg>.btn, 669 | div.action-panel .btn-lg { 670 | padding: 1px 2px; 671 | font-size: 12px; 672 | border-radius: 2px; 673 | } 674 | 675 | #btn-roll { 676 | margin-top: 25%; 677 | } 678 | 679 | div.dice-panel { 680 | min-width: 64px; 681 | height: 32px; 682 | } 683 | 684 | .dice .die { 685 | width: 32px; 686 | height: 32px; 687 | } 688 | } 689 | 690 | @media screen and (max-width: 380px) { 691 | #index-view h1 { 692 | font-size: 20px; 693 | } 694 | #index-view h1 small { 695 | font-size: 12px; 696 | } 697 | 698 | .h1, .h2, .h3, h1, h2, h3 { 699 | margin-top: 8px; 700 | margin-bottom: 4px; 701 | } 702 | } -------------------------------------------------------------------------------- /app/browser/style/ribbons.css: -------------------------------------------------------------------------------- 1 | body{ 2 | overflow-x: hidden; 3 | } 4 | 5 | .ribbon{ 6 | position: absolute; 7 | top: 42px; 8 | width: 200px; 9 | padding: 1px 0; 10 | background: #000; 11 | color: #eee; 12 | 13 | -moz-box-shadow: 0 0 10px rgba(0,0,0,0.5); 14 | -webkit-box-shadow: 0 0 10px rgba(0,0,0,0.5); 15 | box-shadow: 0 0 10px rgba(0,0,0,0.5); 16 | } 17 | 18 | .ribbon.left{ 19 | left: -42px; 20 | -moz-transform: rotate(-45deg); 21 | -webkit-transform: rotate(-45deg); 22 | -o-transform: rotate(-45deg); 23 | -ms-transform: rotate(-45deg); 24 | transform: rotate(-45deg); 25 | } 26 | 27 | .ribbon.right{ 28 | right: -42px; 29 | -moz-transform: rotate(45deg); 30 | -webkit-transform: rotate(45deg); 31 | -o-transform: rotate(45deg); 32 | -ms-transform: rotate(45deg); 33 | transform: rotate(45deg); 34 | } 35 | 36 | .ribbon a, 37 | .ribbon a:visited, 38 | .ribbon a:active, 39 | .ribbon a:hover{ 40 | display: block; 41 | padding: 1px 0; 42 | height: 28px; 43 | line-height: 24px; 44 | 45 | color: inherit; 46 | text-align: center; 47 | text-decoration: underline; 48 | font-family: 'Raleway', 'Arial', sans-serif; 49 | font-size: 14px; 50 | font-weight: 700; 51 | 52 | border: 1px solid rgba(255,255,255,0.3); 53 | 54 | -moz-text-shadow: 0 0 10px rgba(0,0,0,0.31); 55 | -webkit-text-shadow: 0 0 10px rgba(0,0,0,0.31); 56 | text-shadow: 0 0 10px rgba(0,0,0,0.31); 57 | } 58 | 59 | .ribbon.black{ 60 | background: #000; 61 | } 62 | 63 | .ribbon.red{ 64 | background: #c00; 65 | } 66 | 67 | .ribbon.blue{ 68 | background: #09e; 69 | } 70 | 71 | .ribbon.green{ 72 | background: #0a0; 73 | } 74 | 75 | .ribbon.orange{ 76 | background: #d80; 77 | } 78 | 79 | .ribbon.purple{ 80 | background: #c0c; 81 | } 82 | 83 | .ribbon.grey{ 84 | background: #888; 85 | } 86 | 87 | .ribbon.white{ 88 | background: #eee; 89 | color: black; 90 | } 91 | .ribbon.white a{ 92 | border: 2px dotted rgba(100,100,100,0.2); 93 | } -------------------------------------------------------------------------------- /app/server/README.md: -------------------------------------------------------------------------------- 1 | # backgammon.js-server 2 | 3 | See [`project README`](../../README.md) -------------------------------------------------------------------------------- /app/server/config.js: -------------------------------------------------------------------------------- 1 | var config = { 2 | 'rulePath': '../../lib/rules/', 3 | 'enabledRules': [ 4 | 'RuleBgCasual', 5 | 'RuleBgGulbara', 6 | 'RuleBgTapa' 7 | ] 8 | }; 9 | 10 | module.exports = config; 11 | -------------------------------------------------------------------------------- /app/server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backgammon.js-server", 3 | "version": "0.0.1", 4 | "author": "quasoft ", 5 | "description": "Backgammon.js Server", 6 | "license": "MIT", 7 | "main": "server.js", 8 | "dependencies": { 9 | "express": "^4.10.2", 10 | "mongodb": "^2.2.30", 11 | "socket.io": "^1.4.5" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/server/queue_manager.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var model = require('../../lib/model.js'); 4 | 5 | 6 | /** 7 | * There are two types of queues: random queues and challenge queues. 8 | * @readonly 9 | * @enum {number} 10 | */ 11 | var QueueType = { 12 | /** Queue for playing with random players */ 13 | RANDOM : 0, 14 | /** Queue for playing with a friend */ 15 | CHALLENGE : 1 16 | }; 17 | 18 | 19 | /** 20 | * Represents a queue with players waiting to play for a game with 21 | * random player (random queue) or a friend (challenge queue). 22 | * 23 | * @constructor 24 | * @param {string} id - Unique id of this queue 25 | * @param {QueueType} type - Type of queue - RANDOM or CHALLENGE 26 | * @param {ruleName} ruleName - Name of rule. Value can be a regex pattern. 27 | */ 28 | function Queue(id, type, ruleName) { 29 | /** 30 | * For random queues the id matches the name of the rule (eg. RuleBgCasual). 31 | * The id of challenge queues is a unique id, that should be known only by 32 | * two players. 33 | * @type {string} 34 | */ 35 | this.id = id; 36 | 37 | /** 38 | * Type of queue - RANDOM or CHALLENGE. 39 | * @type {QueueType} 40 | */ 41 | this.type = type; 42 | 43 | /** 44 | * Name of rule for this queue. Value can be a regex pattern. 45 | * @type {string} 46 | */ 47 | this.ruleName = ruleName; 48 | 49 | /** 50 | * List of players waiting in this queue 51 | * @type {Player[]} 52 | */ 53 | this.players = []; 54 | } 55 | 56 | /** 57 | * Add player object to queue 58 | * 59 | * @memberOf Queue 60 | * @param {Player} player - Player object 61 | */ 62 | Queue.prototype.addPlayer = function (player) { 63 | this.players.push(player); 64 | }; 65 | 66 | /** 67 | * Pop player object from queue 68 | * 69 | * @memberOf Queue 70 | * @returns {Player} - Player object 71 | */ 72 | Queue.prototype.popPlayer = function () { 73 | return this.players.pop(); 74 | }; 75 | 76 | /** 77 | * Remove player object from queue 78 | * 79 | * @memberOf Queue 80 | * @param {Player} player - Player object 81 | */ 82 | Queue.prototype.removePlayer = function (player) { 83 | model.Utils.removeItem(this.players, player); 84 | }; 85 | 86 | Queue.prototype.matchRuleName = function (ruleName) { 87 | var thisRegex = new RegExp(this.ruleName, "i"); 88 | var otherRegex = new RegExp(ruleName, "i"); 89 | 90 | return (this.ruleName === ruleName) || 91 | (this.ruleName.match(otherRegex)) || 92 | (ruleName.match(thisRegex)); 93 | }; 94 | 95 | 96 | /** 97 | * QueueManager is a singleton keeps track of multiple queues with waiting players 98 | * (one for each game rule and one for each challenge) and performs the addition/removal 99 | * of players to/from those queues. 100 | * 101 | * Queues are created on demand, when a player should be added to one. 102 | * 103 | * @constructor 104 | */ 105 | function QueueManager() { 106 | /** 107 | * Map of queues by id 108 | * @type {{Object.}} 109 | */ 110 | this._queueMap = {}; 111 | 112 | /** 113 | * Creates a new queue with specified id and rule name 114 | * @param {string} id - Unique id of queue 115 | * @param {QueueType} type - Type of queue - RANDOM or CHALLENGE 116 | * @param {ruleName} ruleName - Name of rule. Value can be a regex pattern. 117 | * @returns {Queue} - Created queue object 118 | */ 119 | this.createQueue = function (id, type, ruleName) { 120 | var queue = new Queue(id, type, ruleName); 121 | this._queueMap[id] = queue; 122 | return queue; 123 | }; 124 | 125 | /** 126 | * Get queue object by its id 127 | * @param {string} id - Unique id of this queue 128 | * @returns {Queue} - Queue object 129 | */ 130 | this.getQueue = function (id) { 131 | return this._queueMap[id]; 132 | }; 133 | 134 | /** 135 | * Add player to a random queue, storing the name of the rule the player wants to play. 136 | * If no queue is found that matches given id, a new one is created. 137 | * @param {Player} player - Player object to add 138 | * @param {ruleName} ruleName - Name of rule. Value can be a regex pattern. 139 | * @returns {Queue} - The queue object to which player was added. 140 | */ 141 | this.addToRandom = function (player, ruleName) { 142 | // Note: ID of random queues equals ruleName 143 | var queue = this.getQueue(ruleName); 144 | if (!queue) { 145 | queue = this.createQueue(ruleName, QueueType.RANDOM, ruleName); 146 | } 147 | queue.addPlayer(player); 148 | return queue; 149 | }; 150 | 151 | /** 152 | * Add player to a challenge queue, storing the name of the rule the player wants to play. 153 | * If no queue is found that matches given id, a new one is created. 154 | * @param {Player} player - Player object to add 155 | * @param {ruleName} ruleName - Name of rule. Value can be a regex pattern. 156 | * @param {string} queueID - Unique id of queue 157 | * @returns {Queue} - The queue object to which player was added. 158 | */ 159 | this.addToChallenge = function (player, ruleName, queueID) { 160 | // Note: ID of challenge queues is some unique number 161 | var queue = this.getQueue(queueID); 162 | if (!queue) { 163 | queue = this.createQueue(queueID, QueueType.CHALLENGE, ruleName); 164 | } 165 | queue.addPlayer(player); 166 | return queue; 167 | }; 168 | 169 | /** 170 | * Pop a player from random queue for given rule 171 | * @param {ruleName} ruleName - Name of rule. Value can be a regex pattern to pop from any random queue. 172 | * @returns {{player: Player, ruleName: string}} - Result object containing player object and rule name 173 | */ 174 | this.popFromRandom = function (ruleName) { 175 | var 176 | result = {'player': null, 'ruleName': ''}, 177 | id, 178 | queue; 179 | 180 | // Get first player found in any of random queues that matches ruleName 181 | for (id in this._queueMap) { 182 | if (this._queueMap.hasOwnProperty(id)) { 183 | queue = this.getQueue(id); 184 | if ((queue.type === QueueType.RANDOM) && (queue.matchRuleName(ruleName))) { 185 | result.player = queue.popPlayer(); 186 | if (result.player) { 187 | result.ruleName = queue.ruleName; 188 | break; 189 | } 190 | } 191 | } 192 | } 193 | 194 | return result; 195 | }; 196 | 197 | /** 198 | * Pop a player from challenge queue 199 | * @param {string} queueID - ID of queue 200 | * @returns {{player: Player, ruleName: string}} - Result object containing player object and rule name 201 | */ 202 | this.popFromChallenge = function (queueID) { 203 | var 204 | result = {'player': null, 'ruleName': ''}, 205 | queue; 206 | 207 | queue = this.getQueue(queueID); 208 | if (!queue) { 209 | return result; 210 | } 211 | 212 | result.player = queue.popPlayer(); 213 | result.ruleName = queue.ruleName; 214 | 215 | return result; 216 | }; 217 | 218 | /** 219 | * Remove player from a specified queue 220 | * @param {Player} player - Player object to remove 221 | * @param {string} queueID - Unique id of queue from which to remove player. 222 | */ 223 | this.remove = function (player, queueID) { 224 | var queue = this.getQueue(queueID); 225 | if (queue) { 226 | queue.removePlayer(player); 227 | } 228 | }; 229 | 230 | /** 231 | * Remove player from all queues 232 | * @param {Player} player - Player object to remove 233 | */ 234 | this.removeFromAll = function (player) { 235 | var id; 236 | for (id in this._queueMap) { 237 | if (this._queueMap.hasOwnProperty(id)) { 238 | this.remove(player, id); 239 | } 240 | } 241 | }; 242 | } 243 | 244 | module.exports = { 245 | 'Queue': Queue, 246 | 'QueueManager': QueueManager 247 | }; 248 | -------------------------------------------------------------------------------- /docs/INSTALL.md: -------------------------------------------------------------------------------- 1 | # [backgammon.js](../README.md) :: Installation instructions 2 | 3 | The game server has been tested to work on the following platforms: 4 | 5 | - [Ubuntu 16.04 64-bit](#ubuntu) 6 | - [Windows 10 Professional 64-bit](#windows) 7 | - [Docker](#docker) 8 | - [Heroku](#heroku) 9 | - [OpenShift Online](#openshift-online) 10 | 11 | Client is served automatically by server via HTTP, so after you install the server, all you need to access the game is the URL to the server (by default http://localhost:8080) and a *modern* browser. 12 | 13 | The game client has been tested to work with recent Google Chrome, Firefox 48, IE 11 and Edge browser. 14 | The UI is reponsive, so it should work on most mobile browsers too, but so far has only been tried with up-to-date Google Chrome running under Android 4.1.2. 15 | 16 | ## Ubuntu 17 | 18 | Tested on *Ubuntu 16.04 64-bit*. 19 | 20 | Should work on any linux/unix OS that can run `git` and `node.js`. 21 | 22 | 1. Install latest version of [node.js](https://nodejs.org/en/download/current/) from [official website](https://nodejs.org). 23 | 24 | 2. Install git 25 | 26 | sudo apt-get update 27 | sudo apt-get install git 28 | 29 | 4. Create an empty directory where to put source code: 30 | 31 | mkdir -p ~/backgammonjs 32 | cd ~/backgammonjs 33 | 34 | 3. Clone game repository: 35 | 36 | git clone https://github.com/quasoft/backgammonjs.git . 37 | 38 | 4. Install the game and its dependencies: 39 | 40 | npm install 41 | 42 | If this fails, you can also try to install the client and server separately: 43 | 44 | cd app/browser 45 | npm install 46 | npm build 47 | 48 | cd ../server 49 | npm install 50 | 51 | cd ../.. 52 | 53 | 5. Start the game 54 | 55 | Make sure that port 8080 is not in use on your system and start the game: 56 | 57 | npm start 58 | 59 | If this fails, try to manually start the server: 60 | 61 | cd app/server 62 | node server.js 63 | 64 | 6. To test, open http://localhost:8080 in your browser and you should see the game home page. 65 | 66 | ## Windows 67 | 68 | Tested to work on *Windows 10 Professional 64-bit*. 69 | *Commands can be executed from `Command Prompt` or `Git Bash`.* 70 | 71 | 1. Install latest version of [node.js](https://nodejs.org/dist/v6.6.0/node-v6.6.0-x64.msi) from [official website](https://nodejs.org). 72 | 2. Install [Git for Windows](https://git-scm.com/download/win). 73 | 4. Create an empty directory where to put source code: 74 | 75 | mkdir c:\backgammonjs 76 | c: 77 | cd c:\backgammonjs 78 | 79 | 3. Clone game repository: 80 | 81 | git clone https://github.com/quasoft/backgammonjs.git . 82 | 83 | 4. Install the game and its dependencies: 84 | 85 | npm install 86 | 87 | If this fails, you can also try to install the client and server separately: 88 | 89 | cd app/browser 90 | npm install 91 | npm build 92 | 93 | cd ../server 94 | npm install 95 | 96 | cd ../.. 97 | 98 | 5. Start the game 99 | 100 | Make sure that port 8080 is not in use on your system and start the game: 101 | 102 | npm start 103 | 104 | If this fails, try to manually start the server: 105 | 106 | cd app/server 107 | node server.js 108 | 109 | 6. To test, open http://localhost:8080 in your browser and you should see the game home page. 110 | 111 | ## Docker 112 | 113 | Has been tested with Docker version 1.12.1 under Ubuntu 16.04 host (64-bit). 114 | 115 | 1. To install `docker` follow instructions on [Docker website](https://www.docker.com/products/overview#/install_the_platform) 116 | 117 | 2. Install git 118 | 119 | sudo apt-get update 120 | sudo apt-get install git 121 | 122 | 3. Create an empty directory where to put source code: 123 | 124 | mkdir -p ~/backgammonjs 125 | cd ~/backgammonjs 126 | 127 | 4. Clone game repository: 128 | 129 | git clone https://github.com/quasoft/backgammonjs.git . 130 | 131 | 5. Build docker image 132 | 133 | sudo docker build -t yourself/backgammonjs . 134 | 135 | 6. Start docker container 136 | 137 | sudo docker run -p 8080:8080 -d yourself/backgammonjs 138 | 139 | In command above port redirection is used from container to host (the `-p 8080:8080` part). 140 | If you omit that part, you will still be able to connect to the container, but will have to use the IP of the container, instead of the IP of the host (eg. http://172.17.0.2:8080). 141 | 142 | 7. Test 143 | 144 | curl -i http://localhost:8080 145 | 146 | or 147 | 148 | Open http://localhost:8080 in web browser 149 | 150 | ## Heroku 151 | 152 | Has been tested to work with free tier of Heroku. 153 | 154 | The demo is currently running there. 155 | 156 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/quasoft/backgammonjs/tree/heroku) 157 | 158 | ## OpenShift Online 159 | 160 | Has been tested to work with free tier of OpenShift Online - *small gear* and *node-latest* cartridge. 161 | 162 | TODO: add detailed intructions on using OpenShift 163 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # [backgammon.js](../README.md) :: Detailed documentation 2 | 3 | ## Contents: 4 | 5 | 1. [Motivation/problem](#motivationproblem) 6 | 2. [Goals](#goals) 7 | - [Must have](#must-have) 8 | - [Under consideration](#under-consideration) 9 | 3. [Users/Actors](#usersactors) 10 | 4. [Use cases](#use-cases) 11 | - [Player's use cases](Players-use-cases) 12 | - [Developer's use cases](Developers-use-cases) 13 | 5. [Objectives](#objectives) 14 | - [High level](#high-level) 15 | - [Mid-level](#mid-level) 16 | 6. [Roadmap](#roadmap) 17 | 7. [Architecture](#architecture) 18 | - [Overview](#overview) 19 | - [Environment layer](#environment-layer) 20 | - [Module layer](#module-layer) 21 | - [Application layer](#application-layer) 22 | - [Directory structure](#directory-structure) 23 | 8. [Credits](#credits) 24 | - [Tools used](#tools-used) 25 | - [Frameworks used](#frameworks-used) 26 | 9. [License](#license) 27 | 28 | ## Motivation/problem 29 | 30 | Backgammon is one of the most popular and ancient board games and there are zillion implementations of it for PC and mobile crafted around the world. 31 | 32 | Alas, most implementations share some of the following shortcomings: 33 | 34 | - Not suitable for a quick game 35 | 36 | They require registration, verification by E-mail, manually creating a game and setting up game options before starting the game. 37 | 38 | - Helping players too much 39 | 40 | Most implementations are providing too much help to players, like highlighting movable pieces, pipe counters, and even move hints. 41 | 42 | As a result the experience of playing the game suffers. What's more that prevents junior players from actually learning to play. 43 | 44 | - Based on specific culture 45 | 46 | Most implementations only allow playing a single variant of backgammon (or at best a few). This is an ancient game with many variants being played in different countries on even in different regions in the same country. 47 | 48 | - Require more processing power to run 49 | 50 | Some implementations have too high hardware requirements for a board game, which makes playing them on an old PC unpleasant. 51 | 52 | - Not mobile friendly 53 | 54 | Could not be played on tablet or mobile phone. 55 | 56 | ## Goals: 57 | 58 | The purpose of this project is to create an online backgammon game that has none of these shortcoming. This should be achieved by meeting the project goals. 59 | 60 | Goals have been divided in two categories: "must have" and "under consideration". 61 | 62 | Once a goal makes it to the "must have" list, objectives can be assigned to it. 63 | 64 | ### Must have: 65 | 66 | This is the list of must-have goals, that should be available in first stable release: 67 | 68 | - Allow anyone to challenge friends or play with strangers online with zero time to start the game - requires no registration or configuration. 69 | - Fair gameplay that is as close to real game as possible: 70 | - no visual hints for moves allowed; 71 | - no pip counter; 72 | - quality random generator. 73 | - Extensible and modular engine that would allow the open source community to implement different variants of the game as known in different countries and different user interfaces (eg. themes). 74 | - Lightweight - playable on any device, even old ones - anything that can run a modern browser; 75 | - Works in browser @ PC & Mobile; 76 | 77 | ### Under consideration: 78 | 79 | This is a set of optional goals that might or might not be considered as long-term goals for the future: 80 | 81 | - Add multiple language support. 82 | - Allow optional registration; 83 | - Remember game history; 84 | - Support player ratings; 85 | - Create replay engine; 86 | 87 | ## Users/Actors 88 | 89 | There will be two main types of users of the system: 90 | - **Players** - Players will just play the game 91 | - **Developers** - Developers will host the game at servers and write custom rules 92 | 93 | ## Use cases 94 | 95 | Use cases for those actors complement the goals from users' perspective: 96 | 97 | ### Player's use cases: 98 | 99 | ![Player's use cases](images/use-cases/player-goals.png) 100 | 101 | *Create custom game and Join game are not fully implemented yet.* 102 | 103 | ### Developer's use cases: 104 | 105 | ![Developer's use cases](images/use-cases/developer-goals.png) 106 | 107 | ## Objectives 108 | 109 | ### High level: 110 | 111 | These are business objectives that exactly match goals. 112 | 113 | > Allow anyone to challenge friends or play with strangers online with zero time to start the game - requires no registration or configuration 114 | 115 | - [X] Allow players to quickly start a random game; 116 | - [X] Allow players to send invites by chat or E-mail; 117 | 118 | ----- 119 | 120 | > Fair gameplay that is as close to real game as possible 121 | 122 | - [X] Use quality random generator 123 | 124 | ----- 125 | 126 | > Extensible and modular engine that would allow the open source community to implement different variants of the game as known in different countries and different user interfaces (eg. themes) 127 | 128 | - [X] Allow writing custom rules 129 | - [ ] Allow writing custom UI 130 | 131 | ----- 132 | 133 | > Lightweight - playable on any device, even old ones - anything that can run a modern browser 134 | > Works in browser @ PC & Mobile 135 | 136 | - [X] Make a lightweight client that works in both desktop and mobile browsers alike 137 | 138 | ### Mid-level: 139 | 140 | Coming soon... 141 | 142 | ## Roadmap 143 | 144 | | Objective | State | Time Frame | 145 | |:--------------------------------------------|:-------------------------------------|:----------:| 146 | | Create documentation | :soon: In Progress | | 147 | | Choose network/communication library | :white_check_mark: Completed | | 148 | | Choose DBMS | :white_check_mark: Completed | | 149 | | Create object model | :soon: Working | | 150 | | Create a sample rule | :construction: In Progress | | 151 | | Create simple board UI | :construction: In Progress | | 152 | | Integrate Socket.IO | :soon: Working | | 153 | | Allow player to create and join game | :construction: In Progress | | 154 | | Allow player to start game | :soon: Working | | 155 | | Allow player to start random game | :soon: Working | | 156 | | Update board UI on game state change | :construction: In Progress | | 157 | | Allow player to roll dice (at server) | :white_check_mark: Completed | | 158 | | Use quality random generator | :white_check_mark: Completed | | 159 | | Always show player's pieces at bottom | :white_check_mark: Completed | | 160 | | Play lowest die value on right click | :white_check_mark: Completed | | 161 | | Reverse die values on click at dice | :white_check_mark: Completed | | 162 | | Allow player to move pieces | :white_check_mark: Completed | | 163 | | Validate moves at server, using rules | :white_check_mark: Completed | | 164 | | Allow player to end turn, if a move cannot be played | :white_check_mark: Completed | | 165 | | Force player to use all possible moves, if possible | :white_check_mark: Completed | | 166 | | Continue game on page reload | :soon: Working | | 167 | | Implement matches | :soon: Working | | 168 | | Show an offcanvas game menu | :soon: Working | | 169 | | Show player names and match score in toolbar| :construction: In Progress | | 170 | | Show borne pieces | :white_large_square: Not implemented | | 171 | | Allow player to resign from game/match | :white_check_mark: Completed | | 172 | | Allow user to get "challenge" links | :white_check_mark: Completed | | 173 | | Allow user to see list of games | :white_large_square: Not implemented | | 174 | | Users can filter/sort games by rule | :white_large_square: Not implemented | | 175 | | Users can choose use of clock, cube and match length | :white_large_square: Not implemented | | 176 | | Polish simple board UI | :white_large_square: Not implemented | | 177 | | Allow user to choose game rule (variant) | :white_check_mark: Completed | | 178 | | End match if connection is broken for X mins| :white_check_mark: Not implemented | Next | 179 | 180 | 181 | *Possible states: :white_large_square: Not implemented, :construction: In progress, :soon: Working, :white_check_mark: Completed* 182 | 183 | ## Architecture 184 | 185 | ### Overview 186 | 187 | The project uses a typical client/server architecture with several layers of responsibility. 188 | 189 | ![Player's use cases](images/architecture.png) 190 | 191 | ### Environment layer 192 | 193 | The environment layer contains external systems and frameworks the project depends on, like `Node.js` and `Socket.IO`. 194 | 195 | Foundation of project is laid on `node.js`. Network connectivity is implemented via `Socket.IO`. Storage of objects will be performed by `MongoDB`, but database layer has not been integrated yet, so everything is reset when the server application is restarted. Database will be required if we decide to allow players to register and save their game history. 196 | 197 | ### Module layer 198 | 199 | The module layer contains classes shared between client and server all packaged in a single `node.js` package named `backgammon.js-lib`. 200 | 201 | This package includes: 202 | - Classes describing domain model; 203 | - Messages exchanged on network layer; 204 | - Rules for variants of the game. 205 | 206 | `JsDoc` documentation of library classes is available at [Library Reference](https://cdn.rawgit.com/quasoft/backgammonjs/master/docs/backgammon.js-lib/0.0.1/index.html). 207 | 208 | #### Model classes: 209 | 210 | ![Model Class Diagram](images/class-diagrams/model.png) 211 | 212 | #### Rule classes: 213 | 214 | ![Rules Class Diagram](images/class-diagrams/rules.png) 215 | 216 | Instructions on adding new variants of backgammon (rules) to the game can be found at [Creating rules for `backgammon.js`](rules.md). 217 | 218 | ### Application layer 219 | 220 | The application layer consists of two `node.js` packages: `backgammon.js-client` and `backgammon.js-server`. 221 | 222 | Both packages depend on the common library modules and use `Socket.IO` to communicate with each other. 223 | 224 | ### Directory structure 225 | 226 | Directory structure of code follows project architecture: 227 | ``` 228 | ├─ [app] - Place for applications' code (server, browser, android, etc.) 229 | │ ├─ [browser] - Sample web client application 230 | │ │ ├─ [images] 231 | │ │ ├─ [js] 232 | │ │ │ ├─ bundle.js - browserify's output file (bundling all other scripts) 233 | │ │ │ ├─ config.js - Config script for client 234 | │ │ │ ├─ main.js - Main script file for index.html 235 | │ │ │ └─ SimpleBoardUI.js - Sample user interface for game board 236 | │ │ │─ [style] 237 | │ │ │ └─ backgammon.css - Main style file for index.html 238 | │ │ ├─ bower.json - Bower package file for web client 239 | │ │ ├─ index.html - Home page of web client 240 | │ │ ├─ package.json - Node.js package file 241 | │ │ └─ README.md - Instructions for client installation and development 242 | │ │ 243 | │ └─ [server] - Server application 244 | │ ├─ package.json - Node.js package file 245 | │ ├─ queue_manager.js - Node.js package file 246 | │ ├─ README.md - Instructions for server installation and development 247 | │ └─ server.js - Server startup script 248 | │ 249 | ├─ [docs] 250 | │ ├─ [images] 251 | │ ├─ backgammon.js.uml 252 | │ ├─ INSTALL.md - Detailed installation instructions 253 | │ ├─ README.md - This file 254 | │ ├─ rules.md - Instructions on creating a new rule 255 | │ └─ use-cases.md 256 | │ 257 | ├─ [lib] - Common library shared by clients and server 258 | │ ├─ [rules] - Rules describing different variants of the game 259 | │ │ ├─ rules\rule.js - Base class for defining game rules 260 | │ │ ├─ rules\RuleBgCasual.js - Rule for most popular variant 261 | │ │ ├─ rules\RuleBgGulbara.js - Example for `Gul bara` variant 262 | │ │ └─ rules\RuleBgTapa.js - Example for `Tapa` variant 263 | │ ├─ client.js - Messages exchanged on network layer 264 | │ ├─ comm.js - Messages exchanged on network layer 265 | │ ├─ model.js - Classes of the object oriented model 266 | │ ├─ package.json - Node.js package file 267 | │ └─ README.md - Library documentation and instructions on writing new rules 268 | │ 269 | ├─ .gitignore 270 | ├─ .tern-project - Sample configuration for atom-tern.js plugin 271 | ├─ CHANGELOG.md 272 | ├─ Dockerfile 273 | ├─ LICENSE - MIT License 274 | ├─ package.json - Main project package 275 | └─ README.md - Project's readme with links to all documents 276 | ``` 277 | 278 | ## Credits 279 | 280 | - Heroku - free tier of service used for running the demo 281 | 282 | ### Tools used: 283 | 284 | - Brackets & Atom editor (with `atom-tern.js`) 285 | - Netbeans IDE 286 | - White StarUML 287 | - browserify.js 288 | - watch.js 289 | - watchify.js 290 | - JsDoc 291 | - Git 292 | - Paint.NET 293 | 294 | ### Frameworks and libraries used: 295 | 296 | - Node.js 297 | - Express 298 | - Socket.IO 299 | - jQuery 300 | - Bootstrap 301 | - OhSnap!.js 302 | - Fittext.js 303 | - clipboard.js 304 | - js-cookie 305 | 306 | ## License 307 | 308 | Licensed under the [MIT license](../LICENSE). 309 | 310 | ## Other documents: 311 | 312 | - [`Project README`](../README.md) 313 | - Client application: [`backgammon.js-client`](../app/browser/README.md) 314 | - Server application: [`backgammon.js-server`](../app/server/README.md) 315 | - Common Library: [`backgammon.js-lib`](../lib/README.md) 316 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/MoveAction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: MoveAction 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: MoveAction

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

MoveAction

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new MoveAction()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Actions that can result from making a piece move. 51 | Rules can assign additional properties to those, depending on the action 52 | type 53 |
54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 |
Source:
95 |
98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 |
106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 |
124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |

Members

137 | 138 | 139 | 140 |

type :MoveActionType|string

141 | 142 | 143 | 144 | 145 |
146 | Action type, depends on rule (eg. move, bear, hit) 147 |
148 | 149 | 150 | 151 |
Type:
152 |
    153 |
  • 154 | 155 | MoveActionType 156 | | 157 | 158 | string 159 | 160 | 161 |
  • 162 |
163 | 164 | 165 | 166 | 167 | 168 |
169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 |
Source:
196 |
199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 |
207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 |
222 | 223 |
224 | 225 | 226 | 227 | 228 |
229 | 230 | 233 | 234 |
235 | 236 |
237 | Documentation generated by JSDoc 3.4.3 on Sun Dec 18 2016 20:10:05 GMT+0200 (EET) 238 |
239 | 240 | 241 | 242 | 243 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/Piece.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Piece 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Piece

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Piece

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Piece(type, id)

44 | 45 | 46 | 47 | 48 | 49 |
50 | Pieces are round checkers that are being moved around the board. 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
Parameters:
62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 |
NameTypeDescription
type 90 | 91 | 92 | PieceType 93 | 94 | 95 | 96 | Type of piece
id 113 | 114 | 115 | number 116 | 117 | 118 | 119 | ID of piece
131 | 132 | 133 | 134 | 135 | 136 | 137 |
138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 |
Source:
165 |
168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 |
176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 |
194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 |

Members

207 | 208 | 209 | 210 |

id :number

211 | 212 | 213 | 214 | 215 |
216 | ID of piece 217 |
218 | 219 | 220 | 221 |
Type:
222 |
    223 |
  • 224 | 225 | number 226 | 227 | 228 |
  • 229 |
230 | 231 | 232 | 233 | 234 | 235 |
236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 |
Source:
263 |
266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 |
274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 |

type :PieceType

283 | 284 | 285 | 286 | 287 |
288 | Type of piece (white/black) 289 |
290 | 291 | 292 | 293 |
Type:
294 |
    295 |
  • 296 | 297 | PieceType 298 | 299 | 300 |
  • 301 |
302 | 303 | 304 | 305 | 306 | 307 |
308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 |
Source:
335 |
338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 |
346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 |
361 | 362 |
363 | 364 | 365 | 366 | 367 |
368 | 369 | 372 | 373 |
374 | 375 |
376 | Documentation generated by JSDoc 3.4.3 on Sun Dec 18 2016 20:10:05 GMT+0200 (EET) 377 |
378 | 379 | 380 | 381 | 382 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/Player.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Player 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Player

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Player

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Player()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Player 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |

Members

135 | 136 | 137 | 138 |

currentGame :Game

139 | 140 | 141 | 142 | 143 |
144 | Reference to current game 145 |
146 | 147 | 148 | 149 |
Type:
150 |
    151 |
  • 152 | 153 | Game 154 | 155 | 156 |
  • 157 |
158 | 159 | 160 | 161 | 162 | 163 |
164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
Source:
191 |
194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 |
202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 |

currentMatch :Match

211 | 212 | 213 | 214 | 215 |
216 | Reference to current match 217 |
218 | 219 | 220 | 221 |
Type:
222 |
    223 |
  • 224 | 225 | Match 226 | 227 | 228 |
  • 229 |
230 | 231 | 232 | 233 | 234 | 235 |
236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 |
Source:
263 |
266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 |
274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 |

currentPieceType :PieceType

283 | 284 | 285 | 286 | 287 |
288 | Player's piece type for current game 289 |
290 | 291 | 292 | 293 |
Type:
294 |
    295 |
  • 296 | 297 | PieceType 298 | 299 | 300 |
  • 301 |
302 | 303 | 304 | 305 | 306 | 307 |
308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 |
Source:
335 |
338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 |
346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 |

currentRule :Rule

355 | 356 | 357 | 358 | 359 |
360 | Reference to rule for current game 361 |
362 | 363 | 364 | 365 |
Type:
366 |
    367 |
  • 368 | 369 | Rule 370 | 371 | 372 |
  • 373 |
374 | 375 | 376 | 377 | 378 | 379 |
380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 |
Source:
407 |
410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 |
418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 |

id :number

427 | 428 | 429 | 430 | 431 |
432 | Unique ID 433 |
434 | 435 | 436 | 437 |
Type:
438 |
    439 |
  • 440 | 441 | number 442 | 443 | 444 |
  • 445 |
446 | 447 | 448 | 449 | 450 | 451 |
452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 |
Source:
479 |
482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 |
490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 |

name :string

499 | 500 | 501 | 502 | 503 |
504 | Username 505 |
506 | 507 | 508 | 509 |
Type:
510 |
    511 |
  • 512 | 513 | string 514 | 515 | 516 |
  • 517 |
518 | 519 | 520 | 521 | 522 | 523 |
524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 |
Source:
551 |
554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 |
562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 |

socketID :string

571 | 572 | 573 | 574 | 575 |
576 | ID of player's socket 577 |
578 | 579 | 580 | 581 |
Type:
582 |
    583 |
  • 584 | 585 | string 586 | 587 | 588 |
  • 589 |
590 | 591 | 592 | 593 | 594 | 595 |
596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 |
Source:
623 |
626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 |
634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 |

stats :PlayerStats

643 | 644 | 645 | 646 | 647 |
648 | Player's statistics 649 |
650 | 651 | 652 | 653 |
Type:
654 |
    655 |
  • 656 | 657 | PlayerStats 658 | 659 | 660 |
  • 661 |
662 | 663 | 664 | 665 | 666 | 667 |
668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 |
Source:
695 |
698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 |
706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 |

Methods

717 | 718 | 719 | 720 | 721 | 722 | 723 |

(static) createNew() → {Player}

724 | 725 | 726 | 727 | 728 | 729 |
730 | Create new player object with unique ID. 731 | Player object is not saved to database. 732 |
733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 |
747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 |
Source:
774 |
777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 |
785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 |
Returns:
799 | 800 | 801 |
802 | - New player object 803 |
804 | 805 | 806 | 807 |
808 |
809 | Type 810 |
811 |
812 | 813 | Player 814 | 815 | 816 |
817 |
818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 |
830 | 831 |
832 | 833 | 834 | 835 | 836 |
837 | 838 | 841 | 842 |
843 | 844 |
845 | Documentation generated by JSDoc 3.4.3 on Sun Dec 18 2016 20:10:05 GMT+0200 (EET) 846 |
847 | 848 | 849 | 850 | 851 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/PlayerStats.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: PlayerStats 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: PlayerStats

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

PlayerStats

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new PlayerStats()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Player's statistics 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |

Members

135 | 136 | 137 | 138 |

doubles :number

139 | 140 | 141 | 142 | 143 |
144 | Percent of doubles rolled relative to total number of dice rolled 145 |
146 | 147 | 148 | 149 |
Type:
150 |
    151 |
  • 152 | 153 | number 154 | 155 | 156 |
  • 157 |
158 | 159 | 160 | 161 | 162 | 163 |
164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
Source:
191 |
194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 |
202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 |

loses :number

211 | 212 | 213 | 214 | 215 |
216 | Total number of loses 217 |
218 | 219 | 220 | 221 |
Type:
222 |
    223 |
  • 224 | 225 | number 226 | 227 | 228 |
  • 229 |
230 | 231 | 232 | 233 | 234 | 235 |
236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 |
Source:
263 |
266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 |
274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 |

wins :number

283 | 284 | 285 | 286 | 287 |
288 | Total number of wins 289 |
290 | 291 | 292 | 293 |
Type:
294 |
    295 |
  • 296 | 297 | number 298 | 299 | 300 |
  • 301 |
302 | 303 | 304 | 305 | 306 | 307 |
308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 |
Source:
335 |
338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 |
346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 |
361 | 362 |
363 | 364 | 365 | 366 | 367 |
368 | 369 | 372 | 373 |
374 | 375 |
376 | Documentation generated by JSDoc 3.4.3 on Sun Dec 18 2016 20:10:05 GMT+0200 (EET) 377 |
378 | 379 | 380 | 381 | 382 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/Random.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Random 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Random

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Random

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Random()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Random generator. 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |

Methods

137 | 138 | 139 | 140 | 141 | 142 | 143 |

(static) get() → {number}

144 | 145 | 146 | 147 | 148 | 149 |
150 | Get random number from 1 to 6 151 |
152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 |
166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 |
Source:
193 |
196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 |
204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 |
Returns:
218 | 219 | 220 |
221 | - Random value from 1 to 6 222 |
223 | 224 | 225 | 226 |
227 |
228 | Type 229 |
230 |
231 | 232 | number 233 | 234 | 235 |
236 |
237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 |
249 | 250 |
251 | 252 | 253 | 254 | 255 |
256 | 257 | 260 | 261 |
262 | 263 |
264 | Documentation generated by JSDoc 3.4.3 on Sun Dec 18 2016 20:10:05 GMT+0200 (EET) 265 |
266 | 267 | 268 | 269 | 270 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/comm.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: comm.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: comm.js

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
/**
30 |  * Protocol options
31 |  * @type {{Port: number}}
32 |  */
33 | var Protocol = {
34 |     BindAddress: '0.0.0.0',
35 |     Port: 8080
36 | };
37 | module.exports.Protocol = Protocol;
38 | 
39 | /**
40 |  * Message IDs
41 |  * @readonly
42 |  * @enum {string}
43 |  */
44 | var Message = {
45 |   CONNECT: 'connect',
46 |   DISCONNECT: 'disconnect',
47 |   CREATE_GUEST: 'createGuest',
48 |   GET_MATCH_LIST: 'getMatchList',
49 |   PLAY_RANDOM: 'playRandom',
50 |   CREATE_MATCH: 'createMatch',
51 |   JOIN_MATCH: 'joinMatch',
52 |   ROLL_DICE: 'rollDice',
53 |   MOVE_PIECE: 'movePiece',
54 |   CONFIRM_MOVES: 'confirmMoves',
55 |   UNDO_MOVES: 'undoMoves',
56 |   EVENT_PLAYER_JOINED: 'eventPlayerJoined',
57 |   EVENT_TURN_START: 'eventTurnStart',
58 |   EVENT_DICE_ROLL: 'eventDiceRoll',
59 |   EVENT_PIECE_MOVE: 'eventPieceMove',
60 |   EVENT_MATCH_START: 'eventMatchStart',
61 |   EVENT_MATCH_OVER: 'eventMatchOver',
62 |   EVENT_GAME_OVER: 'eventGameOver',
63 |   EVENT_GAME_RESTART: 'eventGameRestart',
64 |   EVENT_UNDO_MOVES: 'eventUndoMoves',
65 | };
66 | 
67 | module.exports.Message = Message;
68 | 
69 |
70 |
71 | 72 | 73 | 74 | 75 |
76 | 77 | 80 | 81 |
82 | 83 |
84 | Documentation generated by JSDoc 3.4.3 on Sun Dec 18 2016 20:10:05 GMT+0200 (EET) 85 |
86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Bold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Bold-webfont.eot -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Bold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Bold-webfont.woff -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-BoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-BoldItalic-webfont.eot -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-BoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-BoldItalic-webfont.woff -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Italic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Italic-webfont.eot -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Italic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Italic-webfont.woff -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Light-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Light-webfont.eot -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Light-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Light-webfont.woff -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-LightItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-LightItalic-webfont.eot -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-LightItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-LightItalic-webfont.woff -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Regular-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Regular-webfont.eot -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Regular-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/backgammon.js-lib/0.0.1/fonts/OpenSans-Regular-webfont.woff -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Home 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Home

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |

backgammon.js-lib 0.0.1

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 | 52 | 55 | 56 |
57 | 58 |
59 | Documentation generated by JSDoc 3.4.3 on Sun Dec 18 2016 20:10:05 GMT+0200 (EET) 60 |
61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/rules_RuleBgTapa.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: rules/RuleBgTapa.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: rules/RuleBgTapa.js

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
var model = require('../model.js');
 30 | var Rule = require('./rule.js');
 31 | 
 32 | /**
 33 |  * Bulgarian variant of Tapa (тапа).
 34 |  * @constructor
 35 |  * @extends Rule
 36 |  */
 37 | function RuleBgTapa() {
 38 |   Rule.call(this);
 39 | 
 40 |   /**
 41 |    * Rule name, matching the class name (eg. 'RuleBgTapa')
 42 |    * @type {string}
 43 |    */
 44 |   this.name = 'RuleBgTapa';
 45 | 
 46 |   /**
 47 |    * Short title describing rule specifics
 48 |    * @type {string}
 49 |    */
 50 |   this.title = 'Tapa';
 51 | 
 52 |   /**
 53 |    * Full description of rule
 54 |    * @type {string}
 55 |    */
 56 |   this.description = 'Bulgarian variant of Tapa (тапа).';
 57 | 
 58 |   /**
 59 |    * Full name of country where this rule (variant) is played.
 60 |    * To list multiple countries use a pipe ('|') character as separator.
 61 |    * @type {string}
 62 |    */
 63 |   this.country = 'Bulgaria';
 64 | 
 65 |   /**
 66 |    * Two character ISO code of country where this rule (variant) is played.
 67 |    * To list multiple codes use a pipe ('|') character as separator.
 68 |    * List codes in same order as countries in the field above.
 69 |    * @type {string}
 70 |    */
 71 |   this.countryCode = 'bg';
 72 | }
 73 | 
 74 | RuleBgTapa.prototype = Object.create(Rule.prototype);
 75 | RuleBgTapa.prototype.constructor = RuleBgTapa;
 76 | 
 77 | /**
 78 |  * Reset state to initial position of pieces according to current rule.
 79 |  * @memberOf RuleBgTapa
 80 |  * @param {State} state - Board state
 81 |  */
 82 | RuleBgTapa.prototype.resetState = function(state) {
 83 |   /**
 84 |    * Move pieces to correct initial positions for both players.
 85 |    * Values in state.points are zero based and denote the .
 86 |    * the number of pieces on each position.
 87 |    * Index 0 of array is position 1 and increments to the number of maximum
 88 |    * points.
 89 |    *
 90 |    * Position: |12 13 14 15 16 17| |18 19 20 21 22 23| White
 91 |    *           |                 | |              15w| <-
 92 |    *           |                 | |                 |
 93 |    *           |                 | |                 |
 94 |    *           |                 | |                 |
 95 |    *           |                 | |              15b| <-
 96 |    * Position: |11 10 09 08 07 06| |05 04 03 02 01 00| Black
 97 |    *
 98 |    */
 99 | 
100 | 
101 |   model.State.clear(state);
102 | 
103 |   this.place(state, 15, model.PieceType.WHITE, 23);
104 | 
105 |   this.place(state, 15, model.PieceType.BLACK, 0);
106 | };
107 | 
108 | /**
109 |  * Increment position by specified number of steps and return an incremented position
110 |  * @memberOf RuleBgTapa
111 |  * @param {number} position - Denormalized position
112 |  * @param {PieceType} type - Type of piece
113 |  * @param {number} steps - Number of steps to increment towards first home position
114 |  * @returns {number} - Incremented position (denormalized)
115 |  */
116 | RuleBgTapa.prototype.incPos = function(position, type, steps) {
117 |   var newPosition;
118 |   if (type === model.PieceType.WHITE) {
119 |     newPosition = position - steps;
120 |   }
121 |   else {
122 |     newPosition = position + steps;
123 |   }
124 | 
125 |   return newPosition;
126 | };
127 | 
128 | /**
129 |  * Normalize position - Normalized positions start from 0 to 23 for both players,
130 |  * where 0 is the first position in the home part of the board, 6 is the last
131 |  * position in the home part and 23 is the furthest position - in the opponent's
132 |  * home.
133 |  * @memberOf RuleBgTapa
134 |  * @param {number} position - Denormalized position (0 to 23 for white and 23 to 0 for black)
135 |  * @param {PieceType} type - Type of piece (white/black)
136 |  * @returns {number} - Normalized position (0 to 23 for both players)
137 |  */
138 | RuleBgTapa.prototype.normPos = function(position, type) {
139 |   var normPosition = position;
140 | 
141 |   if (type === model.PieceType.BLACK) {
142 |     normPosition = 23 - position;
143 |   }
144 |   return normPosition;
145 | };
146 | 
147 | /**
148 |  * Get denormalized position - start from 0 to 23 for white player and from
149 |  * 23 to 0 for black player.
150 |  * @memberOf RuleBgTapa
151 |  * @param {number} position - Normalized position (0 to 23 for both players)
152 |  * @param {PieceType} type - Type of piece (white/black)
153 |  * @return {number} - Denormalized position (0 to 23 for white and 23 to 0 for black)
154 |  */
155 | RuleBgTapa.prototype.denormPos = function(position, type) {
156 |   var denormPosition = position;
157 | 
158 |   if (type === model.PieceType.BLACK) {
159 |     denormPosition = 23 - position;
160 |   }
161 |   return denormPosition;
162 | };
163 | 
164 | /**
165 |  * Call this method after a request for moving a piece has been made.
166 |  * Determines if the move is allowed and what actions will have to be made as
167 |  * a result. Actions can be `move` or `bear`.
168 |  *
169 |  * Multiple actions can be returned, if required.
170 |  *
171 |  * The list of actions returned would usually be appllied to game state and then
172 |  * sent to client. The client's UI would play the actions (eg. with movement animation)
173 |  * in the same order.
174 |  *
175 |  * @memberOf RuleBgTapa
176 |  * @param {State} state - State
177 |  * @param {Piece} piece - Piece to move
178 |  * @param {PieceType} type - Type of piece
179 |  * @param {number} steps - Number of steps to increment towards first home position
180 |  * @returns {MoveAction[]} - List of actions if move is allowed, empty list otherwise.
181 |  */
182 | RuleBgTapa.prototype.getMoveActions = function(state, piece, steps) {
183 |   var actionList = [];
184 | 
185 |   // Next, check conditions specific to this game rule and build the list of
186 |   // actions that has to be made.
187 | 
188 |   /**
189 |    * Create a new move action and add it to actionList. Used internally.
190 |    *
191 |    * @alias RuleBgTapa.getMoveActions.addAction
192 |    * @memberof RuleBgTapa.getMoveActions
193 |    * @method RuleBgTapa.getMoveActions.addAction
194 |    * @param {MoveActionType} moveActionType - Type of move action (eg. move, bear)
195 |    * @param {Piece} piece - Piece to move
196 |    * @param {number} from - Denormalized source position. If action uses only one position parameter, this one is used.
197 |    * @param {number} to - Denormalized destination position.
198 |    * @returns {MoveAction}
199 |    * @see {@link getMoveActions} for more information on purpose of move actions.
200 |    */
201 |   function addAction(moveActionType, piece, from, to) {
202 |     var action = new model.MoveAction();
203 |     action.type = moveActionType;
204 |     action.piece = piece;
205 |     action.position = from;
206 |     action.from = from;
207 |     if (typeof to !== "undefined") {
208 |       action.to = to;
209 |     }
210 |     actionList.push(action);
211 |     return action;
212 |   }
213 | 
214 |   // TODO: Catch exceptions due to disallowed move requests and pass them as error message to the client.
215 |   try {
216 |     var position = model.State.getPiecePos(state, piece);
217 |     
218 |     // TODO: Consider using state machine? Is it worth, can it be useful in other methods too?
219 |     if (this.allPiecesAreHome(state, piece.type)) {
220 |       /*
221 |       If all pieces are in home field, the player can bear pieces
222 |       Cases:
223 |         - Normalized position >= 0 --> Just move the piece
224 |         - Normalized position === -1 --> Bear piece
225 |         - Normalized position < -1 --> Bear piece, only if there are no player pieces at higher positions
226 | 
227 |         +12-13-14-15-16-17------18-19-20-21-22-23-+
228 |         |                  |   |                  |
229 |         |                  |   |                  |
230 |         |                  |   |                  |
231 |         |                  |   |                  |
232 |         |                  |   |                  |
233 |         |                  |   |                  |
234 |         |                  |   |                  |
235 |         |                  |   |                  |
236 |         |                  |   |                  |
237 |         |                  |   |    O  O          |
238 |         |                  |   | O  O  O          |
239 |         +11-10--9--8--7--6-------5--4--3--2--1--0-+ -1
240 | 
241 |       */
242 |       var destination = this.incPos(position, piece.type, steps);
243 |       var normDestination = this.normPos(destination, piece.type);
244 | 
245 |       // Move the piece, unless point is blocked by opponent
246 |       if (normDestination >= 0) {
247 | 
248 |         var destTopPiece = model.State.getTopPiece(state, destination);
249 |         var destTopPieceType = (destTopPiece) ? destTopPiece.type : null;
250 | 
251 |         // There are no pieces at this point or the top piece is owned by player,
252 |         // so just move piece to that position
253 |         if ((destTopPieceType === null) || (destTopPieceType === piece.type)) {
254 |           addAction(
255 |             model.MoveActionType.MOVE, piece, position, destination
256 |           );
257 |         }
258 |         // The top piece is opponent's and is only one (i.e. the point is not blocked),
259 |         // so move ours on top of opponent's piece
260 |         else if (model.State.countAllAtPos(state, destination) === 1) {
261 |           addAction(
262 |             model.MoveActionType.MOVE, piece, position, destination
263 |           );
264 |         }
265 |       }
266 |       // If steps are just enought to reach position -1, bear piece
267 |       else if (normDestination === -1) {
268 |         addAction(
269 |           model.MoveActionType.BEAR, piece, position
270 |         );
271 |       }
272 |       // If steps move the piece beyond -1 position, the player can bear the piece,
273 |       // only if there are no other pieces at higher positions
274 |       else {
275 |         var normSource = this.normPos(position, piece.type);
276 |         if (this.countAtHigherPos(state, normSource + 1, piece.type) <= 0) {
277 |           addAction(
278 |             model.MoveActionType.BEAR, piece, position
279 |           );
280 |         }
281 |       }
282 |     }
283 |     else {
284 |       /*
285 |         If there is at least one piece outside home, just move the piece.
286 |         Input data: position=13, steps=3
287 |         Cases:
288 |           - Opponent has no pieces there --> move the checker at position 10
289 |           - Opponent has exactly one piece --> move out piece over opponent's one
290 |           - Opponent has two or more pieces --> point is blocked, cannot move piece there
291 |                                           !
292 |         +12-13-14-15-16-17------18-19-20-21-22-23-+
293 |         |    O             |   | X                |
294 |         |    O             |   | X                |
295 |         |                  |   | X                |
296 |         |                  |   |                  |
297 |         |                  |   |                  |
298 |         |                  |   |                  |
299 |         |                  |   |                  |
300 |         |                  |   |                  |
301 |         |                  |   |                  |
302 |         |                  |   |       O          |
303 |         |                  |   | O  O  O          |
304 |         +11-10--9--8--7--6-------5--4--3--2--1--0-+ -1
305 |              !
306 |       */
307 | 
308 |       var destination = this.incPos(position, piece.type, steps);
309 | 
310 |       // Make sure that destination is within board
311 |       if ((destination >= 0) && (destination <= 23)) {
312 |         var normDest = this.normPos(destination, piece.type);
313 |         // TODO: Make sure position is not outside board
314 | 
315 |         var destTopPiece = model.State.getTopPiece(state, destination);
316 |         var destTopPieceType = (destTopPiece) ? destTopPiece.type : null;
317 | 
318 |         // There are no pieces at this point or the top piece is owned by player
319 |         if ((destTopPieceType === null) || (destTopPieceType === piece.type)) {
320 |           addAction(
321 |             model.MoveActionType.MOVE, piece, position, destination
322 |           );
323 |         }
324 |         // The top piece is opponent's and is a blot (i.e. the point is not blocked)
325 |         else if (model.State.countAllAtPos(state, destination) === 1) {
326 |           addAction(
327 |             model.MoveActionType.MOVE, piece, position, destination
328 |           );
329 |         }
330 |       }
331 |     }
332 |   }
333 |   catch (e) {
334 |     actionList = [];
335 |     return actionList;
336 |   }
337 |   
338 |   return actionList;
339 | };
340 | 
341 | /**
342 |  * Call this method to apply a list of actions to a game state.
343 |  * Actions can be `move` or `bear`.
344 |  *
345 |  * @memberOf RuleBgTapa
346 |  * @param {State} state - State to change
347 |  * @param {MoveAction[]} actionList - List of action to apply.
348 |  */
349 | RuleBgTapa.prototype.applyMoveActions = function(state, actionList) {
350 |   for (var i = 0; i < actionList.length; i++) {
351 |     var action = actionList[i];
352 | 
353 |     if (action.type === model.MoveActionType.MOVE) {
354 |       this.move(state, action.piece, action.to);
355 |     }
356 |     else if (action.type === model.MoveActionType.BEAR) {
357 |       this.bear(state, action.piece);
358 |     }
359 |   }
360 | };
361 | 
362 | module.exports = new RuleBgTapa();
363 | 
364 |
365 |
366 | 367 | 368 | 369 | 370 |
371 | 372 | 375 | 376 |
377 | 378 |
379 | Documentation generated by JSDoc 3.4.3 on Sun Dec 18 2016 20:10:05 GMT+0200 (EET) 380 |
381 | 382 | 383 | 384 | 385 | 386 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/scripts/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/scripts/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p th:last-child { border-right: 1px solid #ddd; } 220 | 221 | .ancestors { color: #999; } 222 | .ancestors a 223 | { 224 | color: #999 !important; 225 | text-decoration: none; 226 | } 227 | 228 | .clear 229 | { 230 | clear: both; 231 | } 232 | 233 | .important 234 | { 235 | font-weight: bold; 236 | color: #950B02; 237 | } 238 | 239 | .yes-def { 240 | text-indent: -1000px; 241 | } 242 | 243 | .type-signature { 244 | color: #aaa; 245 | } 246 | 247 | .name, .signature { 248 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 249 | } 250 | 251 | .details { margin-top: 14px; border-left: 2px solid #DDD; } 252 | .details dt { width: 120px; float: left; padding-left: 10px; padding-top: 6px; } 253 | .details dd { margin-left: 70px; } 254 | .details ul { margin: 0; } 255 | .details ul { list-style-type: none; } 256 | .details li { margin-left: 30px; padding-top: 6px; } 257 | .details pre.prettyprint { margin: 0 } 258 | .details .object-value { padding-top: 0; } 259 | 260 | .description { 261 | margin-bottom: 1em; 262 | margin-top: 1em; 263 | } 264 | 265 | .code-caption 266 | { 267 | font-style: italic; 268 | font-size: 107%; 269 | margin: 0; 270 | } 271 | 272 | .prettyprint 273 | { 274 | border: 1px solid #ddd; 275 | width: 80%; 276 | overflow: auto; 277 | } 278 | 279 | .prettyprint.source { 280 | width: inherit; 281 | } 282 | 283 | .prettyprint code 284 | { 285 | font-size: 100%; 286 | line-height: 18px; 287 | display: block; 288 | padding: 4px 12px; 289 | margin: 0; 290 | background-color: #fff; 291 | color: #4D4E53; 292 | } 293 | 294 | .prettyprint code span.line 295 | { 296 | display: inline-block; 297 | } 298 | 299 | .prettyprint.linenums 300 | { 301 | padding-left: 70px; 302 | -webkit-user-select: none; 303 | -moz-user-select: none; 304 | -ms-user-select: none; 305 | user-select: none; 306 | } 307 | 308 | .prettyprint.linenums ol 309 | { 310 | padding-left: 0; 311 | } 312 | 313 | .prettyprint.linenums li 314 | { 315 | border-left: 3px #ddd solid; 316 | } 317 | 318 | .prettyprint.linenums li.selected, 319 | .prettyprint.linenums li.selected * 320 | { 321 | background-color: lightyellow; 322 | } 323 | 324 | .prettyprint.linenums li * 325 | { 326 | -webkit-user-select: text; 327 | -moz-user-select: text; 328 | -ms-user-select: text; 329 | user-select: text; 330 | } 331 | 332 | .params .name, .props .name, .name code { 333 | color: #4D4E53; 334 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 335 | font-size: 100%; 336 | } 337 | 338 | .params td.description > p:first-child, 339 | .props td.description > p:first-child 340 | { 341 | margin-top: 0; 342 | padding-top: 0; 343 | } 344 | 345 | .params td.description > p:last-child, 346 | .props td.description > p:last-child 347 | { 348 | margin-bottom: 0; 349 | padding-bottom: 0; 350 | } 351 | 352 | .disabled { 353 | color: #454545; 354 | } 355 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: #006400; 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /docs/backgammon.js-lib/0.0.1/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: #718c00; } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: #8959a8; } 17 | 18 | /* a comment */ 19 | .com { 20 | color: #8e908c; } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: #4271ae; } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: #f5871f; } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #4d4d4c; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #4d4d4c; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #4d4d4c; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /docs/glossary.md: -------------------------------------------------------------------------------- 1 | # [backgammon.js](../README.md): [Documentation](glossary.md) :: Glossary 2 | 3 | ## Naming notions 4 | 5 | // TODO: Explain basic terms used in source code like board, point, piece 6 | - Board: 7 | - Point: 8 | - Piece: 9 | - Piece type: 10 | - Bar: 11 | - Home field: 12 | - Outside: 13 | - Direction: 14 | - Position: 15 | - Normalized position: 16 | - Denormalized position: 17 | - Move: 18 | - Action: -------------------------------------------------------------------------------- /docs/images/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/images/architecture.png -------------------------------------------------------------------------------- /docs/images/class-diagrams/model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/images/class-diagrams/model.png -------------------------------------------------------------------------------- /docs/images/class-diagrams/rules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/images/class-diagrams/rules.png -------------------------------------------------------------------------------- /docs/images/progress-gameplay-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/images/progress-gameplay-2.jpg -------------------------------------------------------------------------------- /docs/images/progress-gameplay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/images/progress-gameplay.jpg -------------------------------------------------------------------------------- /docs/images/progress-landing-page.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/images/progress-landing-page.jpg -------------------------------------------------------------------------------- /docs/images/use-cases/developer-goals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/images/use-cases/developer-goals.png -------------------------------------------------------------------------------- /docs/images/use-cases/player-goals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyMicky0317/backgammonjs/0ce9cbe7620b6c59d5d8ae3e3848754f90bddcfe/docs/images/use-cases/player-goals.png -------------------------------------------------------------------------------- /docs/rules.md: -------------------------------------------------------------------------------- 1 | # [backgammon.js](../README.md) :: Creating rules for backgammon.js 2 | 3 | Currently three rules have been implemented: 4 | 5 | - [`RuleBgCasual`](lib/rules/RuleBgCasual.js) 6 | - [`RuleBgGulbara`](lib/rules/RuleBgGulbara.js) 7 | - [`RuleBgTapa`](lib/rules/RuleBgTapa.js) 8 | 9 | These are rules for the three variants of backgammon popular in Bulgaria. If in your country or region you play those variants in a different way, or play some other variants, you are free to create a new rule. 10 | 11 | Want a rule where every second dice is 6:6, well, nothing prevents you from creating one :) 12 | 13 | 1. Use one of the built-in examples as a starting point and create a new file in directory [`lib/rules/`](../lib/rules/). 14 | 15 | The filename should start with prefix `Rule`, followed by `ISO 3166-1 alpha-2` country code (the country where this variant of the game is popular - eg. `Bg` for `Bulgaria`) and the name of the rule. Don't use spaces or punctuation/special characters in the filename. 16 | 17 | The file should contain a class that inherits from built-in `Rule` class and implements all abstract methods. Again, use built-in rules as example. The name of the class should match the name of the file. 18 | 19 | Lets say your ISO country code is CC and you want to use the name `YourRule` for it. In this case both filename and class name should be `RuleCCYourRule`. 20 | 21 | 2. After you have created the new rule, you need to enable the rule in both server and client. 22 | 23 | To enable the new rule in server: 24 | 25 | - Open file `app/server/config.js` 26 | - Add the name of the new rule to the `enabledRules` array: 27 | 28 | var config = { 29 | 'rulePath': '../../lib/rules/', 30 | 'enabledRules': [ 31 | 'RuleBgCasual', 32 | 'RuleBgGulbara', 33 | 'RuleBgTapa', 34 | 'RuleCCYourRule' // <- Added a rule with country 35 | // code `CC` and class name RuleCCYourRule. 36 | ] 37 | }; 38 | 39 | To enable the new rule in client: 40 | 41 | - Open file `app/browser/js/config.js` 42 | - Add the name of the new rule to the `selectableRules` array: 43 | 44 | var config = { 45 | 'containerID': 'backgammon', 46 | 'boardUI': '../app/browser/js/SimpleBoardUI.js', 47 | 'defaultRule': 'RuleBgCasual', 48 | 'selectableRules': [ 49 | 'RuleBgCasual', 50 | 'RuleBgGulbara', 51 | 'RuleBgTapa', 52 | 'RuleCCYourRule' // <- Added a rule with country 53 | // code `CC` and class name RuleCCYourRule. 54 | ] 55 | }; 56 | 57 | - Open file `app/browser/js/main.js` and add a new require after others: 58 | 59 | `require('../../../lib/rules/RuleCCYourRule.js');` 60 | 61 | - Open file and add a new require after others: 62 | 63 | `require('./rules/RuleBgCasual.js');` 64 | 65 | *Note that the relative path is not the same as the previous one.* 66 | 67 | - cd to `app/browser` directory and rebuild `bundle.js` with the following command: 68 | 69 | `npm run build` 70 | 71 | or 72 | 73 | `npm run watch`, if you want changes to be automatically rebuild as you edit the javascript files. 74 | 75 | 3. Start server and test if your rule can be selected at home page. 76 | -------------------------------------------------------------------------------- /lib/README.md: -------------------------------------------------------------------------------- 1 | # backgammon.js-lib 2 | 3 | The `backgammon.js-lib` library, used by both `backgammon.js-client` and `backgammon.js-server`, provides the following functionality: 4 | 5 | - Object oriented model of classes modeling real-world and objects and abstract notions ([model.js](model.js) file); 6 | - Message IDs shared by client and server communication objects ([comm.js](comm.js) file); 7 | - Base `Rule` class describing a variant of the game ([rules/rule.js](rules/rule.js) file); 8 | - Sample rules for three variants of the game: [rules/RuleBgCasual.js](rules/RuleBgCasual.js), [rules/RuleBgGulbara.js](rules/RuleBgGulbara.js) and [rules/RuleBgTapa.js](rules/RuleBgTapa.js). 9 | 10 | ## The whole picture 11 | 12 | To get an idea how the library package fits in the whole picture, look at 13 | [project README](../README.md) and [detailed documentation](../docs/README.md). 14 | 15 | ## Library reference 16 | 17 | Check out [library reference](https://cdn.rawgit.com/quasoft/backgammonjs/master/docs/backgammon.js-lib/0.0.1/index.html) and [class diagrams in documentation](../docs/README.md#model-classes) for more details on available classes. 18 | 19 | To recompile library reference, using [jsdoc](http://usejsdoc.org/), execute the following: 20 | 21 | ``` 22 | cd lib 23 | npm run build:docs 24 | ``` 25 | 26 | ## Other documents: 27 | 28 | - [`Project README`](../README.md) 29 | - [`Detailed documentation`](../docs/README.md) 30 | -------------------------------------------------------------------------------- /lib/comm.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Protocol options 3 | * @type {{Port: number}} 4 | */ 5 | var Protocol = { 6 | BindAddress: '0.0.0.0', 7 | Port: 8080 8 | }; 9 | module.exports.Protocol = Protocol; 10 | 11 | /** 12 | * Message IDs 13 | * @readonly 14 | * @enum {string} 15 | */ 16 | var Message = { 17 | CONNECT: 'connect', 18 | RECONNECT: 'reconnect', 19 | DISCONNECT: 'disconnect', 20 | CREATE_GUEST: 'createGuest', 21 | GET_MATCH_LIST: 'getMatchList', 22 | PLAY_RANDOM: 'playRandom', 23 | CREATE_MATCH: 'createMatch', 24 | JOIN_MATCH: 'joinMatch', 25 | ROLL_DICE: 'rollDice', 26 | MOVE_PIECE: 'movePiece', 27 | CONFIRM_MOVES: 'confirmMoves', 28 | UNDO_MOVES: 'undoMoves', 29 | RESIGN_GAME: 'resignGame', 30 | RESIGN_MATCH: 'resignMatch', 31 | EVENT_PLAYER_JOINED: 'eventPlayerJoined', 32 | EVENT_TURN_START: 'eventTurnStart', 33 | EVENT_DICE_ROLL: 'eventDiceRoll', 34 | EVENT_PIECE_MOVE: 'eventPieceMove', 35 | EVENT_MATCH_START: 'eventMatchStart', 36 | EVENT_MATCH_OVER: 'eventMatchOver', 37 | EVENT_GAME_OVER: 'eventGameOver', 38 | EVENT_GAME_RESTART: 'eventGameRestart', 39 | EVENT_UNDO_MOVES: 'eventUndoMoves', 40 | }; 41 | 42 | module.exports.Message = Message; 43 | -------------------------------------------------------------------------------- /lib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backgammon.js-lib", 3 | "version": "0.0.1", 4 | "author": "quasoft ", 5 | "description": "Backgammon.js Server", 6 | "license": "MIT", 7 | "dependencies": { 8 | "socket.io": "^1.4.5", 9 | "socket.io-client": "^1.4.5" 10 | }, 11 | "devDependencies": { 12 | "jsdoc": "^3.4.0" 13 | }, 14 | "scripts": { 15 | "build:docs": "./node_modules/.bin/jsdoc --destination ../docs -P package.json model.js comm.js client.js rules/rule.js rules/RuleBgCasual.js rules/RuleBgGulbara.js rules/RuleBgTapa.js", 16 | "build": "npm run build:docs" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/rules/RuleBgCasual.js: -------------------------------------------------------------------------------- 1 | var model = require('../model.js'); 2 | var Rule = require('./rule.js'); 3 | 4 | /** 5 | * Most popular variant played in Bulgaria called casual (обикновена). 6 | * @constructor 7 | * @extends Rule 8 | */ 9 | function RuleBgCasual() { 10 | Rule.call(this); 11 | 12 | /** 13 | * Rule name, matching the class name (eg. 'RuleBgCasual') 14 | * @type {string} 15 | */ 16 | this.name = 'RuleBgCasual'; 17 | 18 | /** 19 | * Short title describing rule specifics 20 | * @type {string} 21 | */ 22 | this.title = 'General'; 23 | 24 | /** 25 | * Full description of rule 26 | * @type {string} 27 | */ 28 | this.description = 'Most popular variant of backgammon played in Bulgaria.'; 29 | 30 | /** 31 | * Full name of country where this rule (variant) is played. 32 | * To list multiple countries use a pipe ('|') character as separator. 33 | * @type {string} 34 | */ 35 | this.country = 'Bulgaria'; 36 | 37 | /** 38 | * Two character ISO code of country where this rule (variant) is played. 39 | * To list multiple codes use a pipe ('|') character as separator. 40 | * List codes in same order as countries in the field above. 41 | * @type {string} 42 | */ 43 | this.countryCode = 'bg'; 44 | 45 | /** 46 | * Descendents should list all action types that are allowed in this rule. 47 | * @type {MoveActionType[]} 48 | */ 49 | this.allowedActions = [ 50 | model.MoveActionType.MOVE, 51 | model.MoveActionType.BEAR, 52 | model.MoveActionType.HIT, 53 | model.MoveActionType.RECOVER 54 | ]; 55 | } 56 | 57 | RuleBgCasual.prototype = Object.create(Rule.prototype); 58 | RuleBgCasual.prototype.constructor = RuleBgCasual; 59 | 60 | /** 61 | * Reset state to initial position of pieces according to current rule. 62 | * @memberOf RuleBgCasual 63 | * @param {State} state - Board state 64 | */ 65 | RuleBgCasual.prototype.resetState = function(state) { 66 | /** 67 | * Move pieces to correct initial positions for both players. 68 | * Values in state.points are zero based and denote the . 69 | * the number of pieces on each position. 70 | * Index 0 of array is position 1 and increments to the number of maximum 71 | * points. 72 | * 73 | * Position: |12 13 14 15 16 17| |18 19 20 21 22 23| White 74 | * |5w 3b | |5b 2w| <- 75 | * | | | | 76 | * | | | | 77 | * | | | | 78 | * |5b 3w | |5w 2b| <- 79 | * Position: |11 10 09 08 07 06| |05 04 03 02 01 00| Black 80 | * 81 | */ 82 | 83 | 84 | model.State.clear(state); 85 | 86 | this.place(state, 5, model.PieceType.WHITE, 5); 87 | this.place(state, 3, model.PieceType.WHITE, 7); 88 | this.place(state, 5, model.PieceType.WHITE, 12); 89 | this.place(state, 2, model.PieceType.WHITE, 23); 90 | 91 | this.place(state, 5, model.PieceType.BLACK, 18); 92 | this.place(state, 3, model.PieceType.BLACK, 16); 93 | this.place(state, 5, model.PieceType.BLACK, 11); 94 | this.place(state, 2, model.PieceType.BLACK, 0); 95 | }; 96 | 97 | /** 98 | * Increment position by specified number of steps and return an incremented position 99 | * @memberOf RuleBgCasual 100 | * @param {number} position - Denormalized position 101 | * @param {PieceType} type - Type of piece 102 | * @param {number} steps - Number of steps to increment towards first home position 103 | * @returns {number} - Incremented position (denormalized) 104 | */ 105 | RuleBgCasual.prototype.incPos = function(position, type, steps) { 106 | var newPosition; 107 | if (type === model.PieceType.WHITE) { 108 | newPosition = position - steps; 109 | } 110 | else { 111 | newPosition = position + steps; 112 | } 113 | 114 | return newPosition; 115 | }; 116 | 117 | /** 118 | * Normalize position - Normalized positions start from 0 to 23 for both players, 119 | * where 0 is the first position in the home part of the board, 6 is the last 120 | * position in the home part and 23 is the furthest position - in the opponent's 121 | * home. 122 | * @memberOf RuleBgCasual 123 | * @param {number} position - Denormalized position (0 to 23 for white and 23 to 0 for black) 124 | * @param {PieceType} type - Type of piece (white/black) 125 | * @returns {number} - Normalized position (0 to 23 for both players) 126 | */ 127 | RuleBgCasual.prototype.normPos = function(position, type) { 128 | var normPosition = position; 129 | 130 | if (type === model.PieceType.BLACK) { 131 | normPosition = 23 - position; 132 | } 133 | return normPosition; 134 | }; 135 | 136 | /** 137 | * Get denormalized position - start from 0 to 23 for white player and from 138 | * 23 to 0 for black player. 139 | * @memberOf RuleBgCasual 140 | * @param {number} position - Normalized position (0 to 23 for both players) 141 | * @param {PieceType} type - Type of piece (white/black) 142 | * @return {number} - Denormalized position (0 to 23 for white and 23 to 0 for black) 143 | */ 144 | RuleBgCasual.prototype.denormPos = function(position, type) { 145 | var denormPosition = position; 146 | 147 | if (type === model.PieceType.BLACK) { 148 | denormPosition = 23 - position; 149 | } 150 | return denormPosition; 151 | }; 152 | 153 | /** 154 | * Call this method after a request for moving a piece has been made. 155 | * Determines if the move is allowed and what actions will have to be made as 156 | * a result. Actions can be `move`, `place`, `hit` or `bear`. 157 | * 158 | * If move is allowed or not depends on the current state of the game. For example, 159 | * if the player has pieces on the bar, they will only be allowed to place pieces. 160 | * 161 | * Multiple actions can be returned, if required. Placing (or moving) a piece over 162 | * an opponent's blot will result in two actions: `hit` first, then `place` (or `move`). 163 | * 164 | * The list of actions returned would usually be appllied to game state and then 165 | * sent to client. The client's UI would play the actions (eg. with movement animation) 166 | * in the same order. 167 | * 168 | * @memberOf RuleBgCasual 169 | * @param {State} state - State 170 | * @param {Piece} piece - Piece to move 171 | * @param {PieceType} type - Type of piece 172 | * @param {number} steps - Number of steps to increment towards first home position 173 | * @returns {MoveAction[]} - List of actions if move is allowed, empty list otherwise. 174 | */ 175 | RuleBgCasual.prototype.getMoveActions = function(state, piece, steps) { 176 | var actionList = []; 177 | 178 | // Next, check conditions specific to this game rule and build the list of 179 | // actions that has to be made. 180 | 181 | /** 182 | * Create a new move action and add it to actionList. Used internally. 183 | * 184 | * @alias RuleBgCasual.getMoveActions.addAction 185 | * @memberof RuleBgCasual.getMoveActions 186 | * @method RuleBgCasual.getMoveActions.addAction 187 | * @param {MoveActionType} moveActionType - Type of move action (eg. move, hit, bear) 188 | * @param {Piece} piece - Piece to move 189 | * @param {number} from - Denormalized source position. If action uses only one position parameter, this one is used. 190 | * @param {number} to - Denormalized destination position. 191 | * @returns {MoveAction} 192 | * @see {@link getMoveActions} for more information on purpose of move actions. 193 | */ 194 | function addAction(moveActionType, piece, from, to) { 195 | var action = new model.MoveAction(); 196 | action.type = moveActionType; 197 | action.piece = piece; 198 | action.position = from; 199 | action.from = from; 200 | if (typeof to != "undefined") { 201 | action.to = to; 202 | } 203 | actionList.push(action); 204 | return action; 205 | } 206 | 207 | // TODO: Catch exceptions due to disallowed move requests and pass them as error message to the client. 208 | try { 209 | var position = model.State.getPiecePos(state, piece); 210 | 211 | // TODO: Consider using state machine? Is it worth, can it be useful in other methods too? 212 | if (this.havePiecesOnBar(state, piece.type)) { 213 | /* 214 | If there are pieces on the bar, the player can only place pieces on. 215 | Input data: steps=3 216 | Cases: 217 | - Opponent has no pieces there --> place the checker at position 21 218 | - Opponent has exactly one piece --> hit oponent piece and place at position 21 219 | - Opponent has two or more pieces --> point is blocked, cannot place piece there 220 | ! 221 | +12-13-14-15-16-17------18-19-20-21-22-23-+ 222 | | O | @ | X | 223 | | O | | X | 224 | | | | X | 225 | | | | | 226 | | | | | 227 | | | | | 228 | | | | | 229 | | | | | 230 | | | | | 231 | | | | O | 232 | | | | O O O | 233 | +11-10--9--8--7--6-------5--4--3--2--1--0-+ -1 234 | 235 | */ 236 | 237 | if (model.State.isPieceOnBar(state, piece)) { 238 | // Make sure that the piece that the player wants to move 239 | // is on the bar 240 | 241 | var destination = (piece.type === model.PieceType.WHITE) ? (24 - steps) : (steps - 1); 242 | var destTopPiece = model.State.getTopPiece(state, destination); 243 | var destTopPieceType = (destTopPiece) ? destTopPiece.type : null; 244 | 245 | if ((destTopPieceType === null) || (destTopPieceType === piece.type)) { 246 | // There are no pieces at this point or the top piece is owned by player, 247 | // so directly place piece from bar to opponent's home field 248 | 249 | addAction( 250 | model.MoveActionType.RECOVER, piece, destination 251 | ); 252 | } 253 | else if (model.State.countAtPos(state, destination, destTopPieceType) === 1) { 254 | // The top piece is opponent's and is only one (i.e. the point is not blocked), 255 | // so hit opponent's piece from destination and place ours at this position 256 | 257 | addAction( 258 | model.MoveActionType.HIT, destTopPiece, destination 259 | ); 260 | 261 | addAction( 262 | model.MoveActionType.RECOVER, piece, destination 263 | ); 264 | } 265 | } 266 | } 267 | else if (this.allPiecesAreHome(state, piece.type)) { 268 | /* 269 | If all pieces are in home field, the player can bear pieces 270 | Cases: 271 | - Normalized position >= 0 --> Just move the piece 272 | - Normalized position === -1 --> Bear piece 273 | - Normalized position < -1 --> Bear piece, only if there are no player pieces at higher positions 274 | 275 | +12-13-14-15-16-17------18-19-20-21-22-23-+ 276 | | | | | 277 | | | | | 278 | | | | | 279 | | | | | 280 | | | | | 281 | | | | | 282 | | | | | 283 | | | | | 284 | | | | | 285 | | | | O O | 286 | | | | O O O | 287 | +11-10--9--8--7--6-------5--4--3--2--1--0-+ -1 288 | 289 | */ 290 | var destination = this.incPos(position, piece.type, steps); 291 | var normDestination = this.normPos(destination, piece.type); 292 | 293 | // Move the piece, unless point is blocked by opponent 294 | if (normDestination >= 0) { 295 | 296 | var destTopPiece = model.State.getTopPiece(state, destination); 297 | var destTopPieceType = (destTopPiece) ? destTopPiece.type : null; 298 | 299 | // There are no pieces at this point or the top piece is owned by player, 300 | // so just move piece to that position 301 | if ((destTopPieceType === null) || (destTopPieceType === piece.type)) { 302 | addAction( 303 | model.MoveActionType.MOVE, piece, position, destination 304 | ); 305 | } 306 | // The top piece is opponent's and is only one (i.e. the point is not blocked), 307 | // so hit opponent's piece from destination and move ours at this position 308 | else if (model.State.countAtPos(state, destination, destTopPieceType) === 1) { 309 | addAction( 310 | model.MoveActionType.HIT, destTopPiece, destination 311 | ); 312 | 313 | addAction( 314 | model.MoveActionType.MOVE, piece, position, destination 315 | ); 316 | } 317 | } 318 | // If steps are just enought to reach position -1, bear piece 319 | else if (normDestination === -1) { 320 | addAction( 321 | model.MoveActionType.BEAR, piece, position 322 | ); 323 | } 324 | // If steps move the piece beyond -1 position, the player can bear the piece, 325 | // only if there are no other pieces at higher positions 326 | else { 327 | var normSource = this.normPos(position, piece.type); 328 | if (this.countAtHigherPos(state, normSource + 1, piece.type) <= 0) { 329 | addAction( 330 | model.MoveActionType.BEAR, piece, position 331 | ); 332 | } 333 | } 334 | } 335 | else { 336 | /* 337 | If there are no pieces at bar, and at least one piece outside home, 338 | just move the piece. 339 | Input data: position=13, steps=3 340 | Cases: 341 | - Opponent has no pieces there --> place the checker at position 10 342 | - Opponent has exactly one piece --> hit oponent piece and place at position 10 343 | - Opponent has two or more pieces --> point is blocked, cannot place piece there 344 | ! 345 | +12-13-14-15-16-17------18-19-20-21-22-23-+ 346 | | O | | X | 347 | | O | | X | 348 | | | | X | 349 | | | | | 350 | | | | | 351 | | | | | 352 | | | | | 353 | | | | | 354 | | | | | 355 | | | | O | 356 | | | | O O O | 357 | +11-10--9--8--7--6-------5--4--3--2--1--0-+ -1 358 | ! 359 | */ 360 | 361 | var destination = this.incPos(position, piece.type, steps); 362 | 363 | // Make sure that destination is within board 364 | if ((destination >= 0) && (destination <= 23)) { 365 | var normDest = this.normPos(destination, piece.type); 366 | // TODO: Make sure position is not outside board 367 | 368 | var destTopPiece = model.State.getTopPiece(state, destination); 369 | var destTopPieceType = (destTopPiece) ? destTopPiece.type : null; 370 | 371 | // There are no pieces at this point or the top piece is owned by player 372 | if ((destTopPieceType === null) || (destTopPieceType === piece.type)) { 373 | addAction( 374 | model.MoveActionType.MOVE, piece, position, destination 375 | ); 376 | } 377 | // The top piece is opponent's and is a blot (i.e. the point is not blocked) 378 | else if (model.State.countAtPos(state, destination, destTopPieceType) === 1) { 379 | addAction( 380 | model.MoveActionType.HIT, destTopPiece, destination 381 | ); 382 | 383 | addAction( 384 | model.MoveActionType.MOVE, piece, position, destination 385 | ); 386 | } 387 | } 388 | } 389 | } 390 | catch (e) { 391 | actionList = []; 392 | return actionList; 393 | } 394 | 395 | return actionList; 396 | }; 397 | 398 | module.exports = new RuleBgCasual(); 399 | -------------------------------------------------------------------------------- /lib/rules/RuleBgTapa.js: -------------------------------------------------------------------------------- 1 | var model = require('../model.js'); 2 | var Rule = require('./rule.js'); 3 | 4 | /** 5 | * Bulgarian variant of Tapa (тапа). 6 | * @constructor 7 | * @extends Rule 8 | */ 9 | function RuleBgTapa() { 10 | Rule.call(this); 11 | 12 | /** 13 | * Rule name, matching the class name (eg. 'RuleBgTapa') 14 | * @type {string} 15 | */ 16 | this.name = 'RuleBgTapa'; 17 | 18 | /** 19 | * Short title describing rule specifics 20 | * @type {string} 21 | */ 22 | this.title = 'Tapa'; 23 | 24 | /** 25 | * Full description of rule 26 | * @type {string} 27 | */ 28 | this.description = 'Bulgarian variant of Tapa (тапа).'; 29 | 30 | /** 31 | * Full name of country where this rule (variant) is played. 32 | * To list multiple countries use a pipe ('|') character as separator. 33 | * @type {string} 34 | */ 35 | this.country = 'Bulgaria'; 36 | 37 | /** 38 | * Two character ISO code of country where this rule (variant) is played. 39 | * To list multiple codes use a pipe ('|') character as separator. 40 | * List codes in same order as countries in the field above. 41 | * @type {string} 42 | */ 43 | this.countryCode = 'bg'; 44 | 45 | /** 46 | * Descendents should list all action types that are allowed in this rule. 47 | * @type {MoveActionType[]} 48 | */ 49 | this.allowedActions = [ 50 | model.MoveActionType.MOVE, 51 | model.MoveActionType.BEAR 52 | ]; 53 | } 54 | 55 | RuleBgTapa.prototype = Object.create(Rule.prototype); 56 | RuleBgTapa.prototype.constructor = RuleBgTapa; 57 | 58 | /** 59 | * Reset state to initial position of pieces according to current rule. 60 | * @memberOf RuleBgTapa 61 | * @param {State} state - Board state 62 | */ 63 | RuleBgTapa.prototype.resetState = function(state) { 64 | /** 65 | * Move pieces to correct initial positions for both players. 66 | * Values in state.points are zero based and denote the . 67 | * the number of pieces on each position. 68 | * Index 0 of array is position 1 and increments to the number of maximum 69 | * points. 70 | * 71 | * Position: |12 13 14 15 16 17| |18 19 20 21 22 23| White 72 | * | | | 15w| <- 73 | * | | | | 74 | * | | | | 75 | * | | | | 76 | * | | | 15b| <- 77 | * Position: |11 10 09 08 07 06| |05 04 03 02 01 00| Black 78 | * 79 | */ 80 | 81 | 82 | model.State.clear(state); 83 | 84 | this.place(state, 15, model.PieceType.WHITE, 23); 85 | 86 | this.place(state, 15, model.PieceType.BLACK, 0); 87 | }; 88 | 89 | /** 90 | * Increment position by specified number of steps and return an incremented position 91 | * @memberOf RuleBgTapa 92 | * @param {number} position - Denormalized position 93 | * @param {PieceType} type - Type of piece 94 | * @param {number} steps - Number of steps to increment towards first home position 95 | * @returns {number} - Incremented position (denormalized) 96 | */ 97 | RuleBgTapa.prototype.incPos = function(position, type, steps) { 98 | var newPosition; 99 | if (type === model.PieceType.WHITE) { 100 | newPosition = position - steps; 101 | } 102 | else { 103 | newPosition = position + steps; 104 | } 105 | 106 | return newPosition; 107 | }; 108 | 109 | /** 110 | * Normalize position - Normalized positions start from 0 to 23 for both players, 111 | * where 0 is the first position in the home part of the board, 6 is the last 112 | * position in the home part and 23 is the furthest position - in the opponent's 113 | * home. 114 | * @memberOf RuleBgTapa 115 | * @param {number} position - Denormalized position (0 to 23 for white and 23 to 0 for black) 116 | * @param {PieceType} type - Type of piece (white/black) 117 | * @returns {number} - Normalized position (0 to 23 for both players) 118 | */ 119 | RuleBgTapa.prototype.normPos = function(position, type) { 120 | var normPosition = position; 121 | 122 | if (type === model.PieceType.BLACK) { 123 | normPosition = 23 - position; 124 | } 125 | return normPosition; 126 | }; 127 | 128 | /** 129 | * Get denormalized position - start from 0 to 23 for white player and from 130 | * 23 to 0 for black player. 131 | * @memberOf RuleBgTapa 132 | * @param {number} position - Normalized position (0 to 23 for both players) 133 | * @param {PieceType} type - Type of piece (white/black) 134 | * @return {number} - Denormalized position (0 to 23 for white and 23 to 0 for black) 135 | */ 136 | RuleBgTapa.prototype.denormPos = function(position, type) { 137 | var denormPosition = position; 138 | 139 | if (type === model.PieceType.BLACK) { 140 | denormPosition = 23 - position; 141 | } 142 | return denormPosition; 143 | }; 144 | 145 | /** 146 | * Call this method after a request for moving a piece has been made. 147 | * Determines if the move is allowed and what actions will have to be made as 148 | * a result. Actions can be `move` or `bear`. 149 | * 150 | * Multiple actions can be returned, if required. 151 | * 152 | * The list of actions returned would usually be appllied to game state and then 153 | * sent to client. The client's UI would play the actions (eg. with movement animation) 154 | * in the same order. 155 | * 156 | * @memberOf RuleBgTapa 157 | * @param {State} state - State 158 | * @param {Piece} piece - Piece to move 159 | * @param {PieceType} type - Type of piece 160 | * @param {number} steps - Number of steps to increment towards first home position 161 | * @returns {MoveAction[]} - List of actions if move is allowed, empty list otherwise. 162 | */ 163 | RuleBgTapa.prototype.getMoveActions = function(state, piece, steps) { 164 | var actionList = []; 165 | 166 | // Next, check conditions specific to this game rule and build the list of 167 | // actions that has to be made. 168 | 169 | /** 170 | * Create a new move action and add it to actionList. Used internally. 171 | * 172 | * @alias RuleBgTapa.getMoveActions.addAction 173 | * @memberof RuleBgTapa.getMoveActions 174 | * @method RuleBgTapa.getMoveActions.addAction 175 | * @param {MoveActionType} moveActionType - Type of move action (eg. move, bear) 176 | * @param {Piece} piece - Piece to move 177 | * @param {number} from - Denormalized source position. If action uses only one position parameter, this one is used. 178 | * @param {number} to - Denormalized destination position. 179 | * @returns {MoveAction} 180 | * @see {@link getMoveActions} for more information on purpose of move actions. 181 | */ 182 | function addAction(moveActionType, piece, from, to) { 183 | var action = new model.MoveAction(); 184 | action.type = moveActionType; 185 | action.piece = piece; 186 | action.position = from; 187 | action.from = from; 188 | if (typeof to !== "undefined") { 189 | action.to = to; 190 | } 191 | actionList.push(action); 192 | return action; 193 | } 194 | 195 | // TODO: Catch exceptions due to disallowed move requests and pass them as error message to the client. 196 | try { 197 | var position = model.State.getPiecePos(state, piece); 198 | 199 | // TODO: Consider using state machine? Is it worth, can it be useful in other methods too? 200 | if (this.allPiecesAreHome(state, piece.type)) { 201 | /* 202 | If all pieces are in home field, the player can bear pieces 203 | Cases: 204 | - Normalized position >= 0 --> Just move the piece 205 | - Normalized position === -1 --> Bear piece 206 | - Normalized position < -1 --> Bear piece, only if there are no player pieces at higher positions 207 | 208 | +12-13-14-15-16-17------18-19-20-21-22-23-+ 209 | | | | | 210 | | | | | 211 | | | | | 212 | | | | | 213 | | | | | 214 | | | | | 215 | | | | | 216 | | | | | 217 | | | | | 218 | | | | O O | 219 | | | | O O O | 220 | +11-10--9--8--7--6-------5--4--3--2--1--0-+ -1 221 | 222 | */ 223 | var destination = this.incPos(position, piece.type, steps); 224 | var normDestination = this.normPos(destination, piece.type); 225 | 226 | // Move the piece, unless point is blocked by opponent 227 | if (normDestination >= 0) { 228 | 229 | var destTopPiece = model.State.getTopPiece(state, destination); 230 | var destTopPieceType = (destTopPiece) ? destTopPiece.type : null; 231 | 232 | // There are no pieces at this point or the top piece is owned by player, 233 | // so just move piece to that position 234 | if ((destTopPieceType === null) || (destTopPieceType === piece.type)) { 235 | addAction( 236 | model.MoveActionType.MOVE, piece, position, destination 237 | ); 238 | } 239 | // The top piece is opponent's and is only one (i.e. the point is not blocked), 240 | // so move ours on top of opponent's piece 241 | else if (model.State.countAllAtPos(state, destination) === 1) { 242 | addAction( 243 | model.MoveActionType.MOVE, piece, position, destination 244 | ); 245 | } 246 | } 247 | // If steps are just enought to reach position -1, bear piece 248 | else if (normDestination === -1) { 249 | addAction( 250 | model.MoveActionType.BEAR, piece, position 251 | ); 252 | } 253 | // If steps move the piece beyond -1 position, the player can bear the piece, 254 | // only if there are no other pieces at higher positions 255 | else { 256 | var normSource = this.normPos(position, piece.type); 257 | if (this.countAtHigherPos(state, normSource + 1, piece.type) <= 0) { 258 | addAction( 259 | model.MoveActionType.BEAR, piece, position 260 | ); 261 | } 262 | } 263 | } 264 | else { 265 | /* 266 | If there is at least one piece outside home, just move the piece. 267 | Input data: position=13, steps=3 268 | Cases: 269 | - Opponent has no pieces there --> move the checker at position 10 270 | - Opponent has exactly one piece --> move out piece over opponent's one 271 | - Opponent has two or more pieces --> point is blocked, cannot move piece there 272 | ! 273 | +12-13-14-15-16-17------18-19-20-21-22-23-+ 274 | | O | | X | 275 | | O | | X | 276 | | | | X | 277 | | | | | 278 | | | | | 279 | | | | | 280 | | | | | 281 | | | | | 282 | | | | | 283 | | | | O | 284 | | | | O O O | 285 | +11-10--9--8--7--6-------5--4--3--2--1--0-+ -1 286 | ! 287 | */ 288 | 289 | var destination = this.incPos(position, piece.type, steps); 290 | 291 | // Make sure that destination is within board 292 | if ((destination >= 0) && (destination <= 23)) { 293 | var normDest = this.normPos(destination, piece.type); 294 | // TODO: Make sure position is not outside board 295 | 296 | var destTopPiece = model.State.getTopPiece(state, destination); 297 | var destTopPieceType = (destTopPiece) ? destTopPiece.type : null; 298 | 299 | // There are no pieces at this point or the top piece is owned by player 300 | if ((destTopPieceType === null) || (destTopPieceType === piece.type)) { 301 | addAction( 302 | model.MoveActionType.MOVE, piece, position, destination 303 | ); 304 | } 305 | // The top piece is opponent's and is a blot (i.e. the point is not blocked) 306 | else if (model.State.countAllAtPos(state, destination) === 1) { 307 | addAction( 308 | model.MoveActionType.MOVE, piece, position, destination 309 | ); 310 | } 311 | } 312 | } 313 | } 314 | catch (e) { 315 | actionList = []; 316 | return actionList; 317 | } 318 | 319 | return actionList; 320 | }; 321 | 322 | module.exports = new RuleBgTapa(); 323 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backgammon.js", 3 | "version": "0.0.1", 4 | "author": "quasoft ", 5 | "description": "Backgammon.js Game", 6 | "license": "MIT", 7 | "scripts": { 8 | "build:browser": "cd app/browser && npm run build && cd ..", 9 | "build": "npm run build:browser", 10 | "start:server": "node ./app/server/server.js", 11 | "start": "npm run build:browser && npm run start:server", 12 | "install:browser": "cd app/browser && npm install -dd && cd ..", 13 | "install:server": "cd app/server && npm install -dd && cd ..", 14 | "installall": "npm run install:browser && npm run install:server", 15 | "postinstall": "npm run installall && npm run build", 16 | "lint": "jshint ." 17 | }, 18 | "devDependencies": { 19 | "jshint": "^2.9.4" 20 | } 21 | } 22 | --------------------------------------------------------------------------------