//
//
//  chess.cc
//
//      AUTHOR: Russell Lowke
//         T.F: Francis Crick
//  CSCIE-s111: Unit Two, Main - question 8 [worth 2pts],  7/3/2002
//
// Description: Modified version of chess.cc, original by Dr. H.H. Leitner
//
//              A King piece has been added (option 2 at prompt)
//
//              Calculates and displays where
//              a KNIGHT or BISHOP or KING in chess can move from
//              a given location on the board.
//
//       Notes: Modified lines are marked with a "(Russ)" comment  
//

#include  <iostream>
#include  <iomanip>

class Chessboard
{
     private :  int piece_row, piece_column;
       public:  void place_one_piece();
                void show_the_attack();
}; 

void Chessboard ::  place_one_piece()
{
   cout << "Type the ROW where your chess piece is located: ";
   cin >> piece_row;
   cout << "Type the COLUMN where your chess piece is located: ";
   cin >> piece_column;
   if ((piece_row < 1) || (piece_row > 8)
          || (piece_column < 1) || (piece_column > 8))
	          cout << "Invalid input, but I'll try anyway";
}

void Chessboard :: show_the_attack()
{ 
   int piece_type, index_row, index_column;
   int column_diff, row_diff;
   cout << "Type 0 for a BISHOP attack, 1 for a KNIGHT: ";
   cout << " 2 for a KING: ";  // add King (Russ)
   cin >> piece_type;
   cout << "\n   1 2 3 4 5 6 7 8\n";
   for (index_row = 1; index_row <= 8; index_row++)
         {
	        cout << setw(2) << index_row;
            row_diff = piece_row - index_row; 
            for (index_column = 1; index_column <= 8; index_column++)
               { 
                  column_diff = piece_column - index_column;
                  if ( (piece_type == 0) &&
                       ((column_diff+row_diff == 0) || (column_diff==row_diff)))
                            cout << " X"; 
                  else if ((piece_type == 1) &&
                           ((column_diff*column_diff + row_diff*row_diff==5)
                              || (column_diff== 0 && row_diff == 0)))  
                                     cout << " X";
                                     
                                     
                  else if ((piece_type == 2) &&  // piece = King (Russ) 
                          (column_diff > -2 &&
                           column_diff <  2 &&
                           row_diff    > -2 &&
                           row_diff    <  2))
                  	cout << " X";
                   
                  else if((index_column + index_row) % 2 == 0) cout << " b";
		          else  cout << " w";
                     
               }
            cout << endl;
	 }
  cout << endl;
}


void main()
{
    Chessboard c;
   
    c.place_one_piece();
    c.show_the_attack();
}