Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 关于纸牌桥牌游戏的游戏逻辑_Algorithm_Playing Cards_Bridge - Fatal编程技术网

Algorithm 关于纸牌桥牌游戏的游戏逻辑

Algorithm 关于纸牌桥牌游戏的游戏逻辑,algorithm,playing-cards,bridge,Algorithm,Playing Cards,Bridge,我设计了一个类,它的构造函数生成52张卡片对象,每个对象都有自己的颜色、值、isTrump(布尔值)和imageIcon,用于存储每张卡片的图像。现在有另一个类称为Que,它将所有纸牌对象存储到Que中并洗牌。有一种方法可以将4名玩家之间的牌对象处理为一组对象(牌)。现在,我使用LayeredPane和JLabel来显示它们,并且还附带了一个鼠标侦听器 现在我只想知道如何开始每一个技巧。这意味着在根据一些预定义规则分析我的卡后,我会自动放置一张卡,然后再放置三个其他机器人。 有什么建议吗 pub

我设计了一个类,它的构造函数生成52张卡片对象,每个对象都有自己的颜色、值、isTrump(布尔值)和imageIcon,用于存储每张卡片的图像。现在有另一个类称为Que,它将所有纸牌对象存储到Que中并洗牌。有一种方法可以将4名玩家之间的牌对象处理为一组对象(牌)。现在,我使用LayeredPane和JLabel来显示它们,并且还附带了一个鼠标侦听器

现在我只想知道如何开始每一个技巧。这意味着在根据一些预定义规则分析我的卡后,我会自动放置一张卡,然后再放置三个其他机器人。 有什么建议吗

public class Cards {

public Cards(int a, int b){
    this.cardvalue = a;
    this.color = b;
    this.isTrump = false;
    switch(a){
        case 11: this.facevalue = 1;
            break;
        case 12: this.facevalue = 2;
            break;
        case 13: this.facevalue = 3;
            break;
        case 14: this.facevalue = 4;
            break;
        default : this.facevalue = 0;
}
    switch(b){
        case 1: this.colorName = "Spade";
                this.CardImage= new ImageIcon(getClass().getResource("/testing/Cards/Spade/Spade ("+a+").jpg"));
            break;
        case 2: this.colorName = "Heart";
                this.CardImage= new ImageIcon(getClass().getResource("/testing/Cards/Heart/Heart ("+a+").jpg"));
            break;
        case 3: this.colorName = "Diamond";
                this.CardImage= new ImageIcon(getClass().getResource("/testing/Cards/Diamond/Diamond ("+a+").jpg"));
            break;
        default : this.colorName = "Club";
                 this.CardImage= new ImageIcon(getClass().getResource("/testing/Cards/Club/Club ("+a+").jpg"));

    }
}
public void isTrump(){
    this.isTrump = true;
}
public int getCardValue(){
    return this.cardvalue;
}
public int getColor(){
    return this.color;
}
public int getFaceValue(){
    return this.facevalue;
}
public boolean getisTrump(){
    return this.isTrump;
}
public String getColorName(){
    return this.colorName;
}
public ImageIcon getCardImage(){
    return this.CardImage;
}
public ImageIcon getBackSide(){
    return backSide;
}
private String colorName;
private int cardvalue;
private int color; // 1 For Spade 2 For Heart 3 For Diamond 4 For Club
private int facevalue;
private boolean isTrump;
private ImageIcon CardImage;
private ImageIcon backSide = new   
ImageIcon(getClass().getResource("/testing/Cards/Backside.jpg"));

}
类,该卡是哪种交易

