PDA

View Full Version : Computer science java script project


hurricaneace67
05-15-2006, 06:54 PM
if anyone could help me with this i would really appreciate it. okay so i have to make a 5 card poker game. i have it so there are 5 cards and when you click the button it deals out five random cards without repeating any cards. But now i need to do the logic for checking to see if the player wins. The hand rankings i need to do are four of a kind, flush, three of a kind, two pair, and one pair. i am stumped here. if it helps i am using an array in which each card is assigned a number. anybody have any ideas?

TomCollins
05-15-2006, 07:16 PM
The easiest way to figure out pairs/trips/etc.. is to iterate through your cards and see how many pairs you have. For example, check 1 against 2 thru 5. Then check 2 against 3 thru 5. Count a pair if any of them match.

If the number of pairs is 1, obviously 1 pair.
If you get 2- 2 pair
3- Trips
4- Full House
6- Quads

hurricaneace67
05-15-2006, 07:37 PM
what i am struggling with is that how will one card ever equal the other since each element of the array is the number and suit of the card

dtbog
05-15-2006, 07:46 PM
[ QUOTE ]
what i am struggling with is that how will one card ever equal the other since each element of the array is the number and suit of the card

[/ QUOTE ]

1-4 are deuces
5-8 are treys
...

if ( (x / 13) == (y / 13) {
...cards are same rank
} else {
...nope
}

hurricaneace67
05-15-2006, 07:56 PM
would it help if i showed u what i have so far?

<html>

<head>
<title>Dan's Cards</title>

<script>
var random1;
var ramdom2;
var random3;
var random4;
var random5;
var cards = new Array();
cards[0]="ah.jpg";
cards[1]="2h.jpg";
cards[2]="3h.jpg";
cards[3]="4h.jpg";
cards[4]="5h.jpg";
cards[5]="6h.jpg";
cards[6]="7h.jpg";
cards[7]="8h.jpg";
cards[8]="9h.jpg";
cards[9]="10h.jpg";
cards[10]="jh.jpg";
cards[11]="qh.jpg";
cards[12]="kh.jpg";
cards[13]="ad.jpg";
cards[14]="2d.jpg";
cards[15]="3d.jpg";
cards[16]="4d.jpg";
cards[17]="5d.jpg";
cards[18]="6d.jpg";
cards[19]="7d.jpg";
cards[20]="8d.jpg";
cards[21]="9d.jpg";
cards[22]="10d.jpg";
cards[23]="jd.jpg";
cards[24]="qd.jpg";
cards[25]="kd.jpg";
cards[26]="as.jpg";
cards[27]="2s.jpg";
cards[28]="3s.jpg";
cards[29]="4s.jpg";
cards[30]="5s.jpg";
cards[31]="6s.jpg";
cards[32]="7s.jpg";
cards[33]="8s.jpg";
cards[34]="9s.jpg";
cards[35]="10s.jpg";
cards[36]="js.jpg";
cards[37]="qs.jpg";
cards[38]="ks.jpg";
cards[39]="ac.jpg";
cards[40]="2c.jpg";
cards[41]="3c.jpg";
cards[42]="4c.jpg";
cards[43]="5c.jpg";
cards[44]="6c.jpg";
cards[45]="7c.jpg";
cards[46]="8c.jpg";
cards[47]="9c.jpg";
cards[48]="10c.jpg";
cards[49]="jc.jpg";
cards[50]="qc.jpg";
cards[51]="kc.jpg";

function deal()
{
random1=Math.floor(Math.random()*52);
random2=Math.floor(Math.random()*52);
random3=Math.floor(Math.random()*52);
random4=Math.floor(Math.random()*52);
random5=Math.floor(Math.random()*52);
message = "";

while(random1 == (random2 || random3 || random4 || random5))
{
random1 = Math.floor(Math.random()*52);
}
while(random2 == (random1 || random3 || random4 || random5))
{
random2 = Math.floor(Math.random()*52);
}
while(random3 == (random1 || random2 || random4 || random5))
{
random3 = Math.floor(Math.random()*52);
}
while(random4 == (random1 || random2 || random3 || random5))
{
random4 = Math.floor(Math.random()*52);
}
while(random5 == (random1 || random2 || random3 || random4))
{
random5 = Math.floor(Math.random()*52);
}

document.card1.src= './cards/' + cards[random1];
document.card2.src= './cards/' + cards[random2];
document.card3.src= './cards/' + cards[random3];
document.card4.src= './cards/' + cards[random4];
document.card5.src= './cards/' + cards[random5];
}
</script>

</head>

<body>
<table align='center' border='1'>
<tr align='center'><td colspan='5'><h2>Cards</h2></td></tr>

<tr><td><img id='card1' src='./cards/card.jpg'></td><td><img id='card2' src='./cards/card.jpg'></td><td><img id='card3' src='./cards/card.jpg'></td><td><img id='card4' src='./cards/card.jpg'></td><td><img id='card5' src='./cards/card.jpg'></td></tr>
<tr align='center'><td id='the_message' colspan='5'>Click the 'deal cards' button to deal your hand.</td></tr>
<tr align='center'><td colspan='5'><input type='button' value='Deal Cards' onclick='deal()'></td></tr>
</table>


</body>

</html>

dtbog
05-15-2006, 07:58 PM
[ QUOTE ]
would it help if i showed u what i have so far?

[/ QUOTE ]

No.

I told you how to do it; do your own homework.

dtbog
05-15-2006, 07:59 PM
[ QUOTE ]
[ QUOTE ]
would it help if i showed u what i have so far?

[/ QUOTE ]

No.

I told you how to do it; do your own homework.

[/ QUOTE ]

To clarify: if you can't figure out how the advice I gave you can be adjusted to compensate for the fact that you ordered the cards' array indices by suit instead of by number, then you're not cut out for this 'programming' thing.

hurricaneace67
05-15-2006, 08:09 PM
i never claimed to be a programmer, just needed a credit so i took basic computer science

hurricaneace67
05-15-2006, 08:25 PM
[ QUOTE ]
[ QUOTE ]
what i am struggling with is that how will one card ever equal the other since each element of the array is the number and suit of the card

[/ QUOTE ]

1-4 are deuces
5-8 are treys
...

if ( (x / 13) == (y / 13) {
...cards are same rank
} else {
...nope
}

[/ QUOTE ]

what are u referring to by x and y? for x/13 to = y/13 then x would have to equal y, but you cant have two of the same card? or would you use two arrays-- one for suits one for numbers?

TomCollins
05-15-2006, 08:43 PM
[ QUOTE ]
[ QUOTE ]
[ QUOTE ]
what i am struggling with is that how will one card ever equal the other since each element of the array is the number and suit of the card

[/ QUOTE ]

1-4 are deuces
5-8 are treys
...

if ( (x / 13) == (y / 13) {
...cards are same rank
} else {
...nope
}

[/ QUOTE ]

what are u referring to by x and y? for x/13 to = y/13 then x would have to equal y, but you cant have two of the same card? or would you use two arrays-- one for suits one for numbers?

[/ QUOTE ]

I don't know Java, but usually integer division is truncated. 15/13 = 1, 26/13 = 2, 27/13 = 2, etc...

TomCollins
05-15-2006, 08:46 PM
Btw- I think this line is wrong.

while(random1 == (random2 || random3 || random4 || random5))

If you still have a chance to drop this class, you probably should. I think you are in way above your head.

DougShrapnel
05-15-2006, 09:00 PM
[ QUOTE ]
what i am struggling with is that how will one card ever equal the other since each element of the array is the number and suit of the card

[/ QUOTE ] use
(indexOf(card)+1)mod13 to get rank.
use math.floor(indexOf(card)+1)/ 13)) to get suit. Or something like that. And I'm not sure if you random process is the best, or even if it will work.

hurricaneace67
05-15-2006, 09:42 PM
lol tom little late for that. school ends in 2 weeks and this is the last project of the year. ive gotten As in the class, but this one is tough. and no i do not plan on pursuing computer programming in the future lol

Leaky Eye
05-15-2006, 10:05 PM
[ QUOTE ]
And I'm not sure if you random process is the best, or even if it will work.

[/ QUOTE ]

http://en.wikipedia.org/wiki/Shuffling#Shuffling_algorithms

TomCollins
05-15-2006, 11:53 PM
An optimal shuffling algorithm is to take an array of 52 integers from 0 to 51 representing the cards. Since you only need 5 cards, you can shuffle 5 cards deep.

For the first card, pick a random number (x) between 0 and 51. Swap array element 0 with element x. Then pick a number (y) between 1 and 51. Swap array element 1 with y. Continue this 3 more times and you will get a true shuffle for 5 cards with minimal work.

This is explained in the article, but you only need to go 5 deep for this project.

hurricaneace67
05-16-2006, 04:56 PM
hey all, i have figured out how to do it! I think this is sort of what people were telling me. I believe it's called modulo, or something like that. if the remainders of the random number divided by 13 are equal then they are the same rank.

Quads
if(random1%13==random2%13 && random 2%13==random3%13 && random3%13==random4%13 ||

random1%13==random2%13 && random 2%13==random3%13 && random3%13==random5%13 ||

random1%13==random2%13 && random 2%13==random4%13 && random4%13==random5%13 ||

random1%13==random3%13 && random 3%13==random4%13 && random4%13==random5%13 ||

random2%13==random3%13 && random 3%13==random4%13 && random4%13==random5%13)
{
alert("You got quads!");
}

and then else if for the rest of the hand rankings

TomCollins
05-16-2006, 06:46 PM
The method you describe here are a lot easier if you just count up how many "pairs you have. Compaare 1 to 2 3 4 5, 2 to 3 4 5, 3 to 4 5, 4 to 5, and see how many pairs you get.

count = 0;
if (random1%13 == random2%13)
count++;
if (random1%13 == random3%13)
count ++;
....

if (random4%13 == random5%13)
count++;
if (count==0)
alert("you have high card, a straight, or a flush, or a straight flush");
if (count==1)
alert("you have a pair");
if (count==2)
alert("you have two pair");
if (count==3)
alert("you have three of a kind");
if (count==4)
alert("you have a full house");
if (count==6)
alert("you have quads");

hurricaneace67
05-16-2006, 07:49 PM
EDIT: I AM RETARDED
realized it should be if(random1 >=0 && <=12 && random2 >=0 && <=12 && random3 >=0 && <=12 && random4 >=0 && <=12 && random5 >=0 && <=12)
it works now!

the problem with that tom is i need to do flush. i just did it my way. its a lot of typing but very easy. i've got quads, trips, two pair and pair working. im trying to do flush now. do you have any ideas?

i tried if(random1 >=0 || <=12 && random2 >=0 || <=12 && random3 >=0 || <=12 && random4 >=0 || <=12 && random5 >=0 || <=12)

but that didnt work. it just said everything was a flush

hurricaneace67
05-16-2006, 08:05 PM
[ QUOTE ]
Btw- I think this line is wrong.

while(random1 == (random2 || random3 || random4 || random5))

If you still have a chance to drop this class, you probably should. I think you are in way above your head.

[/ QUOTE ]

why is it wrong? the while statement makes it so that the same card won't show up twice.

i have all the hands done. now i gotta add the betting.
here's what i have so far. http://dan.122blue.com/

madnak
05-16-2006, 08:31 PM
(random2 || random3 || random4 || random5) will evaluate to 0 or 1. You need to use something like

while((random1==random2) || (random1==random3) || (random1==random4) || (random1==random5))

DougShrapnel
05-16-2006, 08:37 PM
[ QUOTE ]
[ QUOTE ]
Btw- I think this line is wrong.

while(random1 == (random2 || random3 || random4 || random5))

If you still have a chance to drop this class, you probably should. I think you are in way above your head.

[/ QUOTE ]

why is it wrong? the while statement makes it so that the same card won't show up twice.

i have all the hands done. now i gotta add the betting.
here's what i have so far. http://dan.122blue.com/

[/ QUOTE ]It's wrong because try and shuffle 52 cards that way. It's lame. It's not encapsulated or polymorphic. It's also wrong because I just don't see what it does?

Doesn't this "random2 || random3 || random4 || random5)" evalute to true or false? So, while(random == (true Or false) is always false? Now even if I am wrong about the expression what if random2 and random5 are the same. It's a shoddy way to code.

Create a Card object. Create a Deck object with a shuffle and deal methods and a 52 card object array. Use deck.shuffle() and deck.deal() methods.

madnak
05-16-2006, 09:01 PM
I think you guys are going overboard. He's just getting confused. Any solution he comes up with is going to be pretty dirty. He's not going to be willing or able to implement a Knuth shuffle, and he probably doesn't even know what an object is.

TomCollins
05-16-2006, 09:06 PM
[ QUOTE ]
I think you guys are going overboard. He's just getting confused. Any solution he comes up with is going to be pretty dirty. He's not going to be willing or able to implement a Knuth shuffle, and he probably doesn't even know what an object is.

[/ QUOTE ]

A Knuth shuffle is actually simpler than what hes doing.

madnak
05-16-2006, 09:13 PM
Easier in terms of implementation, not in terms of theory. And it wouldn't be simpler given his setup. Remember he's using the array index to determine rank and suit, the array has to remain static.

TomCollins
05-16-2006, 09:20 PM
[ QUOTE ]
Easier in terms of implementation, not in terms of theory. And it wouldn't be simpler given his setup. Remember he's using the array index to determine rank and suit, the array has to remain static.

[/ QUOTE ]

He only needs to make an array of 52 integers, and swap 5 times. Seems pretty simple to me.

It's funny because we use this exact question to interview people.

DougShrapnel
05-16-2006, 09:22 PM
[ QUOTE ]
I think you guys are going overboard. He's just getting confused. Any solution he comes up with is going to be pretty dirty. He's not going to be willing or able to implement a Knuth shuffle, and he probably doesn't even know what an object is.

[/ QUOTE ]

fine, I'll be nice
All of this

[ QUOTE ]
{
random1=Math.floor(Math.random()*52);
random2=Math.floor(Math.random()*52);
random3=Math.floor(Math.random()*52);
random4=Math.floor(Math.random()*52);
random5=Math.floor(Math.random()*52);
message = "";

while(random1 == (random2 || random3 || random4 || random5))
{
random1 = Math.floor(Math.random()*52);
}
while(random2 == (random1 || random3 || random4 || random5))
{
random2 = Math.floor(Math.random()*52);
}
while(random3 == (random1 || random2 || random4 || random5))
{
random3 = Math.floor(Math.random()*52);
}
while(random4 == (random1 || random2 || random3 || random5))
{
random4 = Math.floor(Math.random()*52);
}
while(random5 == (random1 || random2 || random3 || random4))
{
random5 = Math.floor(Math.random()*52);
}



[/ QUOTE ] Becomes this. You should just use the shuffle they are talking about. But if you insist on doing it your way.
random1=Math.floor(Math.random()*52);

do(
random2=Math.floor(Math.random()*52);)
while(random2 == random1)

do(
random3=Math.floor(Math.random()*52);)
while((random1 == random3) Or (random2 == random3))

do(
random4=Math.floor(Math.random()*52);)
while(
(random4 == random3) OR (random4 == random2) OR (random4 == random1) Or (random4 == random1))

random5=Math.floor(Math.random()*52);
I'll let him type out #5
message = "";

edit and change random1, random2... to card1, card2.. for readability reasons.

madnak
05-16-2006, 09:32 PM
Right now he just needs to alter his conditional statements and he's all set. The fact it's an interview question is a perfect example of why it's too much; this is something a software engineer is supposed to know, not a guy who took an intro course to grab a credit.

hurricaneace67
05-16-2006, 10:01 PM
well this is a high school level computer tools I and II class. i havn't learned about a lot of what you guys are saying, and i think my teacher would find it odd if my code ha d all this stuff we had never learned. the while loop serves it's purpose for me though. it makes it so that 5 different cards come up. i realize that it might not be the best shuffling method, but again this is just a high school project.

my code might be ugly, but it is working perfectly right now. now i am working on adding betting and so that you can check a box to hold cards.

<html>

<head>
<title>Dan's Cards</title>

<script>
var random1;
var ramdom2;
var random3;
var random4;
var random5;
var cards = new Array();
cards[0]="ah.jpg";
cards[1]="2h.jpg";
cards[2]="3h.jpg";
cards[3]="4h.jpg";
cards[4]="5h.jpg";
cards[5]="6h.jpg";
cards[6]="7h.jpg";
cards[7]="8h.jpg";
cards[8]="9h.jpg";
cards[9]="10h.jpg";
cards[10]="jh.jpg";
cards[11]="qh.jpg";
cards[12]="kh.jpg";
cards[13]="ad.jpg";
cards[14]="2d.jpg";
cards[15]="3d.jpg";
cards[16]="4d.jpg";
cards[17]="5d.jpg";
cards[18]="6d.jpg";
cards[19]="7d.jpg";
cards[20]="8d.jpg";
cards[21]="9d.jpg";
cards[22]="10d.jpg";
cards[23]="jd.jpg";
cards[24]="qd.jpg";
cards[25]="kd.jpg";
cards[26]="as.jpg";
cards[27]="2s.jpg";
cards[28]="3s.jpg";
cards[29]="4s.jpg";
cards[30]="5s.jpg";
cards[31]="6s.jpg";
cards[32]="7s.jpg";
cards[33]="8s.jpg";
cards[34]="9s.jpg";
cards[35]="10s.jpg";
cards[36]="js.jpg";
cards[37]="qs.jpg";
cards[38]="ks.jpg";
cards[39]="ac.jpg";
cards[40]="2c.jpg";
cards[41]="3c.jpg";
cards[42]="4c.jpg";
cards[43]="5c.jpg";
cards[44]="6c.jpg";
cards[45]="7c.jpg";
cards[46]="8c.jpg";
cards[47]="9c.jpg";
cards[48]="10c.jpg";
cards[49]="jc.jpg";
cards[50]="qc.jpg";
cards[51]="kc.jpg";

function deal()
{




random1=Math.floor(Math.random()*52);
random2=Math.floor(Math.random()*52);
random3=Math.floor(Math.random()*52);
random4=Math.floor(Math.random()*52);
random5=Math.floor(Math.random()*52);
/*random1 = 1;
random2 = 2;
random3 = 3;
random4 = 4;
random5 = 5;*/


while(random1 == (random2 || random3 || random4 || random5))
{
random1 = Math.floor(Math.random()*52);
}
while(random2 == (random1 || random3 || random4 || random5))
{
random2 = Math.floor(Math.random()*52);
}
while(random3 == (random1 || random2 || random4 || random5))
{
random3 = Math.floor(Math.random()*52);
}
while(random4 == (random1 || random2 || random3 || random5))
{
random4 = Math.floor(Math.random()*52);
}
while(random5 == (random1 || random2 || random3 || random4))
{
random5 = Math.floor(Math.random()*52);
}

document.card1.src= './cards/' + cards[random1];
document.card2.src= './cards/' + cards[random2];
document.card3.src= './cards/' + cards[random3];
document.card4.src= './cards/' + cards[random4];
document.card5.src= './cards/' + cards[random5];

//Four of a kind
if(random1%13==random2%13 && random2%13==random3%13 && random3%13==random4%13 ||

random1%13==random2%13 && random2%13==random3%13 && random3%13==random5%13 ||

random1%13==random2%13 && random2%13==random4%13 && random4%13==random5%13 ||

random1%13==random3%13 && random3%13==random4%13 && random4%13==random5%13 ||

random2%13==random3%13 && random3%13==random4%13 && random4%13==random5%13)
{
alert("You got Four of a kind!");
}
else if(
(random1 >= 0 && random1 <= 12) && (random2 >= 0 && random2 <= 12) && (random3 >= 0 && random3 <= 12) && (random4 >= 0 && random4 <= 12) && (random5 >= 0 && random5 <= 12)
(random1 >= 13 && random1 <= 25) && (random2 >= 13 && random2 <= 25) && (random3 >= 13 && random3 <= 25) && (random4 >= 13 && random4 <= 25) && (random5 >= 13 && random5 <= 25)
(random1 >= 26 && random1 <= 38) && (random2 >= 26 && random2 <= 38) && (random3 >= 26 && random3 <= 38) && (random4 >= 26 && random4 <= 38) && (random5 >= 26 && random5 <= 38)
(random1 >= 39 && random1 <= 51) && (random2 >= 39 && random2 <= 51) && (random3 >= 39 && random3 <= 51) && (random4 >= 39 && random4 <= 51) && (random5 >= 39 && random5 <= 51))
{
alert("You got a Flush!");
}
//Three of a kind
else if(random1%13==random2%13 && random2%13==random3%13 ||
random1%13==random2%13 && random2%13==random4%13 ||
random1%13==random2%13 && random2%13==random5%13 ||
random1%13==random3%13 && random3%13==random4%13 ||
random1%13==random3%13 && random3%13==random5%13 ||
random1%13==random4%13 && random4%13==random5%13 ||
random2%13==random3%13 && random3%13==random4%13 ||
random2%13==random3%13 && random3%13==random5%13 ||
random2%13==random4%13 && random4%13==random5%13 ||
random3%13==random4%13 && random4%13==random5%13)
{
alert("You got Three of a kind!");
}
else if(random1 % 13 == random2 % 13 && random3 % 13 == random4 % 13 ||
random1 % 13 == random2 % 13 && random3 % 13 == random5 % 13 ||
random1 % 13 == random2 % 13 && random4 % 13 == random5 % 13 ||
random1 % 13 == random3 % 13 && random4 % 13 == random5 % 13 ||
random1 % 13 == random3 % 13 && random2 % 13 == random4 % 13 ||
random1 % 13 == random3 % 13 && random2 % 13 == random5 % 13 ||
random1 % 13 == random4 % 13 && random2 % 13 == random3 % 13 ||
random1 % 13 == random4 % 13 && random2 % 13 == random5 % 13 ||
random1 % 13 == random4 % 13 && random3 % 13 == random5 % 13 ||
random1 % 13 == random5 % 13 && random2 % 13 == random3 % 13 ||
random1 % 13 == random5 % 13 && random2 % 13 == random4 % 13 ||
random1 % 13 == random5 % 13 && random3 % 13 == random4 % 13)
{
alert("You got Two Pair!");
}

else if(random1 %13 == random2 %13 || random1 %13 == random3 %13 ||
random1 %13 == random4 %13 || random1 %13 == random5 %13 ||
random2 %13 == random3 %13 || random2 %13 == random4 %13 ||
random2 %13 == random5 %13 || random3 %13 == random4 %13 ||
random3 %13 == random5 %13 || random4 %13 == random5 %13)
{
alert("You got a pair!");
}
else
{
alert("Sorry, you didn't win");
}


}

function reset_cards()
{
document.card1.src= './cards/card.jpg';
document.card2.src= './cards/card.jpg';
document.card3.src= './cards/card.jpg';
document.card4.src= './cards/card.jpg';
document.card5.src= './cards/card.jpg';
}
</script>

</head>

<body>
<form name="myForm">
<table align='center' border='1'>
<tr align='center'><td colspan='5'>Cards</td></tr>
<tr><td><img id='card1' src='./cards/card.jpg'></td><td><img id='card2' src='./cards/card.jpg'></td><td><img id='card3' src='./cards/card.jpg'></td><td><img id='card4' src='./cards/card.jpg'></td><td><img id='card5' src='./cards/card.jpg'></td></tr>
<tr align='center'><td id='the_message' colspan='5'>Click the 'deal cards' button to deal your hand.</td></tr>
<tr align='center'><td colspan='5'><input type='button' value='Deal Cards' onclick='deal()'> - <input type='button' value='Reset Cards' onclick='reset_cards();' /></td></tr>
<tr><th colspan='5'>Betting Center</th></tr>
<tr><td colspan='5'>How much do you want to bet? $<input type='text' name='betBox'></td></tr>
<tr><td colspan='5'>In the bank: $<input type='text' value='500' name='bank'></td></tr>
</table>
</form>

</body>

</html>

madnak
05-16-2006, 10:06 PM
It's not working perfectly, you need to change the (random2 || random3 || random4 || random5) statement or you'll be in danger of having duplicate cards.

hurricaneace67
05-16-2006, 10:37 PM
GRRRRRR. you are right. it doesnt happen a lot, but i just got two 6 diamonds..

madnak
05-17-2006, 01:59 AM
You also never got the 2 of hearts. But fix that and it should be workable.

hurricaneace67
05-18-2006, 12:52 AM
i am just about finished!!!! here is the final code:

<html>

<head>
<title>Dan's Cards</title>

<script>
var total=500;
var random1;
var ramdom2;
var random3;
var random4;
var random5;
var cards = new Array();
var the_deal = 0;
cards[0]="ah.jpg";
cards[1]="2h.jpg";
cards[2]="3h.jpg";
cards[3]="4h.jpg";
cards[4]="5h.jpg";
cards[5]="6h.jpg";
cards[6]="7h.jpg";
cards[7]="8h.jpg";
cards[8]="9h.jpg";
cards[9]="10h.jpg";
cards[10]="jh.jpg";
cards[11]="qh.jpg";
cards[12]="kh.jpg";
cards[13]="ad.jpg";
cards[14]="2d.jpg";
cards[15]="3d.jpg";
cards[16]="4d.jpg";
cards[17]="5d.jpg";
cards[18]="6d.jpg";
cards[19]="7d.jpg";
cards[20]="8d.jpg";
cards[21]="9d.jpg";
cards[22]="10d.jpg";
cards[23]="jd.jpg";
cards[24]="qd.jpg";
cards[25]="kd.jpg";
cards[26]="as.jpg";
cards[27]="2s.jpg";
cards[28]="3s.jpg";
cards[29]="4s.jpg";
cards[30]="5s.jpg";
cards[31]="6s.jpg";
cards[32]="7s.jpg";
cards[33]="8s.jpg";
cards[34]="9s.jpg";
cards[35]="10s.jpg";
cards[36]="js.jpg";
cards[37]="qs.jpg";
cards[38]="ks.jpg";
cards[39]="ac.jpg";
cards[40]="2c.jpg";
cards[41]="3c.jpg";
cards[42]="4c.jpg";
cards[43]="5c.jpg";
cards[44]="6c.jpg";
cards[45]="7c.jpg";
cards[46]="8c.jpg";
cards[47]="9c.jpg";
cards[48]="10c.jpg";
cards[49]="jc.jpg";
cards[50]="qc.jpg";
cards[51]="kc.jpg";

function deal()
{

if(the_deal==0){


random1=Math.floor(Math.random()*52);
random2=Math.floor(Math.random()*52);
while(random2 == random1){
random2 = Math.floor(Math.random()*52);
}
random3=Math.floor(Math.random()*52);
while((random3 == random1) || (random3 == random2)){
random3 = Math.floor(Math.random()*52);
}
random4=Math.floor(Math.random()*52);
while((random4 == random1) || (random4 == random2) || (random4 == random3)){
random4 = Math.floor(Math.random()*52);
}
random5=Math.floor(Math.random()*52);
while((random5 == random1) || (random5 == random2) || (random5 == random3) || (random5 == random4)){
random4 = Math.floor(Math.random()*52);
}
}

if(the_deal == 1){


var used = new Array();
used[0] = random1;
used[1] = random2;
used[2] = random3;
used[3] = random4;
used[4] = random5;
if(document.myForm.C1.checked==false)
{
while ((random1 == used[0]) || (random1 == used[1]) || (random1 == used[2]) || (random1 == used[3]) || (random1 == used[4])){
random1 = Math.floor(Math.random()*52);
}
}

if(document.myForm.C2.checked==false)
{
while ((random2 == used[0]) || (random2 == used[1]) || (random2 == used[2]) || (random2 == used[3]) || (random2 == used[4]) || (random2 == random1)){
random2 = Math.floor(Math.random()*52);
}
}

if(document.myForm.C3.checked==false)
{
while ((random3 == used[0]) || (random3 == used[1]) || (random3 == used[2]) || (random3 == used[3]) || (random3 == used[4]) || (random3 == random1) || (random3 == random2) ){
random3 = Math.floor(Math.random()*52);
}
}

if(document.myForm.C4.checked==false)

{
while ((random4 == used[0]) || (random4 == used[1]) || (random4 == used[2]) || (random4 == used[3]) || (random4 == used[4]) || (random4 == random1) || (random4 == random2) || (random4 == random3) ){
random4 = Math.floor(Math.random()*52);
}
}

if(document.myForm.C5.checked==false)

{
while ((random5 == used[0]) || (random5 == used[1]) || (random5 == used[2]) || (random5 == used[3]) || (random5 == used[4]) || (random5 == random1) || (random5 == random2) || (random5 == random3) || (random5 == random4)){

random5 = Math.floor(Math.random()*52);
}
}
}

document.card1.src= './cards/' + cards[random1];
document.card2.src= './cards/' + cards[random2];
document.card3.src= './cards/' + cards[random3];
document.card4.src= './cards/' + cards[random4];
document.card5.src= './cards/' + cards[random5];




if(the_deal == 1)
{
var bet=document.myForm.betBox.value;
//Four of a kind

if(random1%13==random2%13
&& random2%13==random3%13 && random3%13==random4%13 ||

random1%13==random2%13 && random2%13==random3%13 && random3%13==random5%13 ||

random1%13==random2%13 && random2%13==random4%13 && random4%13==random5%13 ||

random1%13==random3%13 && random3%13==random4%13 && random4%13==random5%13 ||

random2%13==random3%13 && random3%13==random4%13 && random4%13==random5%13)
{
alert("You got Four of a kind!");
total=total+(bet*100);
document.myForm.bank.value=total;
}
else if(random1 %13== random2 %13 && random2 %13== random3%13 && random4 %13==random5 %13 ||
random1 %13== random2 %13 && random2 %13== random4%13 && random3 %13==random5 %13 ||
random1 %13== random2 %13 && random2 %13== random5%13 && random3 %13==random4 %13 ||
random1 %13== random3 %13 && random3 %13== random4%13 && random2 %13==random5 %13 ||
random1 %13== random3 %13 && random3 %13== random5%13 && random2 %13==random4 %13 ||
random1 %13== random4 %13 && random4 %13== random5%13 && random2 %13==random3 %13 ||
random2 %13== random3 %13 && random3 %13== random4%13 && random1 %13==random5 %13 ||
random2 %13== random3 %13 && random3 %13== random5%13 && random1 %13==random4 %13 ||
random2 %13== random4 %13 && random4 %13== random5%13 && random1 %13==random3 %13 ||
random3 %13== random4 %13 && random4 %13== random5%13 && random1 %13==random2 %13 )
{
alert("You got a Full House!");
total=total+(bet*75);
document.myForm.bank.value=total;
}


else if(
//Flush

(random1 >= 0 && random1 <= 12) && (random2 >= 0 && random2 <= 12) && (random3 >= 0 && random3 <= 12) && (random4 >= 0 && random4 <= 12) && (random5 >= 0 && random5 <= 12)
(random1 >= 13 && random1 <= 25) && (random2 >= 13 && random2
<= 25) && (random3 >= 13 && random3 <= 25) && (random4 >= 13 && random4 <= 25) && (random5 >= 13 && random5 <= 25)
(random1 >= 26 && random1 <= 38) && (random2 >= 26 && random2 <= 38) && (random3 >= 26 && random3 <= 38) && (random4 >= 26 && random4 <= 38) && (random5 >= 26 && random5 <= 38)
(random1 >= 39 && random1 <= 51) && (random2 >= 39 && random2 <= 51) && (random3 >= 39 && random3 <= 51) && (random4 >= 39 && random4 <= 51) && (random5 >= 39 && random5 <= 51))
{
alert("You got a Flush!");
total = total + (bet*50);
document.myForm.bank.value=total;
}

//Three of a kind
else if(random1%13==random2%13 && random2%13==random3%13 ||

random1%13==random2%13 && random2%13==random4%13 ||
random1%13==random2%13 && random2%13==random5%13 ||
random1%13==random3%13 && random3%13==random4%13 ||
random1%13==random3%13 && random3%13==random5%13 ||
random1%13==random4%13 && random4%13==random5%13 ||
random2%13==random3%13 && random3%13==random4%13 ||
random2%13==random3%13 && random3%13==random5%13 ||
random2%13==random4%13 && random4%13==random5%13 ||
random3%13==random4%13 && random4%13==random5%13)
{
alert("You got Three of a kind!");
total=total + (bet*10);
document.myForm.bank.value=total;
}
else if(random1 % 13 == random2 % 13 && random3 % 13 == random4 % 13 ||
random1 % 13 == random2 % 13 && random3 % 13 == random5 % 13 ||
random1 % 13 == random2 % 13 && random4 % 13 == random5 % 13 ||

random1 % 13 == random3 % 13 && random4 % 13 == random5 % 13 ||
random1 % 13 == random3 % 13 && random2 % 13 == random4 % 13 ||
random1 % 13 == random3 % 13 && random2 % 13 == random5 % 13 ||
random1 % 13 == random4 % 13 && random2 % 13 == random3 % 13 ||
random1 % 13 == random4 % 13 && random2 % 13 == random5 % 13 ||
random1 % 13 == random4 % 13 && random3 % 13 == random5 % 13 ||
random1 % 13 == random5 % 13 && random2 % 13 == random3 % 13 ||
random1 % 13 == random5 % 13 && random2 % 13 == random4 % 13 ||
random1 % 13 == random5 % 13 && random3 % 13 == random4 % 13)
{
alert("You got Two Pair!");
total=total + (bet*5);
document.myForm.bank.value=total;
}

else if(random1 %13 == random2 %13 || random1 %13 == random3 %13 ||
random1 %13 == random4 %13 || random1 %13 == random5 %13 ||
random2 %13 == random3 %13 ||
random2 %13 == random4 %13 ||
random2 %13 == random5 %13 || random3 %13 == random4 %13 ||
random3 %13 == random5 %13 || random4 %13 == random5 %13)
{
alert("You got a pair!");
total= total + (bet*1.5);
document.myForm.bank.value=total;
}
else
{
alert("Sorry, you didn't win");
total= total - bet;
document.myForm.bank.value=total;
}
}
the_deal++;
if(the_deal >= 2)
{
the_deal = 0;
reset_cards();
}


}

function reset_cards()
{
document.card1.src= './cards/card.jpg';
document.card2.src= './cards/card.jpg';
document.card3.src= './cards/card.jpg';
document.card4.src= './cards/card.jpg';
document.card5.src= './cards/card.jpg';
}
</script>

</head>

<body>
<form name="myForm">
<table align='center' border='1' width="939">
<tr align='center'><td colspan='5'>Cards</td></tr>
<tr><td width="181"><img id='card1' name='card1' src='./cards/card.jpg'></td>
<td width="181"><img id='card2' name='card2' src='./cards/card.jpg'></td>
<td width="181"><img id='card3' name='card3' src='./cards/card.jpg'></td>
<td width="181"><img id='card4' name='card4' src='./cards/card.jpg'></td>
<td width="181"><img id='card5' name='card5' src='./cards/card.jpg'></td></tr>
<tr align='center'><td
id='the_message' width="-6">
<input type="checkbox" name="C1" value="ON"></td>
<td id='the_message' width="181">
<input type="checkbox" name="C2" value="ON"></td>
<td id='the_message' width="181">
<input type="checkbox" name="C3" value="ON"></td>
<td id='the_message' width="181">
<input
type="checkbox" name="C4" value="ON"></td>
<td id='the_message' width="181">
<input type="checkbox" name="C5" value="ON"></td></tr>
<tr align='center'><td id='the_message' colspan='5'>Click the 'deal cards'
button to deal your hand.</td></tr>
<tr align='center'><td colspan='5'><input type='button' value='Deal Cards' onclick='deal()'> - <input type='button' value='Reset Cards' onclick='reset_cards();' /></td></tr>
<tr><th colspan='5'>Betting Center</th></tr>
<tr><td colspan='5'>How much do you want to bet? $<input type='text' name='betBox'></td></tr>
<tr><td colspan='5'>In the bank: $<input type='text' value='500' name='bank'></td></tr>
</table>
</form>

</body>

</html>