Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Card Games
Author Message
TheFerret

Posted: Wed Mar 31, 2004 12:58 pm   Post subject: Card Games

I am making an Euchre game and I am trying to make sure that all cards that are delt are different and I found a way but it is very un-effiecnt and she told me to use parrallel arrays and to have first one generate the num and second one to make sure it is different by using boolean but I am not sure how to do it and I can't get it to work...

 code: var fullcards : array 1 .. 24 of int var temp : array 1 .. 24 of boolean for i : 1 .. 24     temp (i) := false end for for i : 1 .. 24     loop         fullcards (i) := Rand.Int (1, 24)         num := fullcards (i)         if num >= 1 or num <= 24 then             temp (i) := true             exit when temp (i) = true         end if     end loop end for for i : 1 .. 24     c (i) := fullcards (i) end for

Dan

Posted: Wed Mar 31, 2004 1:36 pm   Post subject: (No subject)

this is what i whould do:

 code: var allCards : array 1 .. 25 of boolean %this is set to true if the card has been dealt var hands : array 1 .. 5, 1 .. 5 of int %2ds array, 4 hands for (one each player) with 5 cards + the kiddy thing for i : 1 .. 25     allCards (i) := false end for var temp : int for ii : 1 .. 5     for iii : 1 .. 5         loop             temp := Rand.Int (1, 25)             if allCards (temp) not= true then                 hands (ii, iii) := temp                 allCards (temp) := true                 exit             end if         end loop     end for end for %%%debug for t : 1 .. 5     put "hand ", t     put "cards: "     for y : 1 .. 5         put hands(t,y), " "..     end for     put ""     put "" end for

now there are ways to make this more efishent but it runs prity fast as it is. basily you keep track of what cards have been dealt out and if they are randomly picked agaen it gets a new one rather then uses that all ready used one. also i made it put them in a 2d arrray witch diveds them in to hands so they can be easly useded latter in the progame. also euchre has 25 crads not 24....so i put the right num in my progame.

Note: there are 5 hands and i know there are only 4 players but the 5th hand is put down as the kiddy.

P.S. if u realy whont to make it more effcent u could make it keep track of the max and min card left to generat so the loop will run fewer times but that whould take up more memory so it is a trade off realy.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: