我正在研究一个skat-player的算法。因此,我需要一个地图列表List<Map<Player, CardList>>
。地图总是有3个玩家(FOREHAND,MIDDLEHAND,REARHAND),CardList的长度取决于已经玩过的技巧数量(如果没有玩法,CardList的长度为10)。坐在左侧的玩家可以比坐在右侧的玩家多一张牌(如果正确的玩家在当前技巧中玩牌)。
现在我希望将其他玩家手中的所有发明版本的未知卡片分开。我开始写一个方法:
public class DistributionSimulator {
public static List<Map<Player, CardList>> simulateAllCardDistributions(Player playerPosition,
CardList playerHand, CardList notOpponentCards, CardList knownSkat, int noOfTricks) {
List<Map<Player, CardList>> distributions = new ArrayList<Map<Player, CardList>>();
Map<Player, CardList> singleDistribution = new HashMap<Player, CardList>();
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() < 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;
}
}
这个例子不起作用,也不是一个好的风格。其实我试过像
这样的东西if (unknownCards.size() == 20) {
then set 10 cards to the leftPlayer and 10 to the rightPlayer };
if (unknownCards.size() == 19) { ... }.
好。任何人都可以帮助我获得所有排列吗?我建议答案是递归,但我不知道。