Extract a DOM-free rules core from makeMove and move generation

Ouverte
#31 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
35/100
Type d'issue
Refactorisation
Clarté
Clairement spécifiée
Activité
Active
Stack technique
javascript
Domaine
backend, game-dev

Piste de recherche

Read js/game.js at makeMove (143-276) and move generation (334-461), then check how js/ai.js uses _getAllLegalMoves (132-139). Start by adding the listed undo, SAN, and perft tests; run them with npm test. Done means moves apply to a board copy without DOM access, special-move edits share one implementation, and the stated perft counts pass.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

severity: medium tech-debt

Summary

makeMove is about 130 lines mixing rule execution, the undo snapshot, notation, game-end detection, rendering, sound and persistence, all against module-level state. Move generation and check detection read the same globals. Special-move rules therefore exist in three places that must change together.

Where

  • js/game.js:143-276 (makeMove)
  • js/game.js:334-461 (generateLegalMovesForPiece, including a hand-copied simulation of en passant and castling at :414-444)
  • js/game.js:5-20 (module state and DOM lookups at load)
  • js/ai.js:132-139 (_getAllLegalMoves returns [])

Impact

js/game.js is the most-changed source file. The ordering dependencies inside makeMove produced #24, and the generator and canCastle disagreeing produced #22. Two roadmap features are blocked by this shape: a promotion choice needs the move to pause for a dialog, and an AI search needs to apply moves to a board copy without touching the DOM, sound or storage.

Suggested fix

Tests first: undo round trips, SAN for capture, check, mate, castle and en passant, and perft counts from the start position (20, 400, 8902 at depths 1 to 3).

  1. Extract a pure applyMove(state, from, to, promotion) that returns the new board, king positions, en passant target and move record. makeMove calls it and keeps the UI work.
  2. Extract the UI tail (render, status, history, sound, save) into its own function.
  3. Pass promotion as a parameter, defaulting to queen.
  4. Change generateLegalMovesForPiece and canCastle to take a state object, defaulting to the globals so callers keep working.
  5. Replace the hand-rolled simulation at :414-444 with applyMove.

Each step leaves the app working.

Acceptance criteria

  • Legal moves can be generated and a move applied on a board copy with no DOM
  • Special-move board edits live in one place
  • Perft counts pass

Getting started

  • Relevant files: js/game.js, js/ai.js
  • How to run tests: npm install, then npm test and npm run lint
  • Related docs: docs/ARCHITECTURE.md, .github/CONTRIBUTING.md

Filed by repo-audit/full-audit at 8a2c86c. Severity: medium. Effort: L. audit-key: tech-debt|js/game.js|makeMove

Langage dominant
JavaScript
Étoiles
4
Forks
2
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de TMHSDigital/Static_Chess

Toutes les issues de TMHSDigital/Static_Chess

Issues similaires

Plus d'issues JavaScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.