C++#include<iostream>//输入输出
#include<string>//string字符串
#include<windows.h>//system+Sleep
#include<ctime>//配合srand设置随机种子
#include<conio.h>//调用_getch函数
#include<vector>//用于AI分析
#include<algorithm>//用于AI分析
#include<cmath>//用于概率计算
#include<map>//用于存储AI学习
#define cl system("cls") //清屏函数
using namespace std;
int main();
// ============ 新增AI相关变量和类 ============
class GameAI {
private:
int player_hp, ai_hp;
int player_hp_up, ai_hp_up;
int player_daoju_cnt, ai_daoju_cnt;
int player_daoju[10], ai_daoju[10];
int shi, kong, total_bullets;
int current_bullet_index;
int* bullet_sequence;
bool bullet_known;
bool has_handcuff;
bool can_use_saw;
bool can_reverse;
string player_role, ai_role;
bool is_special_soldier;
bool is_berserker;
bool is_craftsman;
bool is_assassin;
bool is_drunkard;
bool is_doctor;
bool is_tycoon;
bool is_scavenger;
int difficulty; // 1=简单, 2=中等, 3=困难
bool cheating; // 是否作弊(查看子弹属性)
bool cheat_used; // 本次回合是否已作弊
// 概率分析权重
const double KILL_PRIORITY = 10.0;
const double SURVIVE_PRIORITY = 8.0;
const double INFO_PRIORITY = 7.0;
const double UTILITY_PRIORITY = 6.0;
const double RISK_AVERSION = 0.7;
// AI学习数据(简单记忆)
map<string, double> action_weights;
public:
GameAI(int ph, int ah, int php_up, int ahp_up,
int pdc, int adc, int p_daoju[], int a_daoju[],
int s, int k, int curr_idx, int* bullets,
bool known, bool hc, bool saw, bool rev,
string prole, string arole, int diff) {
player_hp = ph;
ai_hp = ah;
player_hp_up = php_up;
ai_hp_up = ahp_up;
player_daoju_cnt = pdc;
ai_daoju_cnt = adc;
for (int i = 0; i < player_daoju_cnt; i++) player_daoju[i] = p_daoju[i + 1];
for (int i = 0; i < ai_daoju_cnt; i++) ai_daoju[i] = a_daoju[i + 1];
shi = s;
kong = k;
total_bullets = s + k;
current_bullet_index = curr_idx;
bullet_sequence = bullets;
bullet_known = known;
has_handcuff = hc;
can_use_saw = saw;
can_reverse = rev;
player_role = prole;
ai_role = arole;
difficulty = diff;
cheating = false;
cheat_used = false;
// 根据难度设置作弊概率(困难AI有作弊能力)
if (difficulty == 3) {
// 困难AI有40%概率在需要时作弊查看子弹
cheating = (rand() % 100 < 40);
}
is_special_soldier = (ai_role == "特种兵");
is_berserker = (ai_role == "狂战士");
is_craftsman = (ai_role == "工匠");
is_assassin = (ai_role == "刺客");
is_drunkard = (ai_role == "酒鬼");
is_doctor = (ai_role == "医生");
is_tycoon = (ai_role == "大亨");
is_scavenger = (ai_role == "拾荒者");
}
// ============ 作弊功能 ============
// 查看子弹属性(作弊)
int cheatCheckBullet() {
if (cheating && !cheat_used && difficulty == 3) {
cheat_used = true;
return bullet_sequence[current_bullet_index];
}
return -1; // 没有作弊或已使用过
}
// 获取高级游戏信息(作弊)
void cheatGetInfo() {
if (cheating && difficulty == 3) {
// 中等作弊:有概率知道下一发子弹
if (rand() % 100 < 30 && current_bullet_index < total_bullets) {
// 实际上这里我们可以调整AI的决策知识
// 但为了不过分,只是调整概率评估
}
}
}
// 评估当前子弹的风险(考虑作弊)
double evaluateBulletRisk() {
// 检查是否作弊查看子弹
int cheat_result = cheatCheckBullet();
if (cheat_result != -1) {
// 作弊知道了真实子弹类型
return (cheat_result == 1) ? 1.0 : 0.0;
}
if (bullet_known) {
return (bullet_sequence[current_bullet_index] == 1) ? 1.0 : 0.0;
} else {
return (double)shi / total_bullets;
}
}
// 计算击杀玩家的概率(考虑作弊)
double calculateKillChance() {
double chance = 0.0;
int cheat_result = cheatCheckBullet();
if (cheat_result != -1) {
// 作弊知道了真实子弹类型
chance = (cheat_result == 1) ? 1.0 : 0.0;
} else if (bullet_known) {
chance = (bullet_sequence[current_bullet_index] == 1) ? 1.0 : 0.0;
} else {
chance = (double)shi / total_bullets;
}
// 考虑手锯效果
if (can_use_saw) chance = min(1.0, chance * 2.0);
return chance;
}
// ============ 简单AI增强 ============
double simpleAI_evaluate() {
double score = 0.0;
// 简单AI的基本逻辑
if (difficulty == 1) {
// 增强1:血量管理
if (ai_hp <= 2) {
// 低血量时强烈倾向于回血
score += SURVIVE_PRIORITY * 3.0;
}
// 增强2:优先使用香烟回血
for (int i = 0; i < ai_daoju_cnt; i++) {
if (ai_daoju[i] == 3) { // 香烟
score += 5.0;
}
}
// 增强3:避免高风险行为
double risk = evaluateBulletRisk();
if (risk > 0.6) {
score -= 4.0; // 高风险时扣分
}
// 增强4:当玩家血量低时,尝试击杀
if (player_hp <= 2) {
score += 3.0;
}
// 增强5:使用啤酒退弹(特别是当实弹多时)
if (shi > kong) {
for (int i = 0; i < ai_daoju_cnt; i++) {
if (ai_daoju[i] == 4) { // 啤酒
score += 3.0;
}
}
}
}
return score;
}
// ============ 中等AI增强 ============
double mediumAI_evaluate(string action_type) {
double score = 0.0;
if (difficulty == 2) {
// 增强1:基本道具组合
if (action_type == "shoot_player") {
// 尝试组合:放大镜+逆转器+手锯
bool has_magnifier = false;
bool has_reverser = false;
bool has_saw = false;
for (int i = 0; i < ai_daoju_cnt; i++) {
if (ai_daoju[i] == 1) has_magnifier = true;
if (ai_daoju[i] == 6) has_reverser = true;
if (ai_daoju[i] == 2) has_saw = true;
}
if (has_magnifier && has_reverser && has_saw) {
score += 8.0; // 强力组合
}
}
// 增强2:战术手铐使用
if (action_type == "use_handcuff") {
// 当玩家有优势时使用手铐
if (player_hp > ai_hp + 1) {
score += 6.0;
}
// 阻止玩家连击
if (shi > 0 && kong == 0) { // 都是实弹时
score += 4.0;
}
}
// 增强3:飞镖策略优化
if (action_type == "use_dart") {
if (is_assassin) {
score += 7.0; // 刺客用飞镖很强
} else {
// 非刺客只在安全时使用
if (ai_hp > 2) {
score += 4.0;
}
}
}
// 增强4:诺基亚使用时机
if (action_type == "use_phone") {
if (total_bullets >= 4) { // 子弹多时用
score += 5.0;
}
}
// 增强5:肾上腺素抢夺策略
if (action_type == "use_adrenaline") {
// 检查玩家有好道具
for (int i = 0; i < player_daoju_cnt; i++) {
int item = player_daoju[i];
if (item == 1 || item == 6 || item == 9) { // 放大镜、逆转器、飞镖
score += 3.0;
}
}
}
// 增强6:身份技能利用
if (is_doctor) {
// 医生更倾向于使用过期药品
if (action_type == "use_medicine") {
score += 4.0;
}
}
if (is_drunkard) {
// 酒鬼更倾向于使用啤酒和香烟
if (action_type == "use_beer" || action_type == "use_cigarette") {
score += 3.0;
}
}
if (is_scavenger) {
// 拾荒者更倾向于使用道具(触发拾荒)
score += 2.0;
}
}
return score;
}
// ============ 评估行动:向玩家开枪 ============
double evaluateShootPlayer() {
double score = 0.0;
// 基础评估
double kill_chance = calculateKillChance();
double damage_expected = kill_chance * (can_use_saw ? 2.0 : 1.0);
// 如果这一枪能击杀玩家
if (damage_expected >= player_hp) {
score += KILL_PRIORITY * 3.0;
}
// 如果能让玩家濒死
else if (damage_expected >= player_hp - 1) {
score += KILL_PRIORITY * 2.0;
}
// 正常伤害
else {
score += KILL_PRIORITY * damage_expected;
}
// 考虑风险:如果这一枪是实弹但没打死,自己会被反击
if (kill_chance > 0.5) {
score -= (1.0 - kill_chance) * SURVIVE_PRIORITY;
}
// 考虑狂战士技能
if (is_berserker && kill_chance > 0.3) {
score += 3.0;
}
// 简单AI增强
score += simpleAI_evaluate();
// 中等AI增强
score += mediumAI_evaluate("shoot_player");
return score;
}
// ============ 评估行动:向自己开枪 ============
double evaluateShootSelf() {
double score = 0.0;
// 安全概率(空弹)
double safe_chance = 1.0 - evaluateBulletRisk();
// 如果是空弹,可以获得额外回合
if (safe_chance > 0.7) {
score += SURVIVE_PRIORITY * 2.0;
}
// 风险:如果是实弹
double risk = 1.0 - safe_chance;
score -= risk * SURVIVE_PRIORITY * 3.0;
// 考虑血量:血量越低,越不能冒险
if (ai_hp <= 2) {
score -= 10.0;
}
// 如果知道自己会被手铐控制
if (has_handcuff) {
score += SURVIVE_PRIORITY;
}
// 简单AI增强:简单AI很少向自己开枪
if (difficulty == 1) {
score -= 5.0;
}
// 中等AI增强:中等AI在特定情况下会向自己开枪
if (difficulty == 2) {
// 如果有很多空弹且需要额外回合
if (kong > shi && ai_hp > 3) {
score += 4.0;
}
}
return score;
}
// ============ 评估使用道具 ============
double evaluateUseItem(int item_id) {
double score = 0.0;
string action_type = "";
switch (item_id) {
case 1: // 放大镜
action_type = "use_magnifier";
if (!bullet_known) {
score = INFO_PRIORITY * 2.0;
if (shi > 0 && kong > 0 && total_bullets > 3) {
score += 2.0;
}
}
break;
case 2: // 手锯
action_type = "use_saw";
if (can_use_saw) {
double kill_chance = calculateKillChance();
if (kill_chance > 0.4) {
score = KILL_PRIORITY * kill_chance * 1.5;
}
}
break;
case 3: // 香烟
action_type = "use_cigarette";
if (ai_hp < ai_hp_up) {
score = SURVIVE_PRIORITY * (ai_hp_up - ai_hp);
// 酒鬼额外加分
if (is_drunkard) {
score += 3.0;
}
}
break;
case 4: // 啤酒
action_type = "use_beer";
if (shi > kong) {
score = SURVIVE_PRIORITY * ((double)shi / total_bullets) * 2.0;
}
if (is_drunkard) {
score += 2.0;
}
break;
case 5: // 手铐
action_type = "use_handcuff";
if (!has_handcuff) {
score = UTILITY_PRIORITY * 1.5;
if (player_hp > ai_hp) {
score += 2.0;
}
}
break;
case 6: // 逆转器
action_type = "use_reverser";
if (bullet_known) {
if (bullet_sequence[current_bullet_index] == 1) {
score = SURVIVE_PRIORITY * 3.0;
}
} else {
if (shi > kong) {
score = SURVIVE_PRIORITY * 2.0;
}
}
break;
case 7: // 肾上腺素
action_type = "use_adrenaline";
if (player_daoju_cnt > 0) {
score = UTILITY_PRIORITY * 2.0;
for (int i = 0; i < player_daoju_cnt; i++) {
int item = player_daoju[i];
if (item == 1 || item == 6 || item == 9) {
score += 1.0;
}
}
}
break;
case 8: // 过期药品
action_type = "use_medicine";
if (ai_hp <= ai_hp_up - 2) {
score = SURVIVE_PRIORITY * 2.0;
} else if (ai_hp == ai_hp_up) {
score = -5.0;
}
// 医生额外加分
if (is_doctor) {
score += 4.0;
}
break;
case 9: // 飞镖
action_type = "use_dart";
if (is_assassin) {
score = KILL_PRIORITY * 1.5;
} else {
double expected_damage = 0.15 * 2 + 0.5 * 1 - 0.2 * 1;
score = KILL_PRIORITY * expected_damage;
}
break;
case 10: // 诺基亚
action_type = "use_phone";
if (total_bullets > 2) {
score = INFO_PRIORITY * 1.5;
}
break;
}
// 中等AI增强
score += mediumAI_evaluate(action_type);
return score;
}
// ============ 评估工匠技能 ============
double evaluateCraftsman() {
if (!is_craftsman) return -100.0;
double best_score = -100.0;
// 评估可以创造的道具
for (int item = 1; item <= 10; item++) {
if (item == 5 || item == 7) continue;
double item_score = evaluateUseItem(item);
if (item_score > best_score) {
best_score = item_score;
}
}
return best_score;
}
// ============ 主决策函数 ============
string makeDecision() {
vector<pair<double, string>> actions;
// 作弊获取额外信息
cheatGetInfo();
// 评估所有可能的行动
// 1. 向玩家开枪
double shoot_player_score = evaluateShootPlayer();
actions.push_back({shoot_player_score, "A"});
// 2. 向自己开枪
double shoot_self_score = evaluateShootSelf();
actions.push_back({shoot_self_score, "B"});
// 3. 使用道具
for (int i = 0; i < ai_daoju_cnt; i++) {
int item = ai_daoju[i];
double item_score = evaluateUseItem(item);
actions.push_back({item_score, to_string(item)});
}
// 4. 工匠技能(如果可用)
if (is_craftsman) {
double craftsman_score = evaluateCraftsman();
actions.push_back({craftsman_score, "C"});
}
// 5. 特种兵双发射击(如果可用且选择开枪)
if (is_special_soldier && total_bullets >= 2) {
// 假设双发会增加50%的效果
double double_shoot_score = shoot_player_score * 1.5;
actions.push_back({double_shoot_score, "A1"});
}
// 按分数排序,选择最高分的行动
sort(actions.begin(), actions.end(),
[](const pair<double, string>& a, const pair<double, string>& b) {
return a.first > b.first;
});
// 根据难度调整选择策略
int choice = 0;
if (difficulty == 1) { // 简单AI
// 70%选择最佳行动,30%选择前3中的随机一个
if (rand() % 100 < 70) {
choice = 0;
} else {
choice = rand() % min(3, (int)actions.size());
}
} else if (difficulty == 2) { // 中等AI
// 85%选择最佳行动,15%选择前2中的随机一个
if (rand() % 100 < 85) {
choice = 0;
} else {
choice = rand() % min(2, (int)actions.size());
}
} else { // 困难AI
// 95%选择最佳行动,5%选择前2中的随机一个(模拟偶尔的非最优选择)
if (rand() % 100 < 95) {
choice = 0;
} else {
choice = rand() % min(2, (int)actions.size());
}
}
if (choice >= actions.size()) choice = 0;
return actions[choice].second;
}
// 获取AI是否作弊(用于显示)
bool isCheating() {
return cheating && cheat_used;
}
};
int huode_daoju = 4; //获得道具
int gailv[11] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; //抽到这个道具的概率
string daoju_name[11] = {"SB", "放大镜", "手锯", "香烟", "啤酒", "手铐",
"逆转器", "肾上腺素", "过期药品", "飞镖", "诺基亚"
};//道具名字
string sf1 = "AE8633", sf2 = "12345zwc"; //双方身份
int daoju1[10] = {}, daoju1cnt = 0; //1P道具、道具个数
int daoju2[10] = {}, daoju2cnt = 0; //2P道具、道具个数
int HP1 = 4, HP_UP1 = 4, HP2 = 4, HP_UP2 = 4; //血量与血量上限
int a[15], add; //子弹、第几发
int shi, kong, zidan; //实弹 空弹 子弹总数
int huihe = 1; //回合(哪位玩家先手)
int shoukao1 = 0, shoukao2 = 0; //双方是否被手铐控制
int xiaodao = 0, nizhuan = 0; //是否使用手锯、逆转器
bool jiugui = true, tezhongbing = false; //酒鬼是否能发动技能 特种兵是否发动过技能
int gongjiang = 0; //工匠技能冷却
int mode = 0; // 0=未选择, 1=双人, 2=单人(对抗AI)
int ai_difficulty = 3; // AI难度: 1=简单, 2=中等, 3=困难
int hddj() { //获得道具
int sum = 0;
for (int i = 1; i < 11; i++)sum += gailv[i];
int x = rand() % sum + 1, y = 0;
for (int i = 1; i < 11; i++) {
if (gailv[i] + y >= x)return i;
else y += gailv[i];
}
}
void XuanShenFen(int p) { //选择身份
cl;
cout << "0.不选择\n";
cout << "1.大亨:每个大回合多获得2个道具\n";
cout << "2.医生:\n";
cout << " (1)过期药品必嗑到真药\n";
cout << " (2)每过1个大回合,回1滴血\n";
cout << "3.拾荒者:当有人使用道具时,你有35%概\n 率获得(不可拾荒烟、肾上腺素、手铐)\n";
cout << "4.壮汉:血量上限+3,初始血量+1\n";
cout << "5.酒鬼:\n";
cout << " (1)使用啤酒时,回1点血\n";
cout << " (2)使用香烟时,可选择视为使用1次啤\n 酒(不能联动技能1)\n";
cout << " (3)飞镖更容易磕到甲沟炎\n";
cout << " (4)血量上限+1\n";
cout << "6.刺客:\n";
cout << " (1)飞镖不会扔空或扔到自己\n";
cout << " (2)手锯只能当飞镖用\n";
cout << "7.特种兵:可以一次射出两发子弹\n";
cout << "8.狂战士:造成伤害后,有60%概率回1滴\n 血(打自己也行)\n";
cout << "9.工匠:每2回合限一次,你可以视为使\n 用任意一个道具(手铐,肾上腺\n 素外)\n";
cout << "-1.随机(非0)(也有可能随机重复的)\n";
int x;
cin >> x;
if (x == -1)
x = rand() % 9 + 1;
if (x == 4 && p == 2 && sf1 != "壮汉")
if (p == 1)
HP1++, HP_UP1 += 3;
else if (p == 2)
HP2++, HP_UP2 += 3;
if (x == 5 && p == 2 && sf1 != "酒鬼")
if (p == 1)HP_UP1++;
else HP_UP2++;
string sf;
if (x == 0)sf = "无";
else if (x == 1)sf = "大亨";
else if (x == 2)sf = "医生";
else if (x == 3)sf = "拾荒者";
else if (x == 4)sf = "壮汉";
else if (x == 5)sf = "酒鬼";
else if (x == 6)sf = "刺客";
else if (x == 7) sf = "特种兵";
else if (x == 8)sf = "狂战士";
else sf = "工匠";
if (p == 1)sf1 = sf;
else sf2 = sf;
if (sf1 == sf2 && sf1 != "无") { //重复情况
cout << "重复,重新选择";
Sleep(1000);
XuanShenFen(p);
return;
}
cout << "选择身份:" << (p == 1 ? sf1 : sf2) << '\n';
Sleep(2500);
}
void in_game() { //规则
cl;
cout << "恶魔轮盘赌\n\n";
cout << "1.开始游戏\n";
cout << "2.查看规则\n";
cout << "3.提示以及技巧\n";
cout << "4.自定义数值\n";
cout << "5.更新日志\n";
cout << "6.退出游戏\n\n";
char x = 100;
while (x < '1' || x > '6')x = _getch();
x -= 48;
if (x == 1) {
cl;
cout << "选择游戏模式:\n";
cout << "1. 双人对战\n";
cout << "2. 单人模式(对抗AI)\n";
char m = _getch();
while (m < '1' || m > '2') m = _getch();
mode = m - '0';
if (mode == 2) {
cl;
cout << "选择AI难度:\n";
cout << "1. 简单 - AI基本策略,偶尔犯错\n";
cout << "2. 中等 - AI战术思考,使用道具组合\n";
cout << "3. 困难 - AI几乎无法战胜,可能作弊\n";
char d = _getch();
while (d < '1' || d > '3') d = _getch();
ai_difficulty = d - '0';
if (ai_difficulty == 3) {
cout << "\n警告:困难AI使用高级策略和概率计算,\n";
cout << "并且有概率作弊查看子弹属性!\n";
cout << "挑战性极高,几乎无法战胜!\n";
Sleep(2000);
}
}
return;
} else if (x == 2) {
cout << "------------规则--------------" << endl;
cout << "你们需要进行一场赌命游戏" << endl;
cout << "这把霰弹枪(其实没有)就是赌命的工具" << endl;
cout << "每轮都会有若干个实弹和空弹" << endl;
cout << "双方轮流拿枪打自己或打对方" << endl;
cout << "实弹可以造成1点伤害,空弹无伤害" << endl;
cout << "但是空弹打自己能再次获得开枪机会" << endl;
cout << "每轮可以获得" << huode_daoju << "个道具,开枪前可以使用" << endl;
cout << "1.放大镜\n";
cout << "2.手锯\n";
cout << "3.香烟\n";
cout << "4.啤酒\n";
cout << "5.手铐\n";
cout << "6.逆转器\n";
cout << "7.肾上腺素\n";
cout << "8.过期药品\n";
cout << "9.飞镖(自创)\n";
cout << "0.诺基亚(一次性手机)\n";
char y = _getch();
y -= 48;
if (y == 1) {
cout << "这是1个放大镜,没什么不一样的\n";
cout << "动作:敲碎镜片,查看弹膛\n";
cout << "作用:查看当前子弹类型\n";
} else if (y == 2) {
cout << "一把生锈的折叠刀,相当的锋利\n";
cout << "动作:割断枪管\n";
cout << "作用:令下次霰弹枪伤害翻倍,不可叠加\n";
} else if (y == 3) {
cout << "一包华子,抽了一根就扔掉了\n";
cout << "动作:打开包装,抽出一根,用火机点燃,剩下的烟扔了\n";
cout << "作用:回一滴血\n";
} else if (y == 4) {
cout << "一瓶易拉罐装的小麦果汁(啤酒)\n";
cout << "动作:将啤酒一饮而尽,退掉一发子弹\n";
cout << "作用:退一发子弹\n";
} else if (y == 5) {
cout << "应该是局子里偷来的\n";
cout << "动作:铐上对方\n";
cout << "作用:令对方跳过下一回合\n";
} else if (y == 6) {
cout << "物理学不存在了,扭个按钮就能逆转子弹\n";
cout << "动作:旋转逆转器上的按钮\n";
cout << "作用:逆转当前子弹类型\n";
} else if (y == 7) {
cout << "扎一针后兴奋极了,管它叫兴奋剂吧\n";
cout << "动作:扭开小盖子,给自己来一针\n";
cout << "作用:抢一个道具\n";
} else if (y == 8) {
cout << "保质期已过,嗑药有风险\n";
cout << "动作:打开药盒,将一颗药放入嘴中\n";
cout << "作用:55%回2滴血,否则扣1滴血(加强了)\n";
} else if (y == 9) {
cout << "不会耍飞镖的,慎用\n";
cout << "有15%对方-2,50%对方-1,15%打空,20%自己-1\n";
} else if (y == 0) {
cout << "未来的人会告诉你答案\n";
cout << "动作:打开手机,听打电话的人瞎BB,然后掰掉手机\n";
cout << "预测从此发子弹开始随机1发子弹类型(第1发不行,1/2发时显示真遗憾)\n";
} else {
cout << "输入错误!\n";
}
system("pause");
in_game();
} else if (x == 3) {
cl;
cout << "提示:\n";
cout << "(1)在输入时,不要输入额外内容,如行动时输入aaa等\n";
cout << "(2)道具上限只有8个,每个大回合获得道具后不超过8个\n";
cout << "(3)回血后,血量不超过上限\n\n";
cout << "技巧:\n";
cout << "(1)放大镜+逆转器+手锯=对方掉2血\n";
cout << " 达成难度:4 实用程度:3\n";
cout << " 优点:伤害高,适合斩杀\n";
cout << " 缺点:对道具要求苛刻,道具消耗大\n";
cout << "(2)尽量保留先手,用啤酒退弹或逆转器转换(高端玩法)\n";
cout << " 达成难度:2 实用程度:4\n";
cout << " 优点:能够有效限制对手行动,也可以刷\"技巧1\"\n";
cout << " 缺点:需要舍弃一些伤害,有点浪费道具\n";
cout << "(3)身份为刺客时,可以屯飞镖(手锯),秒掉对方\n";
cout << " 达成难度:5 实用程度:5\n";
cout << " 优点:一波带走\n";
cout << " 缺点:看脸\n";
cout << "\n对抗AI技巧:\n";
cout << "(1)简单AI:会犯错误,但已加强基本策略\n";
cout << "(2)中等AI:会使用道具组合和战术思考\n";
cout << "(3)困难AI:几乎完美决策,且有概率作弊\n";
system("pause");
in_game();
} else if (x == 4) {
cl;
cout << "1P血量以及上限:";
cin >> HP1 >> HP_UP1;
cout << "2P血量以及上限:";
cin >> HP2 >> HP_UP2;
cout << "每回合获得道具量:";
cin >> huode_daoju;
cout << "接下来输入道具刷新概率,1个自然数,表示所占份数\n";
cout << "如放大镜3,手锯2,其余为0,则两个道具概率分别为60% 40%\n";
Sleep(2000);
for (int i = 1; i < 11; i++) {
cout << "道具" << daoju_name[i] << "刷新概率:";
cin >> gailv[i];
}
cout << "改变完毕!\n";
Sleep(1500);
in_game();
} else if (x == 5) {
cl;
cout << "2025年7月:\n";
cout << "1.游戏出炉!(仅有5个道具)\n";
cout << "2.更新至10个道具\n";
cout << "3.更新身份\n\n";
cout << "2025年9月?日\n";
cout << "新增角色特种兵(双发射击)\n\n";
cout << "2025年10月?日:\n";
cout << "1.新增角色狂战士(吸血)以及工匠(塑造道具)\n";
cout << "2.加强酒鬼,血量上限+1\n";
cout << "3.修复BUG:1P选择壮汉时,2P一直选择壮汉即可无限叠加血量上限/血量\n";
cout << "4.正在更新:模式\n\n";
cout << "2025年11月18日:\n";
cout << "1.更新日志\n";
cout << "2.随机身份(更加完善)\n\n";
cout << "2024年X月X日:\n";
cout << "1.新增单人模式(对抗AI)\n";
cout << "2.AI有三种难度可选\n";
cout << "3.困难AI几乎无法战胜,可能作弊\n";
cout << "4.加强简单和中等AI\n";
Sleep(1500);
system("pause");
in_game();
} else if (x == 6) {
exit(0);
}
}
void huihe_start() { //回合开始
shoukao1 = 0;
shoukao2 = 0;
Sleep(2000);
cl;
add = 1;
kong = 0;
shi = 0;
int q = 0;
f:
zidan = rand() % 7 + 2;
for (int i = 1; i <= zidan; i++) {
int y = rand() % 2;
if (y == 1) {
shi++;
a[++q] = 1;
} else {
kong++;
a[++q] = 0;
}
}//子弹重置
if (kong == zidan || shi == zidan)goto f; //没有实弹或没有空弹时重新分配
cout << "1P获得道具:";
if (sf1 == "大亨")huode_daoju += 2;
if (sf1 == "医生") {
HP1++;
HP1 = min(HP1, HP_UP1);
}
for (int i = 1; i <= huode_daoju && daoju1cnt < 8; i++) {
int h = hddj();
daoju1[++daoju1cnt] = h;
cout << daoju_name[h] << ' ';
}
if (sf1 == "大亨")huode_daoju -= 2;
cout << "\n2P获得道具:";
if (sf2 == "大亨")huode_daoju += 2;
if (sf1 == "医生") {
HP2++;
HP2 = min(HP2, HP_UP2);
}
for (int i = 1; i <= huode_daoju && daoju2cnt < 8; i++) {
int h = hddj();
daoju2[++daoju2cnt] = h;
cout << daoju_name[h] << ' ';
}
if (sf2 == "大亨")huode_daoju -= 2;
cout << endl << huihe << "P玩家先手\n" ;
//获得道具
system("pause");
}
void p(int x) { //打印'.'
for (int i = 0; i < x; i++) {
cout << '.';
Sleep(500);
}
}
void game_over(int winner) { //游戏结束
cl;
if (mode == 2) {
if (winner == 1) {
cout << "恭喜!你战胜了AI!\n\n";
if (ai_difficulty == 3) {
cout << "你竟然战胜了会作弊的困难AI!\n";
cout << "你的游戏水平非常高!\n";
}
} else {
cout << "AI获得了胜利!\n";
if (ai_difficulty == 1) {
cout << "简单AI战胜了你,多练习一下吧!\n";
} else if (ai_difficulty == 2) {
cout << "中等AI战胜了你,它使用了战术策略!\n";
} else {
cout << "困难AI战胜了你,它几乎无法被战胜!\n";
cout << "(它可能作弊查看了子弹属性)\n";
}
}
} else {
cout << winner << "P获得胜利!\n\n";
}
Sleep(1008.6);
cout << "按任意键返回主菜单...";
_getch();
main();
}
void pd() { //判断结束/开启新回合
if (HP1 <= 0)game_over(2);
if (HP2 <= 0)game_over(1);
if (shi <= 0 && kong <= 0)huihe_start();
}
void shanchu(int arr[], int x, int &len) { //删除道具
bool flag = false;
for (int i = 1; i <= len; i++) {
if (flag == true)swap(arr[i], arr[i - 1]);
else if (arr[i] == x)flag = true;
}
int g = rand() % 100 + 1;
if (g <= 35 && x != 7 && x != 5 && x != 3) {
if (sf1 == "拾荒者" && daoju1cnt < 8) {
daoju1[++daoju1cnt] = x;
cout << "拾荒者获得了" << daoju_name[x] << endl;
}
if (sf2 == "拾荒者" && daoju2cnt < 8) {
daoju2[++daoju2cnt] = x;
cout << "拾荒者获得了" << daoju_name[x] << endl;
}
}
--len;
}
void print() { //打印血量
cout << "\n1P:";
for (int i = 0; i < HP1; i++)cout << '#';
for (int i = HP1; i < HP_UP1; i++)cout << '\\';
cout << " 2P:";
for (int i = 0; i < HP2; i++)cout << '#';
for (int i = HP2; i < HP_UP2; i++)cout << '\\';
Sleep(1000);
}
void daoju_fangdajing(int pp) { //使用放大镜
if (pp == 1) {
shanchu(daoju1, 1, daoju1cnt);
} else {
shanchu(daoju2, 1, daoju2cnt);
}
cout << "这发子弹是";
p(4);
cout << (a[add] == 1 ? "实弹" : "空弹");
cout << endl;
}
void daoju_shouju(int p) { //使用手锯
if (p == 1) {
shanchu(daoju1, 2, daoju1cnt);
} else {
shanchu(daoju2, 2, daoju2cnt);
}
xiaodao = 1;
cout << "枪管被锯开了,伤害翻倍!\n";
}
void daoju_pijiu(int p) { //使用啤酒
if (p == 1) {
shanchu(daoju1, 4, daoju1cnt);
} else {
shanchu(daoju2, 4, daoju2cnt);
}
cout << "你退出了1发";
if (a[add] == 1) {
cout << "实弹";
shi--;
} else {
cout << "空弹";
kong--;
}
if (p == 1) {
if (sf1 == "酒鬼" && jiugui) {
HP1++;
HP1 = min(HP_UP1, HP1);
}
} else {
if (sf2 == "酒鬼" && jiugui) {
HP2++;
HP2 = min(HP2, HP_UP2);
}
}
add++;
}
void daoju_xiangyan(int p) { //使用香烟
if (p == 1) {
shanchu(daoju1, 3, daoju1cnt);
} else {
shanchu(daoju2, 3, daoju2cnt);
}
cout << "你回复了1滴血";
if (p == 1) {
HP1++;
if (HP1 > HP_UP1) {
cout << ",但超出了上限,实际并没有回血";
HP1 = HP_UP1;
}
if (sf1 == "酒鬼") {
cout << "\n是否视为使用啤酒(1,0):";
int y;
cin >> y;
if (y == 1) {
daoju1[++daoju1cnt] = 4;
daoju_pijiu(1);
}
}
} else {
HP2++;
if (HP2 > HP_UP2) {
cout << ",但超出了上限,实际并没有回血";
HP2 = HP_UP2;
}
if (sf2 == "酒鬼") {
cout << "\n是否视为使用啤酒(1,0):";
int y;
cin >> y;
if (y == 1) {
daoju2[++daoju2cnt] = 4;
daoju_pijiu(2);
}
}
}
print();
}
void daoju_shoukao(int p) { //使用手铐
if (p == 1) {
shanchu(daoju1, 5, daoju1cnt);
} else {
shanchu(daoju2, 5, daoju2cnt);
}
int x = rand() % 100;
cout << "对方被你控制了";
if (p == 1)shoukao2 = 1;
else shoukao1 = 1;
}
void daoju_nizhuanqi(int p) { //使用逆转器
if (p == 1) {
shanchu(daoju1, 6, daoju1cnt);
} else {
shanchu(daoju2, 6, daoju2cnt);
}
cout << "已逆转当前子弹类型";
a[add]++;
a[add] %= 2;
if (a[add] == 1)shi++, kong--;
else shi--, kong++;
nizhuan = 1;
}
void daoju_guoqiyaopin(int p) { //使用过期药品
if (p == 1) {
shanchu(daoju1, 8, daoju1cnt);
} else {
shanchu(daoju2, 8, daoju2cnt);
}
int x = rand() % 100 + 1;
if (p == 1) {
if (sf1 == "医生")x = 91 - 78;
if (x >= 56) {
cout << "你嗑到了一颗假药,血量-1";
HP1--;
pd();
} else {
cout << "你嗑到了一颗真药,血量+2";
HP1 += 2;
if (HP1 - HP_UP1 == 1) {
cout << ",但超出上限,只回一滴血";
HP1 = HP_UP1;
} else if (HP1 - HP_UP1 == 2) {
cout << ",但超出上限,没有回血";
HP1 = HP_UP1;
}
}
} else {
if (sf2 == "医生")x = 91 - 78;
if (x >= 56) {
cout << "你嗑到了一颗假药,血量-1";
HP2--;
pd();
} else {
cout << "你嗑到了一颗真药,血量+2";
HP2 += 2;
if (HP2 - HP_UP2 == 1) {
cout << ",但超出上限,只回一滴血";
HP2 = HP_UP2;
} else if (HP2 - HP_UP2 == 2) {
cout << ",但超出上限,没有回血";
HP2 = HP_UP2;
}
}
}
}
void daoju_feibiao(int p) { //使用飞镖
if (p == 1) {
shanchu(daoju1, 9, daoju1cnt);
} else {
shanchu(daoju2, 9, daoju2cnt);
}
int x;
string sf;
if (p == 1)sf = sf1;
else sf = sf2;
do {
x = rand() % 100 + 1;
} while (x > 65 && sf == "刺客");
if (sf == "酒鬼" && x > 65)x = 90;
if (p == 1) {
if (x <= 15) {
cout << "你用飞镖刺中对方头部,造成2点伤害\n";
HP2 -= 2;
if (sf1 == "狂战士" && rand() % 100 <= 60) {
cout << "\n狂战士发动技能,回一滴血!";
HP1++;
HP1 = min(HP1, HP_UP1);
}
print();
pd();
} else if (x <= 65) {
cout << "你用飞镖刺伤对方,造成1点伤害\n";
HP2--;
if (sf1 == "狂战士" && rand() % 100 <= 60) {
cout << "\n狂战士发动技能,回一滴血!";
HP1++;
HP1 = min(HP1, HP_UP1);
}
print();
pd();
} else if (x <= 80) {
cout << "你的飞镖扔空了\n";
} else {
cout << "你的飞镖旋回来,命中自己\n";
HP1--;
if (sf1 == "狂战士" && rand() % 100 <= 60) {
cout << "\n狂战士发动技能,回一滴血!";
HP1++;
HP1 = min(HP1, HP_UP1);
}
print();
pd();
}
} else {
if (x <= 10) {
cout << "你用飞镖刺中对方头部,造成2点伤害\n";
HP1 -= 2;
if (sf2 == "狂战士" && rand() % 100 <= 60) {
cout << "\n狂战士发动技能,回一滴血!";
HP2++;
HP2 = min(HP2, HP_UP2);
}
print();
pd();
} else if (x <= 65) {
cout << "你用飞镖刺伤对方,造成1点伤害\n";
HP1--;
if (sf2 == "狂战士" && rand() % 100 <= 60) {
cout << "\n狂战士发动技能,回一滴血!";
HP2++;
HP2 = min(HP2, HP_UP2);
}
print();
pd();
} else if (x <= 80) {
cout << "你的飞镖扔空了\n";
} else {
cout << "你的飞镖旋回来,命中自己\n";
HP2--;
if (sf2 == "狂战士" && rand() % 100 <= 60) {
cout << "\n狂战士发动技能,回一滴血!";
HP2++;
HP2 = min(HP2, HP_UP2);
}
print();
pd();
}
}
}
void daoju_nuojiya(int pp) { //使用诺基亚(一次性手机)
if (pp == 1) {
shanchu(daoju1, 10, daoju1cnt);
} else {
shanchu(daoju2, 10, daoju2cnt);
}
p(3);
if (shi + kong <= 2) {
cout << "非常遗憾!";
return;
}
int x = rand() % (shi + kong - 1) + 2;
cout << "第" << x << "发子弹";
p(3);
cout << (a[add + x] == 1 ? "实弹\n" : "空弹\n");
}
void daoju_shenshangxiansu(int p) { //使用肾上腺素
if (p == 1) {
shanchu(daoju1, 7, daoju1cnt);
} else {
shanchu(daoju2, 7, daoju2cnt);
}
cout << "精神亢奋,可抢夺对方1个道具(非肾上腺素)";
int x;
if (p == 1) {
cout << "对方道具:\n";
for (int i = 1; i <= daoju2cnt; i++) {
cout << i << '.' << daoju_name[daoju2[i]] << ' ';
}
cin >> x;
if (x <= 0 || x > daoju2cnt || daoju2[x] == 7) {
cout << "药效已过,你没有抢到任何道具(不想遵守规则还是咋地)\n";
} else {
cout << "你获得了对方的1个" << daoju_name[daoju2[x]] << ",立即使用:\n";
daoju1[++daoju1cnt] = daoju2[x];
Sleep(750);
x = daoju2[x];
if (x == 1)daoju_fangdajing(1);
else if (x == 2) {
daoju_shouju(1);
xiaodao = 1;
} else if (x == 3)daoju_xiangyan(1);
else if (x == 4)daoju_pijiu(1);
else if (x == 5)daoju_shoukao(1);
else if (x == 6)daoju_nizhuanqi(1);
else if (x == 8)daoju_guoqiyaopin(1);
else if (x == 9)daoju_feibiao(1);
else if (x == 10)daoju_nuojiya(1);
shanchu(daoju2, x, daoju2cnt);
}
} else {
cout << "对方道具:";
for (int i = 1; i <= daoju1cnt; i++) {
cout << i << '.' << daoju_name[daoju1[i]] << ' ';
}
cin >> x;
if (x <= 0 || x > daoju1cnt || daoju1[x] == 7) {
cout << "药效已过,你没有抢到任何道具(不想遵守规则还是咋地)\n";
} else {
cout << "你获得了对方的1个" << daoju_name[daoju1[x]] << ",立即使用:\n";
daoju2[++daoju2cnt] = daoju1[x];
Sleep(750);
x = daoju1[x];
if (x == 1)daoju_fangdajing(2);
else if (x == 2) {
daoju_shouju(2);
xiaodao = 1;
} else if (x == 3)daoju_xiangyan(2);
else if (x == 4)daoju_pijiu(2);
else if (x == 5)daoju_shoukao(2);
else if (x == 6)daoju_nizhuanqi(2);
else if (x == 8)daoju_guoqiyaopin(2);
else if (x == 9)daoju_feibiao(2);
else if (x == 10)daoju_nuojiya(2);
shanchu(daoju1, x, daoju1cnt);
}
}
}
// ============ AI决策函数 ============
string getAIdecision() {
// 创建AI实例
bool bullet_known = (nizhuan == 1);
bool has_handcuff = (shoukao1 == 1);
bool can_use_saw = (xiaodao == 0);
bool can_reverse = true;
GameAI ai(HP1, HP2, HP_UP1, HP_UP2,
daoju1cnt, daoju2cnt, daoju1, daoju2,
shi, kong, add, a,
bullet_known, has_handcuff, can_use_saw, can_reverse,
sf1, sf2, ai_difficulty);
string decision = ai.makeDecision();
// 显示作弊信息(仅调试用)
if (ai_difficulty == 3 && ai.isCheating()) {
// 困难AI作弊时,显示提示(但不要让玩家知道具体信息)
// 这里可以添加一些视觉提示,比如闪烁
if (rand() % 100 < 30) { // 30%概率显示作弊提示
cout << "(AI似乎看穿了什么...)" << endl;
Sleep(500);
}
}
return decision;
}
void play1() { //1P的回合
cl;
if (shoukao1 == 1) {
cout << "1P被手铐控制了,无法行动";
Sleep(3000);
shoukao1 = 0;
huihe = 2;
return ;
}
cout << "1P玩家行动:\n";
cout << "1P身份:" << sf1 << " 2P身份:" << sf2 << endl;
if (mode == 2) cout << "AI难度:" << (ai_difficulty == 1 ? "简单" : ai_difficulty == 2 ? "中等" : "困难") << endl;
cout << "剩余子弹数:实弹";
if (nizhuan == 1)cout << "?";
else cout << shi;
cout << ",空弹";
if (nizhuan == 1)cout << "?";
else cout << kong;
cout << endl;
cout << "1P:";
for (int i = 0; i < HP1; i++)cout << '#';
for (int i = HP1; i < HP_UP1; i++)cout << '\\';
cout << " 2P:";
for (int i = 0; i < HP2; i++)cout << '#';
for (int i = HP2; i < HP_UP2; i++)cout << '\\';
cout << endl;
/* 为什么不调用print?print里有暂停 */
cout << "你拥有的道具:";
for (int i = 1; i <= daoju1cnt; i++) {
cout << daoju_name[daoju1[i]] << ' ';
if (i == 4 && daoju1cnt >= 5)cout << "\n ";
}
cout << "\n对手2P拥有的道具:";
for (int i = 1; i <= daoju2cnt; i++) {
cout << daoju_name[daoju2[i]] << ' ';
if (i == 4 && daoju2cnt >= 5)cout << "\n ";
}
Sleep(2000);
cout << "\n请做出你的选择\n";
cout << "A.向2P开枪\n";
cout << "B.向自己开枪\n";
if (sf1 == "工匠") {
cout << "C.塑造一个道具";
if (gongjiang <= 0) {
cout << "(冷却完毕)\n";
gongjiang = 0;
} else cout << "(还需等待" << gongjiang << "回合)\n";
}
cout << "1.使用放大镜\n";
cout << "2.使用手锯";
if (sf1 == "刺客")cout << "(飞镖)";
cout << endl;
cout << "3.使用香烟\n";
cout << "4.使用啤酒\n";
cout << "5.使用手铐\n";
cout << "6.使用逆转器\n";
cout << "7.使用肾上腺素\n";
cout << "8.使用过期药品\n";
cout << "9.使用飞镖\n";
cout << "10.使用诺基亚\n";
string s;
cin >> s;
char x;
if (s.size() == 1)x = s[0];
else if (s == "10") {
daoju_nuojiya(1);
Sleep(1000);
play1();
}
x = toupper(x);
if (x == 'A' || x == 'B' || (sf1 == "工匠" && x == 'C') || gongjiang == 0 || (x >= '1' && x <= '9')) {
if (x == 'A') {
if (shi + kong >= 2 && sf1 == "特种兵") {
cout << "是否连续发射两发子弹(1,0):";
int z;
cin >> z;
if (z == 1)tezhongbing = true;
}
if (sf1 == "工匠")gongjiang--;
flag1:
if (a[add] == 1) {
HP2 -= 1;
if (xiaodao == 1)HP2 -= 1;
cout << "你打出了1发";
p(4);
cout << "实弹!";
shi--;
if (sf1 == "狂战士" && rand() % 100 <= 60) {
cout << "\n狂战士发动技能,回一滴血!";
HP1++;
HP1 = min(HP1, HP_UP1);
}
print();
} else {
cout << "你打出了1发";
p(4);
cout << "空弹";
kong--;
}
add++;
xiaodao = 0;
Sleep(1000);
cout << endl;
huihe = 2;
if (tezhongbing) {
tezhongbing = false;
Sleep(1000);
goto flag1;
}
system("pause");
return;
} else if (x == 'B') {
if (a[add] == 1) {
HP1--;
if (xiaodao == 1)HP1--;
cout << "你打出了1发";
p(4);
cout << "实弹!";
shi--;
if (sf1 == "狂战士" && rand() % 100 <= 60) {
cout << "\n狂战士发动技能,回一滴血!";
HP1++;
HP1 = min(HP1, HP_UP1);
}
huihe = 2;
print();
if (sf1 == "工匠")gongjiang--;
} else {
cout << "你打出了1发";
p(4);
cout << "空弹";
kong--;
}
add++;
xiaodao = 0;
Sleep(1000);
cout << endl;
system("pause");
} else if (x == 'C') {
if (gongjiang <= 0) {
gongjiang = 2;
cout << "塑造一个道具(同上):";
int y;
cin >> y;
while (y < 1 || y > 10 || y == 5 || y == 7) {
cout << "重新输入:";
cin >> y;
}
daoju1[++daoju1cnt] = y;
if (y == 1)daoju_fangdajing(1);
else if (y == 2) {
daoju_shouju(1);
xiaodao = 1;
} else if (y == 3)daoju_xiangyan(1);
else if (y == 4) {
daoju_pijiu(1);
pd();
} else if (y == 6)daoju_nizhuanqi(1);
else if (y == 8)daoju_guoqiyaopin(1);
else if (y == 9)daoju_feibiao(1);
else if (y == 10)daoju_nuojiya(1);
Sleep(1000);
play1();
} else {
cout << "再等" << gongjiang << "回合!\n";
Sleep(1000);
play1();
}
} else {
x -= 48;
bool flag = false;
for (int i = 1; i <= daoju1cnt; i++) {
if (daoju1[i] == x) {
flag = true;
}
}
if (flag == false) {
cout << "道具" << daoju_name[x] << "不够!";
Sleep(1500);
play1();
} else if (x == 1)daoju_fangdajing(1);
else if (x == 2) {
if (sf1 != "刺客") {
daoju_shouju(1);
xiaodao = 1;
} else {
shanchu(daoju1, 2, daoju1cnt);
daoju1[++daoju1cnt] = 9;
daoju_feibiao(1);
}
} else if (x == 3)daoju_xiangyan(1);
else if (x == 4) {
daoju_pijiu(1);
pd();
} else if (x == 5)daoju_shoukao(1);
else if (x == 6)daoju_nizhuanqi(1);
else if (x == 7)daoju_shenshangxiansu(1);
else if (x == 8)daoju_guoqiyaopin(1);
else if (x == 9)daoju_feibiao(1);
else if (x == 10)daoju_nuojiya(1);
Sleep(1000);
play1();
}
} else if (s != "10") {
cout << "输入错误!";
Sleep(1500);
play1();
} else play1();
}
void play2() { //2P的回合
cl;
if (shoukao2 == 1) {
cout << "2P被手铐控制了,无法行动";
Sleep(3000);
shoukao2 = 0;
huihe = 1;
return ;
}
if (mode == 2) {
cout << "AI正在思考";
p(3);
cout << "\n";
}
cout << "2P玩家行动:\n";
cout << "1P身份:" << sf1 << " 2P身份:" << sf2 << endl;
if (mode == 2 && ai_difficulty == 3) {
cout << "【困难AI - 可能作弊】\n";
}
cout << "剩余子弹数:实弹";
if (nizhuan == 1)cout << "?";
else cout << shi;
cout << ",空弹";
if (nizhuan == 1)cout << "?";
else cout << kong;
cout << endl;
cout << "1P:";
for (int i = 0; i < HP1; i++)cout << '#';
for (int i = HP1; i < HP_UP1; i++)cout << '\\';
cout << " 2P:";
for (int i = 0; i < HP2; i++)cout << '#';
for (int i = HP2; i < HP_UP2; i++)cout << '\\';
cout << endl;
/* 为什么不调用print?print里有暂停 */
cout << "你拥有的道具:";
for (int i = 1; i <= daoju2cnt; i++) {
cout << daoju_name[daoju2[i]] << ' ';
if (i == 4 && daoju2cnt >= 5)cout << "\n ";
}
cout << "\n对手1P拥有的道具:";
for (int i = 1; i <= daoju1cnt; i++) {
cout << daoju_name[daoju1[i]] << ' ';
if (i == 4 && daoju1cnt >= 5)cout << "\n ";
}
Sleep(2000);
string s;
if (mode == 2) {
// 单人模式:AI自动决策
s = getAIdecision();
cout << "\nAI选择了: " << s << endl;
Sleep(1500);
} else {
// 双人模式:玩家输入
cout << "\n请做出你的选择\n";
cout << "A.向1P开枪\n";
cout << "B.向自己开枪\n";
if (sf2 == "工匠") {
cout << "C.塑造一个道具";
if (gongjiang <= 0) {
cout << "(冷却完毕)\n";
gongjiang = 0;
} else cout << "(还需等待" << gongjiang << "回合)\n";
}
cout << "1.使用放大镜\n";
cout << "2.使用手锯";
if (sf2 == "刺客")cout << "(飞镖)";
cout << endl;
cout << "3.使用香烟\n";
cout << "4.使用啤酒\n";
cout << "5.使用手铐\n";
cout << "6.使用逆转器\n";
cout << "7.使用肾上腺素\n";
cout << "8.使用过期药品\n";
cout << "9.使用飞镖\n";
cout << "10.使用诺基亚\n";
cin >> s;
}
char x;
if (s.size() == 1)x = s[0];
else if (s == "10") {
daoju_nuojiya(2);
Sleep(1000);
play2();
return;
} else if (s == "A1") {
// 处理AI的双发射击
cout << "AI选择连续发射两发子弹!\n";
tezhongbing = true;
x = 'A';
}
x = toupper(x);
if (x == 'A' || x == 'B' || x == 'C' || (x >= '1' && x <= '9')) {
if (x == 'A') {
if (sf2 == "工匠")gongjiang--;
if (shi + kong >= 2 && sf2 == "特种兵" && !tezhongbing && mode == 1) {
cout << "是否连续发射两发子弹(1,0):";
int z;
cin >> z;
if (z == 1)tezhongbing = true;
}
flag2:
if (a[add] == 1) {
HP1 -= 1;
if (xiaodao == 1)HP1 -= 1;
cout << "你打出了1发";
p(4);
cout << "实弹!";
shi--;
if (sf2 == "狂战士" && rand() % 100 <= 60) {
cout << "\n狂战士发动技能,回一滴血!";
HP2++;
HP2 = min(HP2, HP_UP2);
}
print();
} else {
cout << "你打出了1发";
p(4);
cout << "空弹";
kong--;
}
add++;
xiaodao = 0;
Sleep(1000);
cout << endl;
huihe = 1;
if (tezhongbing) {
tezhongbing = false;
Sleep(1000);
goto flag2;
}
system("pause");
return ;
} else if (x == 'B') {
if (a[add] == 1) {
if (sf2 == "工匠")gongjiang--;
HP2--;
if (xiaodao == 1)HP2--;
cout << "你打出了1发";
p(4);
cout << "实弹!";
shi--;
if (sf2 == "狂战士" && rand() % 100 <= 60) {
cout << "\n狂战士发动技能,回一滴血!";
HP2++;
HP2 = min(HP2, HP_UP2);
}
huihe = 2;
print();
} else {
cout << "你打出了1发";
p(4);
cout << "空弹";
kong--;
}
add++;
xiaodao = 0;
Sleep(1000);
cout << endl;
system("pause");
} else if (x == 'C') {
if (gongjiang <= 0) {
gongjiang = 2;
int y;
if (mode == 2) {
// AI自动选择最佳道具
double best_score = -100.0;
int best_item = 1;
bool bullet_known = (nizhuan == 1);
bool can_use_saw = (xiaodao == 0);
// 评估每个可创造的道具
for (int item = 1; item <= 10; item++) {
if (item == 5 || item == 7) continue;
double score = 0;
// 简化的评估逻辑
switch (item) {
case 1: // 放大镜
if (!bullet_known) score = 8.0;
break;
case 2: // 手锯
if (can_use_saw && shi > 0) score = 6.0;
break;
case 3: // 香烟
if (HP2 < HP_UP2) score = 7.0;
break;
case 4: // 啤酒
if (shi > kong) score = 6.0;
break;
case 6: // 逆转器
if (bullet_known && a[add] == 1) score = 9.0;
else if (!bullet_known && shi > kong) score = 7.0;
break;
case 8: // 过期药品
if (HP2 <= HP_UP2 - 2) score = 6.0;
break;
case 9: // 飞镖
score = 5.0;
break;
case 10: // 诺基亚
if (shi + kong > 2) score = 5.0;
break;
}
if (score > best_score) {
best_score = score;
best_item = item;
}
}
y = best_item;
cout << "AI塑造了道具:" << daoju_name[y] << endl;
} else {
cout << "塑造一个道具(同上):";
cin >> y;
while (y < 1 || y > 10 || y == 5 || y == 7) {
cout << "重新输入:";
cin >> y;
}
}
daoju2[++daoju2cnt] = y;
if (y == 1)daoju_fangdajing(2);
else if (y == 2) {
daoju_shouju(2);
xiaodao = 1;
} else if (y == 3)daoju_xiangyan(2);
else if (y == 4) {
daoju_pijiu(2);
pd();
} else if (y == 6)daoju_nizhuanqi(2);
else if (y == 8)daoju_guoqiyaopin(2);
else if (y == 9)daoju_feibiao(2);
else if (y == 10)daoju_nuojiya(2);
Sleep(1000);
play2();
} else {
cout << "再等" << gongjiang << "回合!\n";
Sleep(1000);
play2();
}
} else {
x -= 48;
bool flag = false;
for (int i = 1; i <= daoju2cnt; i++) {
if (daoju2[i] == x) {
flag = true;
}
}
if (flag == false) {
cout << "道具" << daoju_name[x] << "不够!";
Sleep(1500);
play2();
} else if (x == 1)daoju_fangdajing(2);
else if (x == 2) {
if (sf2 != "刺客") {
daoju_shouju(2);
xiaodao = 1;
} else {
shanchu(daoju2, 2, daoju2cnt);
daoju2[++daoju2cnt] = 9;
daoju_feibiao(2);
}
} else if (x == 3)daoju_xiangyan(2);
else if (x == 4) {
daoju_pijiu(2);
pd();
} else if (x == 5)daoju_shoukao(2);
else if (x == 6)daoju_nizhuanqi(2);
else if (x == 7)daoju_shenshangxiansu(2);
else if (x == 8)daoju_guoqiyaopin(2);
else if (x == 9)daoju_feibiao(2);
else if (x == 10)daoju_nuojiya(2);
Sleep(1000);
play2();
}
} else if (s != "10") {
cout << "输入错误!";
Sleep(1500);
play2();
} else play2();
}
void title() {
char ch;
int sec = 120000;
cout << "\n\n\n\n\t\t恶魔轮盘赌 Buckshot Roulette\n";
cout << "\t\t 版本: 2.1 (强化AI)\n\n";
cout << "\t\t 按下A开始游戏!\n\n";
while (true) {
if (_kbhit()) {
ch = toupper(_getch());
if (ch == 'A') {
return;
}
}
sec -= 1;
if (sec <= 0) {
sec = 120000;
system("color cf");
Sleep(100);
system("color 0f");
Sleep(100);
system("color cf");
Sleep(100);
system("color 0f");
}
}
}
int main() { //主函数
system("title 恶魔轮盘赌 - 强化AI版本");
srand((unsigned int)time(0));
huihe = rand() % 2 + 1; //随机先手
title();
in_game();
Sleep(750);
cl;
cout << "游戏即将开始";
p(7);
cl;
cout << "是否启用身份玩法(1,0)?\n";
char input = _getch();
while (input < '0' || input > '1')input = _getch();
if (input == '1') {
XuanShenFen(1);
if (mode == 2) {
// 单人模式:为AI选择身份(根据难度)
int ai_role_choice;
if (ai_difficulty == 3) {
// 困难AI选择强力身份
int strong_roles[] = {6, 7, 8, 9, 2}; // 刺客, 特种兵, 狂战士, 工匠, 医生
ai_role_choice = strong_roles[rand() % 5];
} else if (ai_difficulty == 2) {
// 中等AI选择平衡身份
int medium_roles[] = {1, 3, 4, 5, 7}; // 大亨, 拾荒者, 壮汉, 酒鬼, 特种兵
ai_role_choice = medium_roles[rand() % 5];
} else {
// 简单AI选择基础身份
int simple_roles[] = {0, 4, 5, 3}; // 无, 壮汉, 酒鬼, 拾荒者
ai_role_choice = simple_roles[rand() % 4];
}
string sf;
if (ai_role_choice == 0)sf = "无";
else if (ai_role_choice == 1)sf = "大亨";
else if (ai_role_choice == 2)sf = "医生";
else if (ai_role_choice == 3)sf = "拾荒者";
else if (ai_role_choice == 4)sf = "壮汉";
else if (ai_role_choice == 5)sf = "酒鬼";
else if (ai_role_choice == 6)sf = "刺客";
else if (ai_role_choice == 7) sf = "特种兵";
else if (ai_role_choice == 8)sf = "狂战士";
else sf = "工匠";
sf2 = sf;
cout << "AI选择了身份: " << sf2 << endl;
// 应用身份效果
if (sf2 == "壮汉") {
HP2++;
HP_UP2 += 3;
}
if (sf2 == "酒鬼") {
HP_UP2++;
}
Sleep(2000);
} else {
XuanShenFen(2);
}
} else {
sf1 = sf2 = "无";
}
cl;
huihe_start();
while (true) {
if (huihe == 1)play1();
pd();
xiaodao = 0, nizhuan = 0;
if (huihe == 2)play2();
pd();
xiaodao = 0;
nizhuan = 0;
}
return 0;
}