Materia Medica

content

One, the rules

1. Color

2, medicine lead card

3. Herbal Medicine Card

4. Five Actions

5. Four difficulty modes

6. Rules

Second, man-machine battle

1. Player design

2, regular cutting

3. Code implementation V1


One, the rules

1. Color

Materia Medica has 4 colors, there are 6 cases if you choose 2 different colors, 4 cases if you choose 2 of the same color, but combined into 1 case.

2, medicine lead card

There are a total of 7 medicine lead cards:

3. Herbal Medicine Card

14 herbal cards (2 red, 3 yellow, 4 green and 5 blue):

4. Five Actions

There are five actions

Ask, give medicine, make medicine, ask for medicine, antidote

 

 

5. Four difficulty modes

The easiest is to seek medicine + antidote

Simply ask the medicine + antidote

Ordinary is feeding medicine + seeking medicine + antidote

The advanced one is any combination of 5 kinds of actions (I understand that the antidote must have, the other 4 actions have 15 kinds of combinations, and there are 12 kinds after removing the above 3 kinds)

6. Rules

 3 points for a win, 6 points for a win.

Second, man-machine battle

1. Player design

Supports arbitrary distribution of the number of players and AI.

Since this is not chess, the use of a no-intelligence AI doesn't affect the player's gaming experience very much.

The so-called ignorant AI is to randomly select actions and their detailed parameters.

2, regular cutting

The program only supports one round, and multiple rounds of re-running are required.

No difficulty mode is set, and only legal operations can be selected when inputting operations.

Do not check the rule "You can't do the same medicine card twice in a row".

3. Code implementation 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;
}

Guess you like

Origin blog.csdn.net/nameofcsdn/article/details/123300888