Logo di Regex Chess

Regex Chess

Organizzazione
mega-edo
regex-chess

Guidance for implementing chess move generation using only regular expressions. This skill applies to tasks requiring encoding game logic (chess, board games) into regex patterns, or more generally "compile-to-constraints" problems where complex business logic must be expressed in a limited formalism like regex. Use when the task involves generating legal moves, validating game states, or transforming position representations using pattern matching.

Panoramica

Autoremega-edo
Repositorymega-tron
Nome della skillregex-chess
Stelle
27
Fork
2
File inclusi
Solo istruzioni
LicenzaApache-2.0
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • Tutto nelle istruzioni

    Tutto ciò che serve al modello è nelle istruzioni: nessun file aggiuntivo da sincronizzare.

  • Open source

    Pubblicata da mega-edo su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Regex Chess in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/mega-edo/mega-tron/tree/main/benchmarks/feedback_loop/pool/competing/regex-chess
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Nuova skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.
2

Installa in un altro agente

Qualsiasi agente che legge il formato Agent Skills può usare questa skill: copia la cartella nella cartella delle skill di quell'agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mega-edo/mega-tron.git /tmp/mega-tron
mkdir -p .claude/skills
cp -r /tmp/mega-tron/benchmarks/feedback_loop/pool/competing/regex-chess .claude/skills/regex-chess
Dopo la copia, riavvia Claude Code per caricare la nuova skill.

Usala in TypingMind

Attiva Regex Chess in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Regex Chess non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Regex Chess non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

Regex Chess

Overview

This skill provides methodology for implementing chess move generation using regular expressions. The core challenge is encoding chess rules—piece movement, captures, special moves, and legality checking—entirely within regex pattern matching and substitution.

This belongs to a class of "compile-to-constraints" problems where business logic must be expressed in a limited formalism. Success requires understanding the target formalism's limitations, systematic decomposition, and incremental verification.

Critical Prerequisites

Before writing any patterns:

1. Document the Transformation Pipeline

Create a clear specification of the exact string format at each transformation stage:

Stage 1: Raw FEN input
Example: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"

Stage 2: After digit expansion (8 → ........)
Example: "rnbqkbnr/pppppppp/......../......../......../......../PPPPPPPP/RNBQKBNR w KQkq -"

Stage 3: After coordinate labeling (each square gets rank/file)
Example: "[a8:r][b8:n][c8:b]... [a1:R][b1:N]..."

Stage 4: After move applied
Example: "[a8:r][b8:n]... [a3:.][a4:P]..."

Stage 5: Final FEN output
Example: "rnbqkbnr/pppppppp/8/8/P7/8/1PPPPPPP/RNBQKBNR b KQkq a3 0 1"

2. Establish Coordinate Ordering

