Skip to main content
Glama
spaceControl.ts1.41 kB
import { Chess, Color, WHITE, BLACK } from "chess.js"; import { BOARD_CENTRE, BOARD_FLANK, SpaceControl } from "../types/types.js"; function getSpaceControl(chess: Chess, side: Color): number { let spaceMeasure = 0; for(const sq of BOARD_CENTRE){ spaceMeasure += chess.attackers(sq, side).length; } return spaceMeasure; } function getFlankSpaceControl(chess: Chess, side: Color): number { let flankMeasure = 0; for(const sq of BOARD_FLANK){ flankMeasure += chess.attackers(sq, side).length; } return flankMeasure; } export function getSideSpaceControl(chess: Chess, side: Color): SpaceControl { const centre = getSpaceControl(chess, side); const flank = getFlankSpaceControl(chess, side); const total = centre + flank; // Calculate opponent's space control for advantage calculation const enemySide = side === WHITE ? BLACK : WHITE; const enemyCentre = getSpaceControl(chess, enemySide); const enemyFlank = getFlankSpaceControl(chess, enemySide); const enemyTotal = enemyCentre + enemyFlank; // Space advantage: positive = we control more, negative = opponent controls more const spaceAdvantage = total - enemyTotal; return { centerspacecontrolscore: centre, flankspacecontrolscore: flank, totalspacecontrolscore: total, spaceadvantage: spaceAdvantage, // Add this new field }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jalpp/chessagine-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server