Deal or no Deal, stuck on randomizing briefcase values
Author |
Message |
SakuraSasuke
|
Posted: Fri Jan 18, 2008 8:53 pm Post subject: Deal or no Deal, stuck on randomizing briefcase values |
|
|
Okie Dokie. I am a newb at turing, but I am remaking Deal or No Deal. So I have up to the part for when you choose your own briefcase (aka not far) and I am now stuck.
How do i make it so that the briefcase chooses a random money value? For example if they click on briefcase 1, then like, it randomly chooses one of the values from the array of money? I don't want briefcase 1 to always contain $10 or $1 000 000. After they click, the briefcase if going to 'disappear' along with the other money value (i think i kno how to tht tho...) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
ericfourfour
|
Posted: Fri Jan 18, 2008 10:49 pm Post subject: RE:Deal or no Deal, stuck on randomizing briefcase values |
|
|
You need two arrays: one randomized with money values; the other of selected briefcases. The briefcases can be represented with numbers which will be indexes of the money array. Whenever a user selects a briefcase, add the number to the array of selected briefcases.
A few things to note. You are going to need to keep track of the first briefcase (it will be the first element in the array of selected briefcases). You need to keep track of the number of selected briefcases. You can use the selected briefcases, as a reference of briefcases the user cannot select. |
|
|
|
|
|
Sean
|
Posted: Sat Jan 19, 2008 8:39 am Post subject: Re: Deal or no Deal, stuck on randomizing briefcase values |
|
|
Have your array of breifcases from 1 .. 26 and have your money values random. |
|
|
|
|
|
HeavenAgain
|
Posted: Sat Jan 19, 2008 9:41 am Post subject: RE:Deal or no Deal, stuck on randomizing briefcase values |
|
|
using 2 arrays is correct, but WHY would you have another array just to keep track of the briefcase? since it is from 1 to uh 26 anyways?
simply minus 1 from the selected number, and it will become the index of your array (or just ignore the element 0, and start the array from 1 to 26), infact... you could even do this with 1 array |
|
|
|
|
|
ericfourfour
|
Posted: Sat Jan 19, 2008 10:37 am Post subject: Re: Deal or no Deal, stuck on randomizing briefcase values |
|
|
HeavenAgain, can you explain how to do this with one array? You have to keep track of each briefcase's money value and number. You also have to keep track of which briefcases are available and which are not.
The array of money values is filled with all of the possible money values that can be chosen. This array is randomized so the money values are not always at the same index.
The array of selected briefcases contains all of the selected briefcases. For example, if the player selected 2, 2 would be added and then if the player selected 5, 5 would be added. The first element of this array is the initial briefcase that the player gets to keep the whole game.
Whenever you want to display the briefcases that the player can choose, only display the ones that are not in the array of selected briefcases. |
|
|
|
|
|
HeavenAgain
|
Posted: Sat Jan 19, 2008 10:59 am Post subject: RE:Deal or no Deal, stuck on randomizing briefcase values |
|
|
sure, think of it like this, you have an array from 1 to 26, and first user picks a briefcase to keep for himself, you take that element out of the array, you can replace that element with a 0 and keep that as a variable. and now, everytime user picks a number between 1 - 26 (if it have a value of 0, it means its already taken) and each time he/she picks, you take that element out and give it a 0 value
im not sure if you understands it, so i'll put it in code
code: | var cases : int array from 1 - 26
var myCase := 0
put "what do you want to keep"
get num
myCase = cases[num]
cases[num] = 0
for i : 1..26
put "pick a box now"
get num
cases[num] = 0
exit when deal
end for
for i : 1..26
put cases[i] +" " % this will show you the boxes, if it have an value then the box is still alive, if its 0, then its out of the game
end for
put myCase % this is the one you kept
|
make sense? but of course, you will need if statements for some simple checking, i dont want to put out the whole code, since it is not my project but you get the idea right? |
|
|
|
|
|
SakuraSasuke
|
Posted: Sat Jan 19, 2008 1:37 pm Post subject: Re: Deal or no Deal, stuck on randomizing briefcase values |
|
|
I get how i need two arrays: one randomized with money values; the other of selected briefcases. But how do i make the one randomized with money values?
i dont really understand the whole randint or Rand.Int thingy... |
|
|
|
|
|
HeavenAgain
|
Posted: Sat Jan 19, 2008 1:56 pm Post subject: RE:Deal or no Deal, stuck on randomizing briefcase values |
|
|
you can do 1 random shovel
code: | myMoneyArray = { 1, 10, 20, 50, 100, 1000 }
arrayLength = myMoneyArray.length
for i : 1.. arrayLength
swap(myMoneyArray, i , Rand.Int(0 , arrayLength)
end for
procedure swap (int[] array , int curr, int other)
int temp = array[curr]
array[curr] = array[other]
array[other] = temp
end swap |
go through every element in the array, and swap it with a random member inside the same array, like i said, you DONT have to use 2 arrays, 1 work just fine...... |
|
|
|
|
|
Sponsor Sponsor
|
|
|
SakuraSasuke
|
Posted: Mon Jan 21, 2008 8:50 pm Post subject: Re: Deal or no Deal, stuck on randomizing briefcase values |
|
|
one array seems to make sense, but just in case i might need ur help with tht later... so um about the randomizing thing... i substituted my info in kindaish
var money:array 1..26 of real:= init (.01, 1, 5, 10, 25, 50, 75, 100, 200, 300, 400, 500, 750, 1000, 5000, 10000, 25000, 50000, 75000, 100000, 200000, 300000, 400000, 500000, 750000, 1000000)
and then i did
for i : 1.. 26
swap(money, i , Rand.Int(0 , 26)
end for
but then i dont get:
procedure swap (int[] array , int curr, int other)
int temp = array[curr]
array[curr] = array[other]
array[other] = temp
end swap
being me (aka pathetic when it comes to turing) how would i substitute my values into tht? the current and other come from where...?
PS. thnx for helping me, i kno u must be all like : how can she NOT get IT??? but see, u have to accept tht i dont... |
|
|
|
|
|
HeavenAgain
|
Posted: Mon Jan 21, 2008 9:02 pm Post subject: RE:Deal or no Deal, stuck on randomizing briefcase values |
|
|
hehe, its alright if you dont get it at first, but later when i explain it (i hope) you'll get it (sorry im just bad at explainning things..)
anyways, the "swap" method is one of those classic method we using when dealing with array, what this does is, takes in the parameter of your current money array, and the index of the current value, and the other random index which you just passed in by , Rand.Int(0 , 26) and it simply swaps the 2 element
for example here, you have 3 elements in your array {1,2,5} and now you wish to swap the 1 with the 5, and index of 1 is just 1, and 5 is 3, so you pass in the parameter of your array {1,2,5} and the index of 1 (1), and index of 5 (3)
inside the swap method, temp is equal to array at index 1, which is 1, and array at 1 is equal to array at 3 which is 5, and now array at 3 (which is still 5) is now equal to temp, which is 1, and TA DA you just swaped your 2 elements
phew, i hope that helps |
|
|
|
|
|
SakuraSasuke
|
Posted: Mon Jan 28, 2008 7:35 pm Post subject: Re: Deal or no Deal, stuck on randomizing briefcase values |
|
|
YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYYYYYYYYYYYY
i did it
i rule
i accomplished the unacomplishableish
i did DEAL OR NO DEAL!
thnx for ur help
after the whole spaz attack on randomizing was over, it was tres easy
PS. does anybody know how to like take my attahcment off because people keep downloading it and i feel obscurely possessive about tht
i mean, its MY work
people dont desrve to copy it etc. |
|
|
|
|
|
rdrake
|
Posted: Mon Jan 28, 2008 8:39 pm Post subject: Re: Deal or no Deal, stuck on randomizing briefcase values |
|
|
As per the rules, your content is under the Creative Commons license once submitted:
The Rules wrote: All content posted or sumbited in any way to this site most be of your orgainl creation and not copyrighted unless permision is give form the copyrighter. Your agree that all content submiited will be put under the Creative Commons Attribution-ShareAlike 2.5 Canada License copy right agreement (http://creativecommons.org/licenses/by-sa/2.5/ca/legalcode.en). All materals on this site are under the same agreement (http://creativecommons.org/licenses/by-sa/2.5/ca/legalcode.en) and use for them most fallow the code.
Your contributions are of course appreciated. Once submitted, however, they are open for anybody to use. |
|
|
|
|
|
Mazer
|
Posted: Mon Jan 28, 2008 8:43 pm Post subject: RE:Deal or no Deal, stuck on randomizing briefcase values |
|
|
Looks like I was able to delete the attachment. Godspeed, you anime lovin' nerd! Careful with such things in the future; I know how easy it is to miss something like that.
/walkinshadows |
|
|
|
|
|
SakuraSasuke
|
Posted: Wed Jan 30, 2008 9:26 am Post subject: RE:Deal or no Deal, stuck on randomizing briefcase values |
|
|
im going to put up the finished version later
in turing submissions
but there are two problems wit my game:
1. while it chooses values RANDOMLY,
sometimes it chooses the same value twice, ( it may choose a million twice etc) so like when there are three briefcases left, there might be seven values left or something
2. the banker part is screwed...
i mean i didnt get how to do it so i just said if they choose the values like a cent or a dollar: plus some money, if they choose things like a million dollars then lose money...
sometimes, even if a million is gone and 750 000 and 500 000, the bankers offer is like 600 000 which makes no sense.. anyone got ideas for tht?
thnx for taking my turing submission (aka a piece of ****) off but...
whts ur prob with anime?
it rox!
naruto, death note, bleach etc...
looooove it! |
|
|
|
|
|
HeavenAgain
|
Posted: Wed Jan 30, 2008 9:56 am Post subject: RE:Deal or no Deal, stuck on randomizing briefcase values |
|
|
your first problem didnt make sense to me... if you used the shuffle right, you shouldnt encounter any problems, with repeated value of anything
and your 2nd problem, have a look at this and hopefully it will help you how to deal with banker's choice, you shouldn't use a whole bunch of if statements to decide for the banker... its about something like, the avg of the left-over money, and the probabilities... |
|
|
|
|
|
|
|