免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7492 | 回复: 5
打印 上一主题 下一主题

麻将游戏开发 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-09-09 14:00 |只看该作者 |倒序浏览
麻将游戏开发
最近要学习软件工程,学习之余就去网络上玩麻将,呵呵~~~

突发奇想要自己开发一个,边练手,边娱乐,何乐而不为呢

麻将游戏要用到很多模块,慢慢补来

也望各位大大多留下意见,先谢过


麻将网络游戏项目

  项目分为服务器端和客户端两大模块
  服务器端功能:提供游戏玩家注册、登录、积分、聊天服务
                为游戏提供桌号、洗牌、算番
  客户端:游戏界面,判断是否吃、碰、杠、听牌及胡牌

数据结构:麻将的数字表示
用数字0~35表示麻将牌,其中0~8代表一万到九万,9~17代表一条到九条,18~26代表一筒到九筒,27代表东风,28代表南风,29代表西风,30代表北风,31代表中,32代表发,33代表白,34代表春夏秋冬,35代表梅竹兰菊

见下表

============================================
0    1     2   3    4    5    6    7    8
============================================
一万 二万 三万 四万 五万 六万 七万 八万 九万
============================================
9    10   11   12   13   14   15   16   17
============================================
一条 二条 三条 四条 五条 六条 七条 八条 九条
============================================
18    19   20   21   22   23   24   25   26
============================================
一筒 二筒 三筒 四筒 五筒 六筒 七筒 八筒 九筒
============================================
27    28   29   30   31   32   33   34   35
============================================
东风 南风 西风 北风 红中 发财 白板  花1  花2
============================================

每个数字出现四次,代表四张牌,洗牌时采用随机算法提供牌墙

牌墙数据结构:

  圈风:
     quanfeng:(27,28,29,30)
  数组paiqiang[0..143],其中
paiqiang[0]~paiqiang[35]为东(庄)家
paiqiang[36]~paiqiang[71]为南家
paiqiang[72]~paiqiang[107]为西家
paiqiang[108]~paiqiang[143]为北家

玩家数据结构:
玩家wanjia:{
     门风:
        menfeng:(27,28,29,30)
     杠:
        gangpai{
        pai:0~33
        mingAn:0|1
              }
       gangarr[0..3]:gangpai(最多四个杠,数字表示杠的牌,结构体第二位的0表示明杠,1表示暗杠)
     碰:pengpai[0..3]:0~33最多四个碰牌
     吃:
        chipai{
           chimin0~6,9~15,18~24)
           chimax2~8,11~17,20~26)
              }吃牌中只用记录顺子的收尾即可
        chiarr[0..3]:chipai(最多有三个吃牌)
      花牌:0~8(初始化为0,每摸到一个花牌加一)
      手牌:paiInHand{
               pai[0..13],
               num:1,4,7,10,13
                     }
      要牌pai[13]:除庄家外,初始化为-1,待摸牌上手(吃牌,碰牌,杠牌摸牌,任何一家打牌)后,将对应的牌值赋值给要牌,要牌为玩家需要处理牌的标志(当非负时),当玩家处理完牌后,将牌整理后,将要牌置-1

}
当要牌置位(非负)时,要对手牌进行胡牌判断:
由于手牌已经除掉了大量的碰杠吃等情况,简化的胡牌算法:
先对pai数组加上要牌一起排序;
然后用递归算法判断是否胡牌;
最后判断是否为7对,十三么,全不靠牌型:(注,这些牌型一般不容易胡,故番数也不小哦,^_^)

  1. if(num==13)
  2. {
  3.   if(pai[0]==pai[1]&pai[2]==pai[3]&pai[4]==pai[5]&pai[6]==pai[7]&pai[8]==pai[9]&pai[10]==pai[11]&pai[12]==pai[13])
  4.     return 1;//七对

  5.   dblpos=-1;  //记录数组中对牌的位置;-1为没有对牌
  6.   dblnum=0;//对的个数(如果超过两个对(可能是一个刻子)则不能胡十三么,全不靠牌型)
  7.   for(i=0;i<14;i++}
  8.    {
  9.      if(pai[i]==pai[i+1])
  10.        {
  11.            dblpos=i;
  12.            dblnum++;
  13.        }
  14.       if(dblnum>;1) break;
  15.    }


  16.    if(dblnum==1) //可能为十三么
  17.     {
  18.        tirteen=1;
  19.        for(i=0;i<14;i++)
  20.        {
  21.           if(pai[i]>;0&[pai]<8)
  22.             {
  23.                 tirteen=0;
  24.                 break;
  25.             }
  26.           else if(pai[i]>;9&[pai]<17)
  27.             {
  28.                 tirteen=0;
  29.                 break;
  30.             }
  31.            else if(pai[i]>;18&[pai]<26)
  32.             {
  33.                 tirteen=0;
  34.                 break;
  35.             }//如果任何一张牌为非么九和非字牌,则不能胡十三么,
  36.            if(tirteen) return 1;//如果全部是么九和字牌,加上进入该段程序的牌只有一个对,则十三么胡牌
  37.        }
  38.     }
  39.     else//可能为全不靠
  40.     {
  41.       nowordpos=14;//记录下最后一个不是字牌的位置
  42.       for (i=13;i>;=0;i--)
  43.        {
  44.           if(pai[i]<=26)
  45.              {
  46.               nowordpos=i;
  47.               break;
  48.              }
  49.        }
  50.       if(nowordpos<=8)//如果非字牌有9个以上,肯定不能胡全不靠
  51.      {
  52.       istirteen=1;
  53.       for(i=0;i<=nowordpos;i++)
  54.         {
  55.            if(pai[i+1]-pai[i]<3&&pai[i+1]/9==pai[i]/9)//如果存在同一花色里两张可以吃别人的牌,则不能胡全不靠
  56.            {
  57.               istirteen=0;
  58.               break;
  59.             }
  60.         }
  61.       if(istirteen)
  62.       {
  63.        for(i=0;i<nowordpos;i++)
  64.       {
  65.            for(j=i+1;j<=nowordpos;j++)
  66.               if(pai[i]==pai[j] mod 9)
  67.                {
  68.                   istirteen=0;
  69.                   break;
  70.                }
  71.             if(istirteen==0) break;
  72.         }
  73.      }
  74.     }
  75.     }
  76. }

