# Chess Position Test Data

This directory contains FEN (Forsyth-Edwards Notation) strings for various chess positions used in testing.

## FEN Format

FEN notation describes a chess position using 6 fields:
1. Piece placement (from white's perspective, rank 8 to rank 1)
2. Active color (w = white, b = black)
3. Castling availability (KQkq)
4. En passant target square
5. Halfmove clock (for 50-move rule)
6. Fullmove number

Example: `rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1`

## Available Positions

### Initial Position
**File**: `initial-position.fen`
```
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
```
**Description**: Standard starting position

---

### Checkmate Positions

#### Fool's Mate
**File**: `fools-mate.fen`
```
rnb1kbnr/pppp1ppp/8/4p3/6Pq/5P2/PPPPP2P/RNBQKBNR w KQkq - 1 3
```
**Description**: Shortest possible checkmate (2 moves)

#### Scholar's Mate
**File**: `scholars-mate.fen`
```
r1bqkb1r/pppp1Qpp/2n2n2/4p3/2B1P3/8/PPPP1PPP/RNB1K1NR b KQkq - 0 4
```
**Description**: Four-move checkmate pattern

#### Back Rank Mate
**File**: `back-rank-mate.fen`
```
6k1/5ppp/8/8/8/8/5PPP/4R1K1 b - - 0 1
```
**Description**: Classic back rank mate pattern

#### Smothered Mate
**File**: `smothered-mate.fen`
```
5rk1/5ppp/8/8/8/8/5PPP/4R1K1 b - - 0 1
```
**Description**: King trapped by own pieces

---

### Stalemate Positions

#### Basic Stalemate
**File**: `basic-stalemate.fen`
```
k7/8/1Q6/8/8/8/8/7K b - - 0 1
```
**Description**: Black king has no legal moves but not in check

#### Pawn Stalemate
**File**: `pawn-stalemate.fen`
```
7k/5K2/6P1/8/8/8/8/8 b - - 0 1
```
**Description**: Stalemate with pawn blockage

---

### Special Move Positions

#### En Passant Available
**File**: `en-passant-available.fen`
```
rnbqkbnr/ppp1pppp/8/3pP3/8/8/PPPP1PPP/RNBQKBNR w KQkq d6 0 2
```
**Description**: White can capture en passant on d6

#### Castling Positions
**File**: `castling-kingside.fen`
```
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQK2R w KQkq - 0 1
```
**Description**: White can castle kingside

**File**: `castling-queenside.fen`
```
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/R3KBNR w KQkq - 0 1
```
**Description**: White can castle queenside

**File**: `castling-both.fen`
```
r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R w KQkq - 0 1
```
**Description**: Both sides can castle both ways

#### Pawn Promotion
**File**: `pawn-promotion.fen`
```
4k3/P7/8/8/8/8/8/4K3 w - - 0 1
```
**Description**: White pawn ready to promote

---

### Complex Middlegame Positions

#### Italian Game
**File**: `italian-game.fen`
```
r1bqkbnr/pppp1ppp/2n5/4p3/2B1P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3
```
**Description**: Classic Italian opening position

#### Sicilian Defense
**File**: `sicilian-defense.fen`
```
rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2
```
**Description**: Sicilian Defense after 1.e4 c5

#### Queen's Gambit
**File**: `queens-gambit.fen`
```
rnbqkbnr/ppp1pppp/8/3p4/2PP4/8/PP2PPPP/RNBQKBNR b KQkq c3 0 2
```
**Description**: Queen's Gambit position

---

### Endgame Positions

#### King and Queen vs King
**File**: `kq-vs-k.fen`
```
8/8/8/8/8/3k4/3Q4/3K4 w - - 0 1
```
**Description**: Basic queen endgame

#### King and Rook vs King
**File**: `kr-vs-k.fen`
```
8/8/8/8/8/3k4/3R4/3K4 w - - 0 1
```
**Description**: Basic rook endgame

#### Pawn Endgame
**File**: `pawn-endgame.fen`
```
8/5k2/5P2/5K2/8/8/8/8 w - - 0 1
```
**Description**: King and pawn vs king

#### Opposite Color Bishops
**File**: `opposite-bishops.fen`
```
8/5k2/8/3b4/8/8/3B4/5K2 w - - 0 1
```
**Description**: Bishops on opposite colors (often drawn)

---

### Edge Cases

#### Three-Fold Repetition Setup
**File**: `threefold-setup.fen`
```
r1bqkb1r/pppp1ppp/2n2n2/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R w KQkq - 4 4
```
**Description**: Position for testing threefold repetition

#### Fifty-Move Rule
**File**: `fifty-move-rule.fen`
```
8/8/8/8/8/3k4/3Q4/3K4 w - - 99 100
```
**Description**: Near fifty-move rule threshold

#### Insufficient Material (KB vs K)
**File**: `insufficient-kb-vs-k.fen`
```
8/8/8/8/8/3k4/3B4/3K4 w - - 0 1
```
**Description**: Draw due to insufficient material

#### Insufficient Material (KN vs K)
**File**: `insufficient-kn-vs-k.fen`
```
8/8/8/8/8/3k4/3N4/3K4 w - - 0 1
```
**Description**: Draw due to insufficient material

---

### Famous Game Positions

#### Immortal Game (Anderssen vs Kieseritzky, 1851)
**File**: `immortal-game-final.fen`
```
r1b1kb1r/p2pqppp/5n2/1p2p3/2B1P3/1Q6/PPPPNPPP/RNB1K2R w KQkq - 0 1
```
**Description**: Position before the famous sacrifice

#### Opera Game (Morphy vs Duke of Brunswick, 1858)
**File**: `opera-game-final.fen`
```
2kr4/ppp2pp1/4p3/4b3/2B5/2P2Q2/P4PPP/2KR4 b - - 0 1
```
**Description**: Famous tactical position

---

### Test-Specific Positions

#### All Pieces Present
**File**: `all-pieces.fen`
```
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
```
**Description**: For testing piece rendering

#### Empty Board (only kings)
**File**: `empty-board.fen`
```
4k3/8/8/8/8/8/8/4K3 w - - 0 1
```
**Description**: Minimal valid position

#### Maximum Pieces
**File**: `max-pieces.fen`
```
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
```
**Description**: All 32 pieces on board

#### Piece Movement Tests
**File**: `piece-movement-test.fen`
```
8/8/8/3p1p2/2pNPp2/3p1p2/8/8 w - - 0 1
```
**Description**: Knight surrounded by enemy pawns

---

## Usage in Tests

```javascript
import { loadFEN } from '../utils/fixtures';

test('Fool\'s Mate detection', () => {
  const position = loadFEN('fools-mate');
  const chess = new Chess(position);

  expect(chess.isCheckmate()).toBe(true);
});
```

## Adding New Positions

1. Create a new `.fen` file
2. Validate FEN using chess.js or online validator
3. Add description to this README
4. Create corresponding test cases
5. Document expected behavior

## FEN Validation

To validate FEN strings:
```javascript
import { Chess } from 'chess.js';

const isValidFEN = (fen) => {
  try {
    const chess = new Chess(fen);
    return chess.fen() === fen;
  } catch {
    return false;
  }
};
```

## Resources

- FEN Notation: https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation
- Chess.js Library: https://github.com/jhlywa/chess.js
- FEN Validator: https://www.chess.com/analysis
