简体   繁体   English

如何从卡列表中生成所有唯一的卡对?

[英]How can I generate all unique card pairs from a list of cards?

I am implementing a hand strength evaluator, which is to evaluate all possible pairs from the remaining 47 cards, after dealing one hand and the flop. 我正在实施一个手牌力量评估器,用于在处理单手和翻牌后评估其余47张牌中的所有可能对。

I have implemented the evaluator, but I'm missing all the possible combinations for which to compare. 我已经实现了评估器,但是我缺少要比较的所有可能的组合。 I am tempted to create a class for Hand, which consists of two cards, and store each combination in a set, HashSet. 我很想为Hand创建一个类,它由两张卡组成,并将每个组合存储在一个集合HashSet中。 Which data structure should i choose? 我应该选择哪种数据结构? If HashSet is best, then how can i force each instantiation of Hand to be unique? 如果HashSet是最好的,那么我如何强制Hand的每个实例化都是唯一的?

HashSet seems reasonable although since ordering might matter later you might want to consider a TreeSet . HashSet看起来很合理,但由于排序可能稍后TreeSet您可能需要考虑TreeSet If you implements the equals and compareTo / Comparable methods in Hand the Set will force uniqueness. 如果在Hand实现equalscompareTo / Comparable方法,则Set将强制唯一性。

I would number the cards or place them in a List. 我会给卡片编号或将它们放在一个列表中。

If you use a list you can do 如果您使用列表,则可以执行此操作

Set<Card> inHand = ...
for(int i=0;i<list.size();i++) {
  Card card1 = list.get(i);
  if (inHand.contains(card1)) continue;

  for(int j=i+1;j<list.size();j++) {
      Card card2 = list.get(j);
      if (inHand.contains(card2)) continue;

      // process card1 and card2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从唯一的字符串生成唯一的 int? - how can i generate a unique int from a unique string? 从数字列表中生成所有唯一对,n选择2 - generating all unique pairs from a list of numbers, n choose 2 在动态创建的卡片视图上,如果按下特定于卡片的删除按钮,如何删除单个卡片? - On a card view created dynamically, how can I remove individual cards if a delete button specific to a card is pressed? 如何从卡上的按钮切换卡? - How to switch cards from a button on a card? 在BlackJack游戏中,如何将我绘制的2张卡的值添加到我刚刚绘制的卡值中 - How can I add the value of 2 cards that I drew, into the card value that i just draw, in a game of BlackJack 如何在运行时生成卡片视图以显示来自 Sqlite 的数据? - How can I Generate Card view at run time to display data from Sqlite? 我如何在Java中建立卡片改组方法以使卡片按特定顺序排列? - how can i build a card shuffling method in java for cards to go in a specific order? 如何生成 LogN 唯一数字的排序列表,其中 N 是数组的给定大小? - How can I generate a sorted list of LogN unique numbers, where N is the given size of the array? 我如何在 Java 中生成一副纸牌? - How do i generate a deck of cards in Java? 如何从键/值对列表中检索给定键对中的值? - How can I retrieve a value from a list of key/value pairs with the key from a given pair?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM