Есть ли более простой способ вычислить стрит в покере?

У меня есть алгоритм для вычисления того, держит ли рука игрока стрит в Техасском Холдеме. Он работает нормально, но мне интересно, есть ли более простой способ сделать это, не требующий преобразования массива / строки и т. Д.

Вот упрощенная версия того, что у меня есть. Скажем, игроку раздали руку, которая представляет собой массив значений карт из 52 элементов:

var rawHand = [1,0,0,0,0,0,0,0,0,0,0,0,0, //clubs
               0,0,0,0,0,0,0,0,0,0,0,0,0, //diamonds
               0,1,1,0,1,0,0,0,0,0,0,0,0, //hearts
               0,0,0,1,0,0,0,0,1,0,0,0,0];//spades

1 представляет карту в этом слоте значений. Вышеупомянутая рука имеет 2 трефы, без бубен, 3 червы, 4 червы и 6 червей, 5 пик и 10 пик. Теперь я смотрю на него, чтобы найти стрит.

var suits = []; //array to hold representations of each suit

for (var i=0; i<4; i++) {
    var index = i*13;
    // commenting this line as I removed the rest of its use to simplifyy example
    //var hasAce = (rawHand[i+13]);

    //get a "suited" slice of the rawHand, convert it to a string representation
    //of a binary number, then parse the result as an integer and assign it to
    //an element of the "suits" array
    suits[i] = parseInt(rawHand.slice(index,index+13).join(""),2);
}

// OR the suits    
var result = suits[0] | suits[1] | suits[2] | suits[3];

// Store the result in a string for later iteration to determine
// whether straight exists and return the top value of that straight
// if it exists; we will need to determine if there is an ace in the hand
// for purposes of reporting a "low ace" straight (i.e., a "wheel"),
// but that is left out in this example
var resultString = result.toString(2);

//Show the result for the purposes of this example
alert("Result: " + resultString);

Уловка здесь состоит в том, чтобы ИЛИ различных мастей, так что есть только одно представление 2-to-Ace. Я ошибаюсь, полагая, что должен быть более простой способ сделать это?

5
задан Robusto 23 October 2010 в 18:25
поделиться