# Chess Game Test Data (PGN Format)

This directory contains PGN (Portable Game Notation) files of complete chess games for testing game replay, move validation, and analysis features.

## PGN Format

PGN includes:
- Game metadata (Event, Site, Date, Round, White, Black, Result)
- Move sequences in standard algebraic notation
- Optional annotations and variations

## Available Games

### Famous Short Games

#### Fool's Mate
**File**: `fools-mate.pgn`
```pgn
[Event "Fool's Mate Example"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "0-1"]

1. f3 e5 2. g4 Qh4# 0-1
```
**Description**: Shortest possible checkmate (2 moves)
**Moves**: 2
**Result**: Black wins

---

#### Scholar's Mate
**File**: `scholars-mate.pgn`
```pgn
[Event "Scholar's Mate Example"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "1-0"]

1. e4 e5 2. Bc4 Nc6 3. Qh5 Nf6 4. Qxf7# 1-0
```
**Description**: Four-move checkmate
**Moves**: 4
**Result**: White wins

---

### Historic Masterpieces

#### The Immortal Game
**File**: `immortal-game.pgn`
```pgn
[Event "Casual Game"]
[Site "London"]
[Date "1851.06.21"]
[Round "?"]
[White "Adolf Anderssen"]
[Black "Lionel Kieseritzky"]
[Result "1-0"]

1. e4 e5 2. f4 exf4 3. Bc4 Qh4+ 4. Kf1 b5 5. Bxb5 Nf6 6. Nf3 Qh6
7. d3 Nh5 8. Nh4 Qg5 9. Nf5 c6 10. g4 Nf6 11. Rg1 cxb5 12. h4 Qg6
13. h5 Qg5 14. Qf3 Ng8 15. Bxf4 Qf6 16. Nc3 Bc5 17. Nd5 Qxb2
18. Bd6 Bxg1 19. e5 Qxa1+ 20. Ke2 Na6 21. Nxg7+ Kd8 22. Qf6+ Nxf6
23. Be7# 1-0
```
**Description**: Famous 1851 game with brilliant sacrifices
**Moves**: 23
**Result**: White wins
**Notable**: Multiple piece sacrifices leading to checkmate

---

#### The Opera Game
**File**: `opera-game.pgn`
```pgn
[Event "Paris Opera"]
[Site "Paris"]
[Date "1858.??.??"]
[Round "?"]
[White "Paul Morphy"]
[Black "Duke of Brunswick and Count Isouard"]
[Result "1-0"]

1. e4 e5 2. Nf3 d6 3. d4 Bg4 4. dxe5 Bxf3 5. Qxf3 dxe5 6. Bc4 Nf6
7. Qb3 Qe7 8. Nc3 c6 9. Bg5 b5 10. Nxb5 cxb5 11. Bxb5+ Nbd7
12. O-O-O Rd8 13. Rxd7 Rxd7 14. Rd1 Qe6 15. Bxd7+ Nxd7 16. Qb8+ Nxb8
17. Rd8# 1-0
```
**Description**: Morphy's famous game at the Paris Opera
**Moves**: 17
**Result**: White wins
**Notable**: Brilliant tactical play, queen sacrifice

---

### Test Cases for Special Moves

#### En Passant Capture
**File**: `en-passant-game.pgn`
```pgn
[Event "En Passant Test"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "*"]

1. e4 a6 2. e5 d5 3. exd6 *
```
**Description**: Demonstrates en passant capture
**Moves**: 3
**Result**: Unfinished
**Test**: En passant on move 3

---

#### Castling Both Sides
**File**: `castling-game.pgn`
```pgn
[Event "Castling Test"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "*"]

1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. O-O Nf6 5. d3 d6 6. Nc3 O-O *
```
**Description**: Both sides castle kingside
**Moves**: 6
**Result**: Unfinished
**Test**: Castling validation

---

#### Pawn Promotion
**File**: `pawn-promotion-game.pgn`
```pgn
[Event "Promotion Test"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "*"]

1. e4 d5 2. exd5 Qxd5 3. Nc3 Qe6+ 4. Be2 Qg6 5. Nf3 Qxg2 6. Rg1 Qh3
7. Rg3 Qh6 8. Rg8+ Qf8 9. Rxf8# *
```
**Description**: Game with pawn promotion scenario
**Moves**: 9
**Result**: Unfinished

---

### Draw Test Cases

