Long, long ago, there was this article. That article spawned a meteor.js application that was a fully featured poker game, with an overly large GIF engine (for 2014), with which we whiled away a fair amount of time. Time moved…
Long, long ago, there was this article. That article spawned a meteor.js application that was a fully featured poker game, with an overly large GIF engine (for 2014), with which we whiled away a fair amount of time. Time moved…
Introduction subskybox wrote an intimidating 5-card poker hand analyzer in four lines of JavaScript. The original is somewhat tricky to understand initially:
1 2 3 4 5 6 7 8 9 10 11 |
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 }; function rankPokerHand(cs,ss) { var v, i, o, s = 1<<cs[0]|1<<cs[1]|1<<cs[2]|1<<cs[3]|1<<cs[4]; for (i=-1, v=o=0; i<5; i++, o=Math.pow(2,cs[i]*4)) {v += o*((v/o&15)+1);} v = v % 15 - ((s/(s&-s) == 31) || (s == 0x403c) ? 3 : 1); v -= (ss[0] == (ss[1]|ss[2]|ss[3]|ss[4])) * ((s == 0x7c00) ? -5 : 1); document.write("Hand: " + hands[v] + (s == 0x403c?" (Ace low)":"")+"<br/>"); } |
Of course, by somewhat tricky I mean extremely tricky, and by initially I mean always. The shock and…