#1
|
|||
|
|||
Computer science java script project
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?
|
#2
|
|||
|
|||
Re: Computer science java script project
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 |
#3
|
|||
|
|||
Re: Computer science java script project
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
|
#4
|
|||
|
|||
Re: Computer science java script project
[ 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 } |
#5
|
|||
|
|||
Re: Computer science java script project
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> |
#6
|
|||
|
|||
Re: Computer science java script project
[ 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. |
#7
|
|||
|
|||
Re: Computer science java script project
[ 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. |
#8
|
|||
|
|||
Re: Computer science java script project
i never claimed to be a programmer, just needed a credit so i took basic computer science
|
#9
|
|||
|
|||
Re: Computer science java script project
[ 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? |
#10
|
|||
|
|||
Re: Computer science java script project
[ 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... |
|
|