Author |
Message |
person
|
Posted: Mon Jan 31, 2005 12:35 pm Post subject: a = 3 values out of 5 values |
|
|
i was wandering if ther was a command that does this
if (a= 3 out of the 5 values) then |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: Mon Jan 31, 2005 12:57 pm Post subject: (No subject) |
|
|
 |
|
|
|
|
 |
person
|
Posted: Mon Jan 31, 2005 2:26 pm Post subject: (No subject) |
|
|
can u elaborate? cuz i dont understand |
|
|
|
|
 |
Tony

|
Posted: Mon Jan 31, 2005 3:11 pm Post subject: (No subject) |
|
|
actually what you can do is..
take your 5 values and sort them to be in order. Now for the condition to be true, a would equal to the 3rd and ether 1st or 5th.
pseudo: |
sort(values)
if (a == values[3] and (a == values[1] or a == values[5] )) then
//success!
|
|
|
|
|
|
 |
md

|
Posted: Mon Jan 31, 2005 3:13 pm Post subject: (No subject) |
|
|
in psudo code...
code: |
int good_count = 0;
for i = 0 to 5 do
if test[i] == true
good_count++;
if good_count >= 3
// this is where your code goes
|
you can also do it without a loop:
code: |
int good_count = 0;
if cond_1
good_count++;
if cond_2
good_count++;
if cond_3
good_count++;
if cond_4
good_count++;
if cond_5
good_count++;
if good_count >= 3
// your code
|
|
|
|
|
|
 |
person
|
Posted: Mon Jan 31, 2005 3:20 pm Post subject: (No subject) |
|
|
so i have to type that so many times? (im making holdem, and i want to check for a 3 of a kind) |
|
|
|
|
 |
md

|
Posted: Mon Jan 31, 2005 3:28 pm Post subject: (No subject) |
|
|
how do you store cards? There are lots of ways to simplify card functions, depending on how you represent a card. However, I must point out that the code above is fairly simple and short...if you're going to complain about 15 lines then I'm not sure how your going to write any actual programs... |
|
|
|
|
 |
1337_brad
|
Posted: Mon Jan 31, 2005 6:44 pm Post subject: Erm.. |
|
|
What if you save all the cards to an array, and then check the array for 3 cards... D: seems efficiant.
code: |
var Player1hand : array 1..5 of int % 5 cards in the players hand
var HowManyOfEach: array 1..13 of int % 13 possible cards in the hand %(ace-king)
%put code here to get the values to the array
for i: 1..5
HowManyOfEach(Player1hand(i)) += 1 % this adds one to the occurance %of cards array for whatever card is in the players hand
end for
if HowManyOfEach(1) > 3 then
%code for 3 of a kind aces
elsif HowManyOfEach(2) > 3 then
%code for 3 of a kind twos, and just repeat this code for all the hands..
| [/code] |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
|