Output of file : QUEEN2.PAS contained in archive : ITP9004.ZIP
{************************************************
* QUEEN2 - the first attempt at solving the *
* queens problem. *
* *
* INP: c - the column # to place a queen in *
* n - the maximum column (& row) number *
* USES: Soln - updates this solution counter *
* whenever a queen is successfully placed *
* in the n'th column. *
************************************************}

UNIT Queen2;

INTERFACE

CONST
MaxBrd = 25;

VAR
{Chess brd}
Board : ARRAY[0..MaxBrd+1,0..MaxBrd+1] OF Byte;
Solns : Integer;

PROCEDURE InitBoard;
PROCEDURE Queens(C,N: Integer);

IMPLEMENTATION

PROCEDURE InitBoard;
BEGIN
FillChar(Board,SizeOf(Board),#0);
Solns := 0
END;

PROCEDURE Queens;

LABEL
Break;

VAR
I,J : Integer;
Legal : Boolean;

BEGIN
{Have we found a solution?}

IF C=N THEN
Inc(Solns)
ELSE

{Check each spot in the column}

BEGIN
FOR I:= 0 TO N-1 DO
BEGIN

Legal := TRUE; {Legal until disproven}

FOR J := 1 TO C DO

BEGIN

{-- Check row --}

IF (Board[I,C-J] <> 0) THEN
BEGIN
Legal := FALSE;
GOTO Break
END;

{-- Check diagonal 1 --}

IF ((I+J) < N) THEN
IF (Board[I+J,C-J] <> 0) THEN
BEGIN
Legal := FALSE;
GOTO Break
END;

{-- Check diagonal 2 --}

IF ((I-J) >= 0) THEN
IF (Board[I-J,C-J] <> 0) THEN
BEGIN
Legal := FALSE;
GOTO Break
END
END;
Break:
IF (Legal) THEN
BEGIN
Board[I,C] := 1; {Put queen here}
Queens(C+1,N); {Process next col}

Board[I,C] := 0 {Remove & try next}
END;
END;
END;
END;

END.

### 3 Responses to “Category : Files from MagazinesArchive   : ITP9004.ZIPFilename : QUEEN2.PAS”

1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/