PDA

View Full Version : Best way to define the Cards?


Admigo
15/09/2012, 10:35 PM
Heey all,

I want to define the cards from the casino like :Heart,Club,Spade and Diamond.
How can i define all the cards?


Admigo

Babul
15/09/2012, 10:45 PM
Heart, Club, Spade, Diamond
x
Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K
=

new Card[4][13];

or do you mean assigning a value to them? like card=25 (with a max of 51), then


Color=card/13;
Number=card%13;


25/13=1 (Club)
25%13=12 (King)

Admigo
15/09/2012, 10:49 PM
Thanks for u repply.
How i check if someone has the card(playerid)?

Babul
15/09/2012, 10:50 PM
if you dont mind, show me your script. its dead easy to add a check, however you scritped it so far ^^
did you already set a players card, any value? how many cards can a player hold? what game are you scripting?

Admigo
15/09/2012, 10:56 PM
I didnt made something yet. First i need to make the cards. Then i need to make the pokerhands. I want to make Texas Hold Em.

Vince
15/09/2012, 11:06 PM
With all due respect, but I don't think you'll be able to create such sophisticated script. I'd like to guard you against failure and disappointment.

I have tried to create a poker script like that, and believe me it's MUCH harder than you might think. The function to find out what hand a player has from any of 7 cards (5 on the table plus 2 in hand) alone is already 250 lines long, and yet I'm sure there are still unpatched holes in it.

Babul
15/09/2012, 11:12 PM
ok, the best idea is to see the whole cardset as one array of values from 0 to 51. there are 4*13=52 cards, no joker in poker.. argh that rhymes.
the worthless "color" is the diamond, then increasing to heart, spade, club:

#define CARDCOLOR_DIAMOND 0
#define CARDCOLOR_HEART 1
#define CARDCOLOR_SPADE 2
#define CARDCOLOR_CLUB 3

now you can work with those "multiplicators", or a fake 2nd array, to use the values 0-12 aswell.
CARDCOLOR_CLUB*13+1 is the ace indeed, where +12 is the king.

let each player hold 5 cards max:

new PlayerCard[MAX_PLAYERS][5];


now you are facing the problem "how to spread cards to players without repeating a single card?"
to answer this question in advance: how do you do it irl? you take 52 cards,

new CardsToMix[52]={0,1,...};

then you mix them

new temp,swapposition;
for(new a=0;a<52;a++)
{
swapposition=random(52);
temp=CardsToMix[a];
CardsToMix[a]=CardsToMix[swapposition];
CardsToMix[swapposition]=temp;
}

now, since the cards are mixed, give each player one, while increasing the "pointer" to the card array by 1 each time..

if any questions arise, i think we all are glad to help :P

@Vince: i agree, poker is not that easy to script, i prefer (french) roulette ^^
scripting the rules "only" maybe is easier than we might think, but when it comes to a NPC opponent, then i would even place a wager on a fail.

burnuk
15/09/2012, 11:12 PM
@vince i think it is possible, i know a server using a card system which can hold 5 cards each player.

Admigo
15/09/2012, 11:46 PM
With all due respect, but I don't think you'll be able to create such sophisticated script. I'd like to guard you against failure and disappointment.

I have tried to create a poker script like that, and believe me it's MUCH harder than you might think. The function to find out what hand a player has from any of 7 cards (5 on the table plus 2 in hand) alone is already 250 lines long, and yet I'm sure there are still unpatched holes in it.

You will not stop me from making this. I will not giving up making this script;)
EDIT: This is just the beginning.