rei-lang 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/rei-lang)](https://www.npmjs.com/package/rei-lang)
4
4
  [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-gold.svg)](./LICENSE)
5
- [![Tests](https://img.shields.io/badge/tests-762%2F762-brightgreen)]()
5
+ [![Tests](https://img.shields.io/badge/tests-799%2F799-brightgreen)]()
6
6
 
7
7
  **Rei** (0₀式 / れいしき) is a mathematical computation language based on **D-FUMT** (Dimensional Fujimoto Universal Mathematical Theory). Its center-periphery patterns as language primitives achieve an **average 74% code reduction** over equivalent implementations in general-purpose languages.
8
8
 
@@ -10,6 +10,31 @@
10
10
 
11
11
  ---
12
12
 
13
+ ## What's New in v0.5.2 — Phase 4b/4c (Puzzle & Game Deepening)
14
+
15
+ ### Phase 4b: パズル推論深化
16
+ - **Hidden Single 検出** — 制約グループ内で唯一の候補位置を自動確定
17
+ - **Pointing Pair 検出** — Box-Line Reduction による高度候補消去
18
+ - **推論層追跡 (ReasoningTrace)** — 各確定/消去ステップの推論層を記録
19
+ - **難易度分析 (DifficultyAnalysis)** — easy/medium/hard/expert の自動判定(スコア0-100)
20
+ - 新パイプ: `agent_difficulty` / `自律難易度`, `agent_trace` / `自律追跡`
21
+
22
+ ### Phase 4c: ゲーム推論深化
23
+ - **行動パターン分化** — reactive(防御的)/ proactive(攻撃的)/ contemplative(MC評価)/ competitive(minimax)
24
+ - **戦術パターン知覚** — threat, opportunity, fork, block, center, corner の自動検出
25
+ - **対局分析 (MatchAnalysis)** — プレイヤー別の手数・戦術パターン集計・サマリー生成
26
+ - 新パイプ: `agent_analyze` / `自律分析`
27
+
28
+ ```rei
29
+ // Phase 4b: パズル難易度分析
30
+ 30 |> generate_sudoku(42) |> agent_difficulty
31
+ // → { level: "easy", score: 12, layersUsed: ["layer1_elimination"], ... }
32
+
33
+ // Phase 4c: 対局分析(reactive vs minimax)
34
+ "tic_tac_toe" |> game |> agent_analyze("reactive", "minimax")
35
+ // → { winner: 2, players: [{behavior: "reactive", ...}, {behavior: "competitive", ...}] }
36
+ ```
37
+
13
38
  ## What's New in v0.5.1 — AgentSpace (Phase 4a)
14
39
 
15
40
  **Puzzles and games are the same abstraction.** AgentSpace unifies puzzle-solving and game-playing on the v0.5 agent runtime:
package/bin/rei.js CHANGED
@@ -13,7 +13,7 @@ const fs = require('fs');
13
13
  const path = require('path');
14
14
  const readline = require('readline');
15
15
 
16
- const VERSION = '0.5.1';
16
+ const VERSION = '0.5.2';
17
17
 
18
18
  // --- Result formatting ---
19
19
  function formatResult(val) {
package/dist/index.d.mts CHANGED
@@ -929,6 +929,9 @@ interface AgentSpaceResult {
929
929
  winner?: number | null;
930
930
  moveHistory?: GameMove[];
931
931
  finalBoard?: any[];
932
+ difficulty?: DifficultyAnalysis;
933
+ reasoningTrace?: ReasoningTrace[];
934
+ matchAnalysis?: MatchAnalysis;
932
935
  }
933
936
  /** AgentSpace σ */
934
937
  interface AgentSpaceSigma {
@@ -975,15 +978,62 @@ interface PuzzleAgentData {
975
978
  }>;
976
979
  totalEliminations: number;
977
980
  totalConfirmations: number;
981
+ reasoningTrace: ReasoningTrace[];
978
982
  }
979
- /** ゲーム Agent 用データ */
980
983
  interface GameAgentData {
981
984
  gameName: string;
982
985
  rules: GameRules;
983
986
  state: GameState;
984
987
  maxDepth: number;
985
988
  strategies: [string, string];
989
+ behaviors: [string, string];
986
990
  searchNodes: number;
991
+ tacticalHistory: Array<{
992
+ player: number;
993
+ patterns: TacticalPattern[];
994
+ }>;
995
+ }
996
+ /** 推論層レベル (Phase 4b) */
997
+ type ReasoningLayer = 'layer1_elimination' | 'layer2_naked_pair' | 'layer2_hidden_single' | 'layer2_pointing_pair' | 'layer3_backtrack';
998
+ /** 推論追跡エントリ (Phase 4b) */
999
+ interface ReasoningTrace {
1000
+ round: number;
1001
+ layer: ReasoningLayer;
1002
+ cell: [number, number];
1003
+ detail: string;
1004
+ value?: number;
1005
+ }
1006
+ /** 難易度レベル (Phase 4b) */
1007
+ type DifficultyLevel = 'easy' | 'medium' | 'hard' | 'expert';
1008
+ /** 難易度分析結果 (Phase 4b) */
1009
+ interface DifficultyAnalysis {
1010
+ reiType: 'DifficultyAnalysis';
1011
+ level: DifficultyLevel;
1012
+ score: number;
1013
+ layersUsed: ReasoningLayer[];
1014
+ layerCounts: Record<ReasoningLayer, number>;
1015
+ totalSteps: number;
1016
+ backtrackCount: number;
1017
+ }
1018
+ /** 戦術パターン (Phase 4c) */
1019
+ type TacticalPattern = 'threat' | 'opportunity' | 'fork' | 'block' | 'center' | 'corner' | 'none';
1020
+ /** 対局分析結果 (Phase 4c) */
1021
+ interface MatchAnalysis {
1022
+ reiType: 'MatchAnalysis';
1023
+ winner: number | null;
1024
+ totalMoves: number;
1025
+ players: PlayerAnalysis[];
1026
+ tacticalSummary: string;
1027
+ }
1028
+ /** プレイヤー分析 (Phase 4c) */
1029
+ interface PlayerAnalysis {
1030
+ player: number;
1031
+ behavior: string;
1032
+ strategy: string;
1033
+ avgSearchNodes: number;
1034
+ totalSearchNodes: number;
1035
+ moveCount: number;
1036
+ tacticalPatterns: Record<TacticalPattern, number>;
987
1037
  }
988
1038
  /**
989
1039
  * PuzzleSpace を AgentSpace に変換する
@@ -1023,6 +1073,19 @@ declare function formatAgentSpacePuzzle(space: AgentSpace): string;
1023
1073
  * AgentSpace の盤面フォーマット(ゲーム用)
1024
1074
  */
1025
1075
  declare function formatAgentSpaceGame(space: AgentSpace): string;
1076
+ /**
1077
+ * パズル難易度分析 (Phase 4b)
1078
+ * 使用された推論層に基づいて難易度を判定
1079
+ */
1080
+ declare function getDifficultyAnalysis(space: AgentSpace): DifficultyAnalysis;
1081
+ /**
1082
+ * 推論追跡取得 (Phase 4b)
1083
+ */
1084
+ declare function getReasoningTrace(space: AgentSpace): ReasoningTrace[];
1085
+ /**
1086
+ * 対局分析 (Phase 4c)
1087
+ */
1088
+ declare function getMatchAnalysis(space: AgentSpace): MatchAnalysis;
1026
1089
 
1027
1090
  declare function reiFn(source: string): any;
1028
1091
  declare namespace reiFn {
@@ -1031,4 +1094,4 @@ declare namespace reiFn {
1031
1094
  }
1032
1095
  declare const rei: typeof reiFn;
1033
1096
 
1034
- export { AgentRegistry, Evaluator, Lexer, Parser, ReiAgent, ReiEventBus, ReiMediator, agentSpaceRun, agentSpaceRunRound, createGameAgentSpace, createPuzzleAgentSpace, formatAgentSpaceGame, formatAgentSpacePuzzle, getAgentSpaceGameState, getAgentSpaceGrid, getAgentSpaceSigma, rei };
1097
+ export { AgentRegistry, Evaluator, Lexer, Parser, ReiAgent, ReiEventBus, ReiMediator, agentSpaceRun, agentSpaceRunRound, createGameAgentSpace, createPuzzleAgentSpace, formatAgentSpaceGame, formatAgentSpacePuzzle, getAgentSpaceGameState, getAgentSpaceGrid, getAgentSpaceSigma, getDifficultyAnalysis, getMatchAnalysis, getReasoningTrace, rei };
package/dist/index.d.ts CHANGED
@@ -929,6 +929,9 @@ interface AgentSpaceResult {
929
929
  winner?: number | null;
930
930
  moveHistory?: GameMove[];
931
931
  finalBoard?: any[];
932
+ difficulty?: DifficultyAnalysis;
933
+ reasoningTrace?: ReasoningTrace[];
934
+ matchAnalysis?: MatchAnalysis;
932
935
  }
933
936
  /** AgentSpace σ */
934
937
  interface AgentSpaceSigma {
@@ -975,15 +978,62 @@ interface PuzzleAgentData {
975
978
  }>;
976
979
  totalEliminations: number;
977
980
  totalConfirmations: number;
981
+ reasoningTrace: ReasoningTrace[];
978
982
  }
979
- /** ゲーム Agent 用データ */
980
983
  interface GameAgentData {
981
984
  gameName: string;
982
985
  rules: GameRules;
983
986
  state: GameState;
984
987
  maxDepth: number;
985
988
  strategies: [string, string];
989
+ behaviors: [string, string];
986
990
  searchNodes: number;
991
+ tacticalHistory: Array<{
992
+ player: number;
993
+ patterns: TacticalPattern[];
994
+ }>;
995
+ }
996
+ /** 推論層レベル (Phase 4b) */
997
+ type ReasoningLayer = 'layer1_elimination' | 'layer2_naked_pair' | 'layer2_hidden_single' | 'layer2_pointing_pair' | 'layer3_backtrack';
998
+ /** 推論追跡エントリ (Phase 4b) */
999
+ interface ReasoningTrace {
1000
+ round: number;
1001
+ layer: ReasoningLayer;
1002
+ cell: [number, number];
1003
+ detail: string;
1004
+ value?: number;
1005
+ }
1006
+ /** 難易度レベル (Phase 4b) */
1007
+ type DifficultyLevel = 'easy' | 'medium' | 'hard' | 'expert';
1008
+ /** 難易度分析結果 (Phase 4b) */
1009
+ interface DifficultyAnalysis {
1010
+ reiType: 'DifficultyAnalysis';
1011
+ level: DifficultyLevel;
1012
+ score: number;
1013
+ layersUsed: ReasoningLayer[];
1014
+ layerCounts: Record<ReasoningLayer, number>;
1015
+ totalSteps: number;
1016
+ backtrackCount: number;
1017
+ }
1018
+ /** 戦術パターン (Phase 4c) */
1019
+ type TacticalPattern = 'threat' | 'opportunity' | 'fork' | 'block' | 'center' | 'corner' | 'none';
1020
+ /** 対局分析結果 (Phase 4c) */
1021
+ interface MatchAnalysis {
1022
+ reiType: 'MatchAnalysis';
1023
+ winner: number | null;
1024
+ totalMoves: number;
1025
+ players: PlayerAnalysis[];
1026
+ tacticalSummary: string;
1027
+ }
1028
+ /** プレイヤー分析 (Phase 4c) */
1029
+ interface PlayerAnalysis {
1030
+ player: number;
1031
+ behavior: string;
1032
+ strategy: string;
1033
+ avgSearchNodes: number;
1034
+ totalSearchNodes: number;
1035
+ moveCount: number;
1036
+ tacticalPatterns: Record<TacticalPattern, number>;
987
1037
  }
988
1038
  /**
989
1039
  * PuzzleSpace を AgentSpace に変換する
@@ -1023,6 +1073,19 @@ declare function formatAgentSpacePuzzle(space: AgentSpace): string;
1023
1073
  * AgentSpace の盤面フォーマット(ゲーム用)
1024
1074
  */
1025
1075
  declare function formatAgentSpaceGame(space: AgentSpace): string;
1076
+ /**
1077
+ * パズル難易度分析 (Phase 4b)
1078
+ * 使用された推論層に基づいて難易度を判定
1079
+ */
1080
+ declare function getDifficultyAnalysis(space: AgentSpace): DifficultyAnalysis;
1081
+ /**
1082
+ * 推論追跡取得 (Phase 4b)
1083
+ */
1084
+ declare function getReasoningTrace(space: AgentSpace): ReasoningTrace[];
1085
+ /**
1086
+ * 対局分析 (Phase 4c)
1087
+ */
1088
+ declare function getMatchAnalysis(space: AgentSpace): MatchAnalysis;
1026
1089
 
1027
1090
  declare function reiFn(source: string): any;
1028
1091
  declare namespace reiFn {
@@ -1031,4 +1094,4 @@ declare namespace reiFn {
1031
1094
  }
1032
1095
  declare const rei: typeof reiFn;
1033
1096
 
1034
- export { AgentRegistry, Evaluator, Lexer, Parser, ReiAgent, ReiEventBus, ReiMediator, agentSpaceRun, agentSpaceRunRound, createGameAgentSpace, createPuzzleAgentSpace, formatAgentSpaceGame, formatAgentSpacePuzzle, getAgentSpaceGameState, getAgentSpaceGrid, getAgentSpaceSigma, rei };
1097
+ export { AgentRegistry, Evaluator, Lexer, Parser, ReiAgent, ReiEventBus, ReiMediator, agentSpaceRun, agentSpaceRunRound, createGameAgentSpace, createPuzzleAgentSpace, formatAgentSpaceGame, formatAgentSpacePuzzle, getAgentSpaceGameState, getAgentSpaceGrid, getAgentSpaceSigma, getDifficultyAnalysis, getMatchAnalysis, getReasoningTrace, rei };