VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



The Eight Queens Problem Revisited

by Terry Smith - Clarion Clipper and Visual Basic (1 Submission)
Category: Games
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

This program started out as a project in Byte Magazine way back in the 70s.
I wrote it in basic for the IBM 370. In those days I didn't know recursive programming, so I wrote it in procedural format. Yuck. Today I tried to duplicate that, but I found I can't even think like that anymore. Also - it took 3 weeks then and 30 min now, not counting looking up how to run the @#$ MS flex grid...:-)
The article caused quite a sensation. Byte published two issues of mail replies to it...
The problem is to put 8 Queens on a chess board in such a manner that no Queen can take another. This is surprisingly difficult.
The algorithm I use is a common sense one but I didn't think of it - I read it in a book somewhere. What you do is divide the chess board into columns, and, moving from the left, place a Queen in the first column in the lowest available non-tried square. Then you place one penny on each square the Queen covers.
Then you move one column to the right and do this again. Note the Queen is pushed up to the third square by the two pennies already in it's column.
Move right again. When you get to the sixth column you cant place a Queen as the column is full of pennies.
You back to the previous column, remove the Queen and remove all it's pennies. Then you go up in the column, if you can, and replace the Queen and all its pennies, and keep going.
When you can't go up any further, you go back another Queen.
When you place a Queen on the 8th column you record the position and then treat it as if it failed. This program pauses 5 seconds and makes a beep.
When you cannot move the first Queen any higher, the search is over.

Rate The Eight Queens Problem Revisited

Upload

Download this snippet    Add to My Saved Code

The Eight Queens Problem Revisited Comments

No comments have been posted about The Eight Queens Problem Revisited. Why not be the first to post a comment about The Eight Queens Problem Revisited.

Post your comment

Subject:
Message:
0/1000 characters