public class CardsInHand {
public CardsInHand(){
    totalCards  = new Que(52);
    int a =1; int b=2;
    for (int j = 0;j<52;j++){
        if(j==13||j==26||j==39) a++;
        if(b==15) b=2;

        totalCards.put(new Cards(b,a));
        b++;

    }
    totalCards.QueShuffle();
 }
public static void Deal(){
    card = new CardsInHand();
    setPlayers();
}
private static void setPlayers(){
   for(int i =0;i<13;i++){
       Hands[0][i] = totalCards.get();
       Hands[1][i] = totalCards.get();
       Hands[2][i] = totalCards.get();
       Hands[3][i] = totalCards.get();
   }
   sortingarr();
}

private static void Sorting(Cards arr[]){

  //here some Sorting algorithm i used 
   }

private static void sortingarr(){
    Sorting(Hands[0]);
    Sorting(Hands[1]);
    Sorting(Hands[2]);
    Sorting(Hands[3]);
    NumberSorting(Hands[0]);
    NumberSorting(Hands[1]);
    NumberSorting(Hands[2]);
    NumberSorting(Hands[3]);


}
private static void NumberSorting(Cards arr[]){
    //some algorith i used for number sorting
        }
public static Cards[] getPlayer1(){
   return Hands[0];
}
public static Cards[] getPlayer2(){
   return Hands[1];
}
public static Cards[] getPlayer3(){
   return Hands[2];
}
public static Cards[] getPlayer4(){
   return Hands[3];
}
public static Cards[][] getAllHands(){
   return Hands;
}
private final static Cards[] Player1 = new Cards[13];
private final static Cards[] Player2 = new Cards[13];
private final static Cards[] Player3 = new Cards[13];
private final static Cards[] Player4 = new Cards[13];
private final static Cards[][] Hands = {Player1,Player2,Player3,Player4};
private static Que totalCards;
private static CardsInHand card;

}
公共类名片{
公共名片{
totalCards=新的Que(52);
INTA=1;INTB=2;

对于(int j=0;jj)如果没有任何代码和示例,您的问题有点难以理解。您必须将您的问题缩小一点。询问我们如何编写计算机程序以玩桥牌是一种更广泛的方法。
public class ShowCards {
private JFrame frame = new JFrame();
private static JLayeredPane lpane = new JLayeredPane();
private static  JLabel[] Player1 = new JLabel[13];
private static  JLabel[] Player2 = new JLabel[13];
private static  JLabel[] Player3 = new JLabel[13];
private static  JLabel[] Player4 = new JLabel[13];
private static  JButton button = new JButton("Deal Again");

 public ShowCards()
 {
    CardsInHand.Deal();
    frame.setPreferredSize(new Dimension(800, 640));
    frame.setLayout(new BorderLayout());
     frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.LINE_AXIS));
    frame.add(lpane, BorderLayout.CENTER);

    frame.add(button);
    lpane.add(button, new Integer(14), 0);
    button.setBounds(200, 250, 100, 70);
    button.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            buttonActionPerformed(evt);
        }
    });
    lpane.setBounds(30, 30, 270, 270);
    cardDeal();
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
 static void cardDeal(){
  loadJLabels1();
  loadJLabels2();
  loadJLabels3();
  loadJLabels4();
 } 
  static void loadJLabels1(){
    int k = 30;
    for(int i=0;i<13;i++){

    Player1[i] = new JLabel();
    Player1[i].setIcon(CardsInHand.getPlayer1()[i].getCardImage());
    Player1[i].setBounds(k, 20, 170, 100);
    Player1[i].setOpaque(true);
    Player1[i].addMouseListener(new MouseAdapter()
    {
        public void mouseClicked(MouseEvent evt)
        {
            int count = evt.getClickCount();
            if (count == 1){
            int Index = getIndex(Player1, (JLabel)evt.getSource());
            Player1[Index].setIcon(CardsInHand.getPlayer1()[Index].getBackSide());
            }

        }
    });
    lpane.add(Player1[i], new Integer(i), 0);
    k = k+30;
    }
  }
 static void loadJLabels2(){

    int k = 140;
    for(int i=0;i<13;i++){
     Player2[i] = new JLabel();
    Player2[i].setIcon(CardsInHand.getPlayer2()[i].getCardImage());
    Player2[i].setBounds(30, k, 170, 100);
    Player2[i].setOpaque(true);
    Player2[i].addMouseListener(new MouseAdapter()
    {
        public void mouseClicked(MouseEvent evt)
        {
            int count = evt.getClickCount();
            if (count == 1){
            int Index = getIndex(Player2, (JLabel)evt.getSource());
            Player2[Index].setIcon(CardsInHand.getPlayer2()[Index].getBackSide());
            }

        }
    });

    lpane.add(Player2[i], new Integer(i), 0);
    k = k+20;


    }
  }
 static void loadJLabels3(){
    int k = 140;
    for(int i=0;i<13;i++){

    Player3[i] = new JLabel();
    Player3[i].setIcon(CardsInHand.getPlayer3()[i].getCardImage());
    Player3[i].setBounds(400, k, 170, 100);
    Player3[i].setOpaque(true);
    Player3[i].addMouseListener(new MouseAdapter()
    {
        public void mouseClicked(MouseEvent evt)
        {
            int count = evt.getClickCount();
            if (count == 1){
            int Index = getIndex(Player3, (JLabel)evt.getSource());
            Player3[Index].setIcon(CardsInHand.getPlayer2()[Index].getBackSide());
            }

        }
    });
    lpane.add(Player3[i], new Integer(i), 0);
    k = k+20;
    }
  }
 static void loadJLabels4(){
    int k = 30;
    for(int i=0;i<13;i++){
    Player4[i] = new JLabel();
    Player4[i].setIcon(CardsInHand.getPlayer4()[i].getCardImage());
    Player4[i].setBounds(k, 500, 170, 100);
    Player4[i].setOpaque(true);
    Player4[i].addMouseListener(new MouseAdapter()
    {
        public void mouseClicked(MouseEvent evt)
        {
            int count = evt.getClickCount();
            if (count == 1){
            int Index = getIndex(Player4, (JLabel)evt.getSource());
            Player4[Index].setIcon(CardsInHand.getPlayer2()[Index].getBackSide());
            }

        }
    });
    lpane.add(Player4[i], new Integer(i), 0);
    k = k+30;
    }
 }
 private void buttonActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
   CardsInHand.Deal();
   cardDeal();

}    
static int getIndex(JLabel[] arr, JLabel obj){
int index=0;
for(JLabel cmp: arr){
   if(cmp == obj) break;
   index++;
     }
return index;
}
}
public class Players {

public Players(Cards[] arr){

    this.scoreInHand = getScoreInHand(arr);
    getCardOfEachSuit(arr, this.cardsOfEachSuit);
    this.isBalanceHand = getIsBalanceHand(arr);
    this.longestSuit = getLongestSuit(arr);
    this.numberOfTrump = getNumberOfTrump(arr);
    this.smallestSuit = getSmallestSuit(arr);
    this.strongestSuit = getStrongestSuit(arr);
    this.weakestSuit = getWeakestSuit(arr);
    for(int i=0;i<13;i++){
        this.remainingSpade[i] = true;
        this.remainingHeart[i] = true;
        this.remainingClub[i] = true;
        this.remainingDiamond[i] = true;
    }
    for(int i=0;i<4;i++){
        this.rightOpCutSuit[i]= false;
        this.leftOpCutSuit[i] = false;
        this.frontOpCutSuit[i] = false;
    }
    this.coatCaution = false;
    this.gcCaution = false;
    this.numberOfTrumpExist = 13;
    this.openingBet =0;
    this.respondingBet =0;
    this.trickStarter = false;
}

public static void createRobot(){
    CardsInHand.Deal();
    for(int i=0; i<3;i++){
    Robots[i] = new Players(CardsInHand.getAllHands()[i+1]);
            }

}

private int getScoreInHand(Cards[] arr){
    int temp = 0;
    for(Cards x: arr){
        temp = temp + x.getFaceValue();
    }
    return temp;
}
private int getStrongestSuit(Cards[] arr){
    int strong=0;
    int S=0;int C=0;int D=0;int H=0;
        for(Cards x: arr){
            if(x.getColorName()=="Spade") S = S + x.getFaceValue();
            else  if(x.getColorName()=="Heart") H = H + x.getFaceValue();
            else  if(x.getColorName()=="Club") C = C + x.getFaceValue();
            else D = D + x.getFaceValue();
        }
       int[] temp = {S,H,D,C};
       int max = temp[0];
       for(int i=0;i<4;i++){
           if(max<temp[i]){
               max=temp[i];
               strong = i;
           }
       }
        return strong+1;
}
private int getWeakestSuit(Cards[] arr){
    int weak=0;
    int S=0;int C=0;int D=0;int H=0;
        for(Cards x: arr){
            if(x.getColorName()=="Spade") S = S + x.getFaceValue();
            else  if(x.getColorName()=="Heart") H = H + x.getFaceValue();
            else  if(x.getColorName()=="Club") C = C + x.getFaceValue();
            else D = D + x.getFaceValue();
        }
       int[] temp = {S,H,D,C};
       int min = temp[0];
       for(int i=0;i<4;i++){
           if(min>temp[i]){
               min=temp[i];
               weak = i;
           }
       }
        return weak+1;
}

private int getLongestSuit(Cards[] arr){
    int Longest = 0;
    int[] temp = new int[4];
    getCardOfEachSuit(arr, temp);

    int max = temp[0];
       for(int i=0;i<4;i++){
           if(max<temp[i]){
               max=temp[i];
               Longest = i;
           }
       }
       return Longest+1;
}

private int getSmallestSuit(Cards[] arr){
    int Smallest = 0;
    int[] temp = new int[4];
    getCardOfEachSuit(arr, temp);

    int max = temp[0];
       for(int i=0;i<4;i++){
           if(max>temp[i]){
               max=temp[i];
               Smallest = i;
           }
       }
       return Smallest+1;
}

private boolean getIsBalanceHand(Cards[] arr){
    int S=0;int C=0;int D=0;int H=0;
        for(Cards x: arr){
            if(x.getColorName()=="Spade") S++;
            else  if(x.getColorName()=="Heart") H++;
            else  if(x.getColorName()=="Club") C++;
            else  D++;
        }
        if((S<=4&&S>=3)&&(H<=4&&H>=3)&&(D<=4&&D>=3)&&(C<=4&&C>=3)) return true;
        else return false;
}

private void getCardOfEachSuit(Cards[] arr, int[] array){
    int S=0;int C=0;int D=0;int H=0;
        for(Cards x: arr){
            if(x.getColorName()=="Spade") S++;
            else  if(x.getColorName()=="Heart") H++;
            else  if(x.getColorName()=="Club") C++;
            else  D++;
        }
        array[0] = S;
        array[1] = H;
        array[2] = D;
        array[3] = C;
    }
private int getNumberOfTrump(Cards[] arr){
    int temp = 0;
    for(Cards x: arr){
        if(x.getisTrump() == true) temp = temp+1;
    }
    return temp;
}
public void setTrickStarter(boolean a){
    this.trickStarter = a;
}
public boolean getTrickStarter(){
    return this.trickStarter;
}

private static Players[] Robots = new Players[3]; //
private int[] cardsOfEachSuit = new int[4]; // ok
private boolean[] remainingSpade = new boolean[13]; //
private boolean[] remainingHeart = new boolean[13]; //
private boolean[] remainingDiamond = new boolean[13]; //
private boolean[] remainingClub = new boolean[13]; //
private int scoreInHand; // ok
private int longestSuit; // ok
private int smallestSuit; // ok
private int strongestSuit; // ok
private int weakestSuit; // ok
private boolean isBalanceHand; // ok
private int numberOfTrump; // ok
private int numberOfTrumpExist; //
private boolean[] rightOpCutSuit = new boolean[4]; //
private boolean[] frontOpCutSuit = new boolean[4]; //
private boolean[] leftOpCutSuit = new boolean[4]; //
private int openingBet; //
private int respondingBet; // 
private boolean gcCaution; //
private boolean coatCaution; //
private boolean trickStarter;
}