diff --git a/README.md b/README.md index 576ebdc..ac3d87b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# socketserver -A test server for web sockets project +# Real Chess +Real-time chess game diff --git a/app.js b/app.js index 2ac7ede..36cbd2d 100644 --- a/app.js +++ b/app.js @@ -1,10 +1,13 @@ -var app = require('express')(); +var express = require('express'); +var app = express(); +app.use(express.static('public')); var http = require('http').Server(app); var io = require('socket.io')(http); + var port = process.env.PORT || 3000; app.get('/', function(req, res) { - res.sendFile(__dirname + '/index.html'); + res.sendFile(__dirname + '/public/index.html'); }); io.on('connection', function(socket) { diff --git a/index.html b/index.html deleted file mode 100644 index 9f60c14..0000000 --- a/index.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - Socket.IO chat - - - - - - - - - - - \ No newline at end of file diff --git a/package.json b/package.json index 6e21b3d..283d823 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "socketserver", + "name": "RealChess", "version": "0.0.1", - "description": "Socket.io backend for minihacks", + "description": "Real-time chess game ", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/public/default.js b/public/default.js new file mode 100644 index 0000000..6e17093 --- /dev/null +++ b/public/default.js @@ -0,0 +1,57 @@ +var game, board; + +window.init = function () { + game = new Chess(); + board = new ChessBoard('board', cfg); + + var socket = io(); + $('#go').click(function () { + socket.emit('button', $('#name').val()); + //socket.emit('button', "dude"); + }); + + socket.on('button', function (msg) { + $('#messages').append($('
  • ').text(msg)); + }); +}; + + + +// do not pick up pieces if the game is over +// only pick up pieces for the side to move +var onDragStart = function(source, piece, position, orientation) { + if (game.game_over() === true || + (game.turn() === 'w' && piece.search(/^b/) !== -1) || + (game.turn() === 'b' && piece.search(/^w/) !== -1)) { + return false; + } +}; + +var onDrop = function(source, target) { + // see if the move is legal + var move = game.move({ + from: source, + to: target, + promotion: 'q' // NOTE: always promote to a queen for example simplicity + }); + + // illegal move + if (move === null) return 'snapback'; + +}; + +// update the board position after the piece snap +// for castling, en passant, pawn promotion +var onSnapEnd = function() { + board.position(game.fen()); +}; + +var cfg = { + draggable: true, + position: 'start', + onDragStart: onDragStart, + onDrop: onDrop, + onSnapEnd: onSnapEnd +}; + + diff --git a/public/img/chesspieces/wikipedia/bB.png b/public/img/chesspieces/wikipedia/bB.png new file mode 100644 index 0000000..be3007d Binary files /dev/null and b/public/img/chesspieces/wikipedia/bB.png differ diff --git a/public/img/chesspieces/wikipedia/bK.png b/public/img/chesspieces/wikipedia/bK.png new file mode 100644 index 0000000..de9880c Binary files /dev/null and b/public/img/chesspieces/wikipedia/bK.png differ diff --git a/public/img/chesspieces/wikipedia/bN.png b/public/img/chesspieces/wikipedia/bN.png new file mode 100644 index 0000000..e31a6d0 Binary files /dev/null and b/public/img/chesspieces/wikipedia/bN.png differ diff --git a/public/img/chesspieces/wikipedia/bP.png b/public/img/chesspieces/wikipedia/bP.png new file mode 100644 index 0000000..afa0c9d Binary files /dev/null and b/public/img/chesspieces/wikipedia/bP.png differ diff --git a/public/img/chesspieces/wikipedia/bQ.png b/public/img/chesspieces/wikipedia/bQ.png new file mode 100644 index 0000000..4649bb8 Binary files /dev/null and b/public/img/chesspieces/wikipedia/bQ.png differ diff --git a/public/img/chesspieces/wikipedia/bR.png b/public/img/chesspieces/wikipedia/bR.png new file mode 100644 index 0000000..c7eb127 Binary files /dev/null and b/public/img/chesspieces/wikipedia/bR.png differ diff --git a/public/img/chesspieces/wikipedia/wB.png b/public/img/chesspieces/wikipedia/wB.png new file mode 100644 index 0000000..70e0e14 Binary files /dev/null and b/public/img/chesspieces/wikipedia/wB.png differ diff --git a/public/img/chesspieces/wikipedia/wK.png b/public/img/chesspieces/wikipedia/wK.png new file mode 100644 index 0000000..bbf5664 Binary files /dev/null and b/public/img/chesspieces/wikipedia/wK.png differ diff --git a/public/img/chesspieces/wikipedia/wN.png b/public/img/chesspieces/wikipedia/wN.png new file mode 100644 index 0000000..237250c Binary files /dev/null and b/public/img/chesspieces/wikipedia/wN.png differ diff --git a/public/img/chesspieces/wikipedia/wP.png b/public/img/chesspieces/wikipedia/wP.png new file mode 100644 index 0000000..5f9315c Binary files /dev/null and b/public/img/chesspieces/wikipedia/wP.png differ diff --git a/public/img/chesspieces/wikipedia/wQ.png b/public/img/chesspieces/wikipedia/wQ.png new file mode 100644 index 0000000..c3dfc15 Binary files /dev/null and b/public/img/chesspieces/wikipedia/wQ.png differ diff --git a/public/img/chesspieces/wikipedia/wR.png b/public/img/chesspieces/wikipedia/wR.png new file mode 100644 index 0000000..cc69760 Binary files /dev/null and b/public/img/chesspieces/wikipedia/wR.png differ diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..d1c526e --- /dev/null +++ b/public/index.html @@ -0,0 +1,20 @@ + + + + Real Chess + + + +
    + + + + + + + + + + \ No newline at end of file diff --git a/public/lib/chess.min.js b/public/lib/chess.min.js new file mode 100644 index 0000000..e2129eb --- /dev/null +++ b/public/lib/chess.min.js @@ -0,0 +1,5 @@ +/*! Copyright (c) 2014, Jeff Hlywa (jhlywa@gmail.com) + * Released under the BSD license + * https://github.com/jhlywa/chess.js/blob/master/LICENSE + */ +"use strict";var Chess=function(r){function e(){fe=new Array(128),ue={w:Q,b:Q},ae=K,le={w:0,b:0},se=Q,pe=0,ce=1,ve=[],ge={},u(i())}function n(){t(W)}function t(r){var n=r.split(/\s+/),t=n[0],f=0;if(!o(r).valid)return!1;e();for(var a=0;as?K:q;l({type:s.toLowerCase(),color:p},w(f)),f++}}return ae=n[1],n[2].indexOf("K")>-1&&(le.w|=Y.KSIDE_CASTLE),n[2].indexOf("Q")>-1&&(le.w|=Y.QSIDE_CASTLE),n[2].indexOf("k")>-1&&(le.b|=Y.KSIDE_CASTLE),n[2].indexOf("q")>-1&&(le.b|=Y.QSIDE_CASTLE),se="-"===n[3]?Q:oe[n[3]],pe=parseInt(n[4],10),ce=parseInt(n[5],10),u(i()),!0}function o(r){var e={0:"No errors.",1:"FEN string must contain six space-delimited fields.",2:"6th field (move number) must be a positive integer.",3:"5th field (half move counter) must be a non-negative integer.",4:"4th field (en-passant square) is invalid.",5:"3rd field (castling availability) is invalid.",6:"2nd field (side to move) is invalid.",7:"1st field (piece positions) does not contain 8 '/'-delimited rows.",8:"1st field (piece positions) is invalid [consecutive numbers].",9:"1st field (piece positions) is invalid [invalid piece].",10:"1st field (piece positions) is invalid [row too large]."},n=r.split(/\s+/);if(6!==n.length)return{valid:!1,error_number:1,error:e[1]};if(isNaN(n[5])||parseInt(n[5],10)<=0)return{valid:!1,error_number:2,error:e[2]};if(isNaN(n[4])||parseInt(n[4],10)<0)return{valid:!1,error_number:3,error:e[3]};if(!/^(-|[abcdefgh][36])$/.test(n[3]))return{valid:!1,error_number:4,error:e[4]};if(!/^(KQ?k?q?|Qk?q?|kq?|q|-)$/.test(n[2]))return{valid:!1,error_number:5,error:e[5]};if(!/^(w|b)$/.test(n[1]))return{valid:!1,error_number:6,error:e[6]};var t=n[0].split("/");if(8!==t.length)return{valid:!1,error_number:7,error:e[7]};for(var o=0;o0&&(e+=r,r=0);var t=fe[n].color,o=fe[n].type;e+=t===K?o.toUpperCase():o.toLowerCase()}n+1&136&&(r>0&&(e+=r),n!==oe.h1&&(e+="/"),r=0,n+=8)}var i="";le[K]&Y.KSIDE_CASTLE&&(i+="K"),le[K]&Y.QSIDE_CASTLE&&(i+="Q"),le[q]&Y.KSIDE_CASTLE&&(i+="k"),le[q]&Y.QSIDE_CASTLE&&(i+="q"),i=i||"-";var f=se===Q?"-":w(se);return[e,ae,i,f,pe,ce].join(" ")}function f(r){for(var e=0;e0||(r!==W?(ge.SetUp="1",ge.FEN=r):(delete ge.SetUp,delete ge.FEN))}function a(r){var e=fe[oe[r]];return e?{type:e.type,color:e.color}:null}function l(r,e){if(!("type"in r&&"color"in r))return!1;if(-1===G.indexOf(r.type.toLowerCase()))return!1;if(!(e in oe))return!1;var n=oe[e];return r.type==M&&ue[r.color]!=Q&&ue[r.color]!=n?!1:(fe[n]={type:r.type,color:r.color},r.type===M&&(ue[r.color]=n),u(i()),!0)}function s(r){var e=a(r);return fe[oe[r]]=null,e&&e.type===M&&(ue[e.color]=Q),u(i()),e}function p(r,e,n,t,o){var i={color:ae,from:e,to:n,flags:t,piece:r[e].type};return o&&(i.flags|=Y.PROMOTION,i.promotion=o),r[n]?i.captured=r[n].type:t&Y.EP_CAPTURE&&(i.captured=U),i}function c(r){function e(r,e,n,t,o){if(r[n].type!==U||I(t)!==te&&I(t)!==re)e.push(p(r,n,t,o));else for(var i=[B,$,j,x],f=0,u=i.length;u>f;f++)e.push(p(r,n,t,o,i[f]))}var n=[],t=ae,o=L(t),i={b:ne,w:ee},f=oe.a8,u=oe.h1,a=!1,l="undefined"!=typeof r&&"legal"in r?r.legal:!0;if("undefined"!=typeof r&&"square"in r){if(!(r.square in oe))return[];f=u=oe[r.square],a=!0}for(var s=f;u>=s;s++)if(136&s)s+=7;else{var c=fe[s];if(null!=c&&c.color===t)if(c.type===U){var v=s+H[t][0];if(null==fe[v]){e(fe,n,s,v,Y.NORMAL);var v=s+H[t][1];i[t]===I(s)&&null==fe[v]&&e(fe,n,s,v,Y.BIG_PAWN)}for(d=2;4>d;d++){var v=s+H[t][d];136&v||(null!=fe[v]&&fe[v].color===o?e(fe,n,s,v,Y.CAPTURE):v===se&&e(fe,n,s,se,Y.EP_CAPTURE))}}else for(var d=0,E=Z[c.type].length;E>d;d++)for(var b=Z[c.type][d],v=s;;){if(v+=b,136&v)break;if(null!=fe[v]){if(fe[v].color===t)break;e(fe,n,s,v,Y.CAPTURE);break}if(e(fe,n,s,v,Y.NORMAL),"n"===c.type||"k"===c.type)break}}if(!a||u===ue[t]){if(le[t]&Y.KSIDE_CASTLE){var _=ue[t],A=_+2;null!=fe[_+1]||null!=fe[A]||g(o,ue[t])||g(o,_+1)||g(o,A)||e(fe,n,ue[t],A,Y.KSIDE_CASTLE)}if(le[t]&Y.QSIDE_CASTLE){var _=ue[t],A=_-2;null!=fe[_-1]||null!=fe[_-2]||null!=fe[_-3]||g(o,ue[t])||g(o,_-1)||g(o,A)||e(fe,n,ue[t],A,Y.QSIDE_CASTLE)}}if(!l)return n;for(var S=[],s=0,E=n.length;E>s;s++)y(n[s]),h(t)||S.push(n[s]),m();return S}function v(r){var e="";if(r.flags&Y.KSIDE_CASTLE)e="O-O";else if(r.flags&Y.QSIDE_CASTLE)e="O-O-O";else{var n=C(r);r.piece!==U&&(e+=r.piece.toUpperCase()+n),r.flags&(Y.CAPTURE|Y.EP_CAPTURE)&&(r.piece===U&&(e+=w(r.from)[0]),e+="x"),e+=w(r.to),r.flags&Y.PROMOTION&&(e+="="+r.promotion.toUpperCase())}return y(r),d()&&(e+=E()?"#":"+"),m(),e}function g(r,e){for(var n=oe.a8;n<=oe.h1;n++)if(136&n)n+=7;else if(null!=fe[n]&&fe[n].color===r){var t=fe[n],o=n-e,i=o+119;if(z[i]&1<0){if(t.color===K)return!0}else if(t.color===q)return!0;continue}if("n"===t.type||"k"===t.type)return!0;for(var f=J[i],u=n+f,a=!1;u!==e;){if(null!=fe[u]){a=!0;break}u+=f}if(!a)return!0}}return!1}function h(r){return g(L(r),ue[r])}function d(){return h(ae)}function E(){return d()&&0===c().length}function b(){return!d()&&0===c().length}function _(){for(var r={},e=[],n=0,t=0,o=oe.a8;o<=oe.h1;o++)if(t=(t+1)%2,136&o)o+=7;else{var i=fe[o];i&&(r[i.type]=i.type in r?r[i.type]+1:1,i.type===j&&e.push(t),n++)}if(2===n)return!0;if(3===n&&(1===r[j]||1===r[x]))return!0;if(n===r[j]+2){for(var f=0,u=e.length,o=0;u>o;o++)f+=e[o];if(0===f||f===u)return!0}return!1}function A(){for(var r=[],e={},n=!1;;){var t=m();if(!t)break;r.push(t)}for(;;){var o=i().split(" ").slice(0,4).join(" ");if(e[o]=o in e?e[o]+1:1,e[o]>=3&&(n=!0),!r.length)break;y(r.pop())}return n}function S(r){ve.push({move:r,kings:{b:ue.b,w:ue.w},turn:ae,castling:{b:le.b,w:le.w},ep_square:se,half_moves:pe,move_number:ce})}function y(r){var e=ae,n=L(e);if(S(r),fe[r.to]=fe[r.from],fe[r.from]=null,r.flags&Y.EP_CAPTURE&&(ae===q?fe[r.to-16]=null:fe[r.to+16]=null),r.flags&Y.PROMOTION&&(fe[r.to]={type:r.promotion,color:e}),fe[r.to].type===M){if(ue[fe[r.to].color]=r.to,r.flags&Y.KSIDE_CASTLE){var t=r.to-1,o=r.to+1;fe[t]=fe[o],fe[o]=null}else if(r.flags&Y.QSIDE_CASTLE){var t=r.to+1,o=r.to-2;fe[t]=fe[o],fe[o]=null}le[e]=""}if(le[e])for(var i=0,f=ie[e].length;f>i;i++)if(r.from===ie[e][i].square&&le[e]&ie[e][i].flag){le[e]^=ie[e][i].flag;break}if(le[n])for(var i=0,f=ie[n].length;f>i;i++)if(r.to===ie[n][i].square&&le[n]&ie[n][i].flag){le[n]^=ie[n][i].flag;break}se=r.flags&Y.BIG_PAWN?"b"===ae?r.to-16:r.to+16:Q,r.piece===U?pe=0:r.flags&(Y.CAPTURE|Y.EP_CAPTURE)?pe=0:pe++,ae===q&&ce++,ae=L(ae)}function m(){var r=ve.pop();if(null==r)return null;var e=r.move;ue=r.kings,ae=r.turn,le=r.castling,se=r.ep_square,pe=r.half_moves,ce=r.move_number;var n=ae,t=L(ae);if(fe[e.from]=fe[e.to],fe[e.from].type=e.piece,fe[e.to]=null,e.flags&Y.CAPTURE)fe[e.to]={type:e.captured,color:t};else if(e.flags&Y.EP_CAPTURE){var o;o=n===q?e.to-16:e.to+16,fe[o]={type:U,color:t}}if(e.flags&(Y.KSIDE_CASTLE|Y.QSIDE_CASTLE)){var i,f;e.flags&Y.KSIDE_CASTLE?(i=e.to+1,f=e.to-1):e.flags&Y.QSIDE_CASTLE&&(i=e.to-2,f=e.to+1),fe[i]=fe[f],fe[f]=null}return e}function C(r){for(var e=c(),n=r.from,t=r.to,o=r.piece,i=0,f=0,u=0,a=0,l=e.length;l>a;a++){var s=e[a].from,p=e[a].to,v=e[a].piece;o===v&&n!==s&&t===p&&(i++,I(n)===I(s)&&f++,P(n)===P(s)&&u++)}return i>0?f>0&&u>0?w(n):w(n).charAt(u>0?1:0):""}function T(){for(var r=" +------------------------+\n",e=oe.a8;e<=oe.h1;e++){if(0===P(e)&&(r+=" "+"87654321"[I(e)]+" |"),null==fe[e])r+=" . ";else{var n=fe[e].type,t=fe[e].color,o=t===K?n.toUpperCase():n.toLowerCase();r+=" "+o+" "}e+1&136&&(r+="|\n",e+=8)}return r+=" +------------------------+\n",r+=" a b c d e f g h\n"}function I(r){return r>>4}function P(r){return 15&r}function w(r){var e=P(r),n=I(r);return"abcdefgh".substring(e,e+1)+"87654321".substring(n,n+1)}function L(r){return r===K?q:K}function R(r){return-1!=="0123456789".indexOf(r)}function O(r){var e=k(r);e.san=v(e),e.to=w(e.to),e.from=w(e.from);var n="";for(var t in Y)Y[t]&e.flags&&(n+=X[t]);return e.flags=n,e}function k(r){var e=r instanceof Array?[]:{};for(var n in r)e[n]="object"==typeof n?k(r[n]):r[n];return e}function N(r){return r.replace(/^\s+|\s+$/g,"")}function D(r){for(var e=c({legal:!1}),n=0,t=ae,o=0,i=e.length;i>o;o++){if(y(e[o]),!h(t))if(r-1>0){var f=D(r-1);n+=f}else n++;m()}return n}var q="b",K="w",Q=-1,U="p",x="n",j="b",$="r",B="q",M="k",G="pnbrqkPNBRQK",W="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",F=["1-0","0-1","1/2-1/2","*"],H={b:[16,32,17,15],w:[-16,-32,-17,-15]},Z={n:[-18,-33,-31,-14,18,33,31,14],b:[-17,-15,17,15],r:[-16,1,16,-1],q:[-17,-16,-15,1,17,16,15,-1],k:[-17,-16,-15,1,17,16,15,-1]},z=[20,0,0,0,0,0,0,24,0,0,0,0,0,0,20,0,0,20,0,0,0,0,0,24,0,0,0,0,0,20,0,0,0,0,20,0,0,0,0,24,0,0,0,0,20,0,0,0,0,0,0,20,0,0,0,24,0,0,0,20,0,0,0,0,0,0,0,0,20,0,0,24,0,0,20,0,0,0,0,0,0,0,0,0,0,20,2,24,2,20,0,0,0,0,0,0,0,0,0,0,0,2,53,56,53,2,0,0,0,0,0,0,24,24,24,24,24,24,56,0,56,24,24,24,24,24,24,0,0,0,0,0,0,2,53,56,53,2,0,0,0,0,0,0,0,0,0,0,0,20,2,24,2,20,0,0,0,0,0,0,0,0,0,0,20,0,0,24,0,0,20,0,0,0,0,0,0,0,0,20,0,0,0,24,0,0,0,20,0,0,0,0,0,0,20,0,0,0,0,24,0,0,0,0,20,0,0,0,0,20,0,0,0,0,0,24,0,0,0,0,0,20,0,0,20,0,0,0,0,0,0,24,0,0,0,0,0,0,20],J=[17,0,0,0,0,0,0,16,0,0,0,0,0,0,15,0,0,17,0,0,0,0,0,16,0,0,0,0,0,15,0,0,0,0,17,0,0,0,0,16,0,0,0,0,15,0,0,0,0,0,0,17,0,0,0,16,0,0,0,15,0,0,0,0,0,0,0,0,17,0,0,16,0,0,15,0,0,0,0,0,0,0,0,0,0,17,0,16,0,15,0,0,0,0,0,0,0,0,0,0,0,0,17,16,15,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,-15,-16,-17,0,0,0,0,0,0,0,0,0,0,0,0,-15,0,-16,0,-17,0,0,0,0,0,0,0,0,0,0,-15,0,0,-16,0,0,-17,0,0,0,0,0,0,0,0,-15,0,0,0,-16,0,0,0,-17,0,0,0,0,0,0,-15,0,0,0,0,-16,0,0,0,0,-17,0,0,0,0,-15,0,0,0,0,0,-16,0,0,0,0,0,-17,0,0,-15,0,0,0,0,0,0,-16,0,0,0,0,0,0,-17],V={p:0,n:1,b:2,r:3,q:4,k:5},X={NORMAL:"n",CAPTURE:"c",BIG_PAWN:"b",EP_CAPTURE:"e",PROMOTION:"p",KSIDE_CASTLE:"k",QSIDE_CASTLE:"q"},Y={NORMAL:1,CAPTURE:2,BIG_PAWN:4,EP_CAPTURE:8,PROMOTION:16,KSIDE_CASTLE:32,QSIDE_CASTLE:64},re=7,ee=6,ne=1,te=0,oe={a8:0,b8:1,c8:2,d8:3,e8:4,f8:5,g8:6,h8:7,a7:16,b7:17,c7:18,d7:19,e7:20,f7:21,g7:22,h7:23,a6:32,b6:33,c6:34,d6:35,e6:36,f6:37,g6:38,h6:39,a5:48,b5:49,c5:50,d5:51,e5:52,f5:53,g5:54,h5:55,a4:64,b4:65,c4:66,d4:67,e4:68,f4:69,g4:70,h4:71,a3:80,b3:81,c3:82,d3:83,e3:84,f3:85,g3:86,h3:87,a2:96,b2:97,c2:98,d2:99,e2:100,f2:101,g2:102,h2:103,a1:112,b1:113,c1:114,d1:115,e1:116,f1:117,g1:118,h1:119},ie={w:[{square:oe.a1,flag:Y.QSIDE_CASTLE},{square:oe.h1,flag:Y.KSIDE_CASTLE}],b:[{square:oe.a8,flag:Y.QSIDE_CASTLE},{square:oe.h8,flag:Y.KSIDE_CASTLE}]},fe=new Array(128),ue={w:Q,b:Q},ae=K,le={w:0,b:0},se=Q,pe=0,ce=1,ve=[],ge={};return t("undefined"==typeof r?W:r),{WHITE:K,BLACK:q,PAWN:U,KNIGHT:x,BISHOP:j,ROOK:$,QUEEN:B,KING:M,SQUARES:function(){for(var r=[],e=oe.a8;e<=oe.h1;e++)136&e?e+=7:r.push(w(e));return r}(),FLAGS:X,load:function(r){return t(r)},reset:function(){return n()},moves:function(r){for(var e=c(r),n=[],t=0,o=e.length;o>t;t++)n.push("undefined"!=typeof r&&"verbose"in r&&r.verbose?O(e[t]):v(e[t]));return n},in_check:function(){return d()},in_checkmate:function(){return E()},in_stalemate:function(){return b()},in_draw:function(){return pe>=100||b()||_()||A()},insufficient_material:function(){return _()},in_threefold_repetition:function(){return A()},game_over:function(){return pe>=100||E()||b()||_()||A()},validate_fen:function(r){return o(r)},fen:function(){return i()},pgn:function(r){var e="object"==typeof r&&"string"==typeof r.newline_char?r.newline_char:"\n",n="object"==typeof r&&"number"==typeof r.max_width?r.max_width:0,t=[],o=!1;for(var i in ge)t.push("["+i+' "'+ge[i]+'"]'+e),o=!0;o&&ve.length&&t.push(e);for(var f=[];ve.length>0;)f.push(m());for(var u=[],a="",l=1;f.length>0;){var s=f.pop();1===l&&"b"===s.color?(a="1. ...",l++):"w"===s.color&&(a.length&&u.push(a),a=l+".",l++),a=a+" "+v(s),y(s)}if(a.length&&u.push(a),"undefined"!=typeof ge.Result&&u.push(ge.Result),0===n)return t.join("")+u.join(" ");for(var p=0,i=0;in&&0!==i?(" "===t[t.length-1]&&t.pop(),t.push(e),p=0):0!==i&&(t.push(" "),p++),t.push(u[i]),p+=u[i].length;return t.join("")},load_pgn:function(r,e){function t(r){return r.replace(/\\/g,"\\")}function o(r){for(var e=r.replace(/[+#?!=]/,""),n=c(),t=0,o=n.length;o>t;t++)if(e==v(n[t]).replace(/[+#?!=]/,""))return n[t];return null}function i(r){return o(N(r))}function u(r){var e=!1;for(var n in r)e=!0;return e}function a(r,e){for(var n="object"==typeof e&&"string"==typeof e.newline_char?e.newline_char:"\r?\n",o={},i=r.split(new RegExp(t(n))),f="",u="",a=0;a0&&(o[f]=u);return o}var l="object"==typeof e&&"string"==typeof e.newline_char?e.newline_char:"\r?\n",s=new RegExp("^(\\[(.|"+t(l)+")*\\])("+t(l)+")*1.("+t(l)+"|.)*$","g"),p=r.replace(s,"$1");"["!==p[0]&&(p=""),n();var g=a(p,e);for(var h in g)f([h,g[h]]);var d=r.replace(p,"").replace(new RegExp(t(l),"g")," ");d=d.replace(/(\{[^}]+\})+?/g,""),d=d.replace(/\d+\./g,"");var E=N(d).split(new RegExp(/\s+/));E=E.join(",").replace(/,,+/g,",").split(",");for(var b="",_=0;_-1)u(ge)&&"undefined"==typeof ge.Result&&f(["Result",b]);else{if(b=i(b),null==b)return!1;y(b)}return!0},header:function(){return f(arguments)},ascii:function(){return T()},turn:function(){return ae},move:function(r){var e=null,n=c();if("string"==typeof r){for(var t=r.replace(/[+#?!=]/,""),o=0,i=n.length;i>o;o++)if(t===v(n[o]).replace(/[+#?!=]/,"")){e=n[o];break}}else if("object"==typeof r)for(var o=0,i=n.length;i>o;o++)if(!(r.from!==w(n[o].from)||r.to!==w(n[o].to)||"promotion"in n[o]&&r.promotion!==n[o].promotion)){e=n[o];break}if(!e)return null;var f=O(e);return y(e),f},undo:function(){var r=m();return r?O(r):null},clear:function(){return e()},put:function(r,e){return l(r,e)},get:function(r){return a(r)},remove:function(r){return s(r)},perft:function(r){return D(r)},square_color:function(r){if(r in oe){var e=oe[r];return(I(e)+P(e))%2===0?"light":"dark"}return null},history:function(r){for(var e=[],n=[],t=("undefined"!=typeof r&&"verbose"in r&&r.verbose);ve.length>0;)e.push(m());for(;e.length>0;){var o=e.pop();n.push(t?O(o):v(o)),y(o)}return n}}};"undefined"!=typeof exports&&(exports.Chess=Chess),"undefined"!=typeof define&&define(function(){return Chess}); \ No newline at end of file diff --git a/public/lib/chessboard-0.3.0.min.css b/public/lib/chessboard-0.3.0.min.css new file mode 100644 index 0000000..52781a9 --- /dev/null +++ b/public/lib/chessboard-0.3.0.min.css @@ -0,0 +1,2 @@ +/*! chessboard.js v0.3.0 | (c) 2013 Chris Oakman | MIT License chessboardjs.com/license */ +.clearfix-7da63{clear:both}.board-b72b1{border:2px solid #404040;-moz-box-sizing:content-box;box-sizing:content-box}.square-55d63{float:left;position:relative;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.white-1e1d7{background-color:#f0d9b5;color:#b58863}.black-3c85d{background-color:#b58863;color:#f0d9b5}.highlight1-32417,.highlight2-9c5d2{-webkit-box-shadow:inset 0 0 3px 3px yellow;-moz-box-shadow:inset 0 0 3px 3px yellow;box-shadow:inset 0 0 3px 3px yellow}.notation-322f9{cursor:default;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;position:absolute}.alpha-d2270{bottom:1px;right:3px}.numeric-fc462{top:2px;left:2px} \ No newline at end of file diff --git a/public/lib/chessboard-0.3.0.min.js b/public/lib/chessboard-0.3.0.min.js new file mode 100644 index 0000000..81a29a1 --- /dev/null +++ b/public/lib/chessboard-0.3.0.min.js @@ -0,0 +1,31 @@ +/*! chessboard.js v0.3.0 | (c) 2013 Chris Oakman | MIT License chessboardjs.com/license */ +(function(){function l(f){return"string"!==typeof f?!1:-1!==f.search(/^[a-h][1-8]$/)}function Q(f){if("string"!==typeof f)return!1;f=f.replace(/ .+$/,"");f=f.split("/");if(8!==f.length)return!1;for(var b=0;8>b;b++)if(""===f[b]||8m;m++){for(var l=f[m].split(""),r=0,w=0;wm;m++){for(var l=0;8>l;l++){var r=B[l]+n;!0===f.hasOwnProperty(r)?(r=f[r].split(""),r="w"===r[0]?r[1].toUpperCase(): +r[1].toLowerCase(),b+=r):b+="1"}7!==m&&(b+="/");n--}b=b.replace(/11111111/g,"8");b=b.replace(/1111111/g,"7");b=b.replace(/111111/g,"6");b=b.replace(/11111/g,"5");b=b.replace(/1111/g,"4");b=b.replace(/111/g,"3");return b=b.replace(/11/g,"2")}var B="abcdefgh".split("");window.ChessBoard=window.ChessBoard||function(f,b){function n(){return"xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx".replace(/x/g,function(a){return(16*Math.random()|0).toString(16)})}function m(a){return JSON.parse(JSON.stringify(a))}function X(a){a= +a.split(".");return{major:parseInt(a[0],10),minor:parseInt(a[1],10),patch:parseInt(a[2],10)}}function r(a,e,c){if(!0===b.hasOwnProperty("showErrors")&&!1!==b.showErrors){var d="ChessBoard Error "+a+": "+e;"console"===b.showErrors&&"object"===typeof console&&"function"===typeof console.log?(console.log(d),2<=arguments.length&&console.log(c)):"alert"===b.showErrors?(c&&(d+="\n\n"+JSON.stringify(c)),window.alert(d)):"function"===typeof b.showErrors&&b.showErrors(a,e,c)}}function w(a){return"fast"=== +a||"slow"===a?!0:parseInt(a,10)+""!==a+""?!1:0<=a}function I(){for(var a=0;a=b;b++){var c=B[a]+b;s[c]=c+"-"+n()}b="KQRBNP".split("");for(a=0;a';!0===b.sparePieces&&(a+='
    ');a+='
    ';!0===b.sparePieces&&(a+='
    '); +return a+""}function A(a){"black"!==a&&(a="white");var e="",c=m(B),d=8;"black"===a&&(c.reverse(),d=1);for(var C="white",f=0;8>f;f++){for(var e=e+('
    '),k=0;8>k;k++){var g=c[k]+d,e=e+('
    ');if(!0===b.showNotation){if("white"===a&&1===d||"black"===a&&8===d)e+='
    '+c[k]+"
    ";0===k&&(e+='
    '+d+"
    ")}e+="
    ";C="white"===C?"black":"white"}e+='
    ';C="white"===C?"black":"white";"white"===a?d--:d++}return e}function Y(a){if("function"===typeof b.pieceTheme)return b.pieceTheme(a);if("string"===typeof b.pieceTheme)return b.pieceTheme.replace(/{piece}/g,a);r(8272,"Unable to build image source for cfg.pieceTheme.");return""}function D(a,b,c){var d=''}function N(a){var b="wK wQ wR wB wN wP".split(" ");"black"===a&&(b="bK bQ bR bB bN bP".split(" "));a="";for(var c=0;c=d?c:d}function la(a){for(var b=[],c=0;8>c;c++)for(var d=0;8>d;d++){var g=B[c]+(d+1);a!==g&&b.push({square:g,distance:ka(a,g)})}b.sort(function(a,b){return a.distance-b.distance});a=[];for(c=0;c=d.left&&a=d.top&&b=a)p=0;else{for(a-=1;0!==a%8&&0=1E8*b.major+1E4*b.minor+b.patch;return a?!0:(window.alert("ChessBoard Error 1005: Unable to find a valid version of jQuery. Please include jQuery 1.7.0 or higher on the page.\n\nExiting..."), +!1)}()){if("string"===typeof b||!0===F(b))b={position:b};"black"!==b.orientation&&(b.orientation="white");u=b.orientation;!1!==b.showNotation&&(b.showNotation=!0);!0!==b.draggable&&(b.draggable=!1);"trash"!==b.dropOffBoard&&(b.dropOffBoard="snapback");!0!==b.sparePieces&&(b.sparePieces=!1);!0===b.sparePieces&&(b.draggable=!0);if(!0!==b.hasOwnProperty("pieceTheme")||"string"!==typeof b.pieceTheme&&"function"!==typeof b.pieceTheme)b.pieceTheme="img/chesspieces/wikipedia/{piece}.png";if(!0!==b.hasOwnProperty("appearSpeed")|| +!0!==w(b.appearSpeed))b.appearSpeed=200;if(!0!==b.hasOwnProperty("moveSpeed")||!0!==w(b.moveSpeed))b.moveSpeed=200;if(!0!==b.hasOwnProperty("snapbackSpeed")||!0!==w(b.snapbackSpeed))b.snapbackSpeed=50;if(!0!==b.hasOwnProperty("snapSpeed")||!0!==w(b.snapSpeed))b.snapSpeed=25;if(!0!==b.hasOwnProperty("trashSpeed")||!0!==w(b.trashSpeed))b.trashSpeed=100;!0===b.hasOwnProperty("position")&&("start"===b.position?g=m(fa):!0===Q(b.position)?g=K(b.position):!0===F(b.position)?g=m(b.position):r(7263,"Invalid value passed to config.position.", +b.position));W=!0}W&&(I(),ya(),xa());return q};window.ChessBoard.fenToObj=K;window.ChessBoard.objToFen=L})(); \ No newline at end of file