# 1.随手写了一个做牌算法，扑克 麻将 跑胡子 等都可以做牌

1.随手写了一个测试时候做牌

{ 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7 },

https://blog.csdn.net/qq_33237477

#include "stdafx.h"
#include "iostream"
#include "string"
#include "vector"
#include <algorithm>//shuffle头文件
#include "random"//random_device 、mt19937 头文件
using namespace std;
//typedef unsigned char     int;

int main()
{
std::vector<int> vctMuBiaoCard =
{
1,  2,  3,  4,  5,  6,  7,  8,  9,  ///万
11, 12, 13, 14, 15, 16, 17, 18, 19,  ///条
21, 22, 23, 24, 25, 26, 27, 28, 29,  ///筒
31, 32, 33, 34, 35, 36, 37,  ///东南西北中发白

1,  2,  3,  4,  5,  6,  7,  8,  9,  ///万
11, 12, 13, 14, 15, 16, 17, 18, 19,  ///条
21, 22, 23, 24, 25, 26, 27, 28, 29,  ///筒
31, 32, 33, 34, 35, 36, 37,  ///东南西北中发白

1,  2,  3,  4,  5,  6,  7,  8,  9,  ///万
11, 12, 13, 14, 15, 16, 17, 18, 19,  ///条
21, 22, 23, 24, 25, 26, 27, 28, 29,  ///筒
31, 32, 33, 34, 35, 36, 37,  ///东南西北中发白

1,  2,  3,  4,  5,  6,  7,  8,  9,  ///万
11, 12, 13, 14, 15, 16, 17, 18, 19,  ///条
21, 22, 23, 24, 25, 26, 27, 28, 29,  ///筒
31, 32, 33, 34, 35, 36, 37,  ///东南西北中发白
};
//1.创造手牌
int iWinIndex = 0;//庄家座位
std::vector<int> vct;//牌墩
std::vector<int> vctTmp = vctMuBiaoCard;//临时牌墩
std::vector<std::vector<int >> //所有手牌
vctMax = {
{ 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7 },
{},
{},
{}
//{01, 01, 01, 01},
//{02, 02, 02, 02},
//{03, 03, 03, 03},
//{04, 04, 04, 04}
};

//2.删除掉牌墩内创造的手牌
int n = 4;//四人玩法
for (int i = 0; i < n; i++)
{
for (int j = 0; j < vctMax[i].size(); j++)
{
for (int k = 0; k < vctTmp.size(); k++)
{
if (vctMax[i][j] == vctTmp[k])
{
vctTmp[k] = 0;
break;
}
}
}
}
for (auto t : vctTmp)
{
if (t != 0)
vct.push_back(t);
}

//3.打乱牌墩剩余的牌
std::random_device rd;
std::mt19937 gen(rd());
std::shuffle(vct.begin(), vct.end(), gen);

//4.将牌墩里面的牌补充到手牌
for (int i = 0; i < n; i++)
{
if (i == iWinIndex)
{
int n = vctMax[i].size();
vctMax[i].insert(vctMax[i].end(), vct.begin(), vct.begin() + (14 - n));
vct.erase(vct.begin(), vct.begin() + (14 - n));
}
else
{
int m = vctMax[i].size();
vctMax[i].insert(vctMax[i].end(), vct.begin(), vct.begin() + (13 - m));
vct.erase(vct.begin(), vct.begin() + (13 - m));
}
}
//5.将手牌所有牌放入牌墩
for (int i = (n - 1); i >= 0; i--)
{
vct.insert(vct.begin(), vctMax[i].begin(), vctMax[i].end());
}
vctMuBiaoCard.clear();
vctMuBiaoCard.insert(vctMuBiaoCard.begin(), vct.begin(), vct.end());

//6.显示一下最后做好的牌是否正确
int iNum = 0;
for (auto t : vctMuBiaoCard)
{
cout << t << " | ";
iNum++;
if (iNum == 14)
{
cout << endl;
iNum %= 14;
}
}
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120