1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#include <iomanip>
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
void init_board (char board [8][8]);
void move_queen (char board [8][8], int row, int col);
void move_knight (char board [8][8], int row, int col);
void print_board (char board [8][8]);
int main()
{
char board [8][8];
char input;
init_board (board);
cout << "Enter q (queen), k (knight) or e (end): " << endl;
cin >> input;
while (input != 'e')
{
if (input == 'q')
{
move_queen (board, 8, 8);
print_board (board);
system("PAUSE");
return 1;
}
if (input == 'k')
{
move_knight (board, 8, 8);
return 1;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
void init_board (char board [8][8])
{
int row, col;
for (row = 0; row < 8; row++)
for (col = 0; col < 8; col++)
board[row][col] = '.';
}
void move_queen (char board [8][8], int row, int col)
{
int r, c;
cout << "Enter starting row: " << endl;
cin >> r;
cout << "Enter starting column: " <<endl;
cin >> c;
board [r-1][c-1] = 'q';
for (row = r+1; row <= 8; row++)
board [row][col] = ' * ';
}
void move_knight (char board [8][8], int row, int col)
{
int r, c;
cout << "Enter starting row: " << endl;
cin >> r;
cout << "Enter starting column: " <<endl;
cin >> c;
}
void print_board (char board [8][8])
{
int row, col;
for (row = 0; row < 8; row++)
{
for (col = 0; col < 8; col++)
cout << board[row][col] << " ";
cout << endl << endl;
}
cout << endl;
}
|