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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#include <iostream>
#include <iomanip>
#include <cctype>
//function definitions
void cmove(char (&)[8][8], int, int, char);
void displayboard(char (&) [8][8]);
void showboard(char (&) [8][8]);
int main()
{
char pieces[8][8] = {{'r', 'n', 'b', 'k','q', 'b', 'n','r'},
{'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'},
{'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e'},
{'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e'},
{'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e'},
{'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e'},
{'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'},
{'r', 'n', 'b', 'k','q', 'b', 'n','r'}} ;
char choice = ' ';
do
{
std::cout << "Enter a choice: " << std::flush;
std::cin >> choice;
choice = toupper(choice);
while (choice != 'n' && choice != 'b' && choice != 'r' && choice != 'k' && choice != 'q' && choice != 'p')
{
std::cout << "Please enter a valid move: " << std::flush;
std::cin >> choice;
choice = toupper(choice);
}
if (choice == 'n')
{
displayboard(pieces);
cmove(pieces, 8, 8, 'n');
displayboard(pieces);
}
else if (choice == 'b')
{
displayboard(pieces);
cmove(pieces, 8, 8, 'b');
displayboard(pieces);
}
else if (choice == 'r' )
{
displayboard(pieces);
cmove(pieces, 8, 8, 'r');
displayboard(pieces);
}
else if (choice =='k')
{
displayboard(pieces);
cmove(pieces, 8, 8, 'k');
displayboard(pieces);
}
else if (choice == 'q')
{
displayboard(pieces);
cmove(pieces, 8, 8, 'q');
displayboard(pieces);
}
else if (choice == 'p')
{
displayboard(pieces);
cmove(pieces, 8, 8, 'p');
displayboard(pieces);
}
}(while choice != 's');
return(0);
}
void cmove (char (&eightby)[8][8], int a, int b, char c)
{
for (a= 0; a<1; a++)
{
for (b=0; b<1; b++)
{std::cout << "enter row: " << std::flush;
std::cin >> a;
std::cout << "\nenter column: " << std::flush;
std::cin >> b;
a-=1;
b-=2;
}
eightby[a][b]=c;
}
std::cout << "\nchanged\n" << std::endl;
}
void displayboard(char (&byeight)[8][8])
{
for (int i=0; i<8; i++)
{
for (int j=0; j<8; j++)
{
std::cout << std::setw(2) << byeight[i][j] << std::flush;
}
std::cout << std::endl;
}
}
|