if you can give me advice on how to implement it
My advice is to use an array of enumerated and do some magic with bits. The clubs are Clubs (♣ Black), Spades (♠ Black), Diamonds (♦ Red) and Hearts (♥ Red). Being able to combine Red and Black alternately regardless of the suit, so it might be a good idea to code the color of the suit in the list.
Assuming an 8-bit enumeration, we could use the highest weight bit to indicate red or black and bits 4 and 5 to encode the stick:
#define ROJO 0x80
#define NEGRO 0x00
#define CLUBS 0x00
#define SPADES 0x10
#define DIAMONDS 0x20
#define HEARTHS 0x30
typedef enum
{
NINGUNA_CARTA = 0,
C1 = CLUBS | NEGRO | 1, S1 = SPADES | NEGRO | 1, D1 = DIAMONDS | ROJO | 1, H1 = HEARTHS | ROJO | 1,
C2 = CLUBS | NEGRO | 2, S2 = SPADES | NEGRO | 2, D2 = DIAMONDS | ROJO | 2, H2 = HEARTHS | ROJO | 2,
C3 = CLUBS | NEGRO | 3, S3 = SPADES | NEGRO | 3, D3 = DIAMONDS | ROJO | 3, H3 = HEARTHS | ROJO | 3,
C4 = CLUBS | NEGRO | 4, S4 = SPADES | NEGRO | 4, D4 = DIAMONDS | ROJO | 4, H4 = HEARTHS | ROJO | 4,
C5 = CLUBS | NEGRO | 5, S5 = SPADES | NEGRO | 5, D5 = DIAMONDS | ROJO | 5, H5 = HEARTHS | ROJO | 5,
C6 = CLUBS | NEGRO | 6, S6 = SPADES | NEGRO | 6, D6 = DIAMONDS | ROJO | 6, H6 = HEARTHS | ROJO | 6,
C7 = CLUBS | NEGRO | 7, S7 = SPADES | NEGRO | 7, D7 = DIAMONDS | ROJO | 7, H7 = HEARTHS | ROJO | 7,
C8 = CLUBS | NEGRO | 8, S8 = SPADES | NEGRO | 8, D8 = DIAMONDS | ROJO | 8, H8 = HEARTHS | ROJO | 8,
C9 = CLUBS | NEGRO | 9, S9 = SPADES | NEGRO | 9, D9 = DIAMONDS | ROJO | 9, H9 = HEARTHS | ROJO | 9,
CJ = CLUBS | NEGRO | 10, SJ = SPADES | NEGRO | 10, DJ = DIAMONDS | ROJO | 10, HJ = HEARTHS | ROJO | 10,
CQ = CLUBS | NEGRO | 11, SQ = SPADES | NEGRO | 11, DQ = DIAMONDS | ROJO | 11, HQ = HEARTHS | ROJO | 11,
CK = CLUBS | NEGRO | 12, SK = SPADES | NEGRO | 12, DK = DIAMONDS | ROJO | 12, HK = HEARTHS | ROJO | 12,
} cartas;
With this list, we would have for example ...
|colr| palo | numero |
|bit7|bit6|bit5|bit4|bit3|bit2|bit1|bit0|
1♣| | | | | | | | 1 | = 1
2♠| | | | 1 | | | 1 | | = 18
7♦| 1 | | 1 | | | 1 | 1 | 1 | = 167
Q♥| 1 | | 1 | 1 | 1 | | 1 | 1 | = 187
When you try to move a card from a column, you should read the color bit and check that it is different from the destination, for it uses masks:
#define MASCARA_COLOR 0x80
#define MASCARA_PALO 0x30
With those masks, a card ( carta_origen
) can be placed on a column if the top card of the column ( carta_destino
) complies:
(carta_origen & MASCARA_COLOR) != (carta_destino & MASCARA_COLOR)
The columns would be something like:
cartas columna1[13] = {NINGUNA_CARTA};
cartas columna2[13] = {NINGUNA_CARTA};
cartas columna3[13] = {NINGUNA_CARTA};
cartas columna4[13] = {NINGUNA_CARTA};
cartas columna5[13] = {NINGUNA_CARTA};
cartas columna6[13] = {NINGUNA_CARTA};
The implementation is yours:)