Determine definitively which squares come first in the string representation. In standard FEN:

  • Rank 8 (black's back rank) comes before rank 1
  • File 'a' comes before file 'h'
  • So a8 < b8 < ... < h8 < a7 < ... < h1

This ordering affects every pattern that references two squares (moves, captures, sliding pieces).

3. Identify All Move Categories

Enumerate all move types that need patterns:

  • Pawn single push (white: rank 2-6, black: rank 7-3)
  • Pawn double push from starting rank (sets en passant square)
  • Pawn captures (diagonal, including en passant)
  • Pawn promotion (4 piece types × captures + pushes)
  • Knight moves (8 directions from each square)
  • Bishop/Rook/Queen sliding moves (with blocking detection)
  • King single-step moves (8 directions)
  • Castling (kingside and queenside, both colors)
  • Move legality (king not in check after move)

Recommended Approach

Phase 1: Design Before Code

Spend significant time designing the architecture before writing patterns:

  1. Choose a string representation that makes pattern matching tractable
  2. Document the representation with concrete examples for each transformation
  3. Verify coordinate ordering with a simple test case
  4. Decide how to handle blocking for sliding pieces (bishops, rooks, queens)

Phase 2: Incremental Development

Build and verify one piece type at a time:

  1. Start with the simplest case: pawn single push (e.g., a2 to a3)
  2. Write ONE pattern for this specific move
  3. Test it works in isolation before generating more
  4. Add complexity incrementally: other pawns, then captures, then other pieces

Phase 3: Test-Driven Pattern Generation

For each piece type:

1. Write a single hardcoded pattern for one move
2. Verify it matches correctly on a test position
3. Verify it produces correct output
4. Only then generalize to generate all moves of that type
5. Test the full set before moving to next piece type

Phase 4: Handle Special Cases

Only after basic moves work:

  • En passant (requires tracking en passant square in FEN)
  • Castling (requires checking castling rights, path clear, not through check)
  • Promotion (requires different replacement patterns for each piece type)
  • Move legality (filter moves where king ends in check)

Common Pitfalls

String Ordering Confusion

The most common bug is getting coordinate ordering wrong. If pattern expects source before destination but the string has them reversed, nothing will match.

Prevention: Write a helper function to determine ordering, test it explicitly:

python
def square_comes_before(sq1, sq2):
    """Return True if sq1 appears before sq2 in the FEN string."""
    # Implement based on your coordinate system
    # TEST THIS FUNCTION IN ISOLATION

Digit Expansion Timing

FEN uses digits for empty squares (e.g., "8" means 8 empty squares). Expanding these digits must happen at the right time:

  • Expand AFTER removing move counters (or "0 1" becomes "0 .")
  • Track which transformation stage each operation belongs to

Escaping Across Languages

When patterns flow through multiple languages (Python generator → JSON → regex engine):

  • Raw strings (r'') in Python
  • JSON escaping for special characters
  • Regex escaping for metacharacters

Prevention: Print patterns at each stage to verify escaping is correct.

Generating Too Many Patterns at Once

Generating thousands of patterns before testing any is a recipe for debugging nightmares.

Prevention: Test individual patterns first. A single working pawn move is worth more than 10,000 broken patterns.

Missing Trailing/Leading Characters

Off-by-one errors in pattern boundaries cause silent failures:

  • Missing space after piece: "RNBQKBNRw" instead of "RNBQKBNR w"
  • Missing separator between coordinates

Prevention: Include boundary markers in test assertions.

Ignoring Move Legality

Generating pseudo-legal moves (moves that follow piece movement rules) is much easier than generating legal moves (moves that don't leave king in check). Plan for this from the start.

Verification Strategy

Unit Tests for Helpers

Test coordinate functions, ordering functions, and FEN parsing in isolation:

python
assert square_index('a8') == 0
assert square_index('h1') == 63
assert square_comes_before('a8', 'h8') == True
assert square_comes_before('a1', 'a8') == False

Single-Move Tests

Before bulk generation, verify specific moves:

python
# Test: White pawn a2 to a3
input_fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
result = apply_move(input_fen, "a2a3")
expected = "rnbqkbnr/pppppppp/8/8/8/P7/1PPPPPPP/RNBQKBNR b KQkq - 0 1"
assert result == expected

Automated Test Loop

Create a script that regenerates patterns and runs all tests in one command:

bash
#!/bin/bash
python generate_patterns.py && python run_tests.py

Debug Pattern Matching

When patterns don't match, add debug output showing:

  • The exact input string
  • The pattern being applied
  • Expected match location
  • Actual match result

Resources

See references/compile_to_constraints.md for general principles applicable to encoding logic in limited formalisms (regex, SQL constraints, type systems).

Domande frequenti

Cosa fa la skill IA Regex Chess?

Guidance for implementing chess move generation using only regular expressions. This skill applies to tasks requiring encoding game logic (chess, board games) into regex patterns, or more generally "compile-to-constraints" problems where complex business logic must be expressed in a limited formalism like regex. Use when the task involves generating legal moves, validating game states, or transforming position representations using pattern matching.

Perché usare Regex Chess su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Regex Chess è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Regex Chess in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/mega-edo/mega-tron/tree/main/benchmarks/feedback_loop/pool/competing/regex-chess. TypingMind legge il file SKILL.md e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Regex Chess?

Qualsiasi modello che colleghi in TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Regex Chess?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Regex Chess: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Regex Chess è gratuita?

Sì. È pubblicata su GitHub da mega-edo con licenza Apache-2.0. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, modelli o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Vedi tutti

Crea subito la tua area di lavoro IA

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