Computer Science Canada

breaking an array up? 0o

Author:  SpaceDude [ Mon Jun 07, 2004 2:14 pm ]
Post subject:  breaking an array up? 0o

lol
hmm ok lets say this is for a card game ok?
so i make one array of 52
and then i want to split the array into 4 parts cuz there is 4 suits for the deck, and i want to split them in different colours, like red for diamond, purple for club, pink for hearts and black for spades, so how would i do it?

cuz i tried this way and it wouldn't work lol...

var Deck : array 1 .. 52 of int


%Diamonds
color (3)
Deck (1) := Ace
Deck (2) := 2
Deck (3) := 3
Deck (4) := 4
Deck (5) := 5
Deck (6) := 6
Deck (7) := 7
Deck (8) := 8
Deck (9) := 9
Deck (10) := 10
Deck (11) := JACK
Deck (12) := QUEN
Deck (13) := KING

%Clubs
color (5)
Deck (14) := Ace
Deck (15) := 2
Deck (16) := 3
Deck (17) := 4
Deck (18) := 5
Deck (19) := 6
Deck (20) := 7
Deck (21) := 8
Deck (22) := 9
Deck (23) := 10
Deck (24) := JACK
Deck (25) := QUEN
Deck (26) := KING

~~~
and so forth, so hmm is there a easier way to break this 52 array into 4 pieces easier? and can keep the colour?

thanks

Author:  Mazer [ Mon Jun 07, 2004 2:43 pm ]
Post subject: 

code:

var Deck : array 1 .. 52 of string

for i : 0 .. 3
    Deck (i * 13 + 1) := "Ace"
    for j : 2 .. 10
        Deck (i * 13 + j) := intstr (j)
    end for
    Deck (i * 13 + 11) := "Jack"
    Deck (i * 13 + 12) := "Queen"
    Deck (i * 13 + 13) := "King"
end for


EDIT: Hm... perhaps that wasn't what you wanted.
Well, just remember that every 13 cards is a different suit. So, 1-13 spades, 13-26 clubs, etc.

Author:  SpaceDude [ Tue Jun 08, 2004 2:40 am ]
Post subject: 

ic thanks, i guess i know how to do it now


: