Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Card Games
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TheFerret




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: 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:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: