Computer Science Canada

array in an array?

Author:  SpaceDude [ Thu Jun 03, 2004 3:06 pm ]
Post subject:  array in an array?

well hmm i'm trying to make an array inside an array
so i try to do it but its not working lol...

var a : array 1 .. 4 of int := init (b, b, b, b)
var b : array 1 .. 13 of int

??
i dunno how to put it together
like i want the 1..4 array to contain 1..13 array in each spot, how can i do this?

thanks

Author:  Cervantes [ Thu Jun 03, 2004 3:34 pm ]
Post subject: 

making a card game eh? 8)

for this use a 2D array.

code:

var deck : array 1 .. 4, 1 .. 13 of int

Author:  SpaceDude [ Thu Jun 03, 2004 3:47 pm ]
Post subject: 

ya thanks =D
lol
now i just somehow need to make the deck shuffle and have to keep track of the cards using boolean now lol

Author:  Tony [ Thu Jun 03, 2004 3:58 pm ]
Post subject: 

deck shuffle is very simple... well.. if you keep cards in a 1D array (having it as 2D just complicates things)
deck shuffle

Author:  Cervantes [ Thu Jun 03, 2004 4:10 pm ]
Post subject: 

despite being less organized, I think a 1 dimensional array from 1 to 52 is actually the better way to go with this. it makes shuffling and dealing a lot easier.

though I guess it depends on what type of game you are making. For games with trump (Euchre, 500, Bridge) or other games such as Hearts, a 2D array might be best. But for Blackjack or War or something, 1 .. 52 might be easier.

how are you planning on shuffling and keeping track of cards?

EDIT: erg that took me forever to type. damn MSN Mad

Author:  SpaceDude [ Thu Jun 03, 2004 4:14 pm ]
Post subject: 

ya was deciding like wat type of array i want
so i was experimenting it
but if i use 1d array rite, like i can use rand.int to help me shuffle it, but if i need to keep track of it i need to use boolean rite?
so how can i keep track with it with boolean?
when i mean keep track like, if i got a 3rd of spades out, i can't draw another 3rd of spade again

EDIT: like i'm thinking of keeping the suits of the cards by different colour, i don't want any graphics or anything in this game since i'm trying to keep it as simple as possible

Author:  Cervantes [ Thu Jun 03, 2004 4:34 pm ]
Post subject: 

um, I would tag it with an integer. 0 means its in the deck, 1 means its in player 1s hand, 2 means its in player 2s hand.

Author:  SpaceDude [ Thu Jun 03, 2004 4:48 pm ]
Post subject: 

hmm how would i tag them with 0,1,2?
i know i got lots of question i'm sry, i'm new at turing, like i've started from scratch this semester, and is almost due now i;m doing my isu

edit : like i know the basics, cuz thats wat we've learned lol

Author:  SuperGenius [ Thu Jun 03, 2004 5:30 pm ]
Post subject: 

you could have an array like this:

code:

var cardstate : array 1..52 of int

for a: 1..52
cardstate(a) :=0
end for


this will get the array set up, and set the values to 0.

Author:  SpaceDude [ Thu Jun 03, 2004 5:37 pm ]
Post subject: 

thanks =D
i'll see if i can figure out the rest b4 i ask u guys again, i wanna see if i can figure it out lol


: