zoukankan      html  css  js  c++  java
  • [手游项目4]大小单双,开奖算法

    //投注类型定义
    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];		     //统计押注总数
    
    
    
    	

    代码不全,是核心代码,提供思维

  • 相关阅读:
    Java/android下哈希sha1和MD5的实现
    ANDROID SOCKET 开发
    UML补充
    TCP协议中的三次握手和四次挥手(转)
    uva 658 最短路
    uva 11280 最短路
    uva 10246 最短路
    uva 11747,kruskal 并查集
    uva 544 dijkstra
    uva 1395 瓶颈树
  • 原文地址:https://www.cnblogs.com/byfei/p/14104133.html
Copyright © 2011-2022 走看看