Tag: 扑克

c#直接检查扑克

我正在尝试用c#编写一个扑克手评估方法。 我已经成功地使用linq为每个扑克手做了这个,除了直线。 对于那些不玩直线的人,每张卡由5张卡组成,增量为1。 Ace可以高或低。 我创建了一个名为card的对象,它具有套装,等级和值(J = 11,Q = 12等等)。 我的方法将传递一个包含7张卡(孔卡和棋盘)的对象列表。 另外要记住的是,如果玩家有5或10,则只能进行直线操作。 请参阅下面我的其他扑克手的方法,如果您对直接方法有所了解,请告诉我。 伪代码也没关系。 public bool CheckPair(List cards) { //see if exactly 2 cards card the same rank. return cards.GroupBy(card => card.Rank).Count(group => group.Count() == 2) == 1; } public bool CheckTwoPair(List cards) { //see if there are 2 lots of exactly 2 cards card the […]

优化查找:字典键查找与数组索引查找

我正在写一个7卡扑克手评估员作为我的宠物项目之一。 在尝试优化速度时(我喜欢挑战),我惊讶地发现,与数组索引查找相比,Dictionary键查找的性能相当慢。 例如,我运行了这个示例代码,列举了所有52个选择7 = 133,784,560个可能的7个牌手: var intDict = new Dictionary(); var intList = new List(); for (int i = 0; i < 100000; i ++) { intDict.Add(i, i); intList.Add(i); } int result; var sw = new Stopwatch(); sw.Start(); for (int card1 = 0; card1 < 46; card1++) for (int card2 = card1 + 1; card2 […]