用 1 2 3
4 5 6
7 8 9
代表A(红方将) , B(黑方帅) 在棋盘9宫格中的位置
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace xiangqi { class Program { static void Main(string[] args) { string location = "123456789123456789"; for (int i = 0; i < 9; i++) { for (int j = 9; j < 18; j++) { int compare = Math.Abs(Convert.ToInt16(location.Substring(i, 1)) - Convert.ToInt16(location.Substring(j, 1))); if (compare !=0 && compare != 3 && compare !=6) { Console.Out.WriteLine("A at {0}, B at {1}", location.Substring(i, 1), location.Substring(j, 1)); } } } } } }