Regex Chessのロゴ

Regex Chess

組織
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.

概要

公開者mega-edo
リポジトリmega-tron
スキル名regex-chess
スター
27
フォーク
2
同梱ファイル
指示のみ
ライセンスApache-2.0
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    mega-edoがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルRegex ChessをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/mega-edo/mega-tron/tree/main/benchmarks/feedback_loop/pool/competing/regex-chess
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでRegex Chessを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にRegex Chessを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Regex Chessは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

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).

よくある質問

AIスキル「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.

TypingMindでRegex Chessを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Regex Chessはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにRegex Chessをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/mega-edo/mega-tron/tree/main/benchmarks/feedback_loop/pool/competing/regex-chessを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Regex Chessを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Regex Chessは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもRegex Chessを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Regex Chess」は無料ですか?

はい。mega-edoがGitHubでApache-2.0ライセンスの下で公開しています。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