GithubHelp home page GithubHelp logo

chessboardjs's Introduction

chessboard.js npm MIT License

NOTE: chessboard.js can be found on npm as @chrisoakman/chessboardjs

chessboard.js is a JavaScript chessboard component. It depends on jQuery v3.4.1 (or higher).

Please see chessboardjs.com for documentation and examples.

Project Status (Dec 2022)

I am currently focusing my efforts on chessboard2.

What is chessboard.js?

chessboard.js is a standalone JavaScript Chess Board. It is designed to be "just a board" and expose a powerful API so that it can be used in different ways. Here's a non-exhaustive list of things you can do with chessboard.js:

  • Use chessboard.js to show game positions alongside your expert commentary.
  • Use chessboard.js to have a tactics website where users have to guess the best move.
  • Integrate chessboard.js and chess.js with a PGN database and allow people to search and playback games (see Example 5000)
  • Build a chess server and have users play their games out using the chessboard.js board.

chessboard.js is flexible enough to handle any of these situations with relative ease.

What can chessboard.js not do?

The scope of chessboard.js is limited to "just a board." This is intentional and makes chessboard.js flexible for building a variety of chess-related applications.

To be specific, chessboard.js does not understand anything about how the game of chess is played: how a knight moves, whose turn is it, is White in check?, etc.

Fortunately, the chess.js library deals with exactly this sort of problem and plays nicely with chessboard.js's flexible API. Some examples of chessboard.js combined with chess.js: Example 5000, Example 5001, Example 5002

Docs and Examples

Developer Tools

# create a build in the build/ directory
npm run build

# re-build the website
npm run website

License

MIT License

chessboardjs's People

Contributors

aaronfi avatar cybear avatar dependabot[bot] avatar iksarfo avatar madelfino avatar oakmac avatar valker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chessboardjs's Issues

feature request: add ability to move pieces via clicking on start, then destination square

Really enjoy your work thus far.

I noticed the only way to move pieces currently is to click-drag them from their starting square to their destination square.

Adding an additional modality, in which you can click on a piece (thereby selecting it), then click on its destination square, would accommodate those users who for whatever reason naturally expect such behavior.

Just a small suggestion, which you've probably already thought of.

Please document requirements

Hi,

It seems chessboard.js requires jQuery to be loaded, but I cannot find this anywhere in the documentation (and jQuery is not included in the archive). Could you please document this somewhere, preferrably in “Getting started”? (Also, which versions/features you'd need would also be nice.)

Thanks!

Drop pieces onto board to build position

Users need to be able to drop a piece onto the board from outside the board.

Consider: stationary pieces ala chesspaste.com?

What other API methods are needed to make this happen?

Guide to contribute

Well, it was a bit hard to set up the project to work in my machine. I spent some minutes configuring the project (changing config.php, .htacess and etc).
What do you think about writing some little info about how to contribute?

Sync docs with versions

For example, onSnapEnd is documented on chessboardjs.com where the most recent version is v0.1.0. But onSnapEnd handling was not added until 9 days after 0.1.0 was released (acb1074). I spun my wheels for some time debugging why the onSnapEnd event did not fire.

Consider noting in the docs when a feature is added.

No way to castle on move()

Hi,

As the title says. You can board.move("e1-g1"), but only the king moves. I guess the closest you'd get would be board.move("e1-g1", "h1-f1"), but that's two moves as I understand it, and requires the client to keep track of the king's state itself.

Unicode chess symbols

Please consider using the unicode symbols points for your .png files. Alternately, wikipedia has .svg versions of your icons.

♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖
♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙



♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟
♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜

Alice Chess

How can I create Alice Chess board?

Basically I have two boards, and whenever piece moves, at the end of move it moves to same place in another board.

Also, I would like to have small black/white dot in another board where pieces are on the another (can be any picture, it can be changed later). For example, if I have piece in board 2 in place A3, in board 1 place A3 is small dot indicating that there is piece in that place, in another board.

For now I have following:

var init = function() {

var onDrop = function(source, target, piece, newPos) {
board2.move(source + '-' + target);
};

var onDrop2 = function(source, target) {
board1.move(source + '-' + target);
};

var cfg = {
draggable: true,
dropOffBoard: 'snapback',
position: 'start',
onDrop: onDrop,
sparePieces: true
};
var cfg2 = {
draggable: true,
dropOffBoard: 'snapback',
position: 'start',
onDrop: onDrop2,
sparePieces: true
};
var board1 = new ChessBoard('board1', cfg);
var board2 = new ChessBoard('board2', cfg2);

}; // end init()
$(document).ready(init);


When I move something on one board, it follows on another. This would be all I need if 1) after move it would change image of moved piece on both boards and 2) Start in one board with one picture set (pieces) and another on board 2 (dots)