复制代码

论坛徽章:
0
2 [报告]
发表于 2005-09-09 14:01 |只看该作者

麻将游戏开发


  1. /***************************************************************
  2. * 文件名:hu.cpp *
  3. * *
  4. * 功 能:演示一个简洁明了的递归函数——判断[麻将]的和牌。 *
  5. * *
  6. * 说 明:1. 此函数不判断七对和十三幺,读者不难自行判断; *
  7. *     同时由于麻将的规则各不相同,也请读者自己添加和修改。*
  8. * *
  9. *     2. 其他与麻将类似的游戏,如[字牌](又称跑胡子、 *
  10. *     二七十)等牌类游戏,也可采用类似的判断函数。 *
  11. * *
  12. * 环 境: VC 6.0, 但符合ANSI C标准,随便移植 ^_^ *
  13. * *
  14. * 作 者:shyworm(怕怕虫) *
  15. * E_Mail: shyworm@sina.com *
  16. ***************************************************************/
  17. #include <stdio.h>;

  18. int Hu(int PAI[38]);
  19. int Remain(int PAI[38]);

  20. int main()
  21. {
  22. // 把一副牌放在下面的数组里,可以任意填入数字来测试函数正确与否。
  23. // 为了方便,PAI[0],PAI[10],PAI[20],PAI[30]都弃之不用,并且必须
  24. // 置为0,千万注意!
  25. int PAI[38] = { 0,
  26. 1,1,1,0,1,1,1,0,0, // PAI[ 1- 9] 壹万~玖万的个数
  27. 0,
  28. 0,0,0,0,0,3,0,0,0, // PAI[11-19] 壹铜~玖铜的个数
  29. 0,
  30. 0,0,0,0,0,0,0,0,0, // PAI[21-29] 壹条~玖条的个数
  31. 0,
  32. 0,1,1,1,0,0,0 // PAI[31-37] 东南西北中发白的个数
  33. };

  34. // 请务必先排除“七对” 和“十三幺”,由于简单,所以不提供了
  35. // if( QIDUI(PAI) )...
  36. // if( SHISANYAO(PAI) )...

  37. if( Hu(PAI) )
  38. printf("哈!我和啦!\n");
  39. else
  40. printf("哎,和不成!\n");

  41. return 1;
  42. }

  43. // 判断和牌的递归函数,不考虑“七对” 和“十三幺”。因为如果
  44. // 把“七对” 和“十三幺”的判断放在递归函数里,将得不偿失。
  45. int Hu(int PAI[38])
  46. {
  47. static int JIANG = 0; // 将牌标志,即牌型“三三三三二”中的“二”

  48. if( !Remain(PAI) ) return 1; // 递归退出条件:如果没有剩牌,则和牌返回。

  49. for(int i=1;!PAI[i]&&i<38;i++); // 找到有牌的地方,i就是当前牌, PAI[i]是个数

  50. printf("i = %d\n",i); // 跟踪信息

  51. // 4张组合(杠子)
  52. if ( PAI[i] == 4 ) // 如果当前牌数等于4张
  53. {
  54. PAI[i] = 0; // 除开全部4张牌
  55. if( Hu(PAI) ) return 1; // 如果剩余的牌组合成功,和牌
  56. PAI[i] = 4; // 否则,取消4张组合
  57. }

  58. // 3张组合(大对)
  59. if ( PAI[i] >;= 3 ) // 如果当前牌不少于3张
  60. {
  61. PAI[i] -= 3; // 减去3张牌
  62. if( Hu(PAI) ) return 1; // 如果剩余的牌组合成功,和牌
  63. PAI[i] += 3; // 取消3张组合
  64. }

  65. // 2张组合(将牌)
  66. if ( !JIANG && PAI[i] >;= 2 ) // 如果之前没有将牌,且当前牌不少于2张
  67. {
  68. JIANG = 1; // 设置将牌标志
  69. PAI[i] -= 2; // 减去2张牌
  70. if( Hu(PAI) ) return 1; // 如果剩余的牌组合成功,和牌
  71. PAI[i] += 2; // 取消2张组合
  72. JIANG = 0; // 清除将牌标志
  73. }


  74. if ( i >; 30 ) return 0; // “东南西北中发白”没有顺牌组合,不和

  75. // 顺牌组合,注意是从前往后组合!
  76. if( i%10 != 8 && i%10 != 9 && // 排除数值为8和9的牌
  77. PAI[i+1] && PAI[i+2] ) // 如果后面有连续两张牌
  78. {
  79. PAI[i]--;
  80. PAI[i+1]--;
  81. PAI[i+2]--; // 各牌数减1
  82. if( Hu(PAI) ) return 1; // 如果剩余的牌组合成功,和牌
  83. PAI[i]++;
  84. PAI[i+1]++;
  85. PAI[i+2]++; // 恢复各牌数
  86. }

  87. // 无法全部组合,不和!
  88. return 0;
  89. }

  90. // 检查剩余牌数
  91. int Remain(int PAI[38])
  92. {
  93. int sum = 0;
  94. for(int i=1;i<38;i++)
  95. sum += PAI[i];
  96. return sum;
  97. }
