P5380 [THUPC2019]鸭棋

题目描述:传送门
思路:
这一题思路比较简单,但代码量有点惊人(标程400多行)。
就是纯粹的模拟,但要耐下性子写。

下面是代码:
(我写了700多行)

#include <bits/stdc++.h>
using namespace std;

struct Node
{
	string team, kind;
}a[15][15];

int captain_x[5] = {0, 0, 1, 0, -1};
int captain_y[5] = {0, 1, 0, -1, 0};

int guard_x[5] = {0, 1, -1, 1, -1};
int guard_y[5] = {0, 1, 1, -1, -1};

int elephant_x[5] = {0, 2, -2, 2, -2};
int elephant_y[5] = {0, 2, 2, -2, -2};

int horse_x[9] = {0, 2, -2, 2, -2, 1, 1, -1, -1};
int horse_y[9] = {0, 1, 1, -1, -1, 2, -2, 2, -2};
int Horse_x[9] = {0, 0, 0, 0, 0, 1, 1, -1, -1};
int Horse_y[9] = {0, 1, 1, -1, -1, 0, 0, 0, 0};

int duck_x[9] = {0, 2, -2, 2, -2, 3, 3, -3, -3};
int duck_y[9] = {0, 3, 3, -3, -3, 2, -2, 2, -2};

