Two Plus Two Newer Archives  

Go Back   Two Plus Two Newer Archives > Other Topics > Science, Math, and Philosophy
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-15-2006, 06:54 PM
hurricaneace67 hurricaneace67 is offline
Member
 
Join Date: May 2006
Posts: 45
Default 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?
Reply With Quote
  #2  
Old 05-15-2006, 07:16 PM
TomCollins TomCollins is offline
Senior Member
 
Join Date: Jul 2003
Location: Approving of Iron\'s Moderation
Posts: 7,517
Default 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
Reply With Quote
  #3  
Old 05-15-2006, 07:37 PM
hurricaneace67 hurricaneace67 is offline
Member
 
Join Date: May 2006
Posts: 45
Default 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
Reply With Quote
  #4  
Old 05-15-2006, 07:46 PM
dtbog dtbog is offline
Senior Member
 
Join Date: Jun 2004
Location: mostly offline
Posts: 2,615
Default 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
}
Reply With Quote
  #5  
Old 05-15-2006, 07:56 PM
hurricaneace67 hurricaneace67 is offline
Member
 
Join Date: May 2006
Posts: 45
Default 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>
Reply With Quote
  #6  
Old 05-15-2006, 07:58 PM
dtbog dtbog is offline
Senior Member
 
Join Date: Jun 2004
Location: mostly offline
Posts: 2,615
Default 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.
Reply With Quote
  #7  
Old 05-15-2006, 07:59 PM
dtbog dtbog is offline
Senior Member
 
Join Date: Jun 2004
Location: mostly offline
Posts: 2,615
Default 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.
Reply With Quote
  #8  
Old 05-15-2006, 08:09 PM
hurricaneace67 hurricaneace67 is offline
Member
 
Join Date: May 2006
Posts: 45
Default Re: Computer science java script project

i never claimed to be a programmer, just needed a credit so i took basic computer science
Reply With Quote
  #9  
Old 05-15-2006, 08:25 PM
hurricaneace67 hurricaneace67 is offline
Member
 
Join Date: May 2006
Posts: 45
Default 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?
Reply With Quote
  #10  
Old 05-15-2006, 08:43 PM
TomCollins TomCollins is offline
Senior Member
 
Join Date: Jul 2003
Location: Approving of Iron\'s Moderation
Posts: 7,517
Default 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...
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.