├── favicon.gif ├── favicon.ico ├── images ├── marble.jpg ├── king_black.png ├── king_white.png ├── pawn_black.png ├── pawn_white.png ├── rook_black.png ├── rook_white.png ├── small-logo.png ├── bishop_black.png ├── bishop_white.png ├── knight_black.png ├── knight_white.png ├── queen_black.png ├── queen_white.png ├── bjf-logo-color.png ├── thumb │ ├── king_black_thumb.png │ ├── king_white_thumb.png │ ├── pawn_black_thumb.png │ ├── pawn_white_thumb.png │ ├── queen_black_thumb.png │ ├── queen_white_thumb.png │ ├── rook_black_thumb.png │ ├── rook_white_thumb.png │ ├── bishop_black_thumb.png │ ├── bishop_white_thumb.png │ ├── knight_black_thumb.png │ └── knight_white_thumb.png └── ui │ ├── ui-icons_222222_256x240.png │ ├── ui-icons_4b8e0b_256x240.png │ ├── ui-icons_a83300_256x240.png │ ├── ui-icons_cccccc_256x240.png │ ├── ui-icons_ffffff_256x240.png │ ├── ui-bg_flat_30_cccccc_40x100.png │ ├── ui-bg_flat_50_5c5c5c_40x100.png │ ├── ui-bg_glass_20_555555_1x400.png │ ├── ui-bg_glass_40_0078a3_1x400.png │ ├── ui-bg_glass_40_ffc73d_1x400.png │ ├── ui-bg_inset-soft_25_000000_1x100.png │ ├── ui-bg_inset-soft_30_f58400_1x100.png │ ├── ui-bg_gloss-wave_25_333333_500x100.png │ └── ui-bg_highlight-soft_80_eeeeee_1x100.png ├── .gitignore ├── js ├── test.js ├── lib │ ├── head.min.js │ └── jquery │ │ └── jquery-ui-1.8.16.custom.min.js └── chess.js ├── index.html ├── test.html ├── README.md └── css ├── test.css └── style.css /favicon.gif: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /images/marble.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/marble.jpg -------------------------------------------------------------------------------- /images/king_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/king_black.png -------------------------------------------------------------------------------- /images/king_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/king_white.png -------------------------------------------------------------------------------- /images/pawn_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/pawn_black.png -------------------------------------------------------------------------------- /images/pawn_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/pawn_white.png -------------------------------------------------------------------------------- /images/rook_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/rook_black.png -------------------------------------------------------------------------------- /images/rook_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/rook_white.png -------------------------------------------------------------------------------- /images/small-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/small-logo.png -------------------------------------------------------------------------------- /images/bishop_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/bishop_black.png -------------------------------------------------------------------------------- /images/bishop_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/bishop_white.png -------------------------------------------------------------------------------- /images/knight_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/knight_black.png -------------------------------------------------------------------------------- /images/knight_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/knight_white.png -------------------------------------------------------------------------------- /images/queen_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/queen_black.png -------------------------------------------------------------------------------- /images/queen_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/queen_white.png -------------------------------------------------------------------------------- /images/bjf-logo-color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/bjf-logo-color.png -------------------------------------------------------------------------------- /images/thumb/king_black_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/king_black_thumb.png -------------------------------------------------------------------------------- /images/thumb/king_white_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/king_white_thumb.png -------------------------------------------------------------------------------- /images/thumb/pawn_black_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/pawn_black_thumb.png -------------------------------------------------------------------------------- /images/thumb/pawn_white_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/pawn_white_thumb.png -------------------------------------------------------------------------------- /images/thumb/queen_black_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/queen_black_thumb.png -------------------------------------------------------------------------------- /images/thumb/queen_white_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/queen_white_thumb.png -------------------------------------------------------------------------------- /images/thumb/rook_black_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/rook_black_thumb.png -------------------------------------------------------------------------------- /images/thumb/rook_white_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/rook_white_thumb.png -------------------------------------------------------------------------------- /images/thumb/bishop_black_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/bishop_black_thumb.png -------------------------------------------------------------------------------- /images/thumb/bishop_white_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/bishop_white_thumb.png -------------------------------------------------------------------------------- /images/thumb/knight_black_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/knight_black_thumb.png -------------------------------------------------------------------------------- /images/thumb/knight_white_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/thumb/knight_white_thumb.png -------------------------------------------------------------------------------- /images/ui/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /images/ui/ui-icons_4b8e0b_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-icons_4b8e0b_256x240.png -------------------------------------------------------------------------------- /images/ui/ui-icons_a83300_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-icons_a83300_256x240.png -------------------------------------------------------------------------------- /images/ui/ui-icons_cccccc_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-icons_cccccc_256x240.png -------------------------------------------------------------------------------- /images/ui/ui-icons_ffffff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-icons_ffffff_256x240.png -------------------------------------------------------------------------------- /images/ui/ui-bg_flat_30_cccccc_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-bg_flat_30_cccccc_40x100.png -------------------------------------------------------------------------------- /images/ui/ui-bg_flat_50_5c5c5c_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-bg_flat_50_5c5c5c_40x100.png -------------------------------------------------------------------------------- /images/ui/ui-bg_glass_20_555555_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-bg_glass_20_555555_1x400.png -------------------------------------------------------------------------------- /images/ui/ui-bg_glass_40_0078a3_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-bg_glass_40_0078a3_1x400.png -------------------------------------------------------------------------------- /images/ui/ui-bg_glass_40_ffc73d_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-bg_glass_40_ffc73d_1x400.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Thumbs.db 3 | .tmp* 4 | .project 5 | *.sass 6 | *.scss 7 | *.scssc 8 | config.rb 9 | css/scss 10 | 11 | /.settings -------------------------------------------------------------------------------- /images/ui/ui-bg_inset-soft_25_000000_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-bg_inset-soft_25_000000_1x100.png -------------------------------------------------------------------------------- /images/ui/ui-bg_inset-soft_30_f58400_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-bg_inset-soft_30_f58400_1x100.png -------------------------------------------------------------------------------- /images/ui/ui-bg_gloss-wave_25_333333_500x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-bg_gloss-wave_25_333333_500x100.png -------------------------------------------------------------------------------- /images/ui/ui-bg_highlight-soft_80_eeeeee_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminfisher/Web-Chess/HEAD/images/ui/ui-bg_highlight-soft_80_eeeeee_1x100.png -------------------------------------------------------------------------------- /js/test.js: -------------------------------------------------------------------------------- 1 | $(function(){ 2 | $('#clear').click(function(){ 3 | $('#board img').each(function(){ 4 | piece = $(this); 5 | if(!piece.attr('alt').match('king')) piece.remove(); 6 | }); 7 | Game.Players[0].pieces = []; 8 | Game.Players[0].pawns = []; 9 | Game.Players[1].pieces = []; 10 | Game.Players[1].pawns = []; 11 | 12 | $('.legal').removeClass('legal'); 13 | $('.selected').removeClass('selected'); 14 | $('.threat').removeClass('threat'); 15 | $('.attack').removeClass('attack'); 16 | }); 17 | 18 | $('#staging img').draggable({ 19 | containment: Game.board, 20 | helper: 'clone', 21 | opacity: 0.8, 22 | snap: true 23 | }); 24 | 25 | $('#board ul li').droppable({ 26 | drop: function(event, ui){ 27 | $dragging = $('.ui-draggable-dragging'); 28 | info = $dragging.attr('alt').split(' '); 29 | player = (Game.Players[0].color == info[0]) ? Game.Players[0] : Game.Players[1]; 30 | 31 | player.addPiece(info[1], this.id); 32 | } 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |Turn:
189 || White | 194 |Black | 195 ||
|---|---|---|
').html('Select a piece for promotion: ').appendTo(bench);
410 | $('').attr('src', 'images/thumb/knight_' + this.color + '_thumb.png').attr('rel', 'knight').appendTo(bench);
411 | $('
').attr('src', 'images/thumb/queen_' + this.color + '_thumb.png').attr('rel', 'queen').appendTo(bench);
412 |
413 | bench.appendTo(Game.$cover);
414 | Game.$cover.fadeIn();
415 |
416 | // Place the promotion piece, add it to the pieces array and append the promotion
417 | // to the logged move. << B. Fisher 3/29 1630
418 | $(bench).children('img').click(function() {
419 | $(this).fadeTo('slow', 0.6).fadeTo('fast', 1).delay(1000);
420 |
421 | if ($(this).attr('rel') == 'queen') {
422 | self.owner().addPiece('queen', destination.id);
423 | $(logCell).html($(logCell).html() + '=Q');
424 | } else {
425 | self.owner().addPiece('knight', destination.id);
426 | $(logCell).html($(logCell).html() + '=N');
427 | }
428 |
429 | Game.$cover.children().remove();
430 | Game.$cover.fadeOut();
431 | Game.turn();
432 | });
433 |
434 | // Remove the pawn's image, and clear it from the Player's pieces array.
435 | $(self.image).remove();
436 | Game.clearClass();
437 | // Hold turn change. will be called after a new piece is selected.
438 | Game.change = false;
439 | self.kill();
440 | };
441 |
442 | /**
443 | * @author BF
444 | * @constructor
445 | * @member Piece.prototype
446 | */
447 | function rook(color, start) {
448 | Piece.call(this, color, start);
449 | this.type = "rook";
450 | }
451 |
452 |
453 | rook.prototype = new Piece();
454 |
455 | rook.prototype.toString = function() {
456 | return 'rook';
457 | };
458 |
459 | rook.prototype.move = function(destination) {
460 | this._move(destination);
461 | };
462 |
463 | rook.prototype.footprint = function() {
464 | var row = this.position[1], col = this.position[0];
465 |
466 | return ['A' + row, 'H' + row, col + 1, col + 8];
467 | };
468 |
469 | rook.prototype._legal = function(){
470 | return this.hvd_legal();
471 | };
472 |
473 | /**
474 | * @author BF
475 | * @constructor
476 | * @member Piece.prototype
477 | */
478 | function knight(color, start) {
479 | Piece.call(this, color, start);
480 | this.type = "knight";
481 | }
482 |
483 | knight.prototype = new Piece();
484 |
485 | knight.prototype.toString = function() {
486 | return 'knight';
487 | };
488 |
489 | knight.prototype.move = function(destination) {
490 | this._move(destination);
491 | };
492 |
493 | knight.prototype._legal = function(){
494 | var fp = this.footprint(),
495 | moves = fp.map(function(square){
496 | if(!Game.occupied('#' + square)) return square;
497 | }),
498 | capture = fp.map(function(square){
499 | var dest = Game.occupied('#' + square);
500 | if(dest && (dest.color !== this.color)) return dest;
501 | }, this);
502 |
503 | return {
504 | moves: Game.arrayStrip(moves),
505 | capture: Game.arrayStrip(capture)
506 | };
507 | };
508 |
509 | knight.prototype.footprint = function() {
510 | var ids = [],
511 | col = Game.colNumber(this.position[0]),
512 | row = this.position[1] * 1,
513 | cShift = null;
514 |
515 | for (var r = row - 2; r <= row + 2; r++) {
516 | if (r != row && r > 0 && r <= 8) {
517 | cShift = (Math.abs(row - r) === 1) ? cShift = 2 : cShift = 1;
518 | if(col + cShift < 8) ids.push(Game.cLabels[col + cShift] + r);
519 | if(col - cShift >= 0) ids.push(Game.cLabels[col - cShift] + r);
520 | }
521 | }
522 | return ids;
523 | };
524 |
525 | /**
526 | * @author BF
527 | * @constructor
528 | * @member Piece.prototype
529 | */
530 | function bishop(color, start) {
531 | Piece.call(this, color, start);
532 |
533 | this.type = "bishop";
534 | };
535 |
536 | bishop.prototype = new Piece();
537 |
538 | bishop.prototype.toString = function() {
539 | return 'bishop';
540 | };
541 |
542 | bishop.prototype.move = function(destination) {
543 | this._move(destination);
544 | };
545 |
546 | bishop.prototype.footprint = function() {
547 | return [
548 | Game.findDiagonal(this.position, 1, 1),
549 | Game.findDiagonal(this.position, 1, -1),
550 | Game.findDiagonal(this.position, -1, 1),
551 | Game.findDiagonal(this.position, -1, -1)
552 | ];
553 | };
554 |
555 | bishop.prototype._legal = function(){
556 | return this.hvd_legal();
557 | };
558 |
559 | /**
560 | * @author BF
561 | * @constructor
562 | * @member Piece.prototype
563 | */
564 | function queen(color, start) {
565 | Piece.call(this, color, start);
566 | this.type = "queen";
567 | };
568 |
569 | queen.prototype = new Piece();
570 |
571 | queen.prototype.toString = function() {
572 | return 'queen';
573 | };
574 |
575 | queen.prototype.move = function(destination) {
576 | this._move(destination);
577 | };
578 |
579 | queen.prototype.footprint = function() {
580 | var row = this.position[1], col = this.position[0];
581 | return ['A' + row, 'H' + row, col + 1, col + 8, Game.findDiagonal(this.position, 1, 1), Game.findDiagonal(this.position, 1, -1), Game.findDiagonal(this.position, -1, 1), Game.findDiagonal(this.position, -1, -1)];
582 | };
583 |
584 | queen.prototype._legal = function(){
585 | return this.hvd_legal();
586 | };
587 |
588 | /**
589 | * @author BF
590 | * @constructor
591 | * @member Piece.prototype
592 | */
593 | function king(color, start) {
594 | Piece.call(this, color, start);
595 |
596 | this.type = "king";
597 | this.inCheck = false;
598 | };
599 |
600 |
601 | king.prototype = new Piece();
602 |
603 | king.prototype.toString = function() {
604 | return 'king';
605 | };
606 |
607 | king.prototype.move = function(destination) {
608 | var rook = null, dest = null;
609 |
610 | // Evaluate if king is castling. << B. Fisher
611 | if (this.castle() && (destination.id.match('G') || destination.id.match('C'))) {
612 |
613 | // If king is moving to column 'G' (kingside) rook is on column 'H'
614 | if (destination.id.match('G')) {
615 | rook = Game.occupied('H' + this.position[1]);
616 | dest = destination.previousElementSibling;
617 | Game.castled = "king";
618 | }
619 |
620 | // If king is moving to column 'C' (queenside) rook is on column 'A'
621 | else if (destination.id.match('C')) {
622 | rook = Game.occupied('A' + this.position[1]);
623 | dest = destination.nextElementSibling;
624 | Game.castled = "queen";
625 | }
626 | // Move the king, than move the rook to the king's other side (dest). << B. Fisher
627 | this._move(destination);
628 | $(rook.image).fadeOut('fast', function() {
629 | rook.move(dest);
630 | $(rook.image).fadeIn('fast');
631 |
632 | // Reset the castled flag to false so black's moves will be logged << J-M Glenn
633 | Game.castled = null;
634 | });
635 | } else
636 | this._move(destination);
637 | };
638 |
639 | king.prototype.castle = function() {
640 | if (this.inCheck || this.moved)
641 | return false;
642 | else
643 | return true;
644 | };
645 |
646 | king.prototype.footprint = function() {
647 | var row = this.position[1] * 1, column = Game.colNumber(this.position[0]), square, squares = new Array();
648 |
649 | for (var c = column - 1; c <= column + 1; c++) {
650 | for (var r = row - 1; r <= row + 1; r++) {
651 | square = Game.cLabels[c] + r;
652 | if (square != this.position)
653 | squares.push(square);
654 | };
655 | };
656 | return squares;
657 | };
658 |
659 | king.prototype._legal = function(){
660 | // Check for castle legality and add king double step if true. << B. Fisher
661 | if (self.castle()) {
662 | rook = Game.occupied(Game.writeID('H', rNum));
663 |
664 | // Kingside castle squares are unoccupied and unthreatened,
665 | // and the kingside rook has not moved.
666 | if (Game.vector(self.position, 'G' + rNum, self.color).list.match('G') &&
667 | rook && !rook.moved &&
668 | !Game.check('F' + rNum, Game.Players[1]).threat &&
669 | !Game.check('G' + rNum, Game.Players[1]).threat) {
670 | legal.moves.push(Game.writeID('G', rNum));
671 | };
672 |
673 | // Queenside squares between rook and king are not occupied.
674 | // The king is not moving across check.
675 | // and the queenside rook has not moved.
676 | rook = Game.occupied('#A' + rNum);
677 | if (Game.vector(self.position, 'B' + rNum, self.color).list.match('B') &&
678 | rook && !rook.moved &&
679 | !Game.check('D' + rNum, Game.Players[1]).threat &&
680 | !Game.check('E' + rNum, Game.Players[1]).threat) {
681 | legal.moves.push(Game.writeID('C', rNum));
682 | };
683 | } // End Castle legality checks
684 |
685 | // Removes any square ids from legal.moves that would move the king into check << B. Fisher 3.04 1700
686 | $.each(legal.moves, function(index) {
687 | kid = Game.occupied(this);
688 | square_check = Game.check(this, Game.Players[1]);
689 |
690 | // if square is occupied by a piece of opposing color, check for protection
691 | // if protected add .threat class and remove location from legal moves
692 | if (kid.color == Game.Players[1].color) {
693 | if (square_check.protect) {
694 | $(this).addClass('threat');
695 | }
696 | };
697 |
698 | // if square is threatened by an opposing piece add .threat class
699 | if (square_check.threat) {
700 | $(this).addClass('threat');
701 | }
702 |
703 | if (kid && (kid.type === 'bishop' || kid.type === 'rook' || kid.type === 'queen')) {
704 | self.penetration('#' + self.position, kid);
705 | }
706 | for (var s in square_check)
707 | if (square_check[s].type) {
708 | self.penetration(this, square_check[s]);
709 | }
710 | });
711 |
712 | // Remove threatened squares discovered by penetration from legal list
713 | $('.threat').each(function() {
714 | squares.splice(squares.indexOf('#' + this.id), 1);
715 | });
716 | }
717 | // End piece definitions
718 |
719 | self.init();
720 | return false;
721 | };
722 |
723 | Game.prototype = {
724 | init : function() {
725 | var names = this.get_player_names();
726 |
727 | $('button').button();
728 |
729 | Game.Players.push(new Player());
730 | Game.Players.push(new Player());
731 | Game.Players[0].activate();
732 |
733 | $('#turn').html(Game.Players[0].name);
734 | },
735 |
736 | get_player_names : function() {
737 | Game.$cover.fadeIn();
738 |
739 | // Create the starting player form
740 | var form = $('