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
  #11  
Old 05-15-2006, 08:46 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

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.
Reply With Quote
  #12  
Old 05-15-2006, 09:00 PM
DougShrapnel DougShrapnel is offline
Senior Member
 
Join Date: Oct 2004
Posts: 2,155
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 ] 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.
Reply With Quote
  #13  
Old 05-15-2006, 09:42 PM
hurricaneace67 hurricaneace67 is offline
Member
 
Join Date: May 2006
Posts: 45
Default Re: Computer science java script project

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
Reply With Quote
  #14  
Old 05-15-2006, 10:05 PM
Leaky Eye Leaky Eye is offline
Senior Member
 
Join Date: Jan 2005
Location: norcal
Posts: 1,531
Default Re: Computer science java script project

[ 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/Shuffli...ing_algorithms
Reply With Quote
  #15  
Old 05-15-2006, 11:53 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

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.
Reply With Quote
  #16  
Old 05-16-2006, 04:56 PM
hurricaneace67 hurricaneace67 is offline
Member
 
Join Date: May 2006
Posts: 45
Default Re: Computer science java script project

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
Reply With Quote
  #17  
Old 05-16-2006, 06:46 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 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");
Reply With Quote
  #18  
Old 05-16-2006, 07:49 PM
hurricaneace67 hurricaneace67 is offline
Member
 
Join Date: May 2006
Posts: 45
Default Re: Computer science java script project

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
Reply With Quote
  #19  
Old 05-16-2006, 08:05 PM
hurricaneace67 hurricaneace67 is offline
Member
 
Join Date: May 2006
Posts: 45
Default Re: Computer science java script project

[ 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/
Reply With Quote
  #20  
Old 05-16-2006, 08:31 PM
madnak madnak is offline
Senior Member
 
Join Date: Aug 2005
Location: Brooklyn (Red Hook)
Posts: 5,271
Default Re: Computer science java script project

(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))
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 10:14 AM.


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