Skip to content
TheChatArchiveThe Chat Archive
o3-2025-04-16· OpenAIHugging Face LMArena Human Preference 140K

Create an JS and HTML game in OOP style. The name of game is Gryptogram.

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with chatgpt-4o-latest-20250326’s answer.
  1. User

    Create an JS and HTML game in OOP style. The name of game is Gryptogram.

  2. Assistant

    Below is a minimal but fully–working version of “Gryptogram”.
    Everything is written in an Object‑Oriented style and split into two files (index.html & script.js).
    Simply drop both files into the same folder, open index.html in your browser, and start playing!


    index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Gryptogram</title>
        <link rel="stylesheet" href="style.css" />
    </head>
    <body>
        <h1>🗝️ Gryptogram</h1>
    
        <!-- The puzzle board -->
        <div id="board"></div>
    
        <!-- Letter‑mapping pad -->
        <div id="pad"></div>
    
        <button id="newBtn">🔄 New Puzzle</button>
        <p id="msg"></p>
    
        <script type="module" src="script.js"></script>
    </body>
    </html>
    

    style.css (optional – keeps things neat)

    body{
        font-family: system-ui, sans-serif;
        text-align:center; padding:1rem; background:#f8f9fa;
    }
    #board {font-size:1.5rem; margin:1rem auto; max-width:900px; word-wrap:break-word}
    .letterBox{
        display:inline-block; width:1.5rem; border-bottom:1px solid #000;
        margin:.1rem; position:relative
    }
    .letterBox .plain{position:absolute; bottom:100%; font-size:.6rem; color:#666}
    .letterBox .guess{font-weight:bold;}
    #pad{margin:1rem auto; max-width:800px}
    .pad-letter{
        display:inline-block; margin:.2rem; cursor:pointer; padding:.2rem .3rem;
        border:1px solid #aaa; border-radius:3px; min-width:1.2rem; text-align:center
    }
    .pad-letter.used{background:#f1f3f5; color:#888}
    #msg {font-size:1.2rem; font-weight:bold; color:#008000}
    

    script.js

    // ======== Grypogram  (c) 2024 ========
    
    // A small collection of quotations to turn into cryptograms
    const QUOTES = [
        'The only limit to our realization of tomorrow is our doubts of today.',
        'Knowledge speaks, but wisdom listens.',
        'All that we are is the result of what we have thought.',
        'Life is really simple, but we insist on making it complicated.',
        'Experience is the name everyone gives to their mistakes.',
    ];
    
    // ---------- Cipher generator ----------
    class Cipher {
        constructor(plain) {
            this.plain = plain.toUpperCase();
            this.alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            this.mapping = this._generateMapping();
            this.cipher = this._applyMapping(this.plain);
        }
    
        // Create a random mono‑alphabetic substitution (no letter maps to itself)
        _generateMapping() {
            const shuffled = this.alphabet.split('').sort(()=>Math.random()-0.5);
            const mapObj = {};
            for (let i=0;i<26;i++){
                const p = this.alphabet[i];
                let c = shuffled[i];
                // ensure not mapping to itself
                if (c === p) [c, shuffled[(i+1)%26]] = [shuffled[(i+1)%26], c];
                mapObj[p] = c;
            }
            return mapObj;
        }
    
        _applyMapping(str){
            return str.split('').map(ch=>{
                const up = ch.toUpperCase();
                return this.mapping[up] ?? ch;
            }).join('');
        }
    }
    
    // ---------- Main Game ----------
    class GryptogramGame {
        constructor(boardEl, padEl, msgEl) {
            this.boardEl = boardEl;
            this.padEl   = padEl;
            this.msgEl   = msgEl;
            this.startNew();
        }
    
        startNew() {
            // pick a random quote
            const quote = QUOTES[Math.floor(Math.random()*QUOTES.length)];
            this.cipher = new Cipher(quote);
            this.guesses = {};               // current player mappings
            this.uniqueCipherLetters = [...new Set(this.cipher.cipher.match(/[A-Z]/g))];
            this._renderBoard();
            this._renderPad();
            this.msgEl.textContent = '';
        }
    
        // ------- rendering ----------
        _renderBoard() {
            this.boardEl.innerHTML = '';
            [...this.cipher.cipher].forEach(ch=>{
                if(/[A-Z]/.test(ch)){
                    const span = document.createElement('span');
                    span.className = 'letterBox';
                    const small = document.createElement('span');
                    small.className='plain';
                    small.textContent = ch;          // show cipher letter above
                    const big  = document.createElement('span');
                    big.className='guess';
                    big.textContent = this.guesses[ch] ?? '_';
                    span.append(small,big);
                    this.boardEl.appendChild(span);
                }else{
                    // punctuation / space
                    const txt = document.createTextNode(ch);
                    this.boardEl.appendChild(txt);
                }
            });
        }
    
        _renderPad() {
            this.padEl.innerHTML='';
            'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').forEach(l=>{
                const cell = document.createElement('span');
                cell.className='pad-letter';
                cell.textContent = l;
                if(Object.values(this.guesses).includes(l)) cell.classList.add('used');
                cell.onclick = ()=>this._onPadClick(l);
                this.padEl.appendChild(cell);
            });
        }
    
        // user clicked a pad letter to assign as a guess
        _onPadClick(padLetter) {
            // let user choose which cipher letter they are trying to solve
            const cipherLetter = prompt(`Map which cipher letter to "${padLetter}"? (A‑Z)`).toUpperCase();
            if(!/^[A-Z]$/.test(cipherLetter)) return;
    
            // keep mappings consistent: if someone already used that plain letter, remove it
            for (const c in this.guesses){
                if(this.guesses[c] === padLetter) delete this.guesses[c];
            }
            // set new guess
            this.guesses[cipherLetter] = padLetter;
            this._renderBoard();
            this._renderPad();
            this._checkWin();
        }
    
        _checkWin() {
            const currentPlain = this._decryptWithGuesses();
            if (currentPlain === this.cipher.plain){
                this.msgEl.textContent = '🎉 Correct! You solved it!';
            }
        }
    
        _decryptWithGuesses() {
            return [...this.cipher.cipher].map(ch=>{
                if(/[A-Z]/.test(ch)){
                    const g = this.guesses[ch];
                    return g ? g : ch;               // default to cipher letter if not guessed
                }
                return ch;
            }).join('');
        }
    }
    
    // ---------- bootstrapping ----------
    const game = new GryptogramGame(
        document.getElementById('board'),
        document.getElementById('pad'),
        document.getElementById('msg')
    );
    document.getElementById('newBtn').onclick = ()=>game.startNew();
    

    How to play

    1. Every cipher letter is shown on the board with an underscore beneath it.
    2. Click any letter on the bottom “pad”. You’ll be prompted to tell the game which cipher letter you think it stands for (type a single A‑Z).
      • Example: click “E”, then type “T” if you believe every “T” in the cipher represents plain “E”.
    3. The board instantly updates. Keep mapping letters until the full message appears.
    4. When all letters are correct, you’ll see a celebratory message.
    5. Press “🔄 New Puzzle” anytime for a fresh cryptogram.

    Have fun breaking ciphers! 🕵️‍♂️🧩

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