How do I get started?
sombor-shuffle opened this issue · 3 comments
I'd like to use Chessground + scalachess with the intention of validating moves made on a board.
I can't find a documentation on how to use scalachess. I cloned the project, installed sbt, and ran compile (as per the README). But from here on out I'm completely in the dark.
How do I use scalachess to validate a chess position?
I realize that this probably isn't an appropriate issue, and would appreciate any pointer in a more sensible direction.
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:
- https://github.com/lenguyenthanh/scalachess-tests
- https://github.com/lenguyenthanh/chess-position-generator
- https://github.com/lenguyenthanh/scala-examples
Please take a look!
Also you can join our discord and we ask there: https://discord.gg/lichess
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:
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!
that's great too hear! good luck on your adventure!