Computer Science 3675
Summer 2000
Programming Assignment 8

Due: June 19

This assignment can be completed very quickly. The infrastructure has been written for you. You just put in the more interesting (and fairly short) parts.

The N-queens problem is as follows. You must place N queens on an NxN chess board in such a way that no two of the queens are attacking one another. Two queens attack one another if they are in the same row, the same column, or the same diagonal. For example, on a 5x5 board, you can place the queens as follows, where a dot represents an empty square and a Q represents a queen.

       Q . . . .
       . . Q . .
       . . . . Q
       . Q . . .
       . . . Q .
Notice that there must be exactly one queen in each row and one queen in each column.

Your exercise it to write an Astarte program that solves the N-queens problem by using backtracking. The idea is to try placing a queen in each position in the first row. Then try placing a queen in each position in the second row, etc. If a thread tries to place a queen in a position that is already under attack, that thread should fail.

Store the board as an array of nonshared boxes, so that the changes that one thread makes will not affect its sibling threads.

The program should print all possible solutions, and then say how many solutions there are. You will want to use a shared box to accumulate the number of solutions, since that way all of the threads can modify the same box.

A partial solution can be found in file /export/stu/3675/nqueens.ast. Use that as a starting point. Fill in the missing parts.

  • nqueens.ast
  • Turn in your solution by email in the usual way.