
-----------------------------------
bfh
Sun Aug 01, 2010 11:46 pm

Algorithm Help
-----------------------------------
Okay Guys Im trying to think of an algorithm that could help solve this problem..

1-13 = 1 (hearts
14-26 = 2 (diamonds
27-39 = 3 (spades
40-52 = 4 (clubs

0-12 (hearts
13-25 (diamonds
26-39 (spades
40-52 (clubs

Now Each Time I cycle to the next set of card types, we start at value 0

then cross check if set 1 = set 2 or set 1 = 3 so on so forth.


any ideas, im starting to play around but would like some input on this question
[code]
if (player_card2 > 12 && player_card2 = 26 && > 2;  // the rest of the bits


You can also think of this as a packed value with a 2-bit field and another field with the remaining bits.

Now what if you have some other number of possible values for your fields?
The division/modulus approach may be advantageous because every value within a contiguous range is valid (even when you don't happen to have some power of 2).
If you are doing many operations, it may make sense to use the bitwise approach even when you do not have a power of 2 around.

-----------------------------------
QuantumPhysics
Wed May 30, 2012 9:08 am

RE:Algorithm Help
-----------------------------------
haha, you can just read up on these links:

http://en.wikipedia.org/wiki/Minimax

http://en.wikipedia.org/wiki/Bubble_sort

-----------------------------------
bbi5291
Wed May 30, 2012 1:41 pm

Re: RE:Algorithm Help
-----------------------------------
Noting that 4 is a power of two, this could also be done with bitwise operations.

unsigned char suitID = cardValue & 0x03;  // lower 2 bits
unsigned char valueID = cardValue >> 2;  // the rest of the bits

Don't do this. It makes the code harder to read, and the optimizer will catch it anyway.
