c#象棋程序
A chess board is equally divided into 64 identical squares that are black and white alternately. Each square on the chessboard can be identified by the coordinates as 'A' to 'H' on the horizontal axis and '1' to '8' on the vertical axis as shown in the figure.
一块国际象棋棋盘平均分为64个相同的正方形,它们是黑白交替的 。 如图所示,可以通过在水平轴上的坐标从“ A”到“ H”以及在垂直轴上的“ 1”到“ 8”来标识棋盘上的每个正方形。
Each square can be identified using the coordinate system specified above. For example, the square with coordinates G5 is colored Black, A6 is colored White and so on...
可以使用上面指定的坐标系来标识每个正方形。 例如, 坐标为G5的正方形为黑色 , A6为白色 ,依此类推...
A program to identify the color of a specified square is given below.
下面给出识别指定正方形颜色的程序。
在C ++中确定国际象棋方板的颜色 (Determine the color of a chess square board in C++)
#include<iostream>
#include<cctype>
using namespace std;
int main()
{
char string[10], x;
cout << "Enter the coordinates of the square, \
\nthe first coordinate A to H and second coordinate 1 to 8: ";
cin.getline(string, 10);
x = string[0];
x = tolower(x);
string[0] = x;
if (string[0] == 'a' || string[0] == 'c' || string[0] == 'e' || string[0] == 'g')
{
if (string[1] == '1' || string[1] == '3' || string[1] == '5' || string[1] == '7')
cout << "Black square";
else
cout << "White square";
}
else
{
if (string[1] == '1' || string[1] == '3' || string[1] == '5' || string[1] == '7')
cout << "white square";
else
cout << "Black square";
}
return 0;
}
Output
输出量
First run:
Enter the coordinates of the square,
the first coordinate A to H and second coordinate 1 to 8: C5
Black square
Seccond run:
Enter the coordinates of the square,
the first coordinate A to H and second coordinate 1 to 8: F3
white square
翻译自: https://www.includehelp.com/cpp-programs/determine-the-color-of-chess-square.aspx
c#象棋程序