This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-02-10 16:08:55

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Advanced probability help

Right guys, here's a real challange for you: (please only answer if you actually know what you're on about here).

For part of the game I'm currently working on, there's an area called mystery box. This box appears once a day, and once opened, will reveal a randomly chosen item.

Catch 1:
There is a list of possible items that the box could open to reveal, the first of which is highly probable and the last of which is the least probably (so the percentage chance of getting an item is determined by it's place in the list).

Catch 2:
Before you open the box, you have to pay. You can choose how much money you give, and this affects the probability of getting certain items! Giving the maximum amount (say, 1000 gives you the highest probability of getting an item of low probability in the list, though still offers a small chance of getting something of higher probability and less worth whilst paying the smallest amount (1) decreases the probability of getting a highly improbable item and more or less ensures getting a more probably one though there is still a possibility of gaining an improbably item).

Catch 22:
Is a pretty neat piece of work  big_smile

It was easy before catch 2 came along... does anyone have any idea how I might achive this???

Many thanks for taking on the challange!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#2 2011-02-10 16:40:05

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Advanced probability help

have 2 lists
Items in box

Temp.

have a variable
% of max cash entered

set var1 to ( (length of Items in box) / (% of max cash entered) )
set var2 to ( (length of Items in box) * (var1) )
set var2 to ( (length of Items in box) - (var2) )

*Temp list contains all probibilty (percent) per item*
set var1 to 0
repeat ( round (var2 - 0.5) )
| change var1 by 1
| set var3 to ( round var2 - 0.5 )
| set var3 to (var2 / var 3)
| set var3 to (var3 * var1)
| repace item var1 of temp with var3
|__________________


Think that should help


You can now reach me on Twitter @johnnydean1_

Offline

 

#3 2011-02-10 16:55:33

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Advanced probability help


You can now reach me on Twitter @johnnydean1_

Offline

 

#4 2011-02-11 05:15:22

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Advanced probability help

Wow... looks complicated! I'll have to look into it, thanks. I'll remember to credit you  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#5 2011-02-11 11:18:12

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Advanced probability help

Johnnydean's method is correct. That is the way most games with this kind of feature do it. Its a typical use of arrays (lists in scratch).

What I would do exactly is first take the money in and then use that to alter the propability of getting the rare item. So say 100 gold was added, increase the odds of getting the rarer items and decrease the chance of more common items.

When the probability is assigned all the probability should add to 100. Each number represents a item on a list. Create a new item on the list with all the items that may be won and give them the number of items equal to their probalility. So with a 10% chance to get a dragon tooth you would have 10 items on the list saying dragon tooth. Then pick a random item from the list from 1 to 100.

Last edited by archmage (2011-02-11 11:26:53)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#6 2011-02-11 16:25:34

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Advanced probability help

Updated project, fixed math and auto-start calculations here


You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer