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 ?
  1. import java.util.*;  
  2. import java.math.*;  
  3.   
  4. //桥牌发牌类  
  5. public class Poker {  
  6.     static List pokerN=new ArrayList(new Integer(13));//北家的牌  
  7.     static List pokerE=new ArrayList(new Integer(13));//东家的牌  
  8.     static List pokerS=new ArrayList(new Integer(13));//南家的牌  
  9.     static List pokerW=new ArrayList(new Integer(13));//西家的牌  
  10.     static List pokerAll=new ArrayList(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 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 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 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 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 ?
  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 list=Poker.getPokerN();  
  13.                 for(int i=0;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
  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
  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
  35.                 {  
  36.                     System.out.printf("%-3d ",list.get(i));  
  37.                 }  
  38.                 System.out.println();  
  39.           
  40.           
  41.     }  
  42.   
  43. }  

你可能感兴趣的:(java桥牌发牌算法)