c#象棋程序_C ++程序确定象棋方块的颜色
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";elsecout << "White square";}else{if (string[1] == '1' || string[1] == '3' || string[1] == '5' || string[1] == '7')cout << "white square";elsecout << "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 squareSeccond 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#象棋程序
總結
以上是生活随笔為你收集整理的c#象棋程序_C ++程序确定象棋方块的颜色的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java Object Class bo
- 下一篇: 数据结构树二叉树计算节点_查找二叉树中叶