Function to Check validity of a move

As much as I love this library, and love you for making it, doesn't it severely lack a function that checks if a given move is valid of not? I can move just about anything to anything =/ I understand that there might be a need for a movement function that bypasses these rules so you could set up the board etc, but an isValidMove() function would make such a nice addition.

PS: I'd be happy to write the code for you if you think this might be too much work

Need a method to highlight squares

How will this work with the highlighting when dragging pieces?

// return an array of currently highlighted squares
board.highlight();

// highlight some squares
board.highlight('e2', 'e3', 'e4');

// clear highlight
board.highlight('clear');

Minor: Pawns should animate on their column if possible

This is a really minor enhancement; low priority.

When calculating animations, pawns should search their column first when moving square-to-square, then search outside their column.

This would prevent the "cross-pawns" animation back to their starting point, which is slightly jarring.

Cache images

Images are re-requested every animation update.
This may also be the cause of #52
My solution was to cache the images in base64 url strings,
which is implemented here: http://queens.zolmeister.com/

It looks like this:

var imgCache = {}
function cacheImages() {
  var pieces = ['wK', 'wQ', 'wR', 'wB', 'wN', 'wP', 'bK', 'bQ', 'bR', 'bB', 'bN', 'bP'];
  pieces.forEach(function(piece) {
    var img = new Image()
    img.onload = function() {
      imgCache[piece] = getBase64Image(img)
    }
    img.src = buildPieceImgSrc(piece)
  })

  function getBase64Image(img) {
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0);
    var dataURL = canvas.toDataURL("image/png");
    return dataURL;     
  }
}

function buildPieceImgSrc(piece) {
  if(imgCache[piece]) return imgCache[piece]
...

onMoveEnd only fires in onFinish of doAnimations

A simple configuration never invokes the method.

EDIT: A user of the code will almost certainly need to differentiate between a post-valid-move onchange event and all other onchange events. The naming of the onMoveEnd method confused me at first, but now I understand its purpose isn't serving as a post onDrop event.

Better support for the Google Closure compiler

Hi,

I'm compiling chessboard.js together with other code using the Google Closure compiler. Would you be interested in making a few small changes to make it compatible with the advanced optimization level?

Basically the only thing you're doing that's a problem is accessing properties sometimes with [] and sometimes with a dot, because the compiler renames any properties that are ever accessed with a dot. This manifests itself in two places:

  1. You use window['ChessBoard'] one place, and window.ChessBoard somewhere else. Using window.ChessBoard everywhere would make the renaming consistent (or you cold use window['ChessBoard'] everywhere if you want it to be available to external JavaScript that's not compiled together with chessboard.js, but I think this might inhibit some optimizations).
  2. The ”CSS” array is accessed almost always with the dot, but you also use “white” and “black” with []. The simplest thing here is simply moving the constants away from the same array as the one you index variably:

+var CSSColor = {};
+CSSColor['white'] = 'white-1e1d7';
+CSSColor['black'] = 'black-3c85d';

Create a .config() method

// return the current config object
board.config();

// change a single config value
board.config('onChange', fn);

// update the config with an object
board.config({
'draggable': false,
'orientation': 'black
};

Pieces flickers on update

Hi,

When I do board.position(fen), it would seem the pieces are somehow redrawn; at least they flicker ever so shortly during the move somehow. Especially for the pieces that stand still, maybe this could avoided?

I don't think this has anything to do with my code; it happens on e.g. http://chessboardjs.com/examples#3001 when I switch positions.

I'm using Chrome 31.0.1650.57 on Linux.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.