import type { GameState, Point } from "./types.ts"; /** * A POSITION DRAWN AS SVG, as a string: the board in the way its game is * traditionally drawn (stones on the crossings of lines, or inside squares, or * on the hexagon lattice), the stones, the last move, the winning line and, if * asked, the moves the player to move may make. It draws a state it is given * and decides nothing: what is legal, and who has won, is the engine's. * * Every colour is a CSS variable with a default, so a page restyles it from * outside: `--nb-wood`, `--nb-wood-deep`, `--nb-line`, `--nb-cell-light`, * `--nb-cell-dark`, `--nb-black`, `--nb-white`, `--nb-accent`, `--nb-good`, * `--nb-hot` and `--nb-worm`. The string is one `` element and nothing * else, so it can be a file, an `innerHTML` or a server-rendered component. */ /** What to draw besides the board and the stones. Every field is optional. * * @example * ```ts * import type { DrawBoardOptions } from "@johnmorrisdotca/narabe/draw"; * * const value: DrawBoardOptions = {width:480,title:"Opening position",legal:true}; * console.log(value); * ``` */ export type DrawBoardOptions = { /** The width in pixels. Unless said, the SVG has a `viewBox` and no size, and fills what holds it. */ width?: number; /** What a screen reader says for the picture. Unless said, "Board". An empty string makes it decoration. */ title?: string; /** Mark the last move with a dot. Unless said, on. */ lastMove?: boolean; /** Ring the stones of a winning line. Unless said, on. */ winningLine?: boolean; /** Cross the points a forbidden-move rule (renju, omok) refuses. Unless said, off. */ forbidden?: boolean; /** Dot every point the player to move may play, or the squares the piece on `from` may go to. Unless said, off. */ legal?: boolean; /** A piece picked up: its moves are dotted when `legal` is on, and it is ringed. */ selected?: Point; }; /** The position as one `` element, drawn the way its game is traditionally drawn. * * @param state - The current immutable game position. * @param options - SVG size, label and highlighting options. * @returns One standalone SVG string representing the position. * @example * ```ts * import { createGame } from "@johnmorrisdotca/narabe"; * import { boardSvg } from "@johnmorrisdotca/narabe/draw"; * * const state = createGame({variant:"freestyle",size:15}); * console.log(boardSvg(state, { legal: true }).startsWith("