//投注类型定义
enum enBetEnum
{
//大
eTenThousandBig = 1, // 万位
eThousandBig = 2, // 千位
eHundredBig = 3, // 百位
eTenBig = 4, // 十位
eOneBig = 5, // 个位
//小
eTenThousandSmall = 6, // 万位
eThousandSmall = 7, // 千位
eHundredSmall = 8, // 百位
eTenSmall = 9, // 十位
eOneSmall = 10, // 个位
//单
eTenThousandSingle = 11, // 万位
eThousandSingle = 12, // 千位
eHundredSingle = 13, // 百位
eTenSingle = 14, // 十位
eOneSingle = 15, // 个位
//双
eTenThousandDouble = 16, // 万位
eThousandDouble = 17, // 千位
eHundredDouble = 18, // 百位
eTenDouble = 19, // 十位
eOneDouble = 20, // 个位
//豹子
eFront = 21, // 前三豹子
eMiddle = 22, // 中三豹子
eBack = 23, // 后三豹子
eMaxType,
};
int CTableFrameSink::CalculateScoreLogic(int nResult, int type, DWORD dwCount)
{
int nValue = 0;
type = ceil((float)type / 5);
switch (type) {
case 1: {
if (5 <= nResult) {
nValue = dwCount;
}
break;
}
case 2: {
if (nResult < 5) {
nValue = dwCount;
}
break;
}
case 3: {
if (nResult % 2 == 1) {
nValue = dwCount;
}
break;
}
case 4: {
if (nResult % 2 == 0) {
nValue = dwCount;
}
break;
}
}
return nValue;
}
//计算得分
bool CTableFrameSink::CalculateScore()
{
int TenThousandBig = m_dwResult / 10000;
int Thousand = m_dwResult % 10000 / 1000;
int Hundred = m_dwResult % 1000 / 100;
int Ten = m_dwResult % 100 / 10;
int One = m_dwResult % 10;
int Front = m_dwResult / 100;
int Middle = m_dwResult % 10000 / 10;
int Back = m_dwResult % 1000;
int nAllResult = 0;
//计算总营收
for (size_t i = 0; i < eBack; i++)
{
int type = i + 1;
int nValue = m_BetMgr.m_Statistical[i];
nAllResult -= nValue; // 下注扣的钱
DWORD dwCount = nValue * MULTIPLE_XIAN;
if (dwCount <= 0)
continue;
//是否中大小单双
if (type % 5 == 1)
nAllResult += CalculateScoreLogic(TenThousandBig, type, dwCount);
else if (type % 5 == 2)
nAllResult += CalculateScoreLogic(Thousand, type, dwCount);
else if (type % 5 == 3)
nAllResult += CalculateScoreLogic(Hundred, type, dwCount);
else if (type % 5 == 4)
nAllResult += CalculateScoreLogic(Ten, type, dwCount);
else if (type % 5 == 0)
nAllResult += CalculateScoreLogic(One, type, dwCount);
dwCount = nValue * MULTIPLE_PING;
//是否中豹子
if ((TenThousandBig == Thousand && TenThousandBig == Hundred && type == eFront) ||
(Thousand == Hundred && Thousand == Ten && type == eMiddle) ||
(Hundred == Ten && Hundred == One && type == eBack))
{
nAllResult += dwCount;
}
}
tagRecord *Record = new tagRecord();
Record->dwResult = m_dwResult;
CopyMemory(Record->szId, m_szKaiJiangNumber, sizeof(m_szKaiJiangNumber));
m_BetMgr.m_vecRecordData.push_back(Record);
int nMy = 0; //自己的总营收
for (WORD i = 0; i < GAME_PLAYER; ++i)
//for(std::map<DWORD, tagBetList*>::iterator it = m_BetMgr.m_BetListMgr.begin(); it != m_BetMgr.m_BetListMgr.end(); ++it)
{
IServerUserItem * pIServerUserItem = m_pITableFrame->GetTableUserItem(i);
if (NULL == pIServerUserItem || pIServerUserItem->IsAndroidUser())
continue;
tagBetList* pBetList = m_BetMgr.GetUserBet(pIServerUserItem->GetUserID());
//开奖结果
tagResultInfo ResultInfo;
ResultInfo.Record.dwResult = m_dwResult;
ResultInfo.nOther = nAllResult;
CopyMemory(ResultInfo.Record.szId, m_szKaiJiangNumber, sizeof(m_szKaiJiangNumber));
for (size_t i = 0; i < eBack; i++)
{
if (NULL == pBetList)
break;
int type = i + 1;
int nResult = 0; // 自己的营收
nResult -= pBetList->BetList[i]; // 下注扣的钱
DWORD dwCount = pBetList->BetList[i] * MULTIPLE_XIAN;
if (dwCount <= 0)
continue;
//是否中大小单双
if(type % 5 == 1)
nResult += CalculateScoreLogic(TenThousandBig, type, dwCount);
else if (type % 5 == 2)
nResult += CalculateScoreLogic(Thousand, type, dwCount);
else if (type % 5 == 3)
nResult += CalculateScoreLogic(Hundred, type, dwCount);
else if (type % 5 == 4)
nResult += CalculateScoreLogic(Ten, type, dwCount);
else if (type % 5 == 0)
nResult += CalculateScoreLogic(One, type, dwCount);
dwCount = pBetList->BetList[i] * MULTIPLE_PING;
//是否中豹子
if ((TenThousandBig == Thousand && TenThousandBig == Hundred && type == eFront) ||
(Thousand == Hundred && Thousand == Ten && type == eMiddle) ||
(Hundred == Ten && Hundred == One && type == eBack) )
{
nResult += dwCount;
}
ResultInfo.nResult[i] = nResult;
nMy += nResult;
}
int nStockScore = nMy; //中奖扣税
if (0 < nMy) {
nStockScore = nMy*(1000 - m_cbRevenue) / 1000;
OnChangeMoney(pBetList->dwUserId, nStockScore, nMy);
}
ResultInfo.nMy = nStockScore;
// 在线的通知下
if (NULL != pIServerUserItem) {
m_pITableFrame->SendUserItemData(pIServerUserItem, SUB_S_FFC_RESULT_BET, &ResultInfo, sizeof(tagResultInfo));
}
}
m_BetMgr.Clean();
return true;
}
//用到的容器和结构体
//押注列表
struct tagBetList {
tagBetList() { ZeroMemory(this, sizeof(tagBetList)); }
DWORD dwUserId; //用户id
DWORD BetList[eBack]; //押注
};
std::map<DWORD, tagBetList*> m_BetListMgr;
DWORD m_Statistical[eBack]; //统计押注总数
代码不全,是核心代码,提供思维