ai/heuristics/config/connect4-heuristics-config.js

/**
 * @fileoverview Bewertungskonfigurationen für Connect4-Heuristiken (regular, 3d).
 * Definiert je drei Profile pro Variante:
 *   - v1_baseline: Sieg/Verlust + einfache Fensterbewertung
 *   - v2_positional: Zentrumskontrolle, Spaltenqualität, Verbindungsbewertung
 *   - v3_aggressive: Druckmaximierung, Doppel-Drohungen, Mobilitätseinschränkung
 *
 * Alle Werte sind Schema-validiert via heuristic-config-schema.js.
 * @author Alexander Wolf
 */

/**
 * Validiert Config falls Schema-Validator verfügbar ist (Load-Order-sicher).
 * @param {Object} config - Rohkonfiguration.
 * @returns {Object} Validierte oder unveränderte Konfiguration.
 */
function _connect4ValidateConfig(config) {
    if (typeof validateHeuristicConfig === 'function') {
        return validateHeuristicConfig(config);
    }
    return config;
}

// ═══════════════════════════════════════════════════════════════
//  CONNECT4 REGULAR — Standard 6×7
// ═══════════════════════════════════════════════════════════════

const C4_REGULAR_PROFILES = {
    v1_baseline: _connect4ValidateConfig({
        game: 'connect4', variant: 'regular', profile: 'v1_baseline',
        name: 'Connect4 (Baseline)',
        description: 'Standard-Scoring: Fensterbewertung (4er, 3er, 2er) + Center-Bias.',
        weights: {
            win: 100000, loss: -100000, draw: 0,
            fourInRow: 10000, threeInLine: 100, twoInLine: 10,
            opponentThreeInLine: -90, opponentTwoInLine: -5,
            centerWeight: 3
        }
    }),
    v2_positional: _connect4ValidateConfig({
        game: 'connect4', variant: 'regular', profile: 'v2_positional',
        name: 'Connect4 (Positional)',
        description: 'Starke Zentrumskontrolle, Höhenstrafe, Verbindungsbonus.',
        weights: {
            win: 100000, loss: -100000, draw: 0,
            fourInRow: 10000, threeInLine: 120, twoInLine: 15,
            opponentThreeInLine: -110, opponentTwoInLine: -8,
            centerWeight: 6, connectivityBonus: 8, heightPenalty: -2
        }
    }),
    v3_aggressive: _connect4ValidateConfig({
        game: 'connect4', variant: 'regular', profile: 'v3_aggressive',
        name: 'Connect4 (Aggressive)',
        description: 'Maximiert Drohungen, bestraft eigenen Passivismus. Offensiv-First.',
        weights: {
            win: 100000, loss: -100000, draw: 0,
            fourInRow: 10000, threeInLine: 200, twoInLine: 25,
            opponentThreeInLine: -60, opponentTwoInLine: -3,
            centerWeight: 4, pressureWeight: 15,
            setupBonus: 15, threatMultiplier: 5
        }
    })
};

// ═══════════════════════════════════════════════════════════════
//  CONNECT4 3D — 4×4×4
// ═══════════════════════════════════════════════════════════════

const C4_3D_PROFILES = {
    v1_baseline: _connect4ValidateConfig({
        game: 'connect4', variant: '3d', profile: 'v1_baseline',
        name: 'Connect4 3D (Baseline)',
        description: 'Zentrumsdistanz + einfache Raumlinienbewertung.',
        weights: {
            win: 100000, loss: -100000, draw: 0,
            fourInRow: 100000, threeInLine: 1000, twoInLine: 50,
            opponentThreeInLine: -1000, opponentTwoInLine: -50,
            centerWeight: 2
        }
    }),
    v2_positional: _connect4ValidateConfig({
        game: 'connect4', variant: '3d', profile: 'v2_positional',
        name: 'Connect4 3D (Positional)',
        description: 'Raumkontrolle mit Diagonalen-Bonus und Kernzentrierung.',
        weights: {
            win: 100000, loss: -100000, draw: 0,
            fourInRow: 100000, threeInLine: 1200, twoInLine: 60,
            opponentThreeInLine: -1200, opponentTwoInLine: -60,
            centerWeight: 4, spatialControl: 8, connectivityBonus: 10
        }
    }),
    v3_aggressive: _connect4ValidateConfig({
        game: 'connect4', variant: '3d', profile: 'v3_aggressive',
        name: 'Connect4 3D (Aggressive)',
        description: 'Setup-orientiert: mehrdimensionale Drohungen aufbauen.',
        weights: {
            win: 100000, loss: -100000, draw: 0,
            fourInRow: 100000, threeInLine: 1500, twoInLine: 80,
            opponentThreeInLine: -800, opponentTwoInLine: -30,
            centerWeight: 3, pressureWeight: 20,
            setupBonus: 15, threatMultiplier: 5
        }
    })
};

/**
 * Zentrales Konfigurations-Verzeichnis aller Connect4-Profile.
 * @type {Object<string, Object<string, Object>>}
 */
const CONNECT4_HEURISTICS_CONFIGS = {
    regular: C4_REGULAR_PROFILES,
    '3d': C4_3D_PROFILES
};

/**
 * Factory-Funktion: Lädt die Konfiguration für eine Connect4-Variante und ein Profil.
 * @param {string} [variant='regular'] - 'regular' oder '3d'.
 * @param {string} [profile='v1_baseline'] - 'v1_baseline', 'v2_positional' oder 'v3_aggressive'.
 * @returns {Object} Validierte Heuristik-Konfiguration.
 */
function getConnect4HeuristicsConfig(variant = 'regular', profile = 'v1_baseline') {
    const normalizedVariant = variant === '_3d' ? '3d' : variant;
    const variantConfigs = CONNECT4_HEURISTICS_CONFIGS[normalizedVariant];

    if (!variantConfigs) {
        if (typeof DebugConfig !== 'undefined' && typeof DEBUG_DOMAINS !== 'undefined') {
            DebugConfig.log(DEBUG_DOMAINS.AI_HEURISTICS, 'warn',
                `Unbekannte Connect4-Variante: ${variant}. Fallback auf 'regular'.`);
        }
        return CONNECT4_HEURISTICS_CONFIGS.regular.v1_baseline;
    }

    const config = variantConfigs[profile];
    if (!config) {
        if (typeof DebugConfig !== 'undefined' && typeof DEBUG_DOMAINS !== 'undefined') {
            DebugConfig.log(DEBUG_DOMAINS.AI_HEURISTICS, 'warn',
                `Unbekanntes Profil: ${profile} für ${variant}. Fallback auf 'v1_baseline'.`);
        }
        return variantConfigs.v1_baseline;
    }

    return config;
}

/**
 * Gibt alle verfügbaren Profile für eine Connect4-Variante zurück.
 * @param {string} [variant='regular'] - Spielvariante.
 * @returns {Array<{id: string, name: string, description: string}>}
 */
function getConnect4ProfileList(variant = 'regular') {
    const variantConfigs = CONNECT4_HEURISTICS_CONFIGS[variant];
    if (!variantConfigs) return [];

    return Object.entries(variantConfigs).map(([id, cfg]) => ({
        id,
        name: cfg.name,
        description: cfg.description || ''
    }));
}