int soldier_x[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
int soldier_y[9] = {0, 1, 0, -1, 0, 1, 1, -1, -1};

template < typename T > void read(T &x)
{
	int f = 1;x = 0;char c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - '0';
	x *= f;
}

void init()
{
	for(int i = 0;i <= 14;i++)
		for(int j = 0;j <= 14;j++)
		{
			a[i][j].kind = "";
			a[i][j].team = "";
		}
	for(int i = 0;i <= 8;i++)
	{
		a[0][i].team = "red";
		a[9][i].team = "blue";
	}
		
	a[0][0].kind = "car";
	a[0][1].kind = "horse";
	a[0][2].kind = "elephant";
	a[0][3].kind = "guard";
	a[0][4].kind = "captain";
	a[0][5].kind = "guard";
	a[0][6].kind = "elephant";
	a[0][7].kind = "horse";
	a[0][8].kind = "car";
	a[2][0].kind = "duck";
	a[2][0].team = "red";
	a[3][0].kind = "soldier";
	a[3][0].team = "red";
	a[3][2].kind = "soldier";
	a[3][2].team = "red";
	a[3][4].kind = "soldier";
	a[3][4].team = "red";
	a[3][6].kind = "soldier";
	a[3][6].team = "red";
	a[3][8].kind = "soldier";
	a[3][8].team = "red";
	a[2][8].kind = "duck";
	a[2][8].team = "red";
	
	a[9][0].kind = "car";
	a[9][1].kind = "horse";
	a[9][2].kind = "elephant";
	a[9][3].kind = "guard";
	a[9][4].kind = "captain";
	a[9][5].kind = "guard";
	a[9][6].kind = "elephant";
	a[9][7].kind = "horse";
	a[9][8].kind = "car";
	a[7][0].kind = "duck";
	a[7][0].team = "blue";
	a[6][0].kind = "soldier";
	a[6][0].team = "blue";
	a[6][2].kind = "soldier";
	a[6][2].team = "blue";
	a[6][4].kind = "soldier";
	a[6][4].team = "blue";
	a[6][6].kind = "soldier";
	a[6][6].team = "blue";
	a[6][8].kind = "soldier";
	a[6][8].team = "blue";
	a[7][8].kind = "duck";
	a[7][8].team = "blue";
}

bool isgeneral()
{
	int bx = -1, by = -1, rx = -1, ry = -1;
	for(int i = 0;i <= 9;i++)
		for(int j = 0;j <= 8;j++)
			if(a[i][j].kind == "captain") 
			{
				if(a[i][j].team == "blue")
				{
					bx = i; 
					by = j;
				}
				else
				{
					rx = i;
					ry = j;
				}
			}
	//if(bx == -1 || rx == -1) return 0;
	for(int i = 0;i <= 9;i++)
		for(int j = 0;j <= 8;j++)
		{
			if(a[i][j].team == "blue")
			{
				if(a[i][j].kind == "captain")
				{
					for(int k = 1;k <= 4;k++)
					{
						int tx = i + captain_x[k];
						int ty = j + captain_y[k];
						if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && a[tx][ty].team == "red" && a[tx][ty].kind == "captain")
							return 1;
					}
				}
				else if(a[i][j].kind == "guard")
				{
					for(int k = 1;k <= 4;k++)	
					{
						int tx = i + guard_x[k];
						int ty = j + guard_y[k];
						if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && a[tx][ty].team == "red" && a[tx][ty].kind == "captain")
							return 1;
					}
				}
				else if(a[i][j].kind == "elephant")
				{
					for(int k = 1;k <= 4;k++)
					{
						int tx = i + elephant_x[k];
						int ty = j + elephant_y[k];
						if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8)
						{
							if(tx == i + 2 && ty == j + 2)
								if(a[tx - 1][ty - 1].kind != "")
									continue;
							if(tx == i + 2 && ty == j - 2)
								if(a[tx - 1][ty + 1].kind != "")
									continue;
							if(tx == i - 2 && ty == j + 2)
								if(a[tx + 1][ty - 1].kind != "")
									continue;
							if(tx == i - 2 && ty == j - 2)
								if(a[tx + 1][ty + 1].kind != "")
									continue;
							if(a[tx][ty].team == "red" && a[tx][ty].kind == "captain")
								return 1;
						}
					}
				}
				else if(a[i][j].kind == "horse")
				{
					for(int k = 1;k <= 8;k++)
					{
						int tx = i + horse_x[k];
						int ty = j + horse_y[k];
						int px = i + Horse_x[k];
						int py = j + Horse_y[k]; 
						if(a[px][py].kind != "")
							continue;
						if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8)
						{
							if(a[tx][ty].team == "red" && a[tx][ty].kind == "captain")
								return 1;
						}	
					}
				}
				else if(a[i][j].kind == "car")
				{
					if(i == rx)
					{
						int flag2 = 1;
						for(int k = min(j, ry) + 1;k < max(j, ry);k++)
							if(a[rx][k].kind != "")
							{
					 			flag2 = 0;
								break;
							}
						if(flag2) return 1;
					}
					if(j == ry)
					{
						int flag2 = 1;
						for(int k = min(i, rx) + 1;k < max(i, rx);k++)
							if(a[k][ry].kind != "")
							{
								flag2 = 0;
								break;
							}
						if(flag2) return 1;
					}
				}							
				else if(a[i][j].kind == "duck")
				{
					for(int k = 1;k <= 8;k++)
					{
						int tx = i + duck_x[k];
						int ty = j + duck_y[k];
						if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8)
						{
							int flag2 = 1;
							if((tx == i + 2 && ty == j + 3) || (tx == i + 3 && ty == j + 2))
								if(a[tx - 1][ty - 1].kind != "" || a[tx - 2][ty - 2].kind != "")
									flag2 = 0;
							if((tx == i + 2 && ty == j - 3) || (tx == i + 3 && ty == j - 2))
								if(a[tx - 1][ty + 1].kind != "" || a[tx - 2][ty + 2].kind != "")
									flag2 = 0;
							if((tx == i - 2 && ty == j + 3) || (tx == i - 3 && ty == j + 2))
								if(a[tx + 1][ty - 1].kind != "" || a[tx + 2][ty - 2].kind != "")
									flag2 = 0;
							if((tx == i - 2 && ty == j - 3) || (tx == i - 3 && ty == j - 2))
								if(a[tx + 1][ty + 1].kind != "" || a[tx + 2][ty + 2].kind != "")
									flag2 = 0;
							if(a[tx][ty].team == "red" && a[tx][ty].kind == "captain" && flag2)
								return 1;
						}		
					}
				}
				else if(a[i][j].kind == "soldier")
				{
					for(int k = 1;k <= 8;k++)
					{
						int tx = i + soldier_x[k];
						int ty = j + soldier_y[k];
						if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8)
						{
							if(a[tx][ty].team == "red" && a[tx][ty].kind == "captain")
								return 1;
						}
					}
				}
			}
			if(a[i][j].team == "red")
			{
				if(a[i][j].kind == "guard")
				{
					for(int k = 1;k <= 4;k++)	
					{
						int tx = i + guard_x[k];
						int ty = j + guard_y[k];
						if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && a[tx][ty].team == "blue" && a[tx][ty].kind == "captain")
							return 1;
					}
				}
				else if(a[i][j].kind == "elephant")
				{
					for(int k = 1;k <= 4;k++)
					{
						int tx = i + elephant_x[k];
						int ty = j + elephant_y[k];
						if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8)
						{
							int flag2 = 1;
							if(tx == i + 2 && ty == j + 2)
								if(a[tx - 1][ty - 1].kind != "")
									flag2 = 0;
							if(tx == i + 2 && ty == j - 2)
								if(a[tx - 1][ty + 1].kind != "")
									flag2 = 0;
							if(tx == i - 2 && ty == j + 2)
								if(a[tx + 1][ty - 1].kind != "")
									flag2 = 0;
							if(tx == i - 2 && ty == j - 2)
								if(a[tx + 1][ty + 1].kind != "")
									flag2 = 0;
							if(a[tx][ty].team == "blue" && a[tx][ty].kind == "captain" && flag2)
								return 1;
						}
					}
				}
				else if(a[i][j].kind == "horse")
				{
					for(int k = 1;k <= 8;k++)
					{
						
						int tx = i + horse_x[k];
						int ty = j + horse_y[k];
						int px = i + Horse_x[k];
						int py = j + Horse_y[k]; 
						if(a[px][py].kind != "")
							continue;
						if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8)
						{
							if(a[tx][ty].team == "blue" && a[tx][ty].kind == "captain")
								return 1;
						}
					}
				}
				else if(a[i][j].kind == "car")
				{
					if(i == bx)
					{
						int flag2 = 1;
						for(int k = min(j, by) + 1;k < max(j, by);k++)
							if(a[bx][k].kind != "")
							{
								flag2 = 0;
								break;
							}
						if(flag2) return 1;
					}
					if(j == by)
					{
						int flag2 = 1;
						for(int k = min(i, bx) + 1;k < max(i, bx);k++)
							if(a[k][by].kind != "")
							{
								flag2 = 0;
								break;
							}
						if(flag2) return 1;
					}
				}								
				else if(a[i][j].kind == "duck")
				{
					for(int k = 1;k <= 8;k++)
					{
						int tx = i + duck_x[k];
						int ty = j + duck_y[k];
						if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8)
						{
							int flag2 = 1;
							if((tx == i + 2 && ty == j + 3) || (tx == i + 3 && ty == j + 2))
								if(a[tx - 1][ty - 1].kind != "" || a[tx - 2][ty - 2].kind != "")
									flag2 = 0;
							if((tx == i + 2 && ty == j - 3) || (tx == i + 3 && ty == j - 2))
								if(a[tx - 1][ty + 1].kind != "" || a[tx - 2][ty + 2].kind != "")
									flag2 = 0;
							if((tx == i - 2 && ty == j + 3) || (tx == i - 3 && ty == j + 2))
								if(a[tx + 1][ty - 1].kind != "" || a[tx + 2][ty - 2].kind != "")
									flag2 = 0;
							if((tx == i - 2 && ty == j - 3) || (tx == i - 3 && ty == j - 2))
								if(a[tx + 1][ty + 1].kind != "" || a[tx + 2][ty + 2].kind != "")
									flag2 = 0;
							if(a[tx][ty].team == "blue" && a[tx][ty].kind == "captain" && flag2)
								return 1;
						}		
					}
				}
				else if(a[i][j].kind == "soldier")
				{
					for(int k = 1;k <= 8;k++)
					{
						int tx = i + soldier_x[k];
						int ty = j + soldier_y[k];
						if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8)
						{
							if(a[tx][ty].team == "blue" && a[tx][ty].kind == "captain")
								return 1;
						}
					}
				}
			}
		}
	return 0;
}

