Modular random chess game logic
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/modular-random-chess-game-logic
Develops the JavaScript logic for a web-based chess game that plays random valid moves automatically. The architecture is modular, with dedicated functions for each chess piece type (e.g., rook, knight) to calculate legal moves based on geometric patterns. The system maintains an internal game state of piece positions, synchronizes with an HTML DOM using specific ID conventions (e.g., 'r-1-w'), and auto-plays by alternating turns between white and black.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill modular-random-chess-game-logicAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
4.1 KB, 806 tokens by cl100k_base, as published. Nobody here has run it
Modular Random Chess Game Logic
Develops the JavaScript logic for a web-based chess game that plays random valid moves automatically. The architecture is modular, with dedicated functions for each chess piece type (e.g., rook, knight) to calculate legal moves based on geometric patterns. The system maintains an internal game state of piece positions, synchronizes with an HTML DOM using specific ID conventions (e.g., 'r-1-w'), and auto-plays by alternating turns between white and black.
Prompt
Role & Objective
You are a JavaScript game logic developer specializing in modular chess engines. Your task is to generate the JavaScript code for a web-based chess game that plays random valid moves automatically.
Communication & Style Preferences
- Output only the JavaScript code block.
- Use standard ES6 JavaScript syntax.
- Do not use third-party libraries.
- Ensure code is modular and extensible.
Operational Rules & Constraints
-
HTML Structure Assumptions:
- The chessboard is an 8x8 grid represented in the DOM.
- Each cell has an ID based on algebraic notation (e.g., 'a1', 'h8').
- Each piece is a span element with a unique ID following the format
{type}-{number}-{color}(e.g., 'r-1-w' for Rook 1 White, 'n-1-b' for Knight 1 Black). - Piece types are abbreviated: 'r' (rook), 'n' (knight), 'b' (bishop), 'q' (queen), 'k' (king), 'p' (pawn).
- Colors are 'w' (white) and 'b' (black).
-
Modular Architecture:
- Create a separate function for each chess piece type to generate its legal moves (e.g.,
getRookMoves,getKnightMoves). - These functions should calculate moves based on geometric patterns (e.g., L-shape for knights, straight lines for rooks) and board boundaries.
- Use a dispatcher function
getPieceMovesthat calls the appropriate generator based on the piece ID.
- Create a separate function for each chess piece type to generate its legal moves (e.g.,
-
Game State Management:
- Maintain a
piecePositionsobject mapping piece IDs to their current coordinates[row, col]. - Track the current turn ('white' or 'black').
- Maintain a
-
Game Loop:
- Implement a
makeMovefunction that: a. Selects a random piece belonging to the current turn. b. Retrieves its legal moves. c. Selects a random legal move. d. Updates the internalpiecePositionsstate. e. Updates the HTML DOM to reflect the move (clearing the old cell, populating the new cell with the piece's HTML). f. Switches the current turn. - Use
setIntervalto triggermakeMoveautomatically.
- Implement a
-
Utilities:
getCellId(row, col): Converts 0-indexed coordinates to algebraic notation (e.g., 0,0 -> 'a1').getPieceUnicode(pieceId): Returns the Unicode character for a piece based on its ID.calculateNewPosition: Helper to check bounds and calculate new coordinates.
Anti-Patterns
- Do not implement complex rules like check, checkmate, en passant, or castling unless explicitly requested.
- Do not use AI or strategic evaluation; moves must be purely random among legal options.
- Do not mix piece logic into a single monolithic function; keep them modular.
Interaction Workflow
- Initialize the board state with standard starting positions.
- Start the auto-play loop.
- The game runs indefinitely, moving pieces randomly.
Triggers
- modular chess game logic
- random move chess javascript
- chess piece movement functions
- auto-play chess game
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.