N Queens by Mihailo Despotovic, April / May 1997

Place n queens on an n × n chessboard so that no two attack each other: my term project for “Primene veštačke inteligencije” (Applications of Artificial Intelligence) class with professor dr. Vladimir Srdanović, during my MSc studies at the University of Belgrade. It finds every solution by recursion and backtracking, and shows them one by one. It runs here as it did in DOS, in Serbian, with the English translation of the screen beside it. Click the screen and type, or use the buttons.

Keys:
The DOS screen

        
In English

        
The solution on the screen, as a chessboard

The backtracking, step by step

The same search, one square at a time, which the program itself only showed through its solutions: column by column from the left, it tries each row from the top, puts a queen on the first square no queen attacks (green), and when a column has no free square left, it goes back and moves the queen before it (orange). Attacked squares are red, solutions blue.

Notes: the program asks for “1 < dama < 15” but takes 1 to 15, and 1 queen is a solution too. With the pause off ([P] → Ne), it counts the solutions as fast as it can, showing them as it goes: 92 for 8 queens, 724 for 10, and 2,279,184 for 15, which takes a while here and took much longer in 1997. While it pauses at each solution, there is no way out but to see them all, then as now. I checked the port by running the original C++ with scripted keys: every screen is the same.

The original C++ code