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

/**
 * @fileoverview Bewertungskonfigurationen für Connect4-Heuristiken (regular, 3d).
 * Definiert je 7 Profile pro Variante:
 *   - v1_baseline: Sieg/Verlust + einfache Fensterbewertung
 *   - v2_positional: Zentrumskontrolle, Spaltenqualität, Verbindungsbewertung
 *   - v3_aggressive: Druckmaximierung, Doppel-Drohungen, Mobilitätseinschränkung
 *   - v4_defensive: Maximale Gegner-Drohungs-Bestrafung, Höhenkontrolle
 *   - v5_offensive: Schneller Drohungsaufbau, Setup-Bonus, Threat-Eskalation
 *   - v6_local: Maximale Fensterwerte, minimale Positionsgewichte
 *   - v7_global: Spaltenstruktur + Verbindungsqualität dominieren
 *
 * 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') {
        try {
            return validateHeuristicConfig(config);
        } catch (e) {
            if (typeof DebugConfig !== 'undefined' && typeof DEBUG_DOMAINS !== 'undefined') {
                DebugConfig.log(DEBUG_DOMAINS.AI_HEURISTICS, 'warn',
                    `Connect4-Config Validierung fehlgeschlagen für ${config.profile}: ${e.message}. Nutze unvalidierte 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
        }
    }),

    // ═══ OPTIMIERTE STRATEGISCHE PROFILE ═══

    v4_defensive: _connect4ValidateConfig({
        game: 'connect4', variant: 'regular', profile: 'v4_defensive',
        name: 'Connect4 (Defensiv)',
        description: 'loss/win=1.5, opponentThreeInLine=-250, Höhenstrafe, stabile Positionen.',
        weights: {
            win: 100000, loss: -150000, draw: 500,
            fourInRow: 10000, threeInLine: 80, twoInLine: 8,
            opponentThreeInLine: -250, opponentTwoInLine: -20,
            centerWeight: 4, connectivityBonus: 5, heightPenalty: -5
        }
    }),
    v5_offensive: _connect4ValidateConfig({
        game: 'connect4', variant: 'regular', profile: 'v5_offensive',
        name: 'Connect4 (Offensiv)',
        description: 'Schneller Aufbau: threeInLine=250, setupBonus=25, threatMultiplier=8.",',
        weights: {
            win: 100000, loss: -80000, draw: -200,
            fourInRow: 10000, threeInLine: 250, twoInLine: 30,
            opponentThreeInLine: -50, opponentTwoInLine: -3,
            centerWeight: 3, pressureWeight: 20,
            setupBonus: 25, threatMultiplier: 8
        }
    }),
    v6_local: _connect4ValidateConfig({
        game: 'connect4', variant: 'regular', profile: 'v6_local',
        name: 'Connect4 (Lokal)',
        description: 'Maximale Fensterwerte, minimale Position. Taktischer Nahkampf.',
        weights: {
            win: 100000, loss: -100000, draw: 0,
            fourInRow: 10000, threeInLine: 200, twoInLine: 25,
            opponentThreeInLine: -100, opponentTwoInLine: -8,
            centerWeight: 1, setupBonus: 20
        }
    }),
    v7_global: _connect4ValidateConfig({
        game: 'connect4', variant: 'regular', profile: 'v7_global',
        name: 'Connect4 (Global)',
        description: 'Spaltenstruktur + Verbindungen: centerWeight=10, connectivity=12, niedrige Linien.',
        weights: {
            win: 100000, loss: -100000, draw: 0,
            fourInRow: 10000, threeInLine: 60, twoInLine: 5,
            opponentThreeInLine: -80, opponentTwoInLine: -5,
            centerWeight: 10, connectivityBonus: 12, heightPenalty: -3
        }
    })
};

// ═══════════════════════════════════════════════════════════════
//  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
        }
    }),

    // ═══ OPTIMIERTE STRATEGISCHE PROFILE (3D) ═══

    v4_defensive: _connect4ValidateConfig({
        game: 'connect4', variant: '3d', profile: 'v4_defensive',
        name: 'Connect4 3D (Defensiv)',
        description: '3D-Raumdefense: loss=-150000, starke Gegner-Drohungs-Bestrafung, Höhenkontrolle.',
        weights: {
            win: 100000, loss: -150000, draw: 500,
            fourInRow: 100000, threeInLine: 800, twoInLine: 40,
            opponentThreeInLine: -2500, opponentTwoInLine: -100,
            centerWeight: 3, spatialControl: 5,
            connectivityBonus: 8, heightPenalty: -5
        }
    }),
    v5_offensive: _connect4ValidateConfig({
        game: 'connect4', variant: '3d', profile: 'v5_offensive',
        name: 'Connect4 3D (Offensiv)',
        description: '3D-Schnellaufbau: Hohe 3er-Werte, Setup&Threat maximiert, Gegner-Drohungen ignoriert.',
        weights: {
            win: 100000, loss: -80000, draw: -500,
            fourInRow: 100000, threeInLine: 2000, twoInLine: 100,
            opponentThreeInLine: -500, opponentTwoInLine: -20,
            centerWeight: 2, pressureWeight: 25,
            setupBonus: 20, threatMultiplier: 8
        }
    }),
    v6_local: _connect4ValidateConfig({
        game: 'connect4', variant: '3d', profile: 'v6_local',
        name: 'Connect4 3D (Lokal)',
        description: 'Maximale 3D-Fensterwerte, minimale Positionsgewichte. Taktischer Raumkampf.',
        weights: {
            win: 100000, loss: -100000, draw: 0,
            fourInRow: 100000, threeInLine: 1800, twoInLine: 90,
            opponentThreeInLine: -1000, opponentTwoInLine: -50,
            centerWeight: 1, setupBonus: 20
        }
    }),
    v7_global: _connect4ValidateConfig({
        game: 'connect4', variant: '3d', profile: 'v7_global',
        name: 'Connect4 3D (Global)',
        description: '3D-Raumstruktur dominiert: spatialControl=12, Connectivity=15, niedrige Linienwerte.',
        weights: {
            win: 100000, loss: -100000, draw: 0,
            fourInRow: 100000, threeInLine: 600, twoInLine: 30,
            opponentThreeInLine: -800, opponentTwoInLine: -40,
            centerWeight: 5, spatialControl: 12,
            connectivityBonus: 15, heightPenalty: -3
        }
    })
};

/**
 * 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'] - Profil-ID: v1_baseline bis v7_global.
 * @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 || ''
    }));
}