Chess game on meteor

Hello everyone!
I consider ways of making a chess game and trying to choose the most comfortable one for my TI project. I guess my question can be too simple, but I can’t deal with it. Actually - what (in your opinion) is the best way to set up a chessboard? I thought about collection in MongoDB, HTML table (don’t think it would work actually) and using some JS. The thing is my project doesn’t need to be too advanced, but has to be made 100% by me. I am kinda new to Meteor/MongoDB and also don’t have much knowledge about JS.
Later, of course I want to put some figures on and have a possibilty to move them. Is the x,y coordinate system good idea of making a chessboard?

2 Likes

If possible you may want to look into using an HTML5 game engine framework like Phaser and/or look at the source of similar projects built with them for things like the grid system, moving and creating pieces etc.

i will. is it possible to put a game written in c# (with some graphic libraries) into an Internet application? i.e. xampp/meteor/any other framework…?

I think the ‘best way’ varies for what you’re trying to accomplish. Are you trying to build it as fast as possible? Are you trying to make it as maintainable as possible? Are you trying to learn and would like to know how the board would work?

If you’re trying to learn I would start with a multi-dimensional array in memory first. Basically each element can contain a piece of data that can represent a chess piece.

Then you can add this array into mongo so that a 2 player game can be synchronized.

Bonus points if you can plan ahead and write your own abstraction layer so that switching from an in memory implementation to Mongo is just a couple lines of changed code.

Or if you’re in a hurry and are ok with a ‘black box’, just search npm or github for a grid board library… but I would urge you to roll your own since this is a newer concept.

Hope this helps!

2 Likes

You can use a combination of chessboardjs and chessjs
Chessboardjs is simply a JavaScript board which exposes an API for positioning pieces.
On the other hand chess.js is for move generation, validation, check/checkmate/stalemate detection etc.

You can put these two together like this:

Template.play.onRendered(function() {

  var config = {
    draggable: true,
    moveSpeed: 'slow',
    snapbackSpeed: 500,
    snapSpeed: 100,
    onDrop: onDrop,
    onSnapEnd: onSnapEnd,
    onDragStart: onDragStart,
    onMoveEnd: onMoveEnd,
    onMouseoutSquare: onMouseoutSquare,
    onMouseoverSquare: onMouseoverSquare
  };

  board = new ChessBoard('board', config);
  gameEngine = new Chess();
  
  board.orientation("white");


  // find out moves
  Tracker.autorun(function() {
    if (FlowRouter.subsReady("myGameMoves")) {

      var move = GameMoves.findOne();

      board.position(move.position.fen);
      gameEngine.load(move.position.fen);

    }
  });

});

This is an incomplete code snippet, I put it here for giving an idea.

1 Like

Unity3d can export to HTML5, it uses C# & JS