] > Assignment 2: Flow of Control (Due: Tu, April 15)

Assignment 2: Flow of Control (Due: Tu, April 15)

Write a program ‘chess.cpp’ that prepares a HTML file ‘chess.html’ specifying a chess-like board containing chess pieces. The program should get for an input a file ‘chess.txt’ with the following content.

  1. A number stating the dimension of the board
  2. A number stating the number n of pieces
  3. The specification of the pieces, where for each piece the following 4 are provided.

    row, column, color, type

    The pieces are to be listed ordered row-wise within the table, and column-wise within the rows.

The HTML file should represent the pieces through unicode characters. The following table lists the characters.




♔white king



♕white queen



♖white rook



♗white bishop



♘white knight



♙white pawn



♚black king



♛black queen



♜black rook



♝black bishop



♞black knight



♟black pawn



Notes.

 4
 5
 2 4 black knight
 3 3 black king
 3 4 white pawn
 4 1 white king
 4 4 white rook
-_-_-

 <html>
 <head>
    <style type=’text/css’>
       table{ font-size:200%;
       margin-left: auto;
       margin-right: auto;
       border: 1px black solid
                 }
       .white { background-color:#FFFFFF;
                color:#000000}
       .black { background-color:#B0B0B0;
                color:#000000}
       td{ width:1.3em; height:1.3em;
           text-align:center }
    </style>
 </head>
 <body>
     <table class=’chess’>
       <tr>
         <td class=’white’/>
         <td class=’black’/>
         <td class=’white’/>
         <td class=’black’/>
       </tr>
       <tr>
         <td class=’black’/>
         <td class=’white’/>
         <td class=’black’/>
         <td class=’white’>&#x265E;</td>
       </tr>
       <tr>
         <td class=’white’/>
         <td class=’black’/>
         <td class=’white’>&#x265A;</td>
         <td class=’black’>&#x2659;</td>
       </tr>
       <tr>
         <td class=’black’>&#x2654;</td>
         <td class=’white’/>
         <td class=’black’/>
         <td class=’white’>&#x2656;</td>
       </tr>
     </table>
 </body>
 </html>
-_-_-

Suggestion. Build your program incrementally. For instance, as described below.

  1. Have the program read the input and print it out.
  2. Add to the program a code fragment that prints an image of the board as a matrix of 0’s and 1’s. For instance, the following matrix for boards of dimension 4.

    0101
    1010
    0101
    1010

  3. Modify the program to output the matrix into the ‘chess.html’ file
  4. Modify the program to place in the file ‘chess.html’ HTML code that display the desired board without pieces.
  5. Add to the program code that display the character ‘X’ at each entry that should contain a piece.

    Hints.

  6. Fix the program to place the desired unicode chess characters instead of the ‘X’ characters.

Posting web pages. Web pages can be posted in the following manner on the CSE site.

  1. Create at the root directory a subdirectory named WWW.

    mkdir ~/WWW

  2. Make the WWW directory globally accessible.

    chmod 711 ~/WWW

  3. Copy the HTML file to the WWW directory.

    cp chess.html ~/WWW/.

  4. Make the HTML file globally readable.

    chmod 644 ~/WWW/chess.html

  5. The URL for the web page will be

    http://www.cse.ohio-state.edu/~your-user-name/chess.html