这个无锦囊牌的代码哪里出问题了???
查看原帖
这个无锦囊牌的代码哪里出问题了???
890151
zuozedi楼主2024/7/31 11:08
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define ll long long
//#define int long long
//const int N = ;
struct pig
{
	itn tobe;//0 = 主, 1 = 忠, 2 = 反
	int id;// 第几位猪
	int ht;//血量
	int all_cards;//摸到的所有的牌
	char cards[2005];//所有的牌
	bool use_cards[2005]; //是否用过该牌 
	bool zgln;//诸葛连弩
	bool die_or_live;//是否存活
	int shenfen;//对外身份 0 = 未暴露, 1 = 已暴露, 2 = 类反 
	itn front, next;//前一只and后一只 
};
pig a[15]; 
itn n, m;
int m_number;
char shurucards[2005];
int res;
int fanpig;
bool clear_mark;
void read(int x)//确认身份 
{
	string s;
	cin >> s;
	if(s[0] == 'M') a[x].tobe = 0;
	else if(s[0] == 'Z') a[x].tobe = 1;
	else
	{
		a[x].tobe = 2;
		fanpig++;
	}
	a[x].id = x;
	a[x].ht = 4;
	a[x].all_cards = 4;
	for(int i = 1; i <= 4; i++)
	{
		cin >> a[x].cards[i];
		if(a[x].cards[i] == 'Z') a[x].zgln = true;
	}
	memset(a[x].use_cards, true, sizeof(a[x].use_cards));
	a[x].die_or_live = true;
	a[x].shenfen = 0;
	a[x].front = (x - 1) % n;
	a[x].next = (x + 1) % n;  
}
void mocards(int x)//摸牌 
{
		a[x].all_cards++;
		char c;
		if(m_number <= 0)
		{
			c = shurucards[m];
		}
		else
		{
			c = shurucards[m - m_number + 1];
		}
		m_number--;
		a[x].cards[a[x].all_cards] = c;
}
bool use_peach(int x)//吃桃 
{
	if(a[x].ht == 4) return false;
	a[x].ht++;
	//a[x].use_cards[i] = false;
	return true;
}
bool use_zgln(int x)//使用诸葛连弩
{
	a[x].zgln = true;
	return true; 
}
void die(int x, int killer)//濒死 
{
	for(int i = 1; i <= a[x].all_cards; i++)
	{
		if(a[x].cards[i] == 'P' && a[x].use_cards[i])
		{
			a[x].ht++;
			a[x].use_cards[i] = false;
			if(a[x].ht > 0) return;
		}
	} 
	a[x].die_or_live = false;
	a[a[x].next].front = a[x].front;
	a[a[x].front].next = a[x].next;
	if(a[x].tobe == 0)
	{
		res = 0;
		return;
	}
	if(a[x].tobe == 2)
	{
		fanpig--;
		if(fanpig == 0)
		{
			res = 1;
			return;
		}
		mocards(killer);
		mocards(killer);
		mocards(killer);
	}
	else if(a[x].tobe == 1 && a[killer].tobe == 0)
	{
		a[killer].all_cards = 0;
		memset(a[killer].cards, 0, sizeof(a[killer].cards));
		memset(a[killer].use_cards, true, sizeof(a[killer].use_cards));
		a[killer].zgln = false;
		clear_mark = true;
	}
}
bool use_shan(int x)//使用闪
{
	bool is_used_shan = false;
	for(int i = 1; i <= a[x].all_cards; i++)
	{
		if(a[x].cards[i] == 'D' && a[x].use_cards[i])
		{
			is_used_shan = true;
			a[x].use_cards[i] = false;
			break;
		}
	} 
	if(is_used_shan)
	{
		a[x].ht--;
	}
} 
bool use_kill(int x)//使用杀 
{
	if(a[x].tobe == 0)//主出杀
	{
		if(a[a[x].next].shenfen == 2 || a[a[x].next].shenfen == 1 && a[a[x].next].tobe == 2)
		{
			use_shan(a[x].next);
		} 
		if(a[a[x].next].ht <= 0) die(a[x].next, x);
		return true;
	} 
	else if(a[x].tobe == 1)
	{
		if(a[a[x].next].shenfen == 1 && a[a[x].next].tobe == 2)
		{
			use_shan(a[x].next);
		} 
		a[x].shenfen = 1;
		if(a[a[x].next].ht <= 0) die(a[x].next, x);
		return true;
	}
	else
	{
		if(a[a[x].next].tobe == 0) use_shan(a[x].next);
		else if(a[a[x].next].shenfen == 1 && a[a[x].next].tobe == 1)
		{
			use_shan(a[x].next);
		} 
		a[x].shenfen = 1;
		if(a[a[x].next].ht <= 0) die(a[x].next, x);
		return true;
	}
	return false;
} 
void chucards(int x)//出牌 
{
	int kill = 0;
	for(int i = 1; i <= a[x].all_cards; i++)
	{
		bool is = false;
		if(a[x].use_cards[i] == false) continue;
		if(a[x].cards[i] == 'P') is = use_peach(i);
		else if(a[x].cards[i] == 'Z') is = use_zgln(i); 
		else if(a[x].cards[i] == 'K') 
		{
			if(kill == 0 || a[x].zgln == true) is = use_kill(i);
		}
		if(is) 
		{
			if(a[x].tobe = 0 && clear_mark) clear_mark = false;
			else a[x].use_cards[i] = true;
			i = 0;
		}
		if(a[x].die_or_live == false) break;
		if(res != -1) break;
	}
	//if(res != -1) break;
}
void start_game()
{
	while(res == -1)
	{
		for(int i = 1; i <= n; i++)
		{
			mocards(i);
			mocards(i);
			chucards(i);
			if(res != -1) break;
		}
	}
}
void jiance();
void jieshu()//结算 
{
	if(res == 1) cout << "MP" << endl;
	else cout << "FP" << endl;
	for(int i = 1; i <= n; i++)
	{
		if(a[i].die_or_live == false)
		{
			cout << "DEAD" << endl;
			continue;
		}
		for(itn j = 1; j <= a[i].all_cards; j++)
		{
			if(a[i].use_cards[j] == true)
			{
				cout << a[i].cards[j] << " ";
			}
		}
		cout << endl;
	}
}
signed main()
{
	cin >> n >> m;
	res = -1;
	for(itn i = 1; i <= n; i++)
	{
		read(i);
	}
	for(int i = 1; i <= m; i++)
	{
		cin >> shurucards[i];
	}
	m_number = m;
	start_game();
	jieshu();
	return 0;
}
void jiance()
{
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= a[i].all_cards; j++)
		{
			cout << a[i].cards[j] << " ";
		}
		cout << endl;
	}
} 
2024/7/31 11:08
加载中...