#### Stalemate
**File**: `stalemate-game.pgn`
```pgn
[Event "Stalemate Test"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "1/2-1/2"]

1. e3 a5 2. Qh5 Ra6 3. Qxa5 h5 4. Qxc7 Rah6 5. h4 f6 6. Qxd7+ Kf7
7. Qxb7 Qd3 8. Qxb8 Qh7 9. Qxc8 Kg6 10. Qe6 1/2-1/2
```
**Description**: Game ending in stalemate
**Moves**: 10
**Result**: Draw
**Test**: Stalemate detection

---

#### Insufficient Material
**File**: `insufficient-material.pgn`
```pgn
[Event "Insufficient Material Test"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "1/2-1/2"]

1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Bxc6 dxc6 5. Nxe5 Qd4 6. Nxf7 Qxe4+
7. Qe2 Qxe2# 1/2-1/2
```
**Description**: Game ending with insufficient material
**Result**: Draw

---

#### Threefold Repetition
**File**: `threefold-repetition.pgn`
```pgn
[Event "Threefold Repetition Test"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "1/2-1/2"]

1. Nf3 Nf6 2. Ng1 Ng8 3. Nf3 Nf6 4. Ng1 Ng8 5. Nf3 1/2-1/2
```
**Description**: Threefold repetition draw
**Moves**: 5
**Result**: Draw
**Test**: Repetition detection

---

### Opening Repertoire

#### Italian Game
**File**: `italian-game.pgn`
```pgn
[Event "Italian Opening"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "*"]

1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+
7. Nc3 Nxe4 8. O-O Bxc3 9. d5 *
```
**Description**: Italian Game main line
**Moves**: 9

---

#### Sicilian Defense
**File**: `sicilian-defense.pgn`
```pgn
[Event "Sicilian Defense"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "*"]

1. e4 c5 2. Nf3 d6 3. d4 cxd4 4. Nxd4 Nf6 5. Nc3 a6 6. Be3 e5
7. Nb3 Be6 8. f3 *
```
**Description**: Sicilian Defense, Najdorf Variation
**Moves**: 8

---

#### Queen's Gambit
**File**: `queens-gambit.pgn`
```pgn
[Event "Queen's Gambit"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "*"]

1. d4 d5 2. c4 e6 3. Nc3 Nf6 4. Bg5 Be7 5. e3 O-O 6. Nf3 h6
7. Bh4 b6 8. cxd5 *
```
**Description**: Queen's Gambit Declined
**Moves**: 8

---

### Edge Case Games

#### Maximum Moves (Longest Game)
**File**: `long-game.pgn`
```
[Event "Long Game Test"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "*"]

[100+ moves for endurance testing]
```
**Description**: Very long game for stress testing
**Moves**: 100+

---

#### All Piece Types Promoted
**File**: `all-promotions.pgn`
```pgn
[Event "All Promotions Test"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "White"]
[Black "Black"]
[Result "*"]

[Game demonstrating promotion to Q, R, B, N]
```
**Description**: Tests all promotion piece types

---

## Usage in Tests

```javascript
import { loadPGN } from '../utils/fixtures';
import { Chess } from 'chess.js';

test('Replay Immortal Game', () => {
  const pgn = loadPGN('immortal-game');
  const chess = new Chess();

  chess.loadPgn(pgn);
  expect(chess.isCheckmate()).toBe(true);
});

test('Validate all moves in Opera Game', () => {
  const pgn = loadPGN('opera-game');
  const chess = new Chess();

  const result = chess.loadPgn(pgn);
  expect(result).toBe(true); // All moves valid
});
```

## Test Categories

### Functional Tests
- `fools-mate.pgn`, `scholars-mate.pgn` - Basic checkmate
- `en-passant-game.pgn` - Special moves
- `castling-game.pgn` - Castling validation
- `pawn-promotion-game.pgn` - Pawn promotion

### Edge Cases
- `stalemate-game.pgn` - Draw by stalemate
- `threefold-repetition.pgn` - Draw by repetition
- `insufficient-material.pgn` - Draw by insufficient material
- `long-game.pgn` - Endurance testing

### Historic Games
- `immortal-game.pgn` - Tactics and sacrifices
- `opera-game.pgn` - Brilliant play
- Famous games for regression testing

## Adding New Games

1. Create `.pgn` file with proper metadata
2. Validate PGN using chess.js
3. Add description to this README
4. Categorize appropriately
5. Create corresponding test cases

## PGN Validation

```javascript
import { Chess } from 'chess.js';

const isValidPGN = (pgn) => {
  const chess = new Chess();
  return chess.loadPgn(pgn);
};
```

## Resources

- PGN Specification: https://www.chessclub.com/help/PGN-spec
- Chess.js: https://github.com/jhlywa/chess.js
- Online PGN Viewer: https://www.chess.com/analysis
- Game Database: https://www.pgnmentor.com/
