### Run Ban Chess GUI Locally Source: https://github.com/bezalel6/ban-chess.ts/blob/master/README.md These commands navigate into the 'gui' directory, install its dependencies, and start the development server for the Ban Chess GUI. This allows you to run and test the graphical interface locally. ```bash cd gui npm install npm run dev ``` -------------------------------- ### Project Initialization and Dependencies (Bash) Source: https://github.com/bezalel6/ban-chess.ts/blob/master/CLAUDE.md Provides bash commands for setting up the Ban Chess project. It includes initializing the npm project, installing the core `chess.ts` dependency, and installing development dependencies like TypeScript, Jest, and related types. ```Bash # Initialize the project (if not done) npm init -y # Install dependencies npm install chess.ts@^0.16.2 npm install --save-dev typescript @types/node jest @types/jest ts-jest # Initialize TypeScript config npx tsc --init ``` -------------------------------- ### Ban Chess Quick Start Example Source: https://github.com/bezalel6/ban-chess.ts/blob/master/README.md This TypeScript code demonstrates the basic usage of the BanChess class. It illustrates the turn sequence, including Black banning a White move, White moving, White banning a Black move, and Black moving, highlighting the ban-before-move mechanic. ```typescript import { BanChess } from 'ban-chess.ts'; // Create a new Ban Chess game const game = new BanChess(); // Game starts: Black bans a White move (before White has moved at all) console.log(game.turn); // 'black' console.log(game.nextActionType()); // 'ban' // Black bans White's e2-e4 opening BEFORE White's first move game.play({ ban: { from: 'e2', to: 'e4' } }); // Now White moves (with e2-e4 banned) console.log(game.turn); // 'white' console.log(game.nextActionType()); // 'move' console.log(game.legalMoves()); // e2-e4 is NOT available game.play({ move: { from: 'd2', to: 'd4' } }); // White bans a Black move BEFORE Black's first move console.log(game.turn); // 'white' (White does the banning) console.log(game.nextActionType()); // 'ban' game.play({ ban: { from: 'e7', to: 'e5' } }); // Now Black moves (with e7-e5 banned) console.log(game.turn); // 'black' console.log(game.nextActionType()); // 'move' console.log(game.legalMoves()); // e7-e5 is NOT available game.play({ move: { from: 'd7', to: 'd5' } }); // Black bans White's next move BEFORE White moves again console.log(game.turn); // 'black' (Black does the banning) console.log(game.nextActionType()); // 'ban' // Pattern continues: ban-before-move ``` -------------------------------- ### Ban Chess Full State Sync (Client) Source: https://github.com/bezalel6/ban-chess.ts/blob/master/docs/SYNCHRONIZATION.md Illustrates how a client receives and applies the full game synchronization state, ensuring it is up-to-date after joining or recovering from a disconnection. ```typescript function handleFullSync(syncState: SyncState) { game.loadFromSyncState(syncState); // Now client is fully synchronized } ``` -------------------------------- ### Install ban-chess.ts Source: https://github.com/bezalel6/ban-chess.ts/blob/master/README.md These commands show how to install the ban-chess.ts library using either npm or yarn package managers. This is the first step to integrating the Ban Chess variant into your TypeScript projects. ```bash npm install ban-chess.ts # or yarn add ban-chess.ts ``` -------------------------------- ### Ban Chess Action History Replay Source: https://github.com/bezalel6/ban-chess.ts/blob/master/docs/SYNCHRONIZATION.md Demonstrates saving the game's action history to local storage and then loading and replaying these actions to reconstruct the game state. ```typescript // Save game as action history const actions = game.getActionHistory(); localStorage.setItem('game', JSON.stringify(actions)); // Load and replay game const savedActions = JSON.parse(localStorage.getItem('game')); const replayedGame = BanChess.replayFromActions(savedActions); ``` -------------------------------- ### Get Ban Chess Synchronization State Source: https://github.com/bezalel6/ban-chess.ts/blob/master/docs/SYNCHRONIZATION.md Shows how to retrieve the minimal game state required for synchronization, including the FEN string, the last action performed, and the current move number. ```typescript const game = new BanChess(); // ... play some moves ... // Get minimal state for synchronization const syncState = game.getSyncState(); // Returns: { fen: string, lastAction?: string, moveNumber: number } ``` -------------------------------- ### Ban Chess REST API Server and Client Source: https://github.com/bezalel6/ban-chess.ts/blob/master/docs/SYNCHRONIZATION.md Provides examples for a RESTful API to manage Ban Chess games. The server exposes endpoints for retrieving game state, submitting actions, and accessing game history. The client interacts with these endpoints to load game states and send actions, handling responses and potential errors. ```typescript // Server endpoints app.get('/api/game/:id/state', (req, res) => { const game = getGame(req.params.id); res.json(game.getSyncState()); }); app.post('/api/game/:id/action', (req, res) => { const game = getGame(req.params.id); const { action } = req.body; const result = game.playSerializedAction(action); if (result.success) { res.json({ success: true, newState: game.getSyncState() }); } else { res.status(400).json({ success: false, error: result.error }); } }); app.get('/api/game/:id/history', (req, res) => { const game = getGame(req.params.id); res.json({ actions: game.getActionHistory(), currentState: game.getSyncState() }); }); // Client class BanChessAPIClient { async loadGame(gameId: string) { const response = await fetch(`/api/game/${gameId}/state`); const syncState = await response.json(); this.game.loadFromSyncState(syncState); } async sendAction(gameId: string, action: Action) { const response = await fetch(`/api/game/${gameId}/action`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: BanChess.serializeAction(action) }) }); const result = await response.json(); if (result.success) { this.game.loadFromSyncState(result.newState); } return result; } } ``` -------------------------------- ### Ban Chess Full State Sync (Server/Host) Source: https://github.com/bezalel6/ban-chess.ts/blob/master/docs/SYNCHRONIZATION.md Provides the server-side logic for sending the complete game synchronization state to a newly connected client, including FEN, last action, and move number. ```typescript function handleClientJoin(clientId: string) { const syncState = game.getSyncState(); sendToClient(clientId, { type: 'full-sync', data: syncState }); } ``` -------------------------------- ### Apply Serialized Ban Chess Actions Source: https://github.com/bezalel6/ban-chess.ts/blob/master/docs/SYNCHRONIZATION.md Illustrates how to directly apply a serialized action string (BCN format) to a Ban Chess game instance and check the result of the operation. ```typescript const game = new BanChess(); // Apply a serialized action directly const result = game.playSerializedAction('b:e2e4'); if (result.success) { console.log('Action applied successfully'); } ``` -------------------------------- ### Complete Ban Chess Game Example Source: https://github.com/bezalel6/ban-chess.ts/blob/master/README.md Demonstrates a full game of Ban Chess, including making bans and moves, and checking the game state. It shows how to initialize the game, play actions, log the PGN, and check for checkmate. ```typescript import { BanChess } from 'ban-chess.ts'; const game = new BanChess(); // Full game example with optimal play understanding game.play({ ban: { from: 'e2', to: 'e4' } }); // Black bans e4 game.play({ move: { from: 'd2', to: 'd4' } }); // White plays d4 game.play({ ban: { from: 'e7', to: 'e5' } }); // White bans e5 game.play({ move: { from: 'd7', to: 'd5' } }); // Black plays d5 // Continue playing... console.log(game.pgn()); // Output: "1. {banning: e2e4} d4 {banning: e7e5} d5" // Check game state if (game.inCheckmate()) { console.log(`Checkmate! ${game.turn === 'white' ? 'Black' : 'White'} wins!`); } // Reset for a new game game.reset(); ``` -------------------------------- ### Ban Chess Incremental Updates (Client A) Source: https://github.com/bezalel6/ban-chess.ts/blob/master/docs/SYNCHRONIZATION.md Demonstrates the client-side logic for sending a Ban Chess action over a WebSocket connection after playing a move, using the serialized action format. ```typescript const game = new BanChess(); const action = { ban: { from: 'e2', to: 'e4' } }; const result = game.play(action); if (result.success) { // Send only the action to other clients websocket.send(JSON.stringify({ type: 'action', data: BanChess.serializeAction(action) })); } ``` -------------------------------- ### Ban Chess Incremental Updates (Client B) Source: https://github.com/bezalel6/ban-chess.ts/blob/master/docs/SYNCHRONIZATION.md Shows how a client receives a serialized Ban Chess action via WebSocket, applies it to the game state, and requests a full synchronization if the action fails. ```typescript websocket.on('message', (msg) => { const { type, data } = JSON.parse(msg); if (type === 'action') { const result = game.playSerializedAction(data); if (!result.success) { // Request full sync if action fails requestFullSync(); } } }); ``` -------------------------------- ### Development Commands Source: https://github.com/bezalel6/ban-chess.ts/blob/master/README.md Provides essential bash commands for developing the Ban Chess project. These include installing dependencies, running tests, building the library, and enabling watch mode for continuous development. ```bash # Install dependencies npm install # Run tests npm test # Build the library npm run build # Watch mode for development npm run dev ``` -------------------------------- ### Serialize and Deserialize Ban Chess Actions Source: https://github.com/bezalel6/ban-chess.ts/blob/master/docs/SYNCHRONIZATION.md Demonstrates how to serialize a Ban Chess action object into a compact string format (BCN) and deserialize it back into an action object using the BanChess library. ```typescript import { BanChess } from 'ban-chess.ts'; // Serialize any action const action = { ban: { from: 'e2', to: 'e4' } }; const serialized = BanChess.serializeAction(action); // "b:e2e4" // Deserialize back to action object const deserialized = BanChess.deserializeAction(serialized); ``` -------------------------------- ### Ban Chess WebSocket Server and Client Source: https://github.com/bezalel6/ban-chess.ts/blob/master/docs/SYNCHRONIZATION.md Implements a WebSocket server and client for real-time Ban Chess gameplay. The server manages game state and broadcasts actions to connected clients. The client connects to the server, receives game updates, and sends player actions. It handles initialization, action broadcasting, and error reporting. ```typescript class BanChessServer { private game = new BanChess(); private clients = new Set(); handleConnection(ws: WebSocket) { // Send current state to new client ws.send(JSON.stringify({ type: 'init', data: this.game.getSyncState() })); this.clients.add(ws); ws.on('message', (msg) => { const { action } = JSON.parse(msg); const result = this.game.playSerializedAction(action); if (result.success) { // Broadcast to all clients this.broadcast({ type: 'action', data: action, result: result }); } else { // Send error to sender only ws.send(JSON.stringify({ type: 'error', error: result.error })); } }); } broadcast(message: any) { const data = JSON.stringify(message); this.clients.forEach(client => client.send(data)); } } // Client class BanChessClient { private game = new BanChess(); private ws: WebSocket; connect(url: string) { this.ws = new WebSocket(url); this.ws.on('message', (msg) => { const message = JSON.JSON.parse(msg); switch (message.type) { case 'init': this.game.loadFromSyncState(message.data); break; case 'action': this.game.playSerializedAction(message.data); this.updateUI(); break; case 'error': console.error('Action failed:', message.error); this.requestSync(); break; } }); } sendAction(action: Action) { const serialized = BanChess.serializeAction(action); this.ws.send(JSON.stringify({ action: serialized })); } requestSync() { this.ws.send(JSON.stringify({ type: 'sync-request' })); } } ``` -------------------------------- ### Network Example: WebSocket and REST API Source: https://github.com/bezalel6/ban-chess.ts/blob/master/README.md Illustrates how to use Ban Chess serialization for network communication. Actions can be sent over WebSockets by serializing them, and REST APIs can accept serialized actions in minimal payloads. ```typescript // WebSocket - Send only the action (6-8 bytes) ws.send(BanChess.serializeAction(action)); // REST API - Minimal payload POST /api/game/action { "action": "b:e2e4" } ``` -------------------------------- ### Ban Chess Conflict Resolution Strategy Source: https://github.com/bezalel6/ban-chess.ts/blob/master/docs/SYNCHRONIZATION.md Details a strategy for resolving synchronization conflicts in Ban Chess. When an action fails, indicating a desynchronization, the client requests the authoritative game state, resets its local state, and then resumes play, ensuring consistency across all players. ```typescript class ConflictResolver { async handleActionFailure(action: SerializedAction) { console.log(`Action ${action} failed, requesting sync...`); // Get authoritative state const syncState = await this.requestAuthoritativeState(); // Reset local game this.game.loadFromSyncState(syncState); // Notify user this.notifyUser('Game synchronized with server'); } } ``` -------------------------------- ### Recommended package.json Scripts (JSON) Source: https://github.com/bezalel6/ban-chess.ts/blob/master/CLAUDE.md Lists essential npm scripts for managing the Ban Chess project within `package.json`. These scripts cover building the project, running tests (including watch and coverage modes), linting, type checking, and development mode with file watching. ```JSON { "scripts": { "build": "tsc", "test": "jest", "test:watch": "jest --watch", "test:coverage": "jest --coverage", "lint": "eslint . --ext .ts", "typecheck": "tsc --noEmit", "dev": "tsc --watch" } } ``` -------------------------------- ### Clone Ban Chess Repository with GUI Source: https://github.com/bezalel6/ban-chess.ts/blob/master/README.md This command clones the ban-chess.ts repository, including the GUI as a recursive submodule. This ensures you have both the library and its associated graphical interface for local development. ```bash git clone --recursive https://github.com/bezalel6/ban-chess.ts.git ``` -------------------------------- ### Ban Chess Type Definitions (TypeScript) Source: https://github.com/bezalel6/ban-chess.ts/blob/master/CLAUDE.md Specifies the TypeScript types used within the Ban Chess library. It defines `Action` as either a `Move` or a `Ban`, and details the structure of `Move` (from, to, promotion) and `Ban` (from, to), noting that bans are square-to-square and do not include promotion. ```TypeScript type Action = { move: Move } | { ban: Ban }; interface Move { from: string; to: string; promotion?: 'q' | 'r' | 'b' | 'n'; } interface Ban { from: string; to: string; // No promotion field - bans apply to ALL moves from-to } ``` -------------------------------- ### Ban Chess Serialization API Source: https://github.com/bezalel6/ban-chess.ts/blob/master/README.md Details the Ban Chess API for serializing and deserializing game actions, enabling efficient network communication. It includes methods to serialize/deserialize actions, play serialized actions, get/load sync states, and retrieve/replay action history. ```typescript // Serialize actions const serialized = BanChess.serializeAction({ ban: { from: 'e2', to: 'e4' } }); // Returns: "b:e2e4" // Deserialize actions const action = BanChess.deserializeAction('m:d2d4'); // Returns: { move: { from: 'd2', to: 'd4' } } // Apply serialized actions directly game.playSerializedAction('b:e2e4'); // Get sync state for network transmission const syncState = game.getSyncState(); // Returns: { fen: string, lastAction?: string, moveNumber: number } // Load from sync state game.loadFromSyncState(syncState); // Get complete action history const history = game.getActionHistory(); // Returns: ['b:e2e4', 'm:d2d4', 'b:e7e5', 'm:d7d5'] // Replay game from actions const game = BanChess.replayFromActions(history); ``` -------------------------------- ### Ban Chess Core API Design (TypeScript) Source: https://github.com/bezalel6/ban-chess.ts/blob/master/CLAUDE.md Defines the core `BanChess` class structure, extending chess.ts. It includes methods for playing actions (moves or bans), querying game state like next action type and legal moves/bans, and properties for tracking turns and current bans. ```TypeScript class BanChess { constructor(fen?: string, pgn?: string); // Core method handling both bans and moves play(action: Action): ActionResult; // Query methods nextActionType(): 'ban' | 'move'; legalMoves(): Move[]; // Excludes banned moves legalBans(): Move[]; // Opponent moves that can be banned // State properties turn: 'white' | 'black'; currentBannedMove: Ban | null; // State management fen(): string; // Returns extended FEN with ban state field pgn(): string; // Returns PGN with ban annotations } ``` -------------------------------- ### Ban Chess Visual Feedback Classes Source: https://github.com/bezalel6/ban-chess.ts/blob/master/CLAUDE.md CSS classes used for visual feedback in the Ban Chess project. These classes manage the highlighting of selected squares, legal moves, last moves, banned moves, selectable pieces, and inactive squares, ensuring clear user interaction. ```CSS .square-selected { /* Currently selected square (with scale transform) */ } .square-legal-move { /* Valid target squares (green border) */ } .square-last-move-from { /* Previous move highlighting */ } .square-last-move-to { /* Previous move highlighting */ } .square-banned { /* Shows the currently banned move */ } .square-can-select { /* Hoverable pieces that can be selected */ } .square-inactive { /* Non-selectable squares when a piece is selected (opacity: 0.4) */ } ``` -------------------------------- ### Ban Chess Helper Functions Source: https://github.com/bezalel6/ban-chess.ts/blob/master/CLAUDE.md Essential helper functions for Ban Chess: `isLegalTarget` to check valid move/ban targets, `canSelectSquare` to determine if a piece/ban can be selected, and `getPieceAtSquare` to handle board orientation and piece retrieval. These functions are crucial for maintaining consistent game logic and board state. ```TypeScript function isLegalTarget(square): boolean; function canSelectSquare(square): boolean; function getPieceAtSquare(displayRank, displayFile): any; ``` -------------------------------- ### BanChess Class Definition Source: https://github.com/bezalel6/ban-chess.ts/blob/master/README.md Defines the main BanChess class, extending chess.ts with ban mechanics. It includes methods for playing moves and bans, querying legal moves and bans, managing game state, and handling game status. ```typescript class BanChess { constructor(fen?: string, pgn?: string); // Core method handling both bans and moves play(action: Action): ActionResult; // Query methods nextActionType(): 'ban' | 'move'; legalMoves(): Move[]; // Excludes banned moves legalBans(): Move[]; // Opponent moves that can be banned // State properties turn: 'white' | 'black'; currentBannedMove: Ban | null; // State management fen(): string; // Returns extended FEN with ban state field pgn(): string; // Returns PGN with ban annotations history(): HistoryEntry[]; reset(): void; // Game status inCheck(): boolean; inCheckmate(): boolean; inStalemate(): boolean; gameOver(): boolean; } ``` -------------------------------- ### Ban Chess Type Definitions Source: https://github.com/bezalel6/ban-chess.ts/blob/master/README.md Provides type definitions for actions, moves, bans, and action results within the Ban Chess game. An 'Action' can be either a 'move' or a 'ban', with 'Ban' specifically defining a range of moves that are disallowed. ```typescript type Action = { move: Move } | { ban: Ban }; interface Move { from: string; to: string; promotion?: 'q' | 'r' | 'b' | 'n'; } interface Ban { from: string; to: string; // No promotion field - bans apply to ALL moves from-to } interface ActionResult { success: boolean; action?: Action; san?: string; error?: string; newFen?: string; gameOver?: boolean; checkmate?: boolean; stalemate?: boolean; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.