title: Omaha Hi Hand Evaluator
body: <p>Currently I'm trying to port Keith Rule's Texas Holdem Hand Evaluator to Omaha Hi:</p>
  
  <ul>
  <li><a href="http://www.codeproject.com/KB/game/pokerhandevaldoc.aspx" rel="nofollow noreferrer">Texas Holdem Evaluator and Analysis</a> </li>
  <li><a href="http://www.codeproject.com/KB/game/MoreTexasHoldemAnalysis1.aspx" rel="nofollow noreferrer">More Analysis Part1</a></li>
  <li><a href="http://www.codeproject.com/KB/game/MoreTexasHoldemAnalysis2.aspx" rel="nofollow noreferrer">More Analysis Part 2</a></li>
  </ul>
  
  <p>After thinking more about the algorithm, I found a solution which gives me the right percentages for the hands and everything is fine..</p>
  
  <p>But it's really really slow. How can I speed things up?</p>
  
  <p>As the only thing I do right now is to look-up a normal five card hands, a LUT might be right for me. Anyone integrated one before?</p>
  
  <pre><code>static void Main(string[] args)
      {
          long count = 0;
          double player1win = 0.0, player2win=0.0;
          ulong player1 = Hand.ParseHand("Ad Kd As Ks");
          ulong player2 = Hand.ParseHand("Th 5c 2c 7d");
          foreach (ulong board in Hand.Hands(0, player1 | player2, 5))
          {
              uint maxplayer1value = 0, maxplayer2value = 0;
              foreach (ulong boardcards in Hand.Hands(0, ulong.MaxValue ^ board, 3))
              {
                  foreach (ulong player1hand in Hand.Hands(0Ul, ulong.MaxValue ^ player1, 2))
                  {
                      uint player1value = Hand.Evaluate(player1hand | boardcards, 5);
                      if (player1value &gt; maxplayer1value) maxplayer1value = player1value;
  
                  }
              }
              foreach (ulong boardcards in Hand.Hands(0, ulong.MaxValue ^ board, 3))
              {
                  foreach (ulong player2hand in Hand.Hands(0UL, ulong.MaxValue ^ player2, 2))
                  {
                      uint player2value = Hand.Evaluate(player2hand | boardcards, 5);
                      if (player2value &gt; maxplayer2value) maxplayer2value = player2value;
  
                  }
              }
  
              if (maxplayer1value &gt; maxplayer2value)
              {
                  player1win += 1.0;
              }
              else if (maxplayer2value &gt; maxplayer1value)
              {
                  player2win += 1.0;
              }
              else
              {
                  player1win += 0.5;
                  player2win += 0.5;
              }
              count++;
          }
          Console.WriteLine("Player1: {0:0.0000} Player2: {1:0.0000} Count: {2}", player1win / count * 100, player2win / count * 100, count);
          Console.ReadLine();       
      }
  </code></pre>