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

Username:   Password: 
 RegisterRegister   
 help?
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bradyman3




PostPosted: Mon Jan 03, 2011 11:05 pm   Post subject: help?

I was wondering if you could help me out, I have a code i am working on. Its going to be a 21 game but i would like to create the possibility of all the cards being used and then it will stop the game with multiple players ( not sure how to have multi play, maybe with arrays?). i have the numbers generator working fine, it doesnt use the same number more than 4 times like in a deck of cards, but it seems to get caught up in a executing loop when the total cards used reaches around 32+. There should be a better way to regenerate a used number, maybe increase the number randomization range instead of 1 - 13 to say 1 - 52 (one number for each card)?
Thank you for your time, it is appreciated greatly!

THE code:

var rand_n, ace, two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, total, used : int :=0
var card : string := ""


loop



if not total = 52 then

randint(rand_n,1,13)

loop

used:=0



if ace=4 and rand_n = 1 then

loop

randint(rand_n,1,3)

exit when not rand_n = 1
end loop

used:=used+1

end if

if two=4 and rand_n = 2 then

loop

randint(rand_n,1,3)

exit when not rand_n = 2
end loop

used:=used+1

end if

if three=4 and rand_n = 3 then

loop

randint(rand_n,1,3)

exit when not rand_n = 3
end loop

used:=used+1

end if

if four=4 and rand_n = 4 then

loop

randint(rand_n,1,3)

exit when not rand_n = 4
end loop

used:=used+1

end if

if five=4 and rand_n = 5 then

loop

randint(rand_n,1,3)

exit when not rand_n = 5
end loop

used:=used+1

end if

if six=4 and rand_n = 6 then

loop

randint(rand_n,1,3)

exit when not rand_n = 6
end loop

used:=used+1

end if

if seven=4 and rand_n = 7 then

loop

randint(rand_n,1,3)

exit when not rand_n = 7
end loop

used:=used+1

end if

if eight=4 and rand_n = 8 then

loop

randint(rand_n,1,3)

exit when not rand_n = 8
end loop

used:=used+1

end if

if nine=4 and rand_n = 9 then

loop

randint(rand_n,1,3)

exit when not rand_n = 9
end loop

used:=used+1

end if

if ten=4 and rand_n = 10 then

loop

randint(rand_n,1,3)

exit when not rand_n = 10
end loop

used:=used+1

end if

if jack=4 and rand_n = 11 then

loop

randint(rand_n,1,3)

exit when not rand_n = 11
end loop

used:=used+1

end if

if queen=4 and rand_n = 12 then

loop

randint(rand_n,1,3)

exit when not rand_n = 12
end loop

used:=used+1

end if

if king=4 and rand_n = 13 then

loop

randint(rand_n,1,3)

exit when not rand_n = 13
end loop

used:=used+1

end if

exit when used=0
end loop

elsif total = 52 then
put card

put skip

put ace
put two
put three
put four
put five
put six
put seven
put eight
put nine
put ten
put jack
put queen
put king

put skip

put total

put used

put "win!!"

Input.Pause
cls



end if


case rand_n of

label 1 : card := "Ace"

label 2 : card := "Two"

label 3 : card := "Three"

label 4 : card := "Four"

label 5 : card := "Five"

label 6 : card := "Six"

label 7 : card := "Seven"

label 8 : card := "Eight"

label 9 : card := "Nine"

label 10 : card := "Ten"

label 11 : card := "Jack"

label 12 : card := "Queen"

label 13 : card := "King"

label : card := "unknown"

end case

if card = "Ace" and ace < 4 then

ace := ace+1

end if

if card = "Two" and two < 4 then

two := two+1

end if

if card = "Three" and three < 4 then

three := three+1

end if

if card = "Four" and four < 4 then

four := four+1

end if

if card = "Five" and five < 4 then

five := five+1

end if

if card = "Six" and six < 4 then

six := six+1

end if

if card = "Seven" and seven < 4 then

seven := seven+1

end if

if card = "Eight" and eight < 4 then

eight := eight+1

end if

if card = "Nine" and nine < 4 then

nine := nine+1

end if

if card = "Ten" and ten < 4 then

ten := ten+1

end if

if card = "Jack" and jack < 4 then

jack := jack+1

end if

if card = "Queen" and queen < 4 then

queen := queen+1

end if

if card = "King" and king < 4 then

king := king+1

end if


total:=ace+two+three+four+five+six+seven+eight+nine+ten+jack+queen+king



put card

put skip

put ace
put two
put three
put four
put five
put six
put seven
put eight
put nine
put ten
put jack
put queen
put king

put skip

put total

put used


Input.Pause
cls

end loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Jan 03, 2011 11:28 pm   Post subject: RE:help?

code:

loop

randint(rand_n,1,3)

exit when not rand_n = 1
end loop

There are better ways of picking between two random numbers.

code:

loop

randint(rand_n,1,3)

exit when not rand_n = 13
end loop

I'm not sure what's going on here, 1..3 is always not 13, isn't it?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
TokenHerbz




PostPosted: Tue Jan 04, 2011 1:10 am   Post subject: RE:help?

why not try using a record to hold card info, and an array to use that info. It would be alot easier.

Look up info on 2Darrays, even just arrays, and also "type" and "record". I think it would be worth your while.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: