7 Card Poker Hand Evaluator

前端 未结 9 751
死守一世寂寞
死守一世寂寞 2021-01-30 01:30

Does anyone know a fast algorithm for evaluating 7 card poker hands? Something which is more efficient than simply brute-force checking a every 21 5-card combination of hands fr

9条回答
  •  鱼传尺愫
    2021-01-30 02:05

    I wrote one in JavaScript. The core evaluating method uses only bit manipulations so is extremely fast. With this in mind, looking at 21 combinations is still very fast. The only time we need to go deeper is when a tie occurs. When this happens, we need to look into more details to see which 5 card hand is actually the best. Here is the solution I came up with:

    hands=["4 of a Kind", "Straight Flush", "Straight", "Flush", "High Card",
           "1 Pair", "2 Pair", "Royal Flush", "3 of a Kind", "Full House" ];
    var A=14, K=13, Q=12, J=11, _ = { "♠":1, "♣":2, "♥":4, "♦":8 };
    
    //Calculates the Rank of a 5 card Poker hand using bit manipulations.
    function rankPokerHand(cs,ss) {
      var v, i, o, s = 1<");
    }
    
    //Royal Flush   
    rankPokerHand( [ 10, J, Q, K, A],  [ _["♠"], _["♠"], _["♠"], _["♠"], _["♠"] ] ); 
    

    Explanation Here
    Demo Here

提交回复
热议问题