本草

目录

一,规则

1,颜色

2,药引卡

3,药材卡

4,五种行动

5,四种难度模式

6,规则

二,人机对战

1,玩家设计

2,规则裁剪

3,代码实现V1


一,规则

1,颜色

本草有4种颜色,任选2种不同颜色有6种情况,选2张相同颜色的有4种情况,但合并为1种情况。

2,药引卡

一共有7张药引卡:

3,药材卡

14张药材卡(2红3黄4绿5蓝):

4,五种行动

一共有五种行动

问要、喂药、组药、求药、解药

 

 

5,四种难度模式

最简单的是 求药+解药

简单的是 问药+解药

普通的是 喂药+求药+解药

进阶的是 5种行动任意组合(我理解应该是解药必须有,另外4个行动有15种组合,去掉上面3种还有12种)

6,规则

 赢一局得3分,得6分就获胜。

二,人机对战

1,玩家设计

支持玩家和AI数量任意分配。

由于这不是棋,所以使用无智AI不太影响玩家的游戏体验。

所谓的无智AI,就是随机选择行动及其细节参数即可。

2,规则裁剪

程序只支持一局,需要多局的重新运行即可。

不设定难度模式,输入操作时只选合法的操作即可。

不校验“不能连续两次在同一张药材卡做问药问药”这一规则。

3,代码实现V1

#include "data.h"

#include<iostream>
using namespace std;

string colors = "rygb";
string card14 = "rryyyggggbbbbb"; // 14张药材卡,2红3黄4绿5蓝
string card7[] = {"same","ry","rg","rb","yg","yb","gb" };
int players = 0;
vector<int> isPerson;//id是0到players-1,1是真人,0是AI
vector<vector<int>> playerCards;
string ansCard = "";

void Init()
{
	system("cls");
	cout << "输入玩家数总数, 在2-4的范围\n";
	cin >> players;
	if (players < 2 || players>4)return Init();
	cout << "输入每个玩家是不是真人,1是真人,0是AI\n";
	isPerson.resize(players);
	for (int i = 0; i < players; i++)cin >> isPerson[i];
}
int GetColorId(char c)
{
	for (int i = 0; i < 4; i++)
		if (c == colors[i])
			return i;
	return 0;
}
void Deal() //发牌
{
	srand(time(NULL));
	for (int i = 0; i < 100; i++) {
		int x = rand() % 14;
		int y = rand() % 14;
		char c = card14[x];
		card14[x] = card14[y], card14[y] = c;
	}
	playerCards.resize(players);
	for (int i = 0; i < players; i++) {
		playerCards[i].resize(4);
		for (int j = 0; j < 4; j++)playerCards[i][j] = 0;
		for (int j = 0; j < 12 / players; j++) {
			playerCards[i][GetColorId(card14[i * 12 / players + j])]++;
		}
	}
	ansCard += card14[12];
	ansCard += card14[13];
	return;
}

void Show(int playerId)
{
	system("cls");
	cout << "当前玩家: " << playerId << endl;
	cout << "4种颜色: r红,y黄,g绿,b蓝" << endl;
	cout << "7张药引卡: ";
	for (int i = 0; i < 7; i++)cout << card7[i] << " ";
	cout << "\n当前玩家4种颜色的药材卡各有: ";
	for (int i = 0; i < 4; i++)cout << playerCards[playerId][i] << " ";
	cout << endl;
}

char GetAnotherColor(string s, char c)
{
	if (s[0] == c)return s[1];
	return s[0];
}
void action1(int playerId)//"问药"
{
	if (isPerson[playerId]) {
		cout << "问谁?输入id,范围0到" << players - 1 << endl;
		int pid, cardid, colid;
		cin >> pid;
		cout << "问哪张药引卡?输入id,范围0到6\n";
		cin >> cardid;
		cout << "给ta什么颜色的牌?输入id,范围0到3\n";
		cin >> colid;
		if (playerCards[playerId][colid] <= 0)return action1(playerId);
		playerCards[playerId][colid]--;
		playerCards[pid][colid]++;
		if (cardid) {
			char another = GetAnotherColor(card7[cardid], colors[cardid]);
			cout << "ta有" << playerCards[pid][another];
		}
		else cout << "ta有" << playerCards[pid][colid];
	}
	else {
		// AI
	}
	system("pause");
}
void action2(int playerId)//"喂药"
{
	if (isPerson[playerId]) {
		//
	}
	else {
		// AI
	}
}
void action3(int playerId)//"组药"
{
	if (isPerson[playerId]) {
		//
	}
	else {
		// AI
	}
}
void action4(int playerId)//"求药"
{
	if (isPerson[playerId]) {
		//
	}
	else {
		// AI
	}
}
void action5(int playerId)//"解药"
{
	if (isPerson[playerId]) {
		cout << "请仅输入解药的2个字母并回车,否则算你错没商量\n";
		char a, b;
		cin >> a >> b;
		if ((a == ansCard[0] && b == ansCard[1]) || (a == ansCard[1] && b == ansCard[0]))
			cout << "解正确!";
		else cout << "解错误!";
	}
	else {
		cout << "解正确!";
	}
}

typedef void (*func)(int);
func actions[] = { action1 ,action2,action3,action4,action5 };
void action(int playerId)
{
	Show(playerId);
	if (isPerson[playerId]) {
		cout << "选择操作id,0问药,1喂药,2组药,3求药,4解药\n";
		int id;
		cin >> id;
		return actions[id](playerId);
	}
	else {
		// 如果AI已经确定答案就选择解药,否则随机选择合法行动
	}
}

bool IsEnd()
{
	return false;
}

int main()
{
	Init();
	Deal();
	while (!IsEnd())
	{
		for (int i = 0; i < players; i++)action(i);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/nameofcsdn/article/details/123300888