GithubHelp home page GithubHelp logo

Comments (3)

lenguyenthanh avatar lenguyenthanh commented on June 12, 2024 1

Hey @sombor-shuffle,
unfortunately, we don't have a documentation about scalachess. Can you please tell us about your usecase with scalachess, so we can help?

In the mean time, please refer to tests, lila/lila-ws for some references. I also have some standalone examples here:

Please take a look!

Also you can join our discord and we ask there: https://discord.gg/lichess

from scalachess.

sombor-shuffle avatar sombor-shuffle commented on June 12, 2024

Hello, @lenguyenthanh!

Apologies for not writting back faster. Thank you for helping me out!

I wanted to highlight all legal moves (with the rules of antichess) for a selected piece, as seen below:

wNh6vws

My solution ended up using chessops, instead (roughly paraphrased from a component in my Next.js project):

import { Chessground } from 'chessground';

import { chessgroundDests } from 'chessops/compat';
import { Antichess } from "chessops/variant";
import { parseSquare } from 'chessops/util';

import "chessground.base.css";
import "chessground.brown.css";
import "chessground.cburnett.css";

// Create a container for chessground.
const container = document.createElement("div");
document.body.appendChild(container);

// Give it some size. Otherwise it won't be visible.
container.style.width = "500px";
container.style.height = "500px";

// Handles logic and initializes to starting position.
const ops = Antichess.default();

// Chessground config file:
const config = { 
  movable: {
    color: "white",

    // Only the moves given below are allowed to be made.
    free: false,

    // chessops has a built-in function that can be assigned to dests.
    // This will highlight all legal moves.
    dests: chessgroundDests(ops), 
    
  }
}

const cg = Chessground(container, config);

// Can't be set in config as it references cg (which won't exist yet)
cg.set({
  movable: { events: { after: handleMove(cg, ops) } }
});


// Called when a move is made.
function handleMove(cg, ops) { 
  
  return (orig, dest) => {
    
    // Converts e1 - h8 to 0 - 63, for chessops.
    const from = parseSquare(orig), to = parseSquare(dest);

    if(from && to) {

      const move = { from, to }

      // Updates the internal board of chessops.
      ops.play(move);

      // Updates Chessground with new active color
      // and new legal moves.
      cg.set({
        turnColor: ops.turn,
        movable: {
          color: ops.turn,
          dests: chessgroundDests(ops)
        }
      });

    }
  }
}

Thank you for linking me these resources. I'm very interested to learn more about how Lichess works and will dive into them. Appreciate it king!

from scalachess.

lenguyenthanh avatar lenguyenthanh commented on June 12, 2024

that's great too hear! good luck on your adventure!

from scalachess.

Related Issues (20)

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.