| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 746 人关注过本帖
标题:扑克牌洗、发牌简化方法,求帮助,谢谢!
只看楼主 加入收藏
李西甲
Rank: 1
等 级:等待验证会员
帖 子:16
专家分:7
注 册:2011-12-5
结帖率:100%
收藏
已结贴  问题点数:15 回复次数:7 
扑克牌洗、发牌简化方法,求帮助,谢谢!
#include <stdlib.h>
#include <stdio.h>      
main()
{  
     int i,j,row,col;
     char* a[4][13]={{"He: A","He: 2","He:3","He: 4","He: 5","He: 6","He: 7","He: 8",
       "He: 9","He: 10","He: J","He: Q","He: K"},
     {"Di: A","Di: 2","Di:3","Di: 4","Di: 5","Di: 6","Di: 7","Di: 8","Di: 9","Di: 10",
       "Di: J","Di: Q","Di: K"},
     {"Cl: A","Cl: 2","Cl:3","Cl: 4","Cl: 5","Cl: 6","Cl: 7","Cl: 8","Cl: 9","Cl: 10",
       "Cl: J","Cl: Q","Cl: K"},
     {"Sp: A","Sp: 2","Sp:3","Sp: 4","Sp: 5","Sp: 6","Sp: 7","Sp: 8","Sp: 9","Sp: 10",
       "Sp: J","Sp: Q","Sp: K"}};     
     char* deck[4][13];
     srand(time(NULL));
     for(i=0;i<4;i++)      //洗牌
     {  
        for(j=0;j<13;j++)
        {
            row=rand()%4;
            col=rand()%13;
            deck[i][j]=a[row][col];
        }
     }
     for(i=0;i<4;i++)      //发牌
     {
         for(j=0;j<13;j++)
            printf("%8s",deck[i][j]);
         printf("\n");
     }
     getchar();
     getchar();
}
//////char* a[4][13]的初始化如何变得简洁,求帮助,知道的讲一下,谢谢!
搜索更多相关主题的帖子: 扑克牌 include 
2011-12-07 23:12
luchar
Rank: 9Rank: 9Rank: 9
来 自:南京
等 级:蜘蛛侠
帖 子:279
专家分:1263
注 册:2011-11-3
收藏
得分:8 
你这个洗牌方法不对,这样洗出来的牌,会出现两张相同牌的情况
2011-12-08 00:53
李西甲
Rank: 1
等 级:等待验证会员
帖 子:16
专家分:7
注 册:2011-12-5
收藏
得分:0 
恩,    我改成这样:#include <stdlib.h>
 #include <stdio.h>      
 main()
 {  
      int i,j,row,col;
      char* a[4][13]={{"He: A","He: 2","He:3","He: 4","He: 5","He: 6","He: 7","He: 8",
        "He: 9","He: 10","He: J","He: Q","He: K"},
      {"Di: A","Di: 2","Di:3","Di: 4","Di: 5","Di: 6","Di: 7","Di: 8","Di: 9","Di: 10",
        "Di: J","Di: Q","Di: K"},
      {"Cl: A","Cl: 2","Cl:3","Cl: 4","Cl: 5","Cl: 6","Cl: 7","Cl: 8","Cl: 9","Cl: 10",
        "Cl: J","Cl: Q","Cl: K"},
      {"Sp: A","Sp: 2","Sp:3","Sp: 4","Sp: 5","Sp: 6","Sp: 7","Sp: 8","Sp: 9","Sp: 10",
        "Sp: J","Sp: Q","Sp: K"}};     
      char* deck[4][13];
     char* p;
      srand(time(NULL));
      for(i=0;i<4;i++)      //洗牌
      {  
         for(j=0;j<13;j++)
         {
            p=a[i][j];
             row=rand()%4;
             col=rand()%13;
             deck[i][j]=a[row][col];
            a[row][col]=p;
         }
      }
      for(i=0;i<4;i++)      //发牌
     {
          for(j=0;j<13;j++)
             printf("%8s",deck[i][j]);
          printf("\n");
      }
      getchar();
      getchar();
}
可以吗?
2011-12-09 00:03
zy_space
Rank: 5Rank: 5
等 级:职业侠客
帖 子:163
专家分:364
注 册:2011-11-14
收藏
得分:8 
enum   color   {sp, he, sp, di};
enum   value   {A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K};
struct   poker {
   color   type;
   value   data;
}   a[52];
typedef   struct poker   poker;

何必等待?梦在今朝
2011-12-09 08:15
zy_space
Rank: 5Rank: 5
等 级:职业侠客
帖 子:163
专家分:364
注 册:2011-11-14
收藏
得分:0 
。。。。错了,是
enum   color   {sp, he, cl, di};

何必等待?梦在今朝
2011-12-09 08:19
zy_space
Rank: 5Rank: 5
等 级:职业侠客
帖 子:163
专家分:364
注 册:2011-11-14
收藏
得分:0 
for (i = 0; i < 12; i++)   {
   a[i].value = i;      //枚举变量的值默认从0开始
   a[i].color = sp;    //可以为sp, he, sp, di
}   //再循环三次初始化其余三种花色的牌

何必等待?梦在今朝
2011-12-09 08:25
zy_space
Rank: 5Rank: 5
等 级:职业侠客
帖 子:163
专家分:364
注 册:2011-11-14
收藏
得分:0 
或者
for (i = 0; i  < 52; i++) {
   a[i].value = i % 13;
   a[i].color = i % 4;
}

何必等待?梦在今朝
2011-12-09 08:29
李西甲
Rank: 1
等 级:等待验证会员
帖 子:16
专家分:7
注 册:2011-12-5
收藏
得分:0 
回复 7楼 zy_space
谢谢
2011-12-09 12:36
快速回复:扑克牌洗、发牌简化方法,求帮助,谢谢!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.052149 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved