A console-based chess game implemented in TypeScript with full chess rules, input validation, and comprehensive testing.
- Full Chess Implementation: Complete chess rules including piece movement, capturing, and pawn promotion
- Console-Based Interface: Beautiful CLI rendering with colors and formatted board display
- Input Validation: Supports both algebraic notation (e.g., "e2 e4") and numeric coordinates (e.g., "1,4 3,4")
- Game State Management: Turn-based gameplay with proper player switching and game status tracking
- Comprehensive Testing: Extensive unit tests covering all game logic and edge cases
- TypeScript: Fully typed codebase for better development experience and reliability
- Error Handling: Robust error handling with user-friendly error messages
-
Clone the repository:
git clone https://github.com/anshour/chess-game-console.git cd chess-game-console
-
Install dependencies:
npm install
-
Build the project:
npm run build
-
Start the game
npm start
- Enter Player Names: When prompted, enter names for both white and black players
- Make Moves: Enter moves using one of the supported formats:
- Algebraic notation:
e2 e4
,e2,e4
,a1-h8
- Numeric coordinates:
1,4 3,4
(row,column format)
- Algebraic notation:
- Pawn Promotion: When a pawn reaches the opposite end, you'll be prompted to choose the promotion piece
- Game End: The game ends when a king is captured
e2 e4
- Move pawn from e2 to e4a1,h8
- Move piece from a1 to h81,4 3,4
- Move piece from row 1, column 4 to row 3, column 4
npm start
- Run the compiled gamenpm run build
- Compile TypeScript to JavaScriptnpm run build:watch
- Watch mode compilationnpm run build:release
- Clean build for releasenpm run test
- Run all unit testsnpm run test:watch
- Run tests in watch modenpm run lint
- Lint the codebasenpm run prettier
- Format codenpm run prettier:check
- Check code formattingnpm run clean
- Clean build artifacts
src/
├── cli/ # Command-line interface components
│ ├── cli-controller.ts # Main game controller
│ ├── input-handler.ts # User input handling
│ └── renderer.ts # Console output rendering
├── core/ # Core game logic
│ ├── board.ts # Chess board implementation
│ ├── game.ts # Game state management
│ ├── player.ts # Player representation
│ ├── position.ts # Board position utilities
│ ├── types.ts # Type definitions
│ └── pieces/ # Chess piece implementations
│ ├── piece.ts # Base piece class
│ ├── pawn.ts # Pawn piece logic
│ ├── rook.ts # Rook piece logic
│ ├── knight.ts # Knight piece logic
│ ├── bishop.ts # Bishop piece logic
│ ├── queen.ts # Queen piece logic
│ └── king.ts # King piece logic
├── utils/
│ └── enums.ts # Game enumerations
└── main.ts # Application entry point
__tests__/ # Test suite
├── unit/ # Unit tests
├── test-helpers.ts # Test utilities
└── vitest.config.ts # Test configuration
- TypeScript - Main programming language
- Node.js - Runtime environment
- Vitest - Testing framework
- ESLint - Code linting
- Prettier - Code formatting
- Chalk - Terminal colors
- CLI-Table3 - Formatted table display
- Readline-Sync - Synchronous input handling
The project includes comprehensive unit tests covering:
- Game logic and rules
- Piece movement validation
- Board state management
- Player turn handling
- Pawn promotion mechanics
- Game end conditions
- Error handling scenarios
Run tests with:
npm test
For watch mode during development:
npm run test:watch
The project maintains high code quality through:
- TypeScript for type safety
- ESLint for code linting
- Prettier for consistent formatting
- Comprehensive tests with high coverage
- Clear project structure and separation of concerns
This implementation follows standard chess rules:
- Piece Movement: All pieces move according to standard chess rules
- Turn-Based: Players alternate turns (white goes first)
- Capturing: Pieces can capture opponent pieces by moving to their square
- Pawn Promotion: Pawns reaching the opposite end must be promoted to Queen, Rook, Bishop, or Knight
- Game End: Game ends when a king is captured (simplified ruleset - no checkmate detection)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Run tests (
npm test
) - Run linting (
npm run lint
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request