Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

README.md

Golang Chess

This project is bare minimum for building a chess site with golang. It uses javascript chess libraries: Chessboard.js, Chess.js, and the Garbo Chess Engine.

Please visit the project site: http://chessbook.org

Installation

TODO

Features

  • Guest can play againts computer (GarboChess.js, 800ms)
  • Guest can play againts another random guest
  • Guest can watch random game

Not Supported

Below features are not and will not supported. You must implement them.

  • Chess game by time
  • Draw detection by repetition or by 50 moves
  • Registered users
  • Saving chess games
  • ELO or other rank system
  • Play againts diferrent levels of computer
  • Pawn promotion will be only queen

Working with GarboChess.js

To work with GarboChess.js I need to understand some other programmers code. One or two projects use Gary Linscott's main codes from boardui.js. I figured it out how to include only garbochess.js and not include boardui.js (it is a board ui, and we dont need it). I will explain my way. You need to modify for your needs.

First we created a worker:

var g_garbo = new Worker("/js/garbochess.js");

To check messages from worker, we need an onmessage function:

g_garbo.onmessage = function (e) {
   ...
}

And then send messages to worker:

g_garbo.postMessage("position " + game.fen());
g_garbo.postMessage("search 800");

First line sets up a position, second line says "Solve it in 800 ms."

And I check messages from worker like this:

g_garbo.onmessage = function (e) {
    move = { from: e.data[0]+e.data[1], to: e.data[2]+e.data[3] };
    if (e.data[4]) {
        move.promotion = e.data[4];
    }
    g_garbo.terminate();
    game.move(move);
    board.position(game.fen());
    socket.emit("move", {move: move, fen: game.fen()});
}

CAUTION: Since I modified GarboChess.js (latest "Test Harness" part) I only get the best move as message. But original GarboChess.js send more messages if you like it analyze the position. Then you may need something like that:

g_garbo.onmessage = function (e) {
    if (e.data.match("^pv") == "pv") {
    } else if (e.data.match("^sam") == "sam") {
    } else if (e.data.match("^message") == "message") {
    } else {
        move = { from: e.data[0]+e.data[1], to: e.data[2]+e.data[3] };
        if (e.data[4]) {
            move.promotion = e.data[4];
        }
        g_garbo.terminate();
        game.move(move);
        board.position(game.fen());
        socket.emit("move", {move: move, fen: game.fen()});
    }        
}

About

Chess site written in golang

Resources

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.