#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
// 算手牌点数(自动处理A的1/11)
int calcScore(int hand[], int n) {
int sum = 0, aceCount = 0;
for(int i=0; i<n; i++) {
if(hand[i] == 1) { sum += 11; aceCount++; } // A先当11
else sum += min(hand[i], ); // ①J/Q/K算几点?
}
while(sum > && aceCount > 0) { // ②超过几点要把A改小?
sum -= ; // ③A从11改成1,减多少?
aceCount--;
}
return sum;
}
int main() {
srand(time(0));
int pHand[20], dHand[20];
int pCount = 0, dCount = 0;
// 初始发牌:玩家2张,庄家2张
pHand[pCount++] = rand()%13+1;
dHand[dCount++] = rand()%13+1;
pHand[pCount++] = rand()%13+1;
dHand[dCount++] = rand()%13+1;
cout << "庄家明牌:" << dHand[0] << endl;
int pScore = calcScore(pHand, pCount);
// 玩家回合
char choice;
while(pScore <= ) { // ④没爆牌才能继续
cout << "你的点数:" << pScore << ",要牌吗?(h=要 s=停):";
cin >> choice;
if(choice == 's' || choice == 'S') break;
pHand[pCount++] = rand()%+1; // ⑤发一张牌(1~13)
pScore = calcScore(pHand, pCount);
}
if(pScore > 21) { cout << "💥 你爆牌了!" << endl; return 0; }
// 庄家回合:小于17必须要牌
int dScore = calcScore(dHand, dCount);
while(dScore < ) { // ⑥庄家小于几点必须要牌?
dHand[dCount++] = rand()%13+1;
dScore = calcScore(dHand, dCount);
}
cout << "庄家点数:" << dScore << endl;
// 判胜负
if(dScore > 21) cout << "🎉 庄家爆牌,你赢了!" << endl;
else if(pScore > dScore) cout << "🎉 你赢了!" << endl;
else if(pScore < dScore) cout << "😢 你输了!" << endl;
else cout << "🤝 平局!" << endl;
return 0;
}