View Single Post
Old 2012-02-08, 21:39   #8
Bundu
 
Bundu's Avatar
 
Jul 2004
Mid Calder, Scotland

101110012 Posts
Default

If anyone is interested here was my attempt at flush determination! I thought it was only fair to post my work

Code:
<!doctype html>
<head>
 
<style>
 
 
<script type="text/javascript">
 
newline = "<br />"
 
tc1 = document.getElementById('topC1')
tc2 = document.getElementById('topC2')
 
tabc1 = document.getElementById('tableC1')
tabc2 = document.getElementById('tableC2')
tabc3 = document.getElementById('tableC3')
tabc4 = document.getElementById('tableC4')
tabc5 = document.getElementById('tableC5')
 
bc1 = document.getElementById('botC1')
bc1 = document.getElementById('botC2')
 
 
//This generates the card array obtained from http://mickweb.com/javascript/arrays/userDefinedSortingArrays4.html
A= new Array();
 
S = ["h","d","c","s"];
N = [2,3,4,5,6,7,8,9,10,11,12,13,14];
 
for(var j=0;j<S.length;j++){
  for(var i=0;i<N.length;i++){
    A[A.length]=S[j]+N[i];
  }
}
 
// Here is a shuffler by/at:  + Jonas Raoni Soares Silva + http://jsfromhell.com/array/shuffle [rev. #1]
shuffle = function(v){
    for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
    return v;
};
 
 
function init() {
//alert(A);
document.getElementById('startdeck').innerHTML="The Deck is currently stacked like this: " + A;
document.getElementById('shuffleddeck').innerHTML="The Deck has been shuffled to: " + shuffle(A);
 
player1Hand= A[0] + ", " + A[2];
player2Hand= A[1] + ", " + A[3];
theFlop= A[4] + ", " + A[5] + ", " + A[6];
theTurn= A[7]
theRiver= A[8]
 
document.getElementById('predeal').innerHTML="SKULL will have: " + player1Hand + "<br />The Flop: " + theFlop + ", " + theTurn + ", " + theRiver + "<br />BUNDU will have: " + player2Hand;
 
 
//CREATE ARRAYS FOR HANDS AND FLOPS AND COMBINED STRIPPING OUT NUMERICAL CARD VALUE ONLY
numP1 = [A[0].substring(1),A[2].substring(1)]
suiP1 = [A[0].substring(0,1),A[2].substring(0,1)]
numP1.sort(function(a,b){return a - b});
 
numP2 = [A[1].substring(1),A[3].substring(1)]
suiP2 = [A[1].substring(0,1),A[3].substring(0,1)]
numP2.sort(function(a,b){return a - b});
 
numFlop = [A[4].substring(1),A[5].substring(1),A[6].substring(1),A[7].substring(1),A[8].substring(1)];
suiFlop = [A[4].substring(0,1),A[5].substring(0,1),A[6].substring(0,1),A[7].substring(0,1),A[8].substring(0,1)];
numFlop.sort(function(a,b){return a - b});
 
numLongP1 = [A[0].substring(1),A[2].substring(1),A[4].substring(1),A[5].substring(1),A[6].substring(1),A[7].substring(1),A[8].substring(1)];
suiLongP1 = [A[0].substring(0,1),A[2].substring(0,1),A[4].substring(0,1),A[5].substring(0,1),A[6].substring(0,1),A[7].substring(0,1),A[8].substring(0,1)];
numLongP1.sort(function(a,b){return a - b});
 
numLongP2 = [A[1].substring(1),A[3].substring(1),A[4].substring(1),A[5].substring(1),A[6].substring(1),A[7].substring(1),A[8].substring(1)];
suiLongP2 = [A[1].substring(0,1),A[3].substring(0,1),A[4].substring(0,1),A[5].substring(0,1),A[6].substring(0,1),A[7].substring(0,1),A[8].substring(0,1)];
numLongP1.sort(function(a,b){return a - b});
 
suitcounterp1(suiLongP1, 1);
suitcounterp2(suiLongP2, 2);
 
document.getElementById('debug').innerHTML=numP1 + "<br />" + suiP1 + "<br />" + numFlop + "<br />" + suiFlop + "<br />" + numLongP1 + "<br />" + suiLongP1 + "<br />" + flush1 + "<br />" + flush2;
}
 
function suitcounterp1(passedArray, player) {
var s1,s2,s3,s4,i;
s1=0;
s2=0;
s3=0;
s4=0;
flush1 = "Player " + player + " has no Flush";
       for (i=0; i< passedArray.length; i++) {
          switch (passedArray[i]) {
            case "h": s1++; break;
            case "d": s2++; break;
            case "c": s3++; break;
            case "s": s4++; break;
            default:
          }
       }
      
       //alert (s1 + "," + s2 + "," + s3 + "," + s4)
    if (s1>4 || s2>4 || s3>4 || s4>4) {
        flush1 = "Player " + player + " has a Flush!"; 
    }
}
 
function suitcounterp2(passedArray, player) {
var s1,s2,s3,s4,i;
s1=0;
s2=0;
s3=0;
s4=0;
flush2 = "Player " + player + " has no Flush";
       for (i=0; i< passedArray.length; i++) {
          switch (passedArray[i]) {
            case "h": s1++; break;
            case "d": s2++; break;
            case "c": s3++; break;
            case "s": s4++; break;
            default:
          }
       }
      
       //alert (s1 + "," + s2 + "," + s3 + "," + s4)
    if (s1>4 || s2>4 || s3>4 || s4>4) {
        flush2 = "Player " + player + " has a Flush!"; 
    }
}
 
window.onload=init;
 
</script>
 
 
 
</head>
 
<body>
 
<div id="outerwrap" class="">
<br />
<br />
<div id="startdeck"></div>
<div id="shuffleddeck"></div>
<div id="predeal"></div>
<div id="allcards1"></div>
<div id="debug"></div>
<br />
 
 
</div>
 
</body>
 
</html>
Bundu is offline   Reply With Quote