CISC 181 Introduction to Computer Science, Fall, 1998

Nov 9 Lab project -- Using a class, using a makefile

  1. To do in lab

    1. create a directory in which to do this lab, and make it your current working directory:
      mkdir knight
      cd knight
      
    2. Make a copy in your directory of 181/lab9/kt.cc and of 181/lab9/makefile
      cp ~/181/lab9/kt.cc .
      cp ~/181/lab9/makefile .
      
    3. The version of kt you have copied depends on a Board class which has a display() member function as well as the members we looked at in class. The display() member function is defined in kt.cc, but it is an incomplete definition. The display function is called by main (after running kt()), in order to display the knight's tour solution. The makefile contains commands to compile kt.cc in conjunction with the compiled board class in the lab directory. Note that you do not copy the board class definitions or header to your directory. The makefile is used by the make command which is a tool designed to simplify compilation of multi-file programs. Compile and run the program to see the behaviour of the present version:
      make kt
      kt 3 3
      kt 3 4
      
      Remark: Do not call kt with arguments larger than 5! It will engage in a huge search and use too much cpu time. If you want to try kt on a full size chessboard, compile and run it on a pc.
    4. Change the body of the display function so that it prints all the elements of the board array of the Board class instance, row by row. The setw function can be used with cout to line up the numbers by column. Compile using make as in the preceeding step, and run with the same command line arguments.
    5. What did you see for results? Any surprises?
      At the end of lab, hand in a printout of your kt.cc with a handwritten note about the results of
      kt 3 3  
      kt 3 4 
      
  2. For next Monday, Modify the kt() function so that when it returns, the Board is set to a solution having the maximal score (the score that kt returns). In other words the two lines in main()
      int result = kt( B );
      B.display();
    
    should have the effect of displaying B in a state corresponding to the result. (As it stands, the board is sometimes set to a winning board and sometimes not.) This will not involve much programming, but requires you to think thru the issue.
  3. Two week project:
    Design a program to solve the 8 queens puzzle. See exercise 4.26 for a description of the puzzle. The process of searching for a solution can me modelled on the knight's tour example. You may start from kt.cc and from 181/C++examples/knight/board.cc and board.h. While the style of the search is the same, you may wish to modify the way in which the Board class represents things for application to the 8 queens situation. This will be due Monday, Nov 23.