Two Plus Two Newer Archives  

Go Back   Two Plus Two Newer Archives > Other Topics > Computer Technical Help
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-08-2007, 11:47 AM
chrisyt chrisyt is offline
Junior Member
 
Join Date: Mar 2007
Location: England
Posts: 24
Default algorithm

anybody have a good algorithm for seeing if say 6 or 7 cards contain a gut shot draw? thats an example.
currently i'm going the long way if X=2 and X2=3 andX3=4 and X4=5 then its a gut shot (thats an example) programming in Java. was wondering if anybody knew of a more succint method, maybe this is the wrong forum altogether but thougth i'd give it a try.
thanks for any ideas
chris
Reply With Quote
  #2  
Old 10-08-2007, 12:04 PM
fiskebent fiskebent is offline
Senior Member
 
Join Date: Nov 2005
Location: To your right
Posts: 1,124
Default Re: algorithm

Here's how I'd do it (in pseudo-code):
<font class="small">Code:</font><hr /><pre>
int CardPresent[13] = (0, 0, 0, 0, 0... );
for (i=0; i&lt;NoOfCardsInHand; i++) {
CardPresent[ValueOfCard(CardInHand[i])] = 1;
}
for (i=0; i&lt;(13-5); i++) {
int NumberOfCardsInRange = 0;
for (j=i; j&lt;(i+5); j++) {
NumberOfCardsInRange += CardPresent[j];
}
if (NumberOfCardsInRange == 4) {
if ((CardPresent[j] == 1) &amp;&amp; (CardPresent[j+4] == 1))
print "Gutshot draw present";
else
print "Open-ended straight draw present";
}
}
</pre><hr />
First I mark what cards are present in an array.

Then I loop over the possible 5-card ranges, counting how many cards are present in those ranges. If 4 cards are present and both the top and the bottom card in the range is present, then you have a gutshot draw.

Edit: It'll falsely mark A, 2, 3, 4 as an open-ended straight draw. And you need to add some code to handle that aces count as high and low cards. Gotta leave some work for you [img]/images/graemlins/smile.gif[/img]
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 02:14 AM.


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