C++ 桥牌算分小程序

#include <iostream>
using namespace std;

// 定约数据结构
struct Contract {
    bool isAllPass; // 是否为allpass
    bool isVul;     // 局况
    int level;      // 定约阶数 1-7
    int suit;       // 花色  C=1  D=2  H=3  S=4  NT=5
    int dbl;        // 加倍情况  pass=0   double=1   redouble=2
    int result;     // 结果  make=0  范围[-13,+7]
};

// 结果合法性检测
bool isLegalResult(Contract c) {
    if (c.level < 1 || c.level > 7) return false;
    if (c.suit < 1 || c.suit > 5) return false;
    if (c.dbl < 0 || c.dbl > 2) return false;
    if (c.level + 6 + c.result > 13 || c.level + 6 + c.result < 0) return false;
    return true;
}

int getScore(Contract c) {
    if (!isLegalResult(c)) return -1;
    int score = 0;
    if (c.isAllPass) {
        return 0;
    }
    // 定约打成
    if (c.result >= 0) { 
        int singleTrick = c.suit < 3 ? 20 : 30; // 低花每墩20,高花每墩30
        int baseScore = c.level * singleTrick;
        if (c.suit == 5) {
            baseScore += 10; // 无将额外+10
        }
        if (c.dbl == 1) {
            baseScore *= 2; // 加倍定约基本分*2
        }
        if (c.dbl == 2) {
            baseScore *= 4; // 再加倍定约基本分*4
        }
        // 未成局奖50,成局奖300/500
        int bonusScore = baseScore < 100 ? 50 : (c.isVul ? 500 : 300);
        if (c.dbl == 1) {
            bonusScore += 50; // 完成加倍定约额外奖励50分
        }
        if (c.dbl == 2) {
            bonusScore += 100; // 完成再加倍定约额外奖励100分
        }
        if (c.level == 6) {
            bonusScore += (c.isVul ? 750 : 500); // 小满贯额外奖分
        }
        if (c.level == 7) {
            bonusScore += (c.isVul ? 1500 : 1000); // 大满贯额外奖分
        }
        int exceedScore = c.result * singleTrick; // 超墩分
        if (c.dbl == 1) {
            exceedScore = c.result * (c.isVul ? 200 : 100); // 加倍定约每超一墩 100/200
        }
        if (c.dbl == 2) {
            exceedScore = c.result * (c.isVul ? 400 : 200); // 再加倍定约每超一墩 200/400
        }
        return baseScore + bonusScore + exceedScore;
    }

    // 定约打宕
    if (c.dbl > 0) {
        int res;
        if (!c.isVul) {
            // 加倍定约打宕罚分 无局 100 300 500 800 1100 1400 ...
            //                 有局 200 500 800 1100 1400 ...
            switch (c.result) {
            case -1:
                score = -100;
                break;
            case -2:
                score = -300;
                break;
            case -3:
                score = -500;
                break;
            default:
                score = -500;
                res = -3;
                while (res > c.result) {
                    score -= 300;
                    res--;
                }
                break;
            }
        }
        else {
            score = -200;
            res = -1;
            while (res > c.result) {
                score -= 300;
                res--;
            }
        }
        // 再加倍定约打宕罚分 = 加倍罚分*2
        if (c.dbl == 2) {
            score *= 2;
        }
        return score;
    }
    // 未加倍定约打宕,每墩罚50/100
    int punish = c.isVul ? 100 : 50;
    return punish * c.result;
}

int main() {
    Contract c1;
    c1.isAllPass = false;
    c1.isVul = false;
    c1.dbl = 1;
    c1.level = 3;
    c1.suit = 4;
    c1.result = 0;
    cout << "The score of 3Sx= (non-vul) is " << getScore(c1) << endl;
    Contract c2;
    c2.isAllPass = false;
    c2.isVul = true;
    c2.dbl = 2;
    c2.level = 1;
    c2.suit = 5;
    c2.result = 6;
    cout << "The score of 1NTxx+6 (vul) is " << getScore(c2) << endl;
    Contract c3;
    c3.isAllPass = false;
    c3.isVul = true;
    c3.dbl = 2;
    c3.level = 7;
    c3.suit = 5;
    c3.result = -13;
    cout << "The score of 7NTxx-13 (vul) is " << getScore(c3) << endl;
    Contract c4;
    c4.isAllPass = false;
    c4.isVul = true;
    c4.dbl = 0;
    c4.level = 1;
    c4.suit = 1;
    c4.result = 0;
    cout << "The score of 1C= (vul) is " << getScore(c4) << endl;
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值