Solving the 8 Queens Problem

2009 June 20

I will be teaching a course in Artificial Intelligence this summer. For some parts of the course, I plan to show implemented demos along with the course material. Looking from the students’ point of view, such tools not only decrease the learning time while in the class room, but also give enough material to play around at home in case you want to repeat what was taught. (I can empathise because I was once, and will be again (hopefully soon), a student).

While preparing the first few lectures, I realized I needed a simulation of the 8 Queens Problem using Breadth First Search and Depth First Search. While there are many solutions on the Internet, I couldn’t find any program which lets me step through the algorithm. Besides, it had been a long time since  I did any programming in Windows.Forms so my code deprived fingers needed a sink.

8queens

So here’s my version of the 8 queens problem solver. Each board state is represented by a string. The string represent the columns starting from the left most column and the number in that position tells the row in which a queen is present.  The screenshot above thus represents the state 03142. The state 0314 would represent an empty column 4. You can download the compiled binary by clicking on the link below. I will try to upload the source once the assignment deadline has passed The source code is available for download below. Keep in mind that it’s hacky and badly written and should not be used in assignments. If you want a ready-made assignment, search elsewhere (or still better, drop out and do something you really love => ). It was developed in C# so you might have to install Microsoft .NET framework 3.5 to run this program. Comments/Suggestions/Bug Reports are welcome.

Download the 8 Queen Problem Solver     [ Code ]

2 Responses leave one →
  1. 2010 November 11
    alin permalink

    hi, can upload the source code for the 8Queen Problem Solver?
    I really need to take a look!!!

    10x:)

    • 2010 November 11
      awais permalink

      Uploaded. Though you might want to read my disclaimer first :)

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS