#include <iostream>
#include <string>
#include <chrono>
#include <thread>
#include <vector>
#include <algorithm>
using namespace std;
using namespace std::chrono;
bool isValidMessage(const string& message, const vector<string>& history) {
// 检查是否包含禁用词
const string bannedWords[] = {"你", "我", "他"};
for (const string& word : bannedWords) {
if (message.find(word) != string::npos) {
return false;
}
}
// 检查是否长度小于5个字符
if (message.length() < 5) {
return false;
}
// 检查是否重复
if (find(history.begin(), history.end(), message) != history.end()) {
return false;
}
return true;
}
int main() {
vector<string> player1History;
vector<string> player2History;
cout << "欢迎来到特殊对话游戏!" << endl;
cout << "请两位玩家依次输入发言内容,遵守以下规则:" << endl;
cout << "1. 不能说' ', ' ', ' '//自己猜是啥" << endl;
cout << "2. 发言//自己猜是啥" << endl;
cout << "3. 不能//自己猜是啥" << endl;
cout << "4. 对话时间为100秒" << endl;
//cout << "1. 不能说'你', '我', '他'" << endl;
//cout << "2. 发言长度不能低于5个字" << endl;
//cout << "3. 不能重复同一句话" << endl;
//cout << "4. 对话时间为100秒" << endl;
steady_clock::time_point startTime = steady_clock::now();
auto endTime = startTime + seconds(100);
int player1Faults = 0;
int player2Faults = 0;
bool isPlayer1Turn = true;
while (steady_clock::now() < endTime) {
string input;
cout << (isPlayer1Turn ? "玩家1:" : "玩家2:");
getline(cin, input);
vector<string>& currentPlayerHistory = isPlayer1Turn ? player1History : player2History;
if (!isValidMessage(input, currentPlayerHistory)) {
cout << "违规发言!" << endl;
if (isPlayer1Turn) {
player1Faults++;
} else {
player2Faults++;
}
} else {
currentPlayerHistory.push_back(input);
}
isPlayer1Turn = !isPlayer1Turn;
}
cout << "游戏结束!" << endl;
cout << "玩家1违规次数:" << player1Faults << endl;
cout << "玩家2违规次数:" << player2Faults << endl;
if (player1Faults > player2Faults) {
cout << "玩家2胜利!" << endl;
} else if (player1Faults < player2Faults) {
cout << "玩家1胜利!" << endl;
} else {
cout << "平局!" << endl;
}
return 0;
}