void play()
{
	int n, flag = 1, sum = 1;
	read(n);
	for(int i = 1;i <= n;i++)
	{
		int x1, y1, x2, y2;
		read(x1);
		read(y1);
		read(x2);
		read(y2);
		//不合法情况
		if(!flag)
		{
			cout << "Invalid command" << endl;
			continue;
		}
		if(x2 < 0 || x2 > 9 || y2 < 0 || y2 > 8 || x1 < 0 || x1 > 9 || y1 < 0 || y1 > 8)
		{
			cout << "Invalid command" << endl;
			continue;
		}
		if(sum % 2 == 1)
			if(a[x1][y1].team != "red" || a[x2][y2].team == "red")
			{
				cout << "Invalid command" << endl;
				continue;
			}
		if(sum % 2 == 0)
			if(a[x1][y1].team != "blue" || a[x2][y2].team == "blue")
			{
				cout << "Invalid command" << endl;
				continue;
			}
		
		//王
		if(a[x1][y1].kind == "captain")
		{
			int flag2 = 1;
			for(int j = 1;j <= 4;j++)
			{
				int tx = x1 + captain_x[j];
				int ty = y1 + captain_y[j];
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && tx == x2 && ty == y2)
				{
					flag2 = 0;
					break;
				}
			}
			if(flag2)
			{
				cout << "Invalid command" << endl;
				continue;
			}
			
			//这步操作移动了哪个棋子。
			cout << a[x1][y1].team << " " << a[x1][y1].kind << ";";
			
			//这步操作后,是否存在棋子被移出游戏,如有则还需求出被移出游戏的棋子。
			if(a[x2][y2].kind != "") 
			{
				cout << a[x2][y2].team << " " << a[x2][y2].kind << ";";
				if(a[x2][y2].kind == "captain")
					flag = 0;
			}
			else cout << "NA;";
			
			a[x2][y2].team = a[x1][y1].team;
			a[x2][y2].kind = a[x1][y1].kind;
			a[x1][y1].team = "";
			a[x1][y1].kind = "";
			
			//这步操作后,是否形成将军局面。
			if(isgeneral()) cout << "yes;";
			else cout << "no;";
			
			//这步操作后,游戏是否结束。
			if(!flag) cout << "yes" << endl;
			else cout << "no" << endl;
			sum++;
		}
		//士
		else if(a[x1][y1].kind == "guard")
		{
			int flag2 = 1;
			for(int j = 1;j <= 4;j++)
			{
				int tx = x1 + guard_x[j];
				int ty = y1 + guard_y[j];
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && tx == x2 && ty == y2)
				{
					flag2 = 0;
					break;
				}
			}
			if(flag2)
			{
				cout << "Invalid command" << endl;
				continue;
			}
			
			//这步操作移动了哪个棋子。
			cout << a[x1][y1].team << " " << a[x1][y1].kind << ";";
			
			//这步操作后,是否存在棋子被移出游戏,如有则还需求出被移出游戏的棋子。
			if(a[x2][y2].kind != "") 
			{
				cout << a[x2][y2].team << " " << a[x2][y2].kind << ";";
				if(a[x2][y2].kind == "captain")
					flag = 0;
			}
			else cout << "NA;";
			
			a[x2][y2].team = a[x1][y1].team;
			a[x2][y2].kind = a[x1][y1].kind;
			a[x1][y1].team = "";
			a[x1][y1].kind = "";
			
			//这步操作后,是否形成将军局面。
			if(isgeneral()) cout << "yes;";
			else cout << "no;";
			
			//这步操作后,游戏是否结束。
			if(!flag) cout << "yes" << endl;
			else cout << "no" << endl;
			sum++;
		}
		else if(a[x1][y1].kind == "elephant")
		{
			int flag2 = 1;
			for(int k = 1;k <= 4;k++)
			{
				int tx = x1 + elephant_x[k];
				int ty = y1 + elephant_y[k];
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && tx == x1 + 2 && ty == y1 + 2)
					if(a[tx - 1][ty - 1].kind != "")
						continue;
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && tx == x1 + 2 && ty == y1 - 2)
					if(a[tx - 1][ty + 1].kind != "")
						continue;
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && tx == x1 - 2 && ty == y1 + 2)
					if(a[tx + 1][ty - 1].kind != "")
						continue;
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && tx == x1 - 2 && ty == y1 - 2)
					if(a[tx + 1][ty + 1].kind != "")
						continue;
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && tx == x2 && ty == y2)
				{
					flag2 = 0;
					break;
				}
			}
			if(flag2)
			{
				cout << "Invalid command" << endl;
				continue;
			}
			//这步操作移动了哪个棋子。
			cout << a[x1][y1].team << " " << a[x1][y1].kind << ";";
			
			//这步操作后,是否存在棋子被移出游戏,如有则还需求出被移出游戏的棋子。
			if(a[x2][y2].kind != "") 
			{
				cout << a[x2][y2].team << " " << a[x2][y2].kind << ";";
				if(a[x2][y2].kind == "captain")
					flag = 0;
			}
			else cout << "NA;";
			a[x2][y2].team = a[x1][y1].team;
			a[x2][y2].kind = a[x1][y1].kind;
			a[x1][y1].team = "";
			a[x1][y1].kind = "";
			//这步操作后,是否形成将军局面。
			if(isgeneral()) cout << "yes;";
			else cout << "no;";
			
			//这步操作后,游戏是否结束。
			if(!flag) cout << "yes" << endl;
			else cout << "no" << endl;
			sum++;
		}
		else if(a[x1][y1].kind == "horse")
		{
			int flag2 = 1;
			for(int k = 1;k <= 8;k++)
			{
				int tx = x1 + horse_x[k];
				int ty = y1 + horse_y[k];
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && tx == x1 + 2)
					if(a[x1 + 1][y1].kind != "")
						continue;
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && tx == x1 - 2)
					if(a[x1 - 1][y1].kind != "")
						continue;
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && ty == y1 + 2)
					if(a[x1][y1 + 1].kind != "")
						continue;
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && ty == y1 - 2)
					if(a[x1][y1 - 1].kind != "")
						continue;
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8 && tx == x2 && ty == y2)
				{
					flag2 = 0;
					break;
				}
			}
			if(flag2)
			{
				cout << "Invalid command" << endl;
				continue;
			}
			
			//这步操作移动了哪个棋子。
			cout << a[x1][y1].team << " " << a[x1][y1].kind << ";";
			
			//这步操作后,是否存在棋子被移出游戏,如有则还需求出被移出游戏的棋子。
			if(a[x2][y2].kind != "") 
			{
				cout << a[x2][y2].team << " " << a[x2][y2].kind << ";";
				if(a[x2][y2].kind == "captain")
					flag = 0;
			}
			else cout << "NA;";
			
			a[x2][y2].team = a[x1][y1].team;
			a[x2][y2].kind = a[x1][y1].kind;
			a[x1][y1].team = "";
			a[x1][y1].kind = "";
			
			//这步操作后,是否形成将军局面。
			if(isgeneral()) cout << "yes;";
			else cout << "no;";
			
			//这步操作后,游戏是否结束。
			if(!flag) cout << "yes" << endl;
			else cout << "no" << endl;
			sum++;
		}
		else if(a[x1][y1].kind == "car")
		{
			if(x1 != x2 && y1 != y2) 
			{
				cout << "Invalid command" << endl;
				continue;
			}
			if(x1 == x2 && y1 != y2)
			{
				int flag2 = 1;
				for(int j = min(y1, y2) + 1;j < max(y1, y2);j++)
					if(a[x1][j].kind != "")
					{
						flag2 = 0;
						break;
					}
				if(!flag2)
				{
					cout << "Invalid command" << endl;
					continue;
				}
			}
			if(x1 != x2 && y1 == y2)
			{
				int flag2 = 1;
				for(int j = min(x1, x2) + 1;j < max(x1, x2);j++)
					if(a[j][y1].kind != "")
					{
						flag2 = 0;
						break;
					}
				if(!flag2)
				{
					cout << "Invalid command" << endl;
					continue;
				}
			}
			//这步操作移动了哪个棋子。
			cout << a[x1][y1].team << " " << a[x1][y1].kind << ";";
			
			//这步操作后,是否存在棋子被移出游戏,如有则还需求出被移出游戏的棋子。
			if(a[x2][y2].kind != "") 
			{
				cout << a[x2][y2].team << " " << a[x2][y2].kind << ";";
				if(a[x2][y2].kind == "captain")
					flag = 0;
			}
			else cout << "NA;";
			
			a[x2][y2].team = a[x1][y1].team;
			a[x2][y2].kind = a[x1][y1].kind;
			a[x1][y1].team = "";
			a[x1][y1].kind = "";
			
			//这步操作后,是否形成将军局面。
			if(isgeneral()) cout << "yes;";
			else cout << "no;";
			
			//这步操作后,游戏是否结束。
			if(!flag) cout << "yes" << endl;
			else cout << "no" << endl;
			sum++;
		}
		else if(a[x1][y1].kind == "duck")
		{
			int flag2 = 1;
			for(int k = 1;k <= 8;k++)
			{
				int tx = x1 + duck_x[k];
				int ty = y1 + duck_y[k];
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8)
				{
					if((tx == x1 + 2 && ty == y1 + 3) || (tx == x1 + 3 && ty == y1 + 2))
						if(a[tx - 1][ty - 1].kind != "" || a[tx - 2][ty - 2].kind != "")
							continue;
					if((tx == x1 + 2 && ty == y1 - 3) || (tx == x1 + 3 && ty == y1 - 2))
						if(a[tx - 1][ty + 1].kind != "" || a[tx - 2][ty + 2].kind != "")
							continue;
					if((tx == x1 - 2 && ty == y1 + 3) || (tx == x1 - 3 && ty == y1 + 2))
						if(a[tx + 1][ty - 1].kind != "" || a[tx + 2][ty - 2].kind != "")
							continue;
					if((tx == x1 - 2 && ty == y1 - 3) || (tx == x1 - 3 && ty == y1 - 2))
						if(a[tx + 1][ty + 1].kind != "" || a[tx + 2][ty + 2].kind != "")
							continue;
					if(tx == x2 && ty == y2)
					{
						flag2 = 0;
						break;
					}
				}		
			}
			if(flag2)
			{
				cout << "Invalid command" << endl;
				continue;
			}
			//这步操作移动了哪个棋子。
			cout << a[x1][y1].team << " " << a[x1][y1].kind << ";";
			
			//这步操作后,是否存在棋子被移出游戏,如有则还需求出被移出游戏的棋子。
			if(a[x2][y2].kind != "") 
			{
				cout << a[x2][y2].team << " " << a[x2][y2].kind << ";";
				if(a[x2][y2].kind == "captain")
					flag = 0;
			}
			else cout << "NA;";
			
			a[x2][y2].team = a[x1][y1].team;
			a[x2][y2].kind = a[x1][y1].kind;
			a[x1][y1].team = "";
			a[x1][y1].kind = "";
			
			//这步操作后,是否形成将军局面。
			if(isgeneral()) cout << "yes;";
			else cout << "no;";
			
			//这步操作后,游戏是否结束。
			if(!flag) cout << "yes" << endl;
			else cout << "no" << endl;
			sum++;
		}
		if(a[x1][y1].kind == "soldier")
		{
			int flag2 = 1;
			for(int j = 1;j <= 8;j++)
			{
				int tx = x1 + soldier_x[j];
				int ty = y1 + soldier_y[j];
				if(tx >= 0 && tx <= 9 && ty >= 0 && ty <= 8)
				{
					if(tx == x2 && ty == y2)
					{
						flag2 = 0;
						break;
					}
				}
			}
			if(flag2)
			{
				cout << "Invalid command" << endl;
				continue;
			}
			//这步操作移动了哪个棋子。
			cout << a[x1][y1].team << " " << a[x1][y1].kind << ";";
			
			//这步操作后,是否存在棋子被移出游戏,如有则还需求出被移出游戏的棋子。
			if(a[x2][y2].kind != "") 
			{
				cout << a[x2][y2].team << " " << a[x2][y2].kind << ";";
				if(a[x2][y2].kind == "captain")
					flag = 0;
			}
			else cout << "NA;";
			
			a[x2][y2].team = a[x1][y1].team;
			a[x2][y2].kind = a[x1][y1].kind;
			a[x1][y1].team = "";
			a[x1][y1].kind = "";
			
			//这步操作后,是否形成将军局面。
			if(isgeneral()) cout << "yes;";
			else cout << "no;";
			
			//这步操作后,游戏是否结束。
			if(!flag) cout << "yes" << endl;
			else cout << "no" << endl;
			sum++;
		}
	}
}

int main()
{
	//freopen(".in","r",stdin);
	//freopen("duckchess.out","w",stdout);
	init();
	play();
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值