Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Puissance 4

An empty Connect Four board: blue grid, green column selector on the left Four red pieces in a row along the bottom, with the message 'Les Rouges remportent la partie.'

A game of Connect Four in C++ and SFML 1.6, written on 10 July 2012. The whole thing, in one day.

Two players at one keyboard. 339 lines.

That is this exact source, unmodified, compiled to WebAssembly. See the web version below for how.

Both screenshots above are the original 2012 binary running in 2026, not 2012 artifacts. See running it today.

The day

Every file's modification time survived, and together they tell the story better than I could:

03:58  comp.sh          the compile script, written before any code
04:24  event.hpp
04:36  draw.hpp
05:10  draw.cpp
05:11  both headers      int → bool, 22 seconds apart
05:16  event.cpp         drop is still bound to Return
05:20  draw.cpp          fix the win message naming the wrong colour
       · · · · · · ·  thirteen and a half hours  · · · · · · ·
18:46  event.cpp         Return becomes Down
18:58  main.cpp
18:58  it compiles
19:07  todo.list

The last line of that todo.list, written at 19:07 after a day that started at four in the morning:

Ne pas oublier de faire dodo de temps en temps...

("Don't forget to sleep from time to time...")

The rest of the list: test for a draw, add a splash screen, improve the graphics, and this: "Programmer une I.A. si je deviens courageux comme Chuck Norris." Write an AI if I get as brave as Chuck Norris. I did not get as brave as Chuck Norris.

Playing

Key
move the green column selector
drop a piece
Esc quit

Red plays first. A banner along the bottom says whose turn it is, and who won.

Building

Historical interest only. This targets SFML 1.6, whose entire API was replaced in SFML 2.0 in 2013. RenderWindow::IsOpened, GetEvent, sf::String as a drawable, the Shape::Rectangle/Line/Circle factories, and Font::GetDefaultFont are all gone. Installing a current SFML will not make this compile.

sh comp.sh

bin/puissance_quatre is the original 32-bit i386 binary from 10 July 2012, 18:58:40, linked against libsfml-*.so.1.6.

Running it today

The binary still runs. It needs its own era's libraries, not a modern build of them, so the trick is to go back to 2012 rather than drag the game forward. Debian wheezy still carries libsfml-graphics1.6 at exactly the version this was linked against, and the Debian archive still serves it.

podman run --rm -it \
  -v "$PWD":/game:ro -v /tmp/.X11-unix:/tmp/.X11-unix \
  -e DISPLAY="$DISPLAY" \
  <an i386 wheezy image with libsfml-graphics1.6 and mesa> \
  /game/bin/puissance_quatre

The screenshots at the top of this page came out of exactly that: the 2012 binary, unrecompiled, drawing to a 2026 desktop through XWayland. Nothing about it was rebuilt or patched.

The web version

Playable here.

The web build does not port the game. It ports SFML. A shim on the gh-pages branch reimplements the slice of the SFML 1.6 API these files actually use, about 200 lines, backed by a 2D canvas. main.cpp, event.cpp and draw.cpp then compile against it byte for byte as written, under -Wall -Wextra, with no warnings.

The blocking while (app.IsOpened()) loop, which no browser will tolerate, is handled by Emscripten's ASYNCIFY rather than by restructuring main(). Every bug below is still present in the browser, including the out-of-bounds read, which lands in the other player's grid there just as it does on x86.

Layout

src/          main.cpp, event.cpp, draw.cpp      (294 lines)
src/include/  draw.hpp, event.hpp                 (45 lines)
bin/          the 2012 binary
comp.sh       three g++ lines
todo.list     see above

main.cpp holds the window, the colours and the two int[6][7] grids, one for red and one for yellow. event.cpp handles input and win detection. draw.cpp draws.

Known bugs

Kept as-is rather than fixed. The point of this repo is the artifact, not the software.

  • Reading off the front of the array. The scan for the lowest free cell (event.cpp:50) tests grille[y][selCol] at y == -1 before the if (y >= 0) guard on the next line. Drop into a full column and it reads memory in front of the grid. Given the two arrays are declared back to back in main, that is usually the other player's board. It normally stumbles onto a zero and the guard rejects the move, so it looks like it works. It is still undefined behaviour.
  • Win counters aren't reset per move. The seven direction counters (event.cpp:16-17) are initialised once per call, but while (app.GetEvent(event)) can drain several key presses in one frame. Two drops in the same frame add their counts together and can declare a win that isn't there.
  • No draw detection. Fill the board with nobody winning and the game just sits there. It is the first item on the to-do list.
  • No restart, and after a win the selector still slides left and right.
  • The comments in draw.cpp:15,22 label the horizontal and vertical loops the wrong way round.

The win detection itself is sound: it counts up to three along each of seven directions and pairs the opposites (gauche+droite, gaucheHt+droiteBs, droiteHt+gaucheBs). Up is skipped, correctly, since nothing can be above the piece you just dropped.

Everything is named in French, because I was.

About the git history

There was never a git repo in 2012; this was a folder. The commits here were reconstructed in 2026 from the original file modification times, which survived intact.

The early commits are not guesses. My editor renamed each file to name~ on save and kept the old timestamp, so every source file left behind a second, earlier snapshot, and the diffs between them are changes I actually made that day: the drop key moving from Return to Down, int flags becoming bool, and the fix to AfficherInfo, which until 05:20 that morning congratulated the wrong player.

The dates, the order of work, and the contents are real. The commits are not.

About

Connect Four in C++ and SFML 1.6, written in a single day in July 2012. Playable in the browser.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages