Computer Science Canada using arrays for blackjack??? |
Author: | Tony_200004 [ Sun Jan 11, 2004 8:27 am ] |
Post subject: | using arrays for blackjack??? |
Yeah i asked a question earlier and someone mentioned something about using arrays... i looked at the tutiorial and i still dont understand them.... can someone just make a really small example blackjack program so i can see whats going on... i am more of a hands on person need to see it.. cant just read it... thanks |
Author: | Tony_200004 [ Sun Jan 11, 2004 8:44 am ] |
Post subject: | |
or a small game which randomizes numbers and outputs them just something simple that can show me how to do it |
Author: | Thuged_Out_G [ Sun Jan 11, 2004 3:12 pm ] | ||
Post subject: | |||
simple program to store an array with random numbers and output each number
|
Author: | Tony_200004 [ Sun Jan 11, 2004 5:54 pm ] | ||
Post subject: | |||
yeah i took that code you gave me and did this... want to know if it is any good for a first try and if it is alright
|
Author: | Tony_200004 [ Sun Jan 11, 2004 6:25 pm ] | ||
Post subject: | |||
Okay well this is my latest update to that.... if anyone can help me with this please do so....
|
Author: | Grey_Wolf [ Sun Jan 11, 2004 6:37 pm ] |
Post subject: | |
no suggestion about the code but i would suggest you leave out comments like for for i:1..2 %a for loop to run 2 times it clutters things up and insults the intellegence of the person reading it. |
Author: | Tony_200004 [ Sun Jan 11, 2004 6:44 pm ] |
Post subject: | |
yeah it does clutter it up, but it makes it easier if i need help anytime, easier for someone to understand my code, and easier to find something that i cant remember what it is called. |
Author: | Tony_200004 [ Sun Jan 11, 2004 6:45 pm ] |
Post subject: | |
also it is a habbit my computer science teacher has gotten me use to |
Author: | poly [ Sun Jan 11, 2004 6:52 pm ] |
Post subject: | |
Grey_Wolf wrote: no suggestion about the code but i would suggest you leave out comments like for
for i:1..2 %a for loop to run 2 times it clutters things up and insults the intellegence of the person reading it. it doesnt really insult the intillegent's of the person reading it, because if your just reading the code you might not realize exactly why thats there, so the comments do help both the coder and reader understand the code. |
Author: | Poland13 [ Sun Jan 11, 2004 7:28 pm ] |
Post subject: | |
IM doing blackjack to var deck : array 1 .. 52 of string var cardz : array 1 .. 13 of string := init ("2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A") var suit : array 1 .. 4 of string := init ("C", "D", "S", "H") card := 1 function DECK for x : 1 .. 4 for y : 1 .. 13 deck (card) := cardz (y) + suit (x) card := card + 1 end for end for for i : 1 .. 52 randint (a, 1, 52) randint (b, 1, 52) temp := deck (a) deck (a) := deck (b) deck (b) := temp end for result deck end DECK can neone tell me y this doesnt work |
Author: | dude3000 [ Sun Jan 11, 2004 10:42 pm ] |
Post subject: | |
Poland13 wrote: IM doing blackjack to
var deck : array 1 .. 52 of string var cardz : array 1 .. 13 of string := init ("2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A") var suit : array 1 .. 4 of string := init ("C", "D", "S", "H") card := 1 function DECK for x : 1 .. 4 for y : 1 .. 13 deck (card) := cardz (y) + suit (x) card := card + 1 end for end for for i : 1 .. 52 randint (a, 1, 52) randint (b, 1, 52) temp := deck (a) deck (a) := deck (b) deck (b) := temp end for result deck end DECK can neone tell me y this doesnt work This doesn't work because you need to declare temp, a and b |
Author: | McKenzie [ Sun Jan 11, 2004 10:58 pm ] |
Post subject: | |
First. Program is looking good Second. Wolf is right. obvious comments are harmfull to clarity. Third. It's only called a blackjack if you get it on your fist two cards |
Author: | McKenzie [ Sun Jan 11, 2004 11:10 pm ] | ||
Post subject: | |||
Poland, I like the way you shuffle, but if you think about it there is no reason to stop at 52. Run it up to 100 or so to be sure they are well shuffled. Aside from the a,b problem that dude correctly pointed out your big problem is trying to result an an array of string from your function. Make it a procedure and pass your array as a parameter like:
oh I changed the name because it is confusing to have two very different things in your program so similarly named and you should only use ALL CAPS for constants. |
Author: | Poland13 [ Mon Jan 12, 2004 4:35 pm ] |
Post subject: | |
thanks but i figured all of that out now all i have left to do is assign values to the cards |
Author: | Poland13 [ Mon Jan 12, 2004 4:49 pm ] |
Post subject: | |
i used a function instead of a procedure thoguh function DECK : array 1 .. 52 of string var deck : array 1 .. 52 of string var cardz : array 1 .. 13 of string := init ("2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A") var suit : array 1 .. 4 of string := init ("C", "D", "S", "H") for x : 1 .. 4 for y : 1 .. 13 deck (card) := cardz (y) + suit (x) card := card + 1 end for end for for i : 1 .. 52 randint (a, 1, 52) randint (b, 1, 52) temp := deck (a) deck (a) := deck (b) deck (b) := temp end for result deck end DECK |
Author: | Poland13 [ Mon Jan 12, 2004 5:31 pm ] |
Post subject: | |
well i have most of my program figured out but i was having some trouble with assigning values to the cards the only error is substring index is greater then the length of the string i think this means cards is greater then deck but how would i fix this var name, temp, option : string var bet : int := 100 var card, a, b : int card := 1 function DECK : array 1 .. 52 of string var deck : array 1 .. 52 of string var cardz : array 1 .. 13 of string := init ("2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A") var suit : array 1 .. 4 of string := init ("C", "D", "S", "H") for x : 1 .. 4 for y : 1 .. 13 deck (card) := cardz (y) + suit (x) card := card + 1 end for end for for i : 1 .. 52 randint (a, 1, 52) randint (b, 1, 52) temp := deck (a) deck (a) := deck (b) deck (b) := temp end for result deck end DECK function Getvalue (deck: string) : int var value : int:=0 if index (deck(card)(1),"T,J,Q,K,") >0 then value := 10 end if result value end Getvalue View.Set ("nocursor") var count : int := 1 var deck : array 1 .. 52 of string var value : int := 1 var points : int put " Enter your name " get name : * put name, " You have 100$ to start with what is your bet " get bet put " Your bet is ", bet, " dollars Good Luck !!!!! " deck := DECK loop put "Would you like to Hit or Stand (you must hit on your first turn) " get option : * put "Your card is ", deck (count) count := count + 1 points := Getvalue (deck (count)) put "ur total", points exit when option = "stand" end loop |
: |