如何旋转起始播放器?

时间:2013-04-10 04:23:07

标签: java logic poker

我正在设计一款多人扑克游戏。我有人类和计算机对象,两者都实现了一个播放器界面,其中包含扑克玩家所需的方法。我有一个游戏中玩家的ArrayList,我需要去每个玩家并检查他们是否想要折叠他们的手或支架。如果每个人都弃牌,那么最后一个自动检查比赛的人就赢了。对于每手牌,首发球员需要旋转。第一手,ArrayList的索引0中的人将首先出现。第二只手,指数1中的人将首先出现。只是想要反思想法并听取人们对如何实现这些功能的看法。

最初我有想做这样的事情;

public void poker(ArrayList<Player> players){
   int foldCounter = 0;
   int starter = 0; 

   while (weWantToPlay){
      for (int j = starter; j < players.size(); j++){
         //get the players game plan
         players.get(j).getStand

         //the player is folding
         if (!player.stand()){
            foldCounter++;
            //doStuff
         else{
            //doStuff
         }
     }

     //do more stuff and play poker

     //increment starter so the next hand, the second person starts
     // this obviously will not work, cause we need go to the end of the list, then wrap around
     starter++;

     //check who's folded to see if we automatically have a winner
     if (foldCounter == players.size()-1){
        for (Player element:players){
           if (element.stand()){
              winner = element; 
              break;
           }
        }
     }
 }

}

2 个答案:

答案 0 :(得分:1)

我没有看到任何问题所以我不确定你要解决的问题是什么。

如果这是'首发问题':也许,你可以在你的队员列表中从0增加到1号大小,而不是使用你增加的首发,你完成后你可以在0号位置删除玩家并将其添加回列表的末尾,然后再次迭代等等。

答案 1 :(得分:0)

    I am not much aware of the game poker but as  per my understanding i understood that after each hand the starting player will be changed (i.e if A,B,C are three players then at first time A will be playing first then second time C will and third time B will be the first to play.

    If this is the requirement then you can keep on rotating the players after each round and put your logic to find the winner.

    The following code can be used for rotation


    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.List;

    public class Main {
      public static void main(String[] args) {
        List numbers = new ArrayList();

        for (int i = 0; i < 5; i++) {
          numbers.add(i);
        }

        System.out.println("Original Array -" + Arrays.toString(numbers.toArray()));

        for(int i=0;i<numbers.size();i++){
            Collections.rotate(numbers, 1);

            System.out.println("After "+ i +" Rotation  -"+ Arrays.toString(numbers.toArray()));

            System.out.println("Element at first position - " +numbers.get(0));
        }
      }
    }


    Output :-

    Original Array -[0, 1, 2, 3, 4]
    After 0 Rotation  -[4, 0, 1, 2, 3]
    Element at first position - 4
    After 1 Rotation  -[3, 4, 0, 1, 2]
    Element at first position - 3
    After 2 Rotation  -[2, 3, 4, 0, 1]
    Element at first position - 2
    After 3 Rotation  -[1, 2, 3, 4, 0]
    Element at first position - 1
    After 4 Rotation  -[0, 1, 2, 3, 4]
    Element at first position - 0



NOTE:If you want to make rotation is some other fashion just change the digit in the following line
Collections.rotate(numbers, 1);