java桥牌发牌算法

转自:http://blog.csdn.net/friendan/article/details/17530717

参考文章:

http://www.cnblogs.com/Jax/archive/2008/07/19/1246692.html

http://bbs.csdn.net/topics/80333258

--------------------------------------------------------------------------------------------------------------------------------------------------

桥牌发牌类:

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. import java.util.*;  
  2. import java.math.*;  
  3.   
  4. //桥牌发牌类  
  5. public class Poker {  
  6.     static List<Integer> pokerN=new ArrayList<Integer>(new Integer(13));//北家的牌  
  7.     static List<Integer> pokerE=new ArrayList<Integer>(new Integer(13));//东家的牌  
  8.     static List<Integer> pokerS=new ArrayList<Integer>(new Integer(13));//南家的牌  
  9.     static List<Integer> pokerW=new ArrayList<Integer>(new Integer(13));//西家的牌  
  10.     static List<Integer> pokerAll=new ArrayList<Integer>(new Integer(52));//52张牌  
  11.       
  12.     //洗牌  
  13.     public static void Shuffle()  
  14.     {  
  15.         for(int i=1;i<=52;i++)  
  16.         {  
  17.             pokerAll.add(i);  
  18.         }  
  19.           
  20.         Random rd=new Random();  
  21.         int tmp=0,idx=0;  
  22.         for(int i=0;i<52;i++)  
  23.         {  
  24.             idx=rd.nextInt(52);  
  25.             tmp=pokerAll.get(i);  
  26.             pokerAll.set(i,pokerAll.get(idx));  
  27.             pokerAll.set(idx, tmp);  
  28.         }  
  29.     }  
  30.       
  31.     //获取北家的牌  
  32.     public static List<Integer> getPokerN()  
  33.     {  
  34.         for(int i=0;i<13;i++)  
  35.         {  
  36.             pokerN.add(pokerAll.get(i));//0~12  
  37.         }  
  38.         return pokerN;  
  39.     }  
  40.       
  41.     //获取东家的牌  
  42.     public static List<Integer> getPokerE()  
  43.     {  
  44.         for(int i=0;i<13;i++)  
  45.         {  
  46.             pokerE.add(pokerAll.get(i+13));//13~25  
  47.         }  
  48.         return pokerE;  
  49.     }  
  50.       
  51.     //获取南家的牌  
  52.     public static List<Integer> getPokerS()  
  53.     {  
  54.         for(int i=0;i<13;i++)  
  55.         {  
  56.             pokerS.add(pokerAll.get(i+26));//26~38  
  57.         }  
  58.         return pokerS;  
  59.     }  
  60.       
  61.     //获取西家的牌  
  62.     public static List<Integer> getPokerW()  
  63.     {  
  64.         for(int i=0;i<13;i++)  
  65.         {  
  66.             pokerW.add(pokerAll.get(i+39));//39~51  
  67.         }  
  68.         return pokerW;  
  69.     }  
  70.   
  71. }  

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

测试代码:

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. import java.util.*;  
  2. public class main {  
  3.   
  4.     /** 
  5.      * @param args 
  6.      */  
  7.     public static void main(String[] args) {  
  8.           
  9.                 Poker.Shuffle();//洗牌  
  10.           
  11.                 System.out.print("\n北家的牌:");  
  12.                 List<Integer> list=Poker.getPokerN();  
  13.                 for(int i=0;i<list.size();i++)  
  14.                 {  
  15.                     System.out.printf("%-3d ",list.get(i));  
  16.                 }  
  17.           
  18.                 System.out.print("\n东家的牌:");  
  19.                 list=Poker.getPokerE();  
  20.                 for(int i=0;i<list.size();i++)  
  21.                 {  
  22.                     System.out.printf("%-3d ",list.get(i));  
  23.                 }  
  24.                   
  25.                 System.out.print("\n南家的牌:");  
  26.                 list=Poker.getPokerS();  
  27.                 for(int i=0;i<list.size();i++)  
  28.                 {  
  29.                     System.out.printf("%-3d ",list.get(i));  
  30.                 }  
  31.                   
  32.                 System.out.print("\n西家的牌:");  
  33.                 list=Poker.getPokerW();  
  34.                 for(int i=0;i<list.size();i++)  
  35.                 {  
  36.                     System.out.printf("%-3d ",list.get(i));  
  37.                 }  
  38.                 System.out.println();  
  39.           
  40.           
  41.     }  
  42.   
  43. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值