Bola 8

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

How to play

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.

Drag on the table
aim
Power bar
choose how hard you hit
Dot on the cue ball
spin

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 an 8-ball pool game for the browser.

- Table with 6 pockets, 15 numbered balls (1-7 solids, 8 black, 9-15 stripes) and the cue ball, with the correct starting rack and the 8 in the middle.
- Rules: open table until the first ball is potted; after that each player has their group; the 8 goes last and you have to call the pocket.
- Fouls: not hitting any ball, hitting a ball from the other group first, potting the cue ball, or no ball reaching a cushion. After a foul, the opponent plays with ball in hand.
- You aim by dragging, with an aiming line; a power bar and a dot on the cue ball for spin.
- Physics with friction, bounces and ball-to-ball collisions. Deterministic: fixed time step, no randomness and no dependence on the refresh rate.
- Three modes: two players on the same device, against the computer, and online with a 4-character code, sending the shot (angle, power and spin) instead of the positions.
Technical: a single HTML file with the CSS and JavaScript inside, no libraries and no external images, everything drawn on canvas. Vertical table on mobile and horizontal on desktop.

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 billar bola 8 (pool americano) para navegador, con modo de un jugador y modo multijugador por código de sala.

El juego:
- Mesa con 6 troneras, 15 bolas numeradas (1-7 lisas, 8 negra, 9-15 rayadas) y la blanca. Triángulo inicial correcto, con la 8 al centro.
- Reglas de bola 8: mesa abierta hasta la primera bola embocada legalmente; después cada jugador tiene su grupo; la 8 se emboca al final y hay que cantar tronera; se pierde si se emboca la 8 antes de tiempo, en la tronera equivocada o junto con la blanca.
- Faltas: no tocar ninguna bola, tocar primero una del grupo contrario, embocar la blanca, no sacar ninguna bola ni llevar ninguna a la banda. Tras falta, el rival tiene bola en mano.
- Apuntar: arrastrar para el ángulo (con línea de puntería y rebote previsto), una barra de fuerza, y efecto eligiendo un punto en la blanca.
- Física: fricción, rebote con bandas, colisión elástica entre bolas, efecto básico. TIENE QUE SER DETERMINISTA: paso de tiempo fijo, sin Math.random() en la simulación, sin depender de la tasa de refresco. Dos navegadores con el mismo tiro tienen que llegar al mismo resultado, bola por bola.

Modos: dos jugadores en el mismo dispositivo; contra la máquina con dos niveles; y en línea con código de 4 caracteres.

Multijugador:
- Se envía el TIRO, no las posiciones: ángulo, fuerza y efecto, más el número de jugada.
- Junto al tiro viaja una huella corta del estado de la mesa. Si no coincide, se avisa "la partida se desincronizó" en vez de mostrar cosas distintas a cada uno.
- La bola en mano también viaja como jugada.
- Reconexión: con el mismo código se vuelve a entrar y la partida se reconstruye resimulando todos los tiros, sin dibujar.

Pruebas que tienes que correr: el mismo tiro 100 veces con posiciones finales idénticas bit a bit; 20 tiros simulados dos veces por separado; que ninguna bola atraviese otra ni la banda a máxima fuerza; y una partida completa entre dos pestañas con una recarga a mitad.

Técnico: un solo archivo HTML con todo el CSS y el JavaScript dentro, sin librerías, sin CDN y sin imágenes externas. Mesa vertical en celular y horizontal en 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 deterministic physics FROM THE START if there will be multiplayer: it's what lets you send the shot instead of the positions. Adding it later means rewriting the engine.
  • Ask it to check that no ball passes through another at full power: it's the classic bug of this game.
  • Say which rule variant you want (here: free ball in hand, and the 8 potted on the break gets re-spotted). If you don't, every AI picks a different one.

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, y la exigencia de que dos navegadores lleguen al mismo resultado con el mismo tiro.

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

Ajedrez

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.

  • Medium
  • Classic
  • Strategy
  • 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