10-03-2003, 09:23 AM
EDIT::::I added comments to the original post that may make more sense than this post. Review the original code...it may be more clear now. Ciao.
shuffledenough increments after each swap. you have to have some condition that says, "enough already...I'm shuffled". What that condition is is up to you. I chose 100 arbitrarily...with my code, how many "shuffles" you need will depend on how many variabls are in your array. However, there are ways to make this non-hard coded. for example, you could make it so that after shuffledenough > 10 * arraysize, then enough is enough...
x and y are two *different* values that fall within the array index. They are *different* because we kept selecting random x and y values until we got two that didn't match (loop while (x=y) ensures that x and y are not equal *outside* the loop). (which most likely happened on the first try *if* your deck contained more than 2 cards ;- ) As such, array(x) represents the value at array position x, and array(y) represents the value at array position y. swap array(x), array(y) simply swaps these values. after the swap, the value at array(x) will contain the previous value at array(y), and the value at array(y) will contain the previous value held by array(x).
Off Topic:
Arrays are kinda 'hard to get' for people who don't already get them. If you are interested in computer programming...make the effort. It will pay off hugely. An array is simply a bunch of variables held together with a single name. As such, an array of 10 "joe"s, where the variable "joe" is an integer, can contain 10 distinct integers....just as the variable list joea, joeb, joec, ...etc. could. With arrays, instead of naming each *similar purposed* variable, you just name it once...then you can access each *similar purposed* variable by writing the name, followed by it's number. Each array variable is as independent as any 'uniquely named' variable. SO...you can do things like say:
joe(1) = 45 * t
in the same way you might say:
x = 45 * t
then, you can go on to say something like:
joe(2) = joe(1) -(2*t)
This is really powerful. Learn it. Come to terms with it.
With a single name, you can access a whole mess-o-variables...or types...or strings...or whatever!!!
Think of trying to write something like "nibbles" (you know...the snake-game). How to do it without arrays??? With arrays you say...snake1 is 100 pixels long...OK...I'll make a 100 element array...each element holding 1 pixel coordinate. Without arrays, you'd have to write, name, and keep track of 100 variables. I don't think I'd be up to the task.
Cheers, and good luck,
You're welcome,
Mango
Quote:Wow, thanks.... yeah so i understand what your saying. i dont get two parts
LOOP UNTIL (shuffledenough > 100)
i know that is loop untill the value of shuffledenough is greater thatn 100. but why?
shuffledenough increments after each swap. you have to have some condition that says, "enough already...I'm shuffled". What that condition is is up to you. I chose 100 arbitrarily...with my code, how many "shuffles" you need will depend on how many variabls are in your array. However, there are ways to make this non-hard coded. for example, you could make it so that after shuffledenough > 10 * arraysize, then enough is enough...
Quote:LOOP WHILE (x = y)
SWAP array(x), array(y)
i dont full get what swap does. and how does array(x) and array(y) get a value in for the numbers in the array?
x and y are two *different* values that fall within the array index. They are *different* because we kept selecting random x and y values until we got two that didn't match (loop while (x=y) ensures that x and y are not equal *outside* the loop). (which most likely happened on the first try *if* your deck contained more than 2 cards ;- ) As such, array(x) represents the value at array position x, and array(y) represents the value at array position y. swap array(x), array(y) simply swaps these values. after the swap, the value at array(x) will contain the previous value at array(y), and the value at array(y) will contain the previous value held by array(x).
Off Topic:
Arrays are kinda 'hard to get' for people who don't already get them. If you are interested in computer programming...make the effort. It will pay off hugely. An array is simply a bunch of variables held together with a single name. As such, an array of 10 "joe"s, where the variable "joe" is an integer, can contain 10 distinct integers....just as the variable list joea, joeb, joec, ...etc. could. With arrays, instead of naming each *similar purposed* variable, you just name it once...then you can access each *similar purposed* variable by writing the name, followed by it's number. Each array variable is as independent as any 'uniquely named' variable. SO...you can do things like say:
joe(1) = 45 * t
in the same way you might say:
x = 45 * t
then, you can go on to say something like:
joe(2) = joe(1) -(2*t)
This is really powerful. Learn it. Come to terms with it.
With a single name, you can access a whole mess-o-variables...or types...or strings...or whatever!!!
Think of trying to write something like "nibbles" (you know...the snake-game). How to do it without arrays??? With arrays you say...snake1 is 100 pixels long...OK...I'll make a 100 element array...each element holding 1 pixel coordinate. Without arrays, you'd have to write, name, and keep track of 100 variables. I don't think I'd be up to the task.
Cheers, and good luck,
You're welcome,
Mango