title: How to generate all permutations of a list of maps?
body: <p>I'm working on an algorithm for a skat-player. Therefore I need a List of Maps <code>List&lt;Map&lt;Player, CardList&gt;&gt;</code>. The map has always 3 players (FOREHAND, MIDDLEHAND, REARHAND) and the length of the CardList depends on number of tricks already played (if no trick is played the CardList has a length of 10). The player sitting ont the left side can have one card more than the player sitting on the right side (if the right player played a card in the current trick).</p>
  
  <p>Now I want to get all distributions of unknownCards on the hands of the other players. I started writing a method:</p>
  
  <pre><code>public class DistributionSimulator {
  
      public static List&lt;Map&lt;Player, CardList&gt;&gt; simulateAllCardDistributions(Player playerPosition,
              CardList playerHand, CardList notOpponentCards, CardList knownSkat, int noOfTricks) {
  
          List&lt;Map&lt;Player, CardList&gt;&gt; distributions = new ArrayList&lt;Map&lt;Player, CardList&gt;&gt;();
          Map&lt;Player, CardList&gt; singleDistribution = new HashMap&lt;Player, CardList&gt;();
  
          for (Player player : Player.values()) {
              // set empty card list
              singleDistribution.put(player, new CardList());
          }
  
          // sets the own player cards
          singleDistribution.get(playerPosition).addAll(playerHand);
  
          // get unknown cards
          CardDeck unknownCards = new CardDeck();
          unknownCards.removeAll(notOpponentCards);
  
          unknownCards.sort(null);
  
          CardList leftPlayerCards = singleDistribution.get(playerPosition.getLeftNeighbor());
          CardList rightPlayerCards = singleDistribution.get(playerPosition.getRightNeighbor());
  
          for (Card c : unknownCards) {
              if (leftPlayerCards.contains(c) || rightPlayerCards.contains(c)) {
                  continue;
              }
              leftPlayerCards.add(c);
              if (leftPlayerCards.size() &lt; 10 - noOfTricks) {
                  for (Card d : unknownCards) {
                      if (leftPlayerCards.contains(c) || rightPlayerCards.contains(c)) {
                          continue;
                      }
                      leftPlayerCards.add(d);
                      // ... and so on and so on, if (leftPlayerCards.size() == 10 - noOfTricks) { rightPlayerCards.addAll(allRemainedCards) }
                      // distributions.add(singleDistribution)
                  }
              }
          }
  
  
          return distributions;
      }
  
  }
  </code></pre>
  
  <p>This example doesn't work and isn't a good style as well. Actually I tried out something like  </p>
  
  <pre><code>if (unknownCards.size() == 20) { 
      then set 10 cards to the leftPlayer and 10 to the rightPlayer }; 
  if (unknownCards.size() == 19) { ... }.
  </code></pre>
  
  <p>Okay. Can anyone help me getting all permutations? I suggest that the answer is a recursion, but I don't have any idea.</p>