Computer Science Canada Random Generation of cards (total in deck 40)

Author:  xHoly-Divinity [ Thu Dec 02, 2004 4:21 pm ]
Post subject:  Random Generation of cards (total in deck 40)

Our assignment is to create a program (using procedures, for loops, and 2 dimensional arrays) that will randomly draw cards from a deck. Once a card is selected, that same card cannot be drawn again. After all 40 cards have been processed, then the program terminates. So far I've only gotten the drawings of all four suites using procedures. I have no idea where to go from there!!! I really need some help!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 code: procedure spade (xx, yy : int)     drawfilloval (113 + xx, 98 + yy, 12, 10, black)     Draw.ThickLine (113 + xx, 98 + yy, 113 + xx, 80 + yy, 7, black)     Draw.ThickLine (105 + xx, 79 + yy, 120 + xx, 79 + yy, 3, black)     drawline (100 + xx, 100 + yy, 113 + xx, 119 + yy, black)     drawline (113 + xx, 119 + yy, 126 + xx, 100 + yy, black)     drawline (126 + xx, 100 + yy, 100 + xx, 100 + yy, black)     drawfill (110 + xx, 110 + yy, black, black) end spade procedure diamond (xx, yy : int)     drawline (200 + xx, 200 + yy, 215 + xx, 220 + yy, black)     drawline (215 + xx, 220 + yy, 200 + xx, 240 + yy, black)     drawline (200 + xx, 240 + yy, 185 + xx, 220 + yy, black)     drawline (185 + xx, 220 + yy, 200 + xx, 200 + yy, black)     drawfill (200 + xx, 219 + yy, brightred, black) end diamond procedure heart (xx, yy : int)     Draw.FillArc (300 + xx, 300 + yy, 10, 10, 0, 180, brightred)     Draw.FillArc (320 + xx, 300 + yy, 10, 10, 0, 180, brightred)     drawline (290 + xx, 300 + yy, 310 + xx, 275 + yy, brightred)     drawline (310 + xx, 275 + yy, 330 + xx, 300 + yy, brightred)     drawline (330 + xx, 300 + yy, 290 + xx, 300 + yy, brightred)     drawfill (310 + xx, 285 + yy, brightred, brightred) end heart procedure club (xx, yy : int)     drawfilloval (400 + xx, 100 + yy, 7, 7, black)     drawfilloval (392 + xx, 90 + yy, 7, 7, black)     drawfilloval (408 + xx, 90 + yy, 7, 7, black)     Draw.ThickLine (400 + xx, 90 + yy, 400 + xx, 75 + yy, 5, black)     Draw.ThickLine (396 + xx, 74 + yy, 404 + xx, 74 + yy, 3, black) end club

Author:  SuperGenius [ Thu Dec 02, 2004 7:25 pm ]
Post subject:

What you'll want to do is have a 2d array. At the start of the pram have two for loops and set every element in the array to 0. Then you'll need two random integers to select a card. If the array element that corresponds to that number is 0, then say "ok this is the card", and then set that particular element to 1. You're going to have to put this code inside a structure that says

 code: if cards(num1, num2) = 0 then      pick this card elsif      pick a different card

as well you will have to check that you've got a valid card selected before you can exit this structure.

 :