复制代码

论坛徽章:
0
3 [报告]
发表于 2005-09-13 13:05 |只看该作者

麻将游戏开发

胡牌判断函数
  1. //----------------unt_mainwin.cpp---------------------------------------------------------

  2. /*-----------------------------------------------------------------------------------------
  3. *该函数判断手牌有没有胡牌,手牌的数量一定为[2,5,8,11,14]
  4. *当手牌数量为14时,判断是否有特殊牌型的胡牌[十三么,七对,全不靠]
  5. *当不存在以上牌型时,用递归算法判断是否存在一般的胡牌牌型
  6. *
  7. *作者:yutian(于恬)
  8. *E_main:yution@126.com
  9. *
  10. *作者声明:本代码为学习时编写的代码,大家可以随意转贴及编译修改
  11. *但不得用于商业用途和赌博,作者保留一切权力
  12. *
  13. *鸣谢:网友  shyworm(怕怕虫) E_mail:shyworm@sina.com
  14. *       CSDN  ChinaUnix
  15. */

  16. //-----------------------------------------------------------------------------------------------
  17. int       TWanJia::IsWin()
  18. {
  19.     int i,dblpos,dblcount;

  20.     if(this->;PaiCount==13) //先处理特殊牌型,七对、十三么及全不靠
  21.     {
  22.        if((this->;PaiInHand[0]==this->;PaiInHand[1])&(this->;PaiInHand[2]==this->;PaiInHand[3])
  23.        &(this->;PaiInHand[4]==this->;PaiInHand[5])&(this->;PaiInHand[6]==this->;PaiInHand[7])
  24.        &(this->;PaiInHand[8]==this->;PaiInHand[9])&(this->;PaiInHand[10]==this->;PaiInHand[11])
  25.        &(this->;PaiInHand[12]==this->;PaiInHand[13]))
  26.          return SevenDbl; //七对胡了   

  27.        dblcount=0;


  28.        for(i=0;i<13;i++)  //以下判断手牌中对子的数量及位置
  29.        {
  30.          if(this->;PaiInHand[i]==this->;PaiInHand[i+1])
  31.          {
  32.             dblcount++;
  33.          }

  34.          if(dblcount>;1) break; //如果手牌中含有两个对子(或一个刻子)以上,只能胡基本牌型
  35.        }



  36.        if(dblcount==1) //有一个对子的十三张手牌,可能为十三么
  37.          {
  38.            /***********************************************
  39.             十三么牌型必须是么九牌和字牌组成的十四张牌,按牌的数值定义
  40.              手牌数组PaiInHand中,只要没有1~7,10~16,19~25这些值,
  41.             则可以断定,该数组为十三么
  42.            */
  43.           int IsThirteen=1;
  44.           for(i=0;i<14;i++)
  45.            {
  46.               if(this->;PaiInHand[i]>;0&&this->;PaiInHand[i]<8)
  47.                 {
  48.                     IsThirteen=0;
  49.                     break;
  50.                 }
  51.               else if(this->;PaiInHand[i]>;9&&this->;PaiInHand[i]<17)
  52.                 {
  53.                     IsThirteen=0;
  54.                     break;
  55.                 }
  56.               else if(this->;PaiInHand[i]>;18&&this->;PaiInHand[i]<26)
  57.                 {
  58.                     IsThirteen=0;
  59.                     break;
  60.                 }
  61.            }
  62.           if(IsThirteen) return ThirteenSmall;
  63.          }   //end of 十三么

  64.        if(dblcount==0)//没有对子,可能是全不靠
  65.          {
  66.          /*-------------------------------------------
  67.          十三不靠牌型为万筒条三个花色的147,258,369加上字牌的七张牌共16张
  68.          的任意十四张组成的胡牌,147,258,369的花色可以为任意花色,但不能有两副
  69.          出现相同的序数,如一万,四万,一条,四条是不能组成胡牌的。

  70.          判定的算法是:
  71.          先确定所以序数牌(不是字牌)的个数;
  72.          如果序数牌个数大于9,则返回错误;
  73.          如果有吃牌的序列(存在两张牌可以吃掉另外一张牌),返回错误;
  74.          对于所有的序数牌,自第一个开始,分别与其后的所有牌值mod9得
  75.          到的值比较,如果存在相等,返回错误。
  76.          如果上面判断都通过,则为十三不靠

  77.          */

  78.          int NoWordPos=14;

  79.          for(i=13;i>;=0;i--)
  80.            {
  81.               if(this->;PaiInHand[i]<=26)
  82.               {
  83.                  NoWordPos=i;
  84.                  break;
  85.               }
  86.            }

  87.          if(NoWordPos<=8)   //如果非字牌有9个以上,肯定不能胡全不靠
  88.            {
  89.               int IsThirteenSingle=1;

  90.               for(i=0;i<NoWordPos;i++)
  91.                 {
  92.                   if((this->;PaiInHand[i+1]<=(this->;PaiInHand[i]+2))&(this->;PaiInHand[i]%9==this->;PaiInHand[i+1]%9))
  93.                     {
  94.                        IsThirteenSingle=0;
  95.                        break;
  96.                     }
  97.                 }

  98.               if(IsThirteenSingle)
  99.                 {
  100.                   for(i=0;i<NoWordPos&IsThirteenSingle;i++)
  101.                     {
  102.                        for(int j=0;j<=NoWordPos;j++)
  103.                          {
  104.                             if(this->;PaiInHand[i]==this->;PaiInHand[j]%9)
  105.                               {
  106.                                 IsThirteenSingle=0;
  107.                                 break;
  108.                               }
  109.                          }
  110.                     }
  111.                 }

  112.                 if(IsThirteenSingle) return   ThirteenSingle;
  113.            }


  114.          } //end of 不靠
  115.     }
  116.    
  117.    
  118.     int TempPai[33];
  119.    
  120.     for(i=0;i<34;i++) TempPai=0;
  121.    
  122.     for(i=0;i<14;i++)
  123.       {
  124.         TempPai[this->;PaiInHand[i]]++;       
  125.       }      
  126.    if(HuPai(TempPai)) return GenaralWin;
  127.     return 0;
  128. }
  129. //-----------------------------------------------------------------------------------------------------------------
  130. int TWanJia::HuPai(int *arr)
  131. {
  132.         /*
  133.         以下代码参考了网友
  134.         shyworm(怕怕虫) E_mail:shyworm@sina.com
  135.         在csdn论坛发表的算法及源码,在此感谢
  136.        
  137.         原来的算法中要对杠牌进行处理,但我设计的数据结构中,不需要对他们进行判断了,
  138.         故略去了一段代码
  139.         */
  140.    static int Jiang=0;  // 将牌标志,即牌型“三三三三二”中的“二”
  141.    
  142.    if(!RemainPai(arr)) return 1;  // 递归退出条件:如果没有剩牌,则和牌返回。
  143.    
  144.    for(int i=1;!arr[i]&i<34;i++);  // 找到有牌的地方,i就是当前牌, arr[i]是个数
  145.   
  146.   // 3张组合(刻子)
  147.    if(arr[i]>;=3)  // 如果当前牌不少于3张
  148.    {
  149.       arr[i]-=3;  // 减去3张牌
  150.       if(HuPai(arr)) return 1;   // 如果剩余的牌组合成功,和牌
  151.       arr[i]+=3;  // 取消3张组合        
  152.    }
  153.    
  154.    // 2张组合(将牌)
  155.    if(!Jiang&arr[i]>;=2)  // 如果之前没有将牌,且当前牌不少于2张
  156.    {
  157.      Jiang=1;  // 设置将牌标志
  158.      arr[i]-=2;  // 减去2张牌
  159.      if(HuPai(arr)) return 1;  // 如果剩余的牌组合成功,和牌
  160.      arr[i]+=2;  // 取消2张组合
  161.      Jiang=0;        // 清除将牌标志
  162.    }
  163.    
  164.    if(i>;26) return 0;  // “东南西北中发白”没有顺牌组合,不和
  165.    
  166.    
  167.    // 顺牌组合,注意是从前往后组合!
  168.    if(i%9!=7&i%9!=8&arr[i+1]&arr[i+2])// 排除数值为8和9的牌且如果后面有连续两张牌  
  169.    {
  170.      arr[i]--;
  171.      arr[i+1]--;
  172.      arr[i+2]--;   // 各牌数减1
  173.      if(HuPai(arr)) return 1;  // 如果剩余的牌组合成功,和牌
  174.      arr[i]++;
  175.      arr[i+1]++;
  176.      arr[i+2]++;  // 恢复各牌数        
  177.    }
  178.    
  179.    
  180.    // 无法全部组合,不和!
  181.    return 0;
  182. }
  183. //----------------------------------------------------------------------------
  184. // 检查剩余牌数
  185. int TWanJia::RemainPai(int *arr)
  186. {
  187.         int sum=0;
  188.        
  189.         for(int i=0;i<34;i++)
  190.           sum+=arr[i];       
  191.          
  192.         return sum;  
  193.        
  194. }
  195. //----------------------------------------------------------------------------

