#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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<NoOfCardsInHand; i++) { CardPresent[ValueOfCard(CardInHand[i])] = 1; } for (i=0; i<(13-5); i++) { int NumberOfCardsInRange = 0; for (j=i; j<(i+5); j++) { NumberOfCardsInRange += CardPresent[j]; } if (NumberOfCardsInRange == 4) { if ((CardPresent[j] == 1) && (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] |
|
|