大模拟怎么调试啊(鸭棋
  • 板块灌水区
  • 楼主sundyLIUXY
  • 当前回复6
  • 已保存回复6
  • 发布时间2023/7/13 12:32
  • 上次更新2023/11/3 10:08:48
查看原帖
大模拟怎么调试啊(鸭棋
706737
sundyLIUXY楼主2023/7/13 12:32

三百行,能想到的都过了,样例也过,但是第四个点的285行错了,这个怎么调试……

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

int q, now, x_1, y_1, x_2, y_2;
bool game = 1;
char mp[11][10] = {
	"JMXSWSXMJ", ".........", "Y.......Y", "B.B.B.B.B", ".........",
	".........", "b.b.b.b.b", "y.......y", ".........", "jmxswsxmj"
};

string seewhat(char c) {
	switch(c) {
		case 'J': case 'j': return "car"; case 'M': case 'm': return "horse";
		case 'X': case 'x': return "elephant"; case 'S': case 's': return "guard";
		case 'W': case 'w': return "captain"; case 'Y': case 'y': return "duck";
		case 'B': case 'b': return "soldier";
	}
	return "";
}
bool seecolor(char c) {
	if(c >= 'A' && c <= 'Z') return 0;
	return 1;
}
bool checkd(int x, int y, char mod) {
	if(seewhat(mp[x][y]) == "car") {
		for(int i = x-1; i >= 0; i--) {
			if(mp[i][y] == '.') continue;
			if(seewhat(mp[i][y]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[i][y])) return 1;
			break;
		}
		for(int i = x+1; i <= 9; i++) {
			if(mp[i][y] == '.') continue;
			if(seewhat(mp[i][y]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[i][y])) return 1;
			break;
		}
		for(int i = y-1; i >= 0; i--) {
			if(mp[x][i] == '.') continue;
			if(seewhat(mp[x][i]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x][i])) return 1;
			break;
		}
		for(int i = y+1; i <= 8; i++) {
			if(mp[x][i] == '.') continue;
			if(seewhat(mp[x][i]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x][i])) return 1;
			break;
		}
	}
	if(seewhat(mp[x][y]) == "horse") {
		if(mp[x+1][y] == '.' && ((seewhat(mp[x+2][y-1]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+2][y-1])) || 
			(seewhat(mp[x+2][y+1]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+2][y+1])))) return 1;
		if(mp[x-1][y] == '.' && ((seewhat(mp[x-2][y-1]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-2][y-1])) || 
			(seewhat(mp[x-2][y+1]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-2][y+1])))) return 1;
		if(mp[x][y+1] == '.' && ((seewhat(mp[x+1][y+2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+1][y+2])) || 
			(seewhat(mp[x-1][y+2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-1][y+2])))) return 1;
		if(mp[x][y-1] == '.' && ((seewhat(mp[x+1][y-2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+1][y-2])) || 
			(seewhat(mp[x-1][y-2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-1][y-2])))) return 1;
	}
	if(seewhat(mp[x][y]) == "elephant") {
		if(mp[x+1][y+1] == '.' && seewhat(mp[x+2][y+2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+2][y+2])) return 1;
		if(mp[x+1][y-1] == '.' && seewhat(mp[x+2][y-2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+2][y-2])) return 1;
		if(mp[x-1][y+1] == '.' && seewhat(mp[x-2][y+2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-2][y+2])) return 1;
		if(mp[x-1][y-1] == '.' && seewhat(mp[x-2][y-2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-2][y-2])) return 1;
	}
	if(seewhat(mp[x][y]) == "guard") {
		if((seewhat(mp[x+1][y+1]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+1][y+1])) || 
			(seewhat(mp[x+1][y-1]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+1][y-1]))) return 1;
		if((seewhat(mp[x-1][y+1]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-1][y+1])) || 
			(seewhat(mp[x-1][y-1]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-1][y-1]))) return 1;
	}
	if(seewhat(mp[x][y]) == "captain") {
		if(seewhat(mp[x+1][y]) == "captain" || seewhat(mp[x-1][y]) == "captain") return 1;
		if(seewhat(mp[x][y-1]) == "captain" || seewhat(mp[x][y+1]) == "captain") return 1;
	}
	if(seewhat(mp[x][y]) == "duck") {
		if(mp[x+1][y] == '.') {
			if(mp[x+2][y+1] == '.' && seewhat(mp[x+3][y+2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+3][y+2])) return 1;
			if(mp[x+2][y-1] == '.' && seewhat(mp[x+3][y-2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+3][y-2])) return 1;
		}
		if(mp[x-1][y] == '.') {
			if(mp[x-2][y+1] == '.' && seewhat(mp[x-3][y+2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-3][y+2])) return 1;
			if(mp[x-2][y-1] == '.' && seewhat(mp[x-3][y-2]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-3][y-2])) return 1;
		}
		if(mp[x][y+1] == '.') {
			if(mp[x+1][y+2] == '.' && seewhat(mp[x+2][y+3]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+2][y+3])) return 1;
			if(mp[x-1][y+2] == '.' && seewhat(mp[x-2][y+3]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-2][y+3])) return 1;
		}
		if(mp[x][y-1] == '.') {
			if(mp[x+1][y-2] == '.' && seewhat(mp[x+2][y-3]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x+2][y-3])) return 1;
			if(mp[x-1][y-2] == '.' && seewhat(mp[x-2][y-3]) == "captain" && seecolor(mp[x][y]) != seecolor(mp[x-2][y-3])) return 1;
		}
	}
	return 0;
}
bool danger() {
	for(int i = 0; i <= 10; i++) {
		for(int j = 0; j <= 9; j++) {
			if(mp[i][j] != '.') {
				if(mp[i][j] >= 'A' && mp[i][j] <= 'Z' && checkd(i, j, 'r')) return 1;
				if(mp[i][j] >= 'a' && mp[i][j] <= 'z' && checkd(i, j, 'b')) return 1;
			}
		}
	}
	return 0;
}
bool out(char mode, string chess) {
	if(mode == 'r') {
		if(mp[x_2][y_2] <= 'Z' && mp[x_2][y_2] >= 'A') {
			printf("Invalid command\n");
			return 1;
		}
		else {
			cout << "red " << chess << ";";
			if(mp[x_2][y_2] == '.') printf("NA;");
			else cout << "blue " << seewhat(mp[x_2][y_2]) << ';';
			if(seewhat(mp[x_2][y_2]) == "captain") game = 0;
		}
	}
	else {
		if(mp[x_2][y_2] <= 'z' && mp[x_2][y_2] >= 'a') {
			printf("Invalid command\n");
			return 1;
		}
		else {
			cout << "blue " << chess << ";";
			if(mp[x_2][y_2] == '.') printf("NA;");
			else cout << "red " << seewhat(mp[x_2][y_2]) << ';';
			if(seewhat(mp[x_2][y_2]) == "captain") game = 0;
		}
	}
	return 0;
}
void moveJ(char mode) {
	if(x_1 == x_2) {
		int a = y_1, b = y_2;
		if(a > b) swap(a, b);
		for(int j = a+1; j < b; j++)
			if(mp[x_1][j] != '.') {
				printf("Invalid command\n");
				return;
			}
	}
	else if(y_1 == y_2) {
		int a = x_1, b = x_2;
		if(a > b) swap(a, b);
		for(int j = a+1; j < b; j++)
			if(mp[j][y_1] != '.') {
				printf("Invalid command\n");
				return;
			}
	}
	else {
		printf("Invalid command\n");
		return;
	}
	if(out(mode, "car")) return;
	mp[x_2][y_2] = mp[x_1][y_1], mp[x_1][y_1] = '.';
	if(!danger()) printf("no;");
	else printf("yes;");
	if(game) printf("no\n");
	else printf("yes\n");
	now = !now;
}
void moveM(char mode) {
	if(abs(x_1-x_2) > 2 || !abs(x_1-x_2) ||
		abs(y_1-y_2) > 2 || !abs(y_1-y_2) ||
		abs(x_1-x_2) == abs(y_1-y_2)) {
		printf("Invalid command\n");
		return;
	}
	if(x_2 == x_1+2 && mp[x_1+1][y_1] == '.') {}
	else if(x_2 == x_1-2 && mp[x_1-1][y_1] == '.') {}
	else if(y_2 == y_1+2 && mp[x_1][y_1+1] == '.') {}
	else if(y_2 == y_1-2 && mp[x_1][y_1-1] == '.') {}
	else {
		printf("Invalid command\n");
		return;
	}
	if(out(mode, "horse")) return;
	mp[x_2][y_2] = mp[x_1][y_1], mp[x_1][y_1] = '.';
	if(!danger()) printf("no;");
	else printf("yes;");
	if(game) printf("no\n");
	else printf("yes\n");
	now = !now;
}
void moveX(char mode) {
	if(abs(x_1-x_2) != 2 || abs(y_1-y_2) != 2) {
		printf("Invalid command\n");
		return;
	}
	if(x_2 == x_1+2 && y_2 == y_1+2 && mp[x_1+1][y_1+1] != '.') {
		printf("Invalid command\n");
		return;
	}
	if(x_2 == x_1+2 && y_2 == y_1-2 && mp[x_1+1][y_1-1] != '.') {
		printf("Invalid command\n");
		return;
	}
	if(x_2 == x_1-2 && y_2 == y_1+2 && mp[x_1-1][y_1+1] != '.') {
		printf("Invalid command\n");
		return;
	}
	if(x_2 == x_1-2 && y_2 == y_1-2 && mp[x_1-1][y_1-1] != '.') {
		printf("Invalid command\n");
		return;
	}
	if(out(mode, "elephant")) return;
	mp[x_2][y_2] = mp[x_1][y_1], mp[x_1][y_1] = '.';
	if(!danger()) printf("no;");
	else printf("yes;");
	if(game) printf("no\n");
	else printf("yes\n");
	now = !now;
}
void moveS(char mode) {
	if(abs(x_1-x_2) != 1 || abs(y_1-y_2) != 1) {
		printf("Invalid command\n");
		return;
	}
	if(out(mode, "guard")) return;
	mp[x_2][y_2] = mp[x_1][y_1], mp[x_1][y_1] = '.';
	if(!danger()) printf("no;");
	else printf("yes;");
	if(game) printf("no\n");
	else printf("yes\n");
	now = !now;
}
void moveW(char mode) {
	if(abs(x_1-x_2) > 1 || abs(y_1-y_2) > 1 || (abs(x_1-x_2) == 1 && abs(y_1-y_2) == 1)) {
		printf("Invalid command\n");
		return;
	}
	if(out(mode, "captain")) return;
	mp[x_2][y_2] = mp[x_1][y_1], mp[x_1][y_1] = '.';
	if(!danger()) printf("no;");
	else printf("yes;");
	if(game) printf("no\n");
	else printf("yes\n");
	now = !now;
}
void moveY(char mode) {
	if((abs(x_1-x_2) == 2 && abs(y_1-y_2) == 3) || (abs(x_1-x_2) == 3 && abs(y_1-y_2) == 2)) {}
	else {
		printf("Invalid command\n");
		return;
	}
	if(x_2 == x_1+3 && y_2 == y_1+2 && mp[x_1+1][y_1] == '.' && mp[x_1+2][y_1+1] == '.') {}
	else if(x_2 == x_1+3 && y_2 == y_1-2 && mp[x_1+1][y_1] == '.' && mp[x_1+2][y_1-1] == '.') {}
	else if(x_2 == x_1-3 && y_2 == y_1+2 && mp[x_1-1][y_1] == '.' && mp[x_1-2][y_1+1] == '.') {}
	else if(x_2 == x_1+3 && y_2 == y_1-2 && mp[x_1+1][y_1] == '.' && mp[x_1+2][y_1-1] == '.') {}
	else if(y_2 == y_1+3 && x_2 == x_1+2 && mp[x_1][y_1+1] == '.' && mp[x_1+1][y_1+2] == '.') {}
	else if(y_2 == y_1+3 && x_2 == x_1-2 && mp[x_1][y_1+1] == '.' && mp[x_1-1][y_1+2] == '.') {}
	else if(y_2 == y_1-3 && x_2 == x_1+2 && mp[x_1][y_1-1] == '.' && mp[x_1+1][y_1-2] == '.') {}
	else if(y_2 == y_1-3 && x_2 == x_1-2 && mp[x_1][y_1-1] == '.' && mp[x_1-1][y_1-2] == '.') {}
	else {
		printf("Invalid command\n");
		return;
	}
	if(out(mode, "duck")) return;
	mp[x_2][y_2] = mp[x_1][y_1], mp[x_1][y_1] = '.';
	if(!danger()) printf("no;");
	else printf("yes;");
	if(game) printf("no\n");
	else printf("yes\n");
	now = !now;
}
void moveB(char mode) {
	if(abs(x_1-x_2) > 1 || abs(y_1-y_2) > 1) {
		printf("Invalid command\n");
		return;
	}
	if(out(mode, "soldier")) return;
	mp[x_2][y_2] = mp[x_1][y_1], mp[x_1][y_1] = '.';
	if(!danger()) printf("no;");
	else printf("yes;");
	if(game) printf("no\n");
	else printf("yes\n");
	now = !now;
}
void redmove(int i) {
	if(!game) {
		printf("Invalid command\n");
		return;
	}
	if(mp[x_1][y_1] == 'J') moveJ('r');
	else if(mp[x_1][y_1] == 'M') moveM('r');
	else if(mp[x_1][y_1] == 'X') moveX('r');
	else if(mp[x_1][y_1] == 'S') moveS('r');
	else if(mp[x_1][y_1] == 'W') moveW('r');
	else if(mp[x_1][y_1] == 'Y') moveY('r');
	else if(mp[x_1][y_1] == 'B') moveB('r');
	else printf("Invalid command\n");
}
void bluemove(int i) {
	if(!game) {
		printf("Invalid command\n");
		return;
	}
	if(mp[x_1][y_1] == 'j') moveJ('b');
	else if(mp[x_1][y_1] == 'm') moveM('b');
	else if(mp[x_1][y_1] == 'x') moveX('b');
	else if(mp[x_1][y_1] == 's') moveS('b');
	else if(mp[x_1][y_1] == 'w') moveW('b');
	else if(mp[x_1][y_1] == 'y') moveY('b');
	else if(mp[x_1][y_1] == 'b') moveB('b');
	else printf("Invalid command\n");
}

signed main() {
	scanf("%lld", &q);
	for(int i = 1; i <= q; i++) {
		scanf("%lld%lld%lld%lld", &x_1, &y_1, &x_2, &y_2);
		if(!now) redmove(i);
		else bluemove(i);
	}
	
    return 0;
}
2023/7/13 12:32
加载中...