复制代码


头文件



  1. //-------------------玩家类及窗体的头文件(修改中)----------------------------------------

  2. #ifndef unt_mainwinH
  3. #define unt_mainwinH
  4. //---------------------------------------------------------------------------
  5. #include <Classes.hpp>;
  6. #include <Controls.hpp>;
  7. #include <StdCtrls.hpp>;
  8. #include <Forms.hpp>;
  9. #include <Buttons.hpp>;

  10. #define   SevenDbl              7       //七对
  11. #define   ThirteenSmall         13      //十三么
  12. #define   ThirteenSingle        14      //十三不靠
  13. #define   GenaralWin            15      //一般胡牌

  14. //============================================
  15. // 0    1     2   3    4    5    6    7    8
  16. //============================================
  17. //一万 二万 三万 四万 五万 六万 七万 八万 九万
  18. //============================================
  19. // 9    10   11   12   13   14   15   16   17
  20. //============================================
  21. //一条 二条 三条 四条 五条 六条 七条 八条 九条
  22. //============================================
  23. //18    19   20   21   22   23   24   25   26
  24. //============================================
  25. //一筒 二筒 三筒 四筒 五筒 六筒 七筒 八筒 九筒
  26. //============================================
  27. //27    28   29   30   31   32   33   34   35
  28. //============================================
  29. //东风 南风 西风 北风 红中 发财 白板  花1  花2
  30. //============================================









  31. //---------------------------------------------------------------------------
  32. struct SChiPai  //吃牌的结构体,吃的牌为顺子,故记录首尾两张牌
  33. {
  34.   int MinPai;    //麻将牌值,吃牌中最小的牌
  35.   int MaxPai;   //麻将牌值,吃牌中最大的牌
  36. };
  37. //---------------------------------------------------------------------------
  38. struct SGangPai     //杠牌的结构体
  39. {
  40.   int Pai;    //麻将牌值,取值范围为[0..33]
  41.   int MingAn;//数值为0或1,1代表为暗杠,0代表明杠
  42. };
  43. //---------------------------------------------------------------------------
  44. class TWanJia
  45. {
  46. //__published:

  47. private:
  48.       AnsiString PlayerID;
  49.       int        FenShu;                //玩家的分数,要和数据库保持一致

  50.       int        MenFeng;               //玩家的门风

  51.       SGangPai   Gangpai[3];            //玩家手中杠的牌

  52.       SChiPai    ChiPai[3];             //玩家手中吃的牌

  53.       int        PengPai[3];            //玩家手中的碰牌

  54.       int        HuaPai;                //花牌的数量,算番时要用

  55.       int        PaiInHand[13];         //玩家的手牌,除掉吃碰杠牌后手中的牌
  56.                                         //即其他玩家看不到的牌,最多为十四张
  57.                                         //其中,PaiInHand[13]在处理完成后,被赋值为-1

  58.       int        PaiCount;              //手牌的数量,取值为1,4,7,10,13

  59.       int        NewPai;                //新摸到或别人打的牌,在处理完成后,被赋值为-1
  60.                                         //如果NewPai为非负值,则必须处理掉一张牌或胡牌

  61. protected:
  62.         int HuPai(int *arr);
  63.         int RemainPai(int *arr);
  64. public:
  65.                  TWanJia(AnsiString PlayID,int fenzhi);
  66.      int       SetMenFeng(int menfeng);
  67.      int       SetFenShu(int fenshu);
  68.      int       SetGangPai(int pai,int mingan);
  69.      int       SetChiPai(int min,int max);
  70.      int       SetPengPai(int pengpai);
  71.      int       SetPaiInHand(int * paiarr);
  72.      int       SetPaiCount(int count);

  73.      int       GetMenFeng();
  74.      int       GetFenShu();
  75.      SGangPai * GetGangPai();
  76.      int      * GetPengPai();
  77.      SChiPai  * GetChiPai();
  78.      int      * GetPaiInHand();
  79.      int       GetPaiCount();

  80.      int       Buhua();
  81.      int       ChiPaiWithTwoPai(int min,int max);
  82.      int       PengPaiWithOneDbl(int pai);
  83.      int       IsWin();
  84.      int       SendThePaiToServer();
  85.      int       RequireOnePai();
  86. };
  87. //---------------------------------------------------------------------------
  88. class TMJZhuo
  89. {
  90. //__published:

  91. private:
  92.      int QuanFen,Header,Tail;
  93.      int PaiQiang[143];
  94.      TWanJia Players[3];
  95. public:

  96. };

  97. //----------------------------------------------------------------------------
  98. class Tfrm_mainwin : public TForm
  99. {
  100. __published:        // IDE-managed Components
  101.         TEdit *edt_paiInHand1;
  102.         TLabel *Label1;
  103.         TEdit *edt_GangPai1;
  104.         TLabel *Label2;
  105.         TLabel *Label3;
  106.         TLabel *Label4;
  107.         TEdit *edt_ChiPai11;
  108.         TEdit *edt_ChiPai12;
  109.         TEdit *edt_ChiPai21;
  110.         TEdit *edt_ChiPai22;
  111.         TEdit *edt_ChiPai31;
  112.         TEdit *edt_ChiPai32;
  113.         TEdit *edt_ChiPai41;
  114.         TEdit *edt_ChiPai42;
  115.         TEdit *edt_GangPai2;
  116.         TEdit *edt_GangPai3;
  117.         TEdit *edt_GangPai4;
  118.         TEdit *edt_GangPai11;
  119.         TEdit *edt_GangPai22;
  120.         TEdit *edt_GangPai33;
  121.         TEdit *edt_GangPai44;
  122.         TEdit *edt_PengPai1;
  123.         TEdit *edt_PengPai2;
  124.         TEdit *edt_PengPai3;
  125.         TEdit *edt_PengPai4;
  126.         TEdit *edt_paiInHand2;
  127.         TEdit *edt_paiInHand3;
  128.         TEdit *edt_paiInHand4;
  129.         TEdit *edt_paiInHand5;
  130.         TEdit *edt_paiInHand6;
  131.         TEdit *edt_paiInHand7;
  132.         TEdit *edt_paiInHand8;
  133.         TEdit *edt_paiInHand9;
  134.         TEdit *edt_paiInHand10;
  135.         TEdit *edt_paiInHand11;
  136.         TEdit *edt_paiInHand12;
  137.         TEdit *edt_paiInHand13;
  138.         TEdit *edt_paiInHand14;
  139.         TBitBtn *btn_IsWin;
  140.         void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
  141.         void __fastcall btn_IsWinClick(TObject *Sender);
  142.         void __fastcall FormCreate(TObject *Sender);
  143. private:        // User declarations
  144.     TWanJia * Player;

  145. public:                // User declarations
  146.         void SendDataToWanJia();
  147.         void DispWanJiaData();
  148.         __fastcall Tfrm_mainwin(TComponent* Owner);
  149.         
  150. };
  151. //---------------------------------------------------------------------------
  152. extern PACKAGE Tfrm_mainwin *frm_mainwin;
  153. //---------------------------------------------------------------------------
  154. #endif

复制代码


敬请斧正,谢谢

论坛徽章:
0
4 [报告]
发表于 2005-09-13 16:30 |只看该作者

麻将游戏开发

  1. /*-----------------------------------------------------------------------------
  2. *该函数为牌墙洗牌
  3. *先分配一个temparr[143]的数组(牌堆),依次赋值为0~35,每个数字的个数为4个;
  4. * 设置剩余牌数为144;
  5. * 当剩余牌数不为0时:
  6. *   产生一个随机数n;
  7. *   将n模去剩余牌数再加一赋值给num;
  8. * 在牌堆里找到第num个牌,存进牌墙中;
  9. *
  10. *
  11. *作者:yutian(于恬)
  12. *E_main:yution@126.com
  13. *
  14. *作者声明:本代码为学习时编写的代码,大家可以随意转贴及编译修改
  15. *但不得用于商业用途和赌博,作者保留一切权力
  16. ******************************************************************************/

  17. #include <math.h>;
  18. #include <time.h>;
  19. #include <stdlib.h>;

  20. int arr[143];

  21. int initpaiqiang()
  22. {
  23.    int temparr[143];
  24.    int i,j,rempai;

  25.    j=0;
  26.    rempai=144;   //设置剩余牌数
  27.    
  28.   for(i=0;i<144;i++)
  29.    {
  30.     temparr[i]=i/4; //将牌堆初始化
  31.    }

  32.   while(rempai)
  33.   {
  34.     srand((unsigned)time(NULL));
  35.     int num=random()%rempai+1;

  36.     for(i=0;i<144;i++)
  37.       {
  38.         if(temparr[i]!=-1) num--;//找到第num张牌
  39.         
  40.         if(!num)
  41.           {
  42.             arr[j]=temparr[i];   //将这张牌放入牌墙
  43.             j++;
  44.             rempai--;
  45.             temparr[i]=-1;
  46.             break;
  47.           }
  48.       }
  49.   }
  50. }
复制代码


洗牌的函数

论坛徽章:
0
5 [报告]
发表于 2005-09-15 17:23 |只看该作者

麻将游戏开发

只能说句佩服佩服...

不过我可以提个需求嘛? 北京的玩法是每局有个牌是混,就是可以替代任何字,可不可以把这种牌型也算进去?

论坛徽章:
0
6 [报告]
发表于 2005-09-16 09:02 |只看该作者

麻将游戏开发

原帖由 "yulc" 发表:
只能说句佩服佩服...

不过我可以提个需求嘛? 北京的玩法是每局有个牌是混,就是可以替代任何字,可不可以把这种牌型也算进去?


谢谢你的建议

可以是当然可以的,但要实现就可能要更改类的实现,

我是根据麻将的规则写的,至于其他的牌型及规则,兄台可以修改一下代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP