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
|
#include <iostream>
#include <cstdlib>
using namespace std;
int Chess (int row, int column)
{
int possiblemoves[8][2]={{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1}};
int moves=0;
for (int i=0; i<8; i++)
{
if (row+possiblemoves[i][0]>=1 && row+possiblemoves[i][0]<=8)
{
if (column+possiblemoves[i][1]>=1 && column+possiblemoves[i][1]<=8)
{
moves++;
}
}
}
return moves;
}
int main()
{
cout << "Row: ";
int row, column;
cin >> row;
cout << "Column: ";
cin >> column;
cout << Chess(row, column) << endl;
system("pause");
}
| |