Restructured project from nested workspace pattern to flat single-repo layout. This eliminates redundant nesting and consolidates all project files under version control. ## Migration Summary **Before:** ``` alex/ (workspace, not versioned) ├── chess-game/ (git repo) │ ├── js/, css/, tests/ │ └── index.html └── docs/ (planning, not versioned) ``` **After:** ``` alex/ (git repo, everything versioned) ├── js/, css/, tests/ ├── index.html ├── docs/ (project documentation) ├── planning/ (historical planning docs) ├── .gitea/ (CI/CD) └── CLAUDE.md (configuration) ``` ## Changes Made ### Structure Consolidation - Moved all chess-game/ contents to root level - Removed redundant chess-game/ subdirectory - Flattened directory structure (eliminated one nesting level) ### Documentation Organization - Moved chess-game/docs/ → docs/ (project documentation) - Moved alex/docs/ → planning/ (historical planning documents) - Added CLAUDE.md (workspace configuration) - Added IMPLEMENTATION_PROMPT.md (original project prompt) ### Version Control Improvements - All project files now under version control - Planning documents preserved in planning/ folder - Merged .gitignore files (workspace + project) - Added .claude/ agent configurations ### File Updates - Updated .gitignore to include both workspace and project excludes - Moved README.md to root level - All import paths remain functional (relative paths unchanged) ## Benefits ✅ **Simpler Structure** - One level of nesting removed ✅ **Complete Versioning** - All documentation now in git ✅ **Standard Layout** - Matches open-source project conventions ✅ **Easier Navigation** - Direct access to all project files ✅ **CI/CD Compatible** - All workflows still functional ## Technical Validation - ✅ Node.js environment verified - ✅ Dependencies installed successfully - ✅ Dev server starts and responds - ✅ All core files present and accessible - ✅ Git repository functional ## Files Preserved **Implementation Files:** - js/ (3,517 lines of code) - css/ (4 stylesheets) - tests/ (87 test cases) - index.html - package.json **CI/CD Pipeline:** - .gitea/workflows/ci.yml - .gitea/workflows/release.yml **Documentation:** - docs/ (12+ documentation files) - planning/ (historical planning materials) - README.md **Configuration:** - jest.config.js, babel.config.cjs, playwright.config.js - .gitignore (merged) - CLAUDE.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
137 lines
3.8 KiB
JavaScript
137 lines
3.8 KiB
JavaScript
/**
|
|
* @file pawn-implementation.js
|
|
* @description Complete example implementation of the Pawn class
|
|
* Use this as a reference for implementing other pieces
|
|
*/
|
|
|
|
import Piece from '../models/Piece.js';
|
|
import { DIRECTIONS } from '../utils/Constants.js';
|
|
import { isValidPosition } from '../utils/Helpers.js';
|
|
|
|
/**
|
|
* @class Pawn
|
|
* @extends Piece
|
|
* @description Implements pawn movement rules
|
|
*
|
|
* Rules:
|
|
* - Moves forward one square (or two from starting position)
|
|
* - Captures diagonally forward
|
|
* - En passant capture
|
|
* - Promotion on reaching opposite end
|
|
*/
|
|
class Pawn extends Piece {
|
|
constructor(color, position) {
|
|
super(color, position, 'pawn');
|
|
|
|
/**
|
|
* @property {number} _direction - Movement direction (-1 for white, 1 for black)
|
|
*/
|
|
this._direction = color === 'white' ? -1 : 1;
|
|
|
|
/**
|
|
* @property {number} _startRow - Starting row (6 for white, 1 for black)
|
|
*/
|
|
this._startRow = color === 'white' ? 6 : 1;
|
|
}
|
|
|
|
/**
|
|
* Gets all valid moves for this pawn
|
|
*
|
|
* @param {Board} board - Current board state
|
|
* @returns {Array<Object>} Array of valid positions
|
|
*/
|
|
getValidMoves(board) {
|
|
const moves = [];
|
|
const { row, col } = this.position;
|
|
|
|
// One square forward
|
|
const oneForward = { row: row + this._direction, col };
|
|
if (isValidPosition(oneForward.row, oneForward.col)) {
|
|
const piece = board.getPieceAt(oneForward);
|
|
if (!piece) {
|
|
moves.push(oneForward);
|
|
|
|
// Two squares forward (only from starting position)
|
|
if (!this.hasMoved && row === this._startRow) {
|
|
const twoForward = { row: row + (2 * this._direction), col };
|
|
const pieceTwoForward = board.getPieceAt(twoForward);
|
|
if (!pieceTwoForward) {
|
|
moves.push(twoForward);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Diagonal captures
|
|
const captureOffsets = [-1, 1];
|
|
for (const offset of captureOffsets) {
|
|
const capturePos = { row: row + this._direction, col: col + offset };
|
|
if (isValidPosition(capturePos.row, capturePos.col)) {
|
|
const piece = board.getPieceAt(capturePos);
|
|
if (piece && piece.color !== this.color) {
|
|
moves.push(capturePos);
|
|
}
|
|
}
|
|
}
|
|
|
|
// TODO: Add en passant logic
|
|
// Check if adjacent square has enemy pawn that just moved two squares
|
|
// Add the en passant capture move if valid
|
|
|
|
return moves;
|
|
}
|
|
|
|
/**
|
|
* Checks if this pawn can be promoted
|
|
*
|
|
* @returns {boolean} True if on promotion row
|
|
*/
|
|
canPromote() {
|
|
const promotionRow = this.color === 'white' ? 0 : 7;
|
|
return this.position.row === promotionRow;
|
|
}
|
|
|
|
/**
|
|
* Clones this pawn
|
|
*
|
|
* @returns {Pawn} Cloned pawn
|
|
*/
|
|
clone() {
|
|
const clone = new Pawn(this.color, { ...this.position });
|
|
clone.hasMoved = this.hasMoved;
|
|
return clone;
|
|
}
|
|
}
|
|
|
|
export default Pawn;
|
|
|
|
/**
|
|
* IMPLEMENTATION NOTES:
|
|
*
|
|
* 1. Direction handling:
|
|
* - White pawns move "up" the board (row decreases)
|
|
* - Black pawns move "down" the board (row increases)
|
|
* - Use _direction multiplier to handle both cases
|
|
*
|
|
* 2. Two-square move:
|
|
* - Only allowed from starting position
|
|
* - Must check that both squares are empty
|
|
* - Sets up potential en passant capture
|
|
*
|
|
* 3. En passant:
|
|
* - Complex special move requiring game state
|
|
* - Need to check if adjacent pawn just moved two squares
|
|
* - Capture happens "in passing" on empty square
|
|
*
|
|
* 4. Promotion:
|
|
* - Handled by game controller, not move validation
|
|
* - Pawn reaches opposite end (row 0 for white, row 7 for black)
|
|
* - Player chooses replacement piece (usually queen)
|
|
*
|
|
* 5. Common bugs to avoid:
|
|
* - Forgetting pawns can't move backward
|
|
* - Allowing diagonal moves when no capture
|
|
* - Allowing capture forward
|
|
* - Forgetting to check if two-square path is clear
|
|
*/
|