Skip to content
TheChatArchiveThe Chat Archive
Mistralmistral-medium-2505· Mistral AIHugging Face LMArena Human Preference 140K

Write html5 traditional roguelike game, focused on items that glitch the game for real,…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Metallama-4-maverick-03-26-experimental’s answer.
  1. User

    Write html5 traditional roguelike game, focused on items that glitch the game for real, really effecting the code, make sure to write the program to deal with crazy code changes through the items, without the game crashing. Add descriptions and a help menu and NUMPad controls

  2. Mistral Assistant

    Glitch Roguelike: A Self-Modifying HTML5 Game

    Here's a complete HTML5 roguelike game where items can actually modify the game's code in real ways. The game is designed to handle these modifications gracefully without crashing.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Glitch Roguelike</title>
        <style>
            body {
                font-family: 'Courier New', monospace;
                background-color: #111;
                color: #eee;
                margin: 0;
                padding: 0;
                display: flex;
                flex-direction: column;
                align-items: center;
                height: 100vh;
                overflow: hidden;
            }
    
            #game-container {
                display: flex;
                flex-direction: column;
                align-items: center;
                width: 100%;
                max-width: 800px;
            }
    
            #game-canvas {
                border: 2px solid #444;
                background-color: #222;
                font-size: 16px;
                line-height: 16px;
                letter-spacing: 1px;
                margin: 10px 0;
            }
    
            #status-bar {
                display: flex;
                justify-content: space-between;
                width: 100%;
                padding: 5px;
                background-color: #333;
                border: 1px solid #444;
                margin-bottom: 10px;
            }
    
            #message-log {
                width: 100%;
                height: 100px;
                border: 1px solid #444;
                background-color: #222;
                padding: 5px;
                overflow-y: auto;
                margin-bottom: 10px;
                font-size: 12px;
            }
    
            #help-menu {
                position: absolute;
                top: 10px;
                right: 10px;
                background-color: #222;
                border: 1px solid #444;
                padding: 10px;
                max-width: 300px;
                display: none;
                font-size: 12px;
            }
    
            .help-toggle {
                position: absolute;
                top: 5px;
                right: 5px;
                background-color: #333;
                border: 1px solid #444;
                padding: 2px 5px;
                cursor: pointer;
                font-size: 12px;
            }
    
            .inventory-item {
                margin-right: 5px;
                color: #ff0;
                cursor: pointer;
            }
    
            .inventory-item:hover {
                text-decoration: underline;
            }
    
            .glitch-effect {
                animation: glitch 0.5s infinite;
            }
    
            @keyframes glitch {
                0% { transform: translate(0); }
                20% { transform: translate(-2px, 2px); }
                40% { transform: translate(-2px, -2px); }
                60% { transform: translate(2px, 2px); }
                80% { transform: translate(2px, -2px); }
                100% { transform: translate(0); }
            }
        </style>
    </head>
    <body>
        <div id="game-container">
            <div class="help-toggle" onclick="toggleHelp()">HELP</div>
            <div id="help-menu">
                <h3>Glitch Roguelike</h3>
                <p>A game where items can modify the game's code in real ways!</p>
                <h4>Controls:</h4>
                <ul>
                    <li>NUMPAD or VI KEYS: Movement</li>
                    <li>5/.: Wait a turn</li>
                    <li>,: Pick up item</li>
                    <li>i: Open inventory</li>
                    <li>?: Show this help</li>
                    <li>ESC: Close menus</li>
                </ul>
                <h4>Game Concept:</h4>
                <p>Find and use glitch items that modify the game's code. Some changes are beneficial, some are dangerous, and some are just weird!</p>
                <p>The game is designed to handle these modifications without crashing.</p>
                <h4>Glitch Items:</h4>
                <p>Each glitch item has a unique effect that modifies the game's behavior. Some might:</p>
                <ul>
                    <li>Change how movement works</li>
                    <li>Modify enemy behavior</li>
                    <li>Alter the rendering system</li>
                    <li>Add new game mechanics</li>
                    <li>Or do something completely unexpected!</li>
                </ul>
            </div>
            <div id="status-bar">
                <div id="player-stats">HP: 100 | LVL: 1 | XP: 0</div>
                <div id="inventory-display"></div>
            </div>
            <div id="message-log"></div>
            <canvas id="game-canvas" width="800" height="480"></canvas>
        </div>
    
        <script>
            // Game state
            const gameState = {
                player: {
                    x: 1,
                    y: 1,
                    hp: 100,
                    maxHp: 100,
                    level: 1,
                    xp: 0,
                    inventory: [],
                    equipped: null,
                    glitchEffects: []
                },
                map: [],
                entities: [],
                items: [],
                messages: [],
                gameOver: false,
                turnCount: 0,
                glitchLevel: 0,
                originalCode: {
                    playerMove: playerMove.toString(),
                    render: render.toString(),
                    generateMap: generateMap.toString(),
                    processTurn: processTurn.toString()
                },
                glitchHistory: []
            };
    
            // Canvas setup
            const canvas = document.getElementById('game-canvas');
            const ctx = canvas.getContext('2d');
            const tileSize = 16;
            const mapWidth = Math.floor(canvas.width / tileSize);
            const mapHeight = Math.floor(canvas.height / tileSize);
    
            // Initialize game
            function initGame() {
                generateMap();
                placePlayer();
                placeEntities(5);
                placeItems(3);
                render();
                logMessage("Welcome to Glitch Roguelike! Find items that modify the game's code.");
                logMessage("Press ? for help.");
            }
    
            // Generate a new map
            function generateMap() {
                gameState.map = [];
                for (let y = 0; y < mapHeight; y++) {
                    gameState.map[y] = [];
                    for (let x = 0; x < mapWidth; x++) {
                        if (x === 0 || y === 0 || x === mapWidth - 1 || y === mapHeight - 1) {
                            gameState.map[y][x] = '#'; // Wall
                        } else if (Math.random() < 0.2) {
                            gameState.map[y][x] = '#'; // Wall
                        } else {
                            gameState.map[y][x] = '.'; // Floor
                        }
                    }
                }
            }
    
            // Place the player
            function placePlayer() {
                // Find an empty spot
                let x, y;
                do {
                    x = Math.floor(Math.random() * (mapWidth - 2)) + 1;
                    y = Math.floor(Math.random() * (mapHeight - 2)) + 1;
                } while (gameState.map[y][x] !== '.');
    
                gameState.player.x = x;
                gameState.player.y = y;
            }
    
            // Place random entities
            function placeEntities(count) {
                gameState.entities = [];
                for (let i = 0; i < count; i++) {
                    let x, y;
                    do {
                        x = Math.floor(Math.random() * (mapWidth - 2)) + 1;
                        y = Math.floor(Math.random() * (mapHeight - 2)) + 1;
                    } while (gameState.map[y][x] !== '.' || (x === gameState.player.x && y === gameState.player.y));
    
                    gameState.entities.push({
                        x: x,
                        y: y,
                        type: 'enemy',
                        hp: 10,
                        symbol: 'E',
                        color: '#f00',
                        behavior: 'chase'
                    });
                }
            }
    
            // Place random items
            function placeItems(count) {
                gameState.items = [];
                const itemTypes = [
                    { name: "Code Injector", description: "Modifies a random game function", effect: injectRandomCode },
                    { name: "Memory Leak", description: "Slows down the game over time", effect: createMemoryLeak },
                    { name: "Null Pointer", description: "Randomly crashes enemies", effect: addNullPointerEffect },
                    { name: "Stack Overflow", description: "Creates recursive effects", effect: createStackOverflow },
                    { name: "Buffer Overflow", description: "Expands your inventory", effect: bufferOverflow },
                    { name: "Race Condition", description: "Makes turns unpredictable", effect: addRaceCondition },
                    { name: "Segmentation Fault", description: "Randomly teleports you", effect: addSegmentationFault },
                    { name: "Heap Corruption", description: "Modifies item properties", effect: corruptHeap },
                    { name: "DLL Injection", description: "Adds new game mechanics", effect: injectDLL },
                    { name: "Blue Screen", description: "Resets part of the game", effect: blueScreenEffect }
                ];
    
                for (let i = 0; i < count; i++) {
                    let x, y;
                    do {
                        x = Math.floor(Math.random() * (mapWidth - 2)) + 1;
                        y = Math.floor(Math.random() * (mapHeight - 2)) + 1;
                    } while (gameState.map[y][x] !== '.' || (x === gameState.player.x && y === gameState.player.y));
    
                    const itemType = itemTypes[Math.floor(Math.random() * itemTypes.length)];
                    gameState.items.push({
                        x: x,
                        y: y,
                        name: itemType.name,
                        description: itemType.description,
                        effect: itemType.effect,
                        symbol: '?',
                        color: '#0f0'
                    });
                }
            }
    
            // Render the game
            function render() {
                // Clear canvas
                ctx.fillStyle = '#222';
                ctx.fillRect(0, 0, canvas.width, canvas.height);
    
                // Apply glitch effects if any
                if (gameState.player.glitchEffects.includes('invertedColors')) {
                    ctx.filter = 'invert(1)';
                }
    
                if (gameState.player.glitchEffects.includes('scanlines')) {
                    for (let y = 0; y < mapHeight; y++) {
                        if (y % 2 === 0) {
                            ctx.fillStyle = 'rgba(0, 0, 0, 0.2)';
                            ctx.fillRect(0, y * tileSize, canvas.width, tileSize);
                        }
                    }
                }
    
                // Draw map
                for (let y = 0; y < mapHeight; y++) {
                    for (let x = 0; x < mapWidth; x++) {
                        const tile = gameState.map[y][x];
                        if (tile === '#') {
                            ctx.fillStyle = '#555';
                            ctx.fillRect(x * tileSize, y * tileSize, tileSize, tileSize);
                        }
                    }
                }
    
                // Draw items
                gameState.items.forEach(item => {
                    ctx.fillStyle = item.color;
                    ctx.fillText(item.symbol, x * tileSize + tileSize/2, y * tileSize + tileSize/2);
                });
    
                // Draw entities
                gameState.entities.forEach(entity => {
                    ctx.fillStyle = entity.color;
                    ctx.fillText(entity.symbol, entity.x * tileSize + tileSize/2, entity.y * tileSize + tileSize/2);
                });
    
                // Draw player
                ctx.fillStyle = '#0af';
                ctx.fillText('@', gameState.player.x * tileSize + tileSize/2, gameState.player.y * tileSize + tileSize/2);
    
                // Update status bar
                document.getElementById('player-stats').textContent =
                    `HP: ${gameState.player.hp}/${gameState.player.maxHp} | LVL: ${gameState.player.level} | XP: ${gameState.player.xp} | GLITCH: ${gameState.glitchLevel}`;
    
                // Update inventory display
                const inventoryDisplay = document.getElementById('inventory-display');
                inventoryDisplay.innerHTML = '';
                gameState.player.inventory.forEach((item, index) => {
                    const itemSpan = document.createElement('span');
                    itemSpan.className = 'inventory-item';
                    itemSpan.textContent = `${String.fromCharCode(97 + index)}:${item.name}`;
                    itemSpan.onclick = () => useItem(index);
                    inventoryDisplay.appendChild(itemSpan);
                });
    
                // Reset filters
                ctx.filter = 'none';
            }
    
            // Process a game turn
            function processTurn() {
                if (gameState.gameOver) return;
    
                // Process entities
                gameState.entities.forEach(entity => {
                    if (entity.behavior === 'chase') {
                        // Simple AI to chase player
                        const dx = gameState.player.x - entity.x;
                        const dy = gameState.player.y - entity.y;
    
                        if (Math.abs(dx) > Math.abs(dy)) {
                            if (dx > 0) entity.x++;
                            else entity.x--;
                        } else {
                            if (dy > 0) entity.y++;
                            else entity.y--;
                        }
    
                        // Check for collision with player
                        if (entity.x === gameState.player.x && entity.y === gameState.player.y) {
                            gameState.player.hp -= 5;
                            logMessage(`Enemy hits you for 5 damage! HP: ${gameState.player.hp}`);
                            if (gameState.player.hp <= 0) {
                                gameOver();
                            }
                        }
                    }
                });
    
                // Apply glitch effects
                applyGlitchEffects();
    
                gameState.turnCount++;
                render();
            }
    
            // Player movement
            function playerMove(dx, dy) {
                if (gameState.gameOver) return;
    
                const newX = gameState.player.x + dx;
                const newY = gameState.player.y + dy;
    
                // Check if new position is valid
                if (gameState.map[newY][newX] === '.') {
                    // Check for items
                    const itemIndex = gameState.items.findIndex(item => item.x === newX && item.y === newY);
                    if (itemIndex !== -1) {
                        const item = gameState.items[itemIndex];
                        logMessage(`You see a ${item.name}: ${item.description}`);
                        logMessage("Press ',' to pick it up.");
                    }
    
                    // Check for enemies
                    const enemyIndex = gameState.entities.findIndex(e => e.x === newX && e.y === newY);
                    if (enemyIndex !== -1) {
                        const enemy = gameState.entities[enemyIndex];
                        enemy.hp -= 10;
                        logMessage(`You hit the enemy for 10 damage!`);
    
                        if (enemy.hp <= 0) {
                            gameState.entities.splice(enemyIndex, 1);
                            gameState.player.xp += 20;
                            logMessage(`You defeated the enemy! +20 XP`);
    
                            if (gameState.player.xp >= gameState.player.level * 50) {
                                gameState.player.level++;
                                gameState.player.maxHp += 20;
                                gameState.player.hp = gameState.player.maxHp;
                                logMessage(`Level up! You are now level ${gameState.player.level}`);
                            }
                        }
                    } else {
                        gameState.player.x = newX;
                        gameState.player.y = newY;
                    }
                }
    
                processTurn();
            }
    
            // Pick up item
            function pickUpItem() {
                const itemIndex = gameState.items.findIndex(item =>
                    item.x === gameState.player.x && item.y === gameState.player.y);
    
                if (itemIndex !== -1) {
                    const item = gameState.items[itemIndex];
                    gameState.player.inventory.push(item);
                    gameState.items.splice(itemIndex, 1);
                    logMessage(`You picked up: ${item.name}`);
                    render();
                } else {
                    logMessage("There's nothing here to pick up.");
                }
            }
    
            // Use an item from inventory
            function useItem(index) {
                if (index < 0 || index >= gameState.player.inventory.length) return;
    
                const item = gameState.player.inventory[index];
                logMessage(`You use: ${item.name} - ${item.description}`);
    
                // Apply the item's effect
                try {
                    item.effect(item);
                } catch (e) {
                    logMessage(`Error applying item effect: ${e.message}`);
                    logMessage("The game continues despite the error!");
                }
    
                // Remove the item
                gameState.player.inventory.splice(index, 1);
                render();
            }
    
            // Log a message to the message log
            function logMessage(message) {
                gameState.messages.push(message);
                if (gameState.messages.length > 5) {
                    gameState.messages.shift();
                }
    
                const messageLog = document.getElementById('message-log');
                messageLog.innerHTML = gameState.messages.join('<br>');
                messageLog.scrollTop = messageLog.scrollHeight;
            }
    
            // Game over
            function gameOver() {
                gameState.gameOver = true;
                logMessage("GAME OVER");
                logMessage("Press F5 to restart");
            }
    
            // Toggle help menu
            function toggleHelp() {
                const helpMenu = document.getElementById('help-menu');
                helpMenu.style.display = helpMenu.style.display === 'block' ? 'none' : 'block';
            }
    
            // Apply glitch effects each turn
            function applyGlitchEffects() {
                // Random teleportation
                if (gameState.player.glitchEffects.includes('randomTeleport') && Math.random() < 0.1) {
                    let newX, newY;
                    do {
                        newX = Math.floor(Math.random() * (mapWidth - 2)) + 1;
                        newY = Math.floor(Math.random() * (mapHeight - 2)) + 1;
                    } while (gameState.map[newY][newX] !== '.');
    
                    gameState.player.x = newX;
                    gameState.player.y = newY;
                    logMessage("Glitch effect: Random teleportation!");
                }
    
                // Memory leak - slow down the game
                if (gameState.player.glitchEffects.includes('memoryLeak')) {
                    // Simulate slowdown by adding a delay
                    const start = performance.now();
                    while (performance.now() - start < 50 * gameState.glitchLevel) {
                        // Busy wait
                    }
                }
    
                // Race condition - sometimes skip turns
                if (gameState.player.glitchEffects.includes('raceCondition') && Math.random() < 0.3) {
                    logMessage("Glitch effect: Turn skipped due to race condition!");
                    processTurn(); // Process another turn immediately
                }
            }
    
            // Glitch item effects
            function injectRandomCode(item) {
                const functions = ['playerMove', 'render', 'generateMap', 'processTurn'];
                const functionName = functions[Math.floor(Math.random() * functions.length)];
    
                // Get the original function
                const originalFunction = gameState.originalCode[functionName];
    
                // Create a modified version
                let modifiedCode = originalFunction;
    
                // Random modifications
                if (Math.random() < 0.3) {
                    // Add random console.log
                    modifiedCode = modifiedCode.replace('{', '{ console.log("GLITCH: This function has been modified!");');
                }
    
                if (Math.random() < 0.3) {
                    // Add random condition
                    modifiedCode = modifiedCode.replace('{', '{ if (Math.random() < 0.1) { return; }');
                }
    
                if (Math.random() < 0.3) {
                    // Add random variable modification
                    modifiedCode = modifiedCode.replace('{', '{ gameState.glitchLevel += 0.1;');
                }
    
                try {
                    // Try to evaluate the modified code
                    const newFunction = new Function('return ' + modifiedCode)();
    
                    // Replace the original function
                    window[functionName] = newFunction;
    
                    logMessage(`GLITCH: ${functionName} has been modified!`);
                    gameState.glitchLevel++;
                    gameState.player.glitchEffects.push('codeModified');
                } catch (e) {
                    logMessage(`GLITCH: Failed to modify ${functionName}: ${e.message}`);
                }
            }
    
            function createMemoryLeak(item) {
                gameState.player.glitchEffects.push('memoryLeak');
                gameState.glitchLevel++;
    
                // Create a memory leak by keeping references to large objects
                const leak = new Array(1000000).fill(0);
                gameState.memoryLeaks = gameState.memoryLeaks || [];
                gameState.memoryLeaks.push(leak);
    
                logMessage("GLITCH: Memory leak created! Game may slow down.");
            }
    
            function addNullPointerEffect(item) {
                gameState.player.glitchEffects.push('nullPointer');
    
                // Add a chance for enemies to crash
                gameState.entities.forEach(enemy => {
                    if (Math.random() < 0.1) {
                        enemy.crashed = true;
                        logMessage("GLITCH: An enemy crashed due to null pointer!");
                    }
                });
    
                gameState.entities = gameState.entities.filter(e => !e.crashed);
                gameState.glitchLevel++;
            }
    
            function createStackOverflow(item) {
                gameState.player.glitchEffects.push('stackOverflow');
    
                // Create a recursive function that might cause stack overflow
                try {
                    function recursiveFunction(n) {
                        if (n <= 0) return;
                        recursiveFunction(n - 1);
                    }
    
                    recursiveFunction(1000);
                    logMessage("GLITCH: Stack overflow attempted! (but caught)");
                } catch (e) {
                    logMessage(`GLITCH: Stack overflow occurred! ${e.message}`);
                }
    
                gameState.glitchLevel++;
            }
    
            function bufferOverflow(item) {
                gameState.player.glitchEffects.push('bufferOverflow');
    
                // Simulate buffer overflow by expanding inventory
                const overflowItem = {
                    name: "Overflow Data",
                    description: "This shouldn't exist!",
                    effect: () => logMessage("GLITCH: This item does nothing but take up space")
                };
    
                gameState.player.inventory.push(overflowItem);
                logMessage("GLITCH: Buffer overflow! Inventory expanded with junk data.");
                gameState.glitchLevel++;
            }
    
            function addRaceCondition(item) {
                gameState.player.glitchEffects.push('raceCondition');
                logMessage("GLITCH: Race condition added! Turns may be unpredictable.");
                gameState.glitchLevel++;
            }
    
            function addSegmentationFault(item) {
                gameState.player.glitchEffects.push('randomTeleport');
                logMessage("GLITCH: Segmentation fault! You may teleport randomly.");
                gameState.glitchLevel++;
            }
    
            function corruptHeap(item) {
                gameState.player.glitchEffects.push('heapCorruption');
    
                // Randomly modify item properties
                gameState.items.forEach(item => {
                    if (Math.random() < 0.5) {
                        item.name = item.name.split('').reverse().join('');
                    }
                    if (Math.random() < 0.3) {
                        item.color = `#${Math.floor(Math.random()*16777215).toString(16)}`;
                    }
                });
    
                logMessage("GLITCH: Heap corrupted! Items may be modified.");
                gameState.glitchLevel++;
            }
    
            function injectDLL(item) {
                gameState.player.glitchEffects.push('dllInjected');
    
                // Add a new game mechanic
                gameState.player.newMechanic = {
                    name: "Dynamic Loading",
                    description: "New mechanics can be added at runtime",
                    effect: () => logMessage("GLITCH: New mechanic activated!")
                };
    
                logMessage("GLITCH: DLL injected! New mechanics available.");
                gameState.glitchLevel++;
            }
    
            function blueScreenEffect(item) {
                gameState.player.glitchEffects.push('blueScreen');
    
                // Reset part of the game state
                gameState.entities = gameState.entities.filter(e => Math.random() < 0.5);
                gameState.items = gameState.items.filter(i => Math.random() < 0.5);
    
                logMessage("GLITCH: Blue screen! Part of the game state was reset.");
                gameState.glitchLevel++;
            }
    
            // Event listeners
            document.addEventListener('keydown', (e) => {
                if (gameState.gameOver) return;
    
                // Numpad controls
                if (e.key === 'ArrowUp' || e.key === '8') playerMove(0, -1);
                else if (e.key === 'ArrowDown' || e.key === '2') playerMove(0, 1);
                else if (e.key === 'ArrowLeft' || e.key === '4') playerMove(-1, 0);
                else if (e.key === 'ArrowRight' || e.key === '6') playerMove(1, 0);
                else if (e.key === 'ArrowUp' && e.key === 'ArrowRight' || e.key === '9') playerMove(1, -1);
                else if (e.key === 'ArrowUp' && e.key === 'ArrowLeft' || e.key === '7') playerMove(-1, -1);
                else if (e.key === 'ArrowDown' && e.key === 'ArrowRight' || e.key === '3') playerMove(1, 1);
                else if (e.key === 'ArrowDown' && e.key === 'ArrowLeft' || e.key === '1') playerMove(-1, 1);
                else if (e.key === '5' || e.key === '.') {
                    // Wait
                    processTurn();
                }
                else if (e.key === ',') {
                    pickUpItem();
                }
                else if (e.key === 'i') {
                    // Open inventory - would need more UI for this
                    logMessage("Inventory: " + gameState.player.inventory.map(i => i.name).join(', '));
                }
                else if (e.key === '?') {
                    toggleHelp();
                }
                else if (e.key === 'Escape') {
                    // Close menus
                    document.getElementById('help-menu').style.display = 'none';
                }
            });
    
            // Start the game
            initGame();
        </script>
    </body>
    </html>
    

    Game Features:

    1. Self-Modifying Code: Items can actually modify game functions at runtime

    2. Glitch Effects: Various items create different types of glitches:

      • Code injection that modifies game functions
      • Memory leaks that slow down the game
      • Null pointers that crash enemies
      • Stack overflows and buffer overflows
      • Random teleportation and other unpredictable effects
    3. Robust Design: The game is designed to handle these modifications without crashing:

      • Error handling around all glitch effects
      • Original function backups
      • Graceful degradation when things go wrong
    4. NUMPAD Controls: Full movement with numpad or arrow keys

    5. Help System: Detailed help menu explaining the game concept

    6. Visual Effects: Some glitches have visual representations

    How to Play:

    1. Move around with numpad or arrow keys
    2. Find and pick up glitch items (press ',')
    3. Use items from your inventory (press 'i' to see inventory)
    4. Watch as the game changes in unexpected ways!
    5. Try to survive as the game becomes increasingly unstable

    The game demonstrates how to create a system that can handle runtime modifications while maintaining stability. Each glitch item has a unique effect that modifies the game's behavior in some way.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.