Ajedrez

  • Difficulty: Medium
  • Classic
  • Strategy
  • Online
Click inside the game to use the keyboard. Open in a new tab

How to play

Full chess with the real rules: castling, en passant, promotion and draws. Against the computer, two players on one device, or online with a code.

Click or tap a piece
see its legal moves
Click or tap a square
move
Flip button
turn the board around

The game runs isolated from the rest of the site. Your high score and settings are saved only in this browser.

How this game was made

This game came out of a single message to an AI. Below: a short prompt to copy and paste, how to get the game as one HTML file, the full prompt that was actually used, and what it was missing.

Ask for it like this

Copy this prompt, paste it into Claude or ChatGPT, and that's it. It's the short version: the minimum for the game to come out playable.

Make me a complete chess game for the browser.

- All 6 pieces with their real rules: short and long castling, en passant, promotion with a choice of piece, check, checkmate, stalemate and draws by insufficient material, threefold repetition and the 50-move rule.
- Touching a piece highlights its legal squares; a move that leaves your own king in check is not allowed.
- Board and pieces drawn on canvas with their own shapes, readable at 40 px. Not the chess font, which looks different on every system.
- Move history in algebraic notation, an undo button and an optional 5 or 10 minute clock.
- Three modes: two players on the same device with a board that flips, against the computer at three levels, and online against a friend with a 4-character code.
- The computer answers in under a second and doesn't freeze the screen.
Technical: a single HTML file with the CSS and JavaScript inside, no libraries and no external images, everything drawn on canvas. It should fill the window and be playable with a finger on a phone and with the mouse on a computer.

Getting it as an HTML file

A game like this is a single file you open with a double click. These four steps are the same in any AI.

  1. 1. Ask for the whole file

    Add this line at the end of your prompt: Give me a single, complete HTML file, nothing cut out, ready to save as index.html and open in the browser. Without it, you often get the code in pieces.

  2. 2. Copy all of the code

    In Claude the game shows up on the side, already running, with a button to copy or download it. In ChatGPT, copy the whole code block: it has to start with <!DOCTYPE html> and end with </html>.

  3. 3. Save it as index.html

    Paste it into Notepad (Windows) or TextEdit in plain text mode (Mac) and save it as index.html. Watch out for .txt: if the file ends up as index.html.txt, it won't open as a page.

  4. 4. Double-click to open it

    It opens in your browser and it's ready to play, with nothing to install and no internet needed. To share it, upload it to any web host or send it by email: it's just one file.

If the game shows up blank, go back to the AI and paste the error from the browser console (right click → Inspect → Console). With that text it fixes it fast.

The full prompt, the one actually used

Longer and more specific: numbers, screens and style details. It's the one that produced exactly this game, unedited. Use it if you want to fine-tune the result.

Diego wrote it in Spanish and it stays in Spanish on purpose: it's the honest record of how the game was made, and a translation would be a prompt nobody used. Claude and ChatGPT understand it as is; add "Answer in English" if you want the game's text in English.

Construye un juego de ajedrez para navegador, con modo de un jugador y modo multijugador por código de sala.

El juego:
- Ajedrez completo y correcto: movimientos de las 6 piezas, enroque corto y largo, captura al paso, coronación (con elección de pieza), jaque, jaque mate, ahogado, tablas por material insuficiente, por repetición triple y por la regla de 50 movimientos.
- Tablero dibujado en canvas, piezas dibujadas con formas (nada de imágenes ni de la fuente de ajedrez Unicode, que se ve distinta en cada sistema). Que se distingan bien a 40 px.
- Al tocar una pieza se marcan sus casillas legales; solo se permiten jugadas legales.
- Historial de jugadas en notación algebraica, con botón para deshacer solo en el modo sin red.
- Reloj opcional por jugador (5 o 10 minutos, o sin reloj).

Modos:
1. Dos jugadores en el mismo dispositivo (el tablero se puede girar).
2. Contra la máquina: 3 niveles. Búsqueda alfa-beta con tabla de valores de pieza y posición. Tiene que responder en menos de 1 segundo en celular y NO congelar la interfaz.
3. En línea por código: "Crear partida" (muestra el código de 4 caracteres, grande, con botón de copiar, y espera) y "Entrar con código". El anfitrión juega con blancas.

Multijugador:
- Cada jugada se manda como una cadena corta: casilla origen, casilla destino y pieza de coronación si aplica.
- Lo que llega del rival se valida contra tu propio tablero: si es ilegal, se descarta y se muestra "la partida se desincronizó", sin romperse.
- Reconexión: si se recarga la página, con el mismo código se vuelve a entrar y la partida se reconstruye desde las jugadas.
- Avisos claros: esperando rival, turno del rival, rival desconectado, rival se fue. Rendirse y ofrecer tablas, con confirmación del otro lado.

Pruebas que tienes que correr: tests de reglas en node con perft en posiciones estándar (enroque, al paso, coronación, mate, ahogado, 50 movimientos, repetición triple), y una partida completa entre dos pestañas.

Técnico: un solo archivo HTML con todo el CSS y el JavaScript dentro, sin librerías, sin CDN y sin imágenes externas. Que llene la ventana y se juegue con el dedo en el celular y con mouse en la PC. Tiene que funcionar dentro de un iframe con sandbox="allow-scripts".

For ChatGPT, add the line from step 1 at the end: it tends to hand over the code in pieces.

What this prompt was missing

What became clear once the game was finished. If you're making your own from this one, add these from the start: fixing things later costs another round.

  • Ask for online play with a room code from the start: adding it later means redoing how the game stores the match.
  • Say how long the computer may take to answer (here: under 1 second, without freezing the screen). Without that limit, a stronger engine locked up the phone.
  • Ask for rule tests against known positions (perft): that's what exposes castling and en passant bugs.

What was asked after the first result, in Diego's own words (Spanish):

  • A diferencia de los demás, este juego no salió de un prompt corto: se le pasó además el protocolo de salas del sitio, con cómo crear la sala, cómo pedir el estado y qué hacer si la partida se desincroniza.

It works in any AI

Claude, ChatGPT, Gemini, Copilot: the prompt is the same and so is the method. What changes is where you see the result. Four things that hold in all of them:

  1. Ask for a single file

    "A single HTML file with everything inside, no libraries or CDN." That way the game works with a double click, with nothing to install, and you can upload it to any website.

  2. Ask it to tell you what it assumed

    End with: "before writing the code, tell me in 5 lines what you assumed". That's where the gaps in your prompt show up, while fixing them is still cheap.

  3. One fix per message

    Say what happens and what you expected. If you ask for three changes at once, one usually undoes another.

  4. Ask it to test, not to promise

    "Check that every level can be won and tell me how you checked." That's how the games on this page found their bugs before going live.

The 6 parts of a good prompt, with a template to copy

More games

Bola 8

8-ball pool with its own physics: spin, cushions and ball in hand. Against the computer, two players on one device, or online with a code.

  • Medium
  • Physics
  • Sports
  • Online

Kuru

Greedy worms in a night field: eat the seeds, grow long and make the others crash into you. Solo against bots or online with up to 6.

  • Medium
  • Action
  • Arcade
  • Online

Horda

Hold out against waves of shadows in a closed map. Four weapons, exploding barrels and barricades. Solo, two on one keyboard, or online.

  • Hard
  • Action
  • Co-op
  • Online