Web Hosting Talk







View Full Version : PHP/Mysql Help


Mooecow
09-18-2004, 12:41 PM
Hello, I own www.XchaosX.com I coded it myself except i have one small thing that is confuzing me. When sombody attacks i want their items ( weapons ) to be removed depending on their net worth. I have their net worth auto totalled up. How would i get it to determine how many weapons are worth 3% of the users total inventory, and then remove them?

So basically it has to remove a certain # of weapons ( that vary ) depending on the users total worth.

I know that was confuzing :(

Hopefully sombody out there knows how :D

mattwade
09-18-2004, 12:55 PM
Are the weapons worth the same amount or is each weapon worth different amounts? This will greatly change the algorithm..

Mooecow
09-18-2004, 12:59 PM
Originally posted by mattwade
Are the weapons worth the same amount or is each weapon worth different amounts? This will greatly change the algorithm..

All the weapons are worth different amounts.

gogocode
09-18-2004, 01:37 PM
Originally posted by Mooecow
All the weapons are worth different amounts.

Then you have a greatly more difficult problem on your hands, known as the knapsack problem, which it's NP-complete; essentially this means for you that there is no 'easy' way to work out which set of weapons can be removed, adding up to exactly 3%, all you can do is try combinations (brute-force) until you find one, of course, the more weapons they have, the more (many many more) combinations you have to try :-)

I would simplify the problem, remove the higest valued weapons until you reach or exceed the 3% threshold.

mattwade
09-18-2004, 02:01 PM
Or you could make it a tad bit more random by doing this:

1. Order the items from highest to lowest.
2. Randomly generate a number between 1 and 5 (x)
3. Go x number into the stack
4. Add item to remove stack
5. repeat from step 2 until you have 3 percent.

Loop back around the stack if need be.

Mooecow
09-18-2004, 04:55 PM
Originally posted by gogocode

I would simplify the problem, remove the higest valued weapons until you reach or exceed the 3% threshold.

I was thinking about trying to do somthing like that, but once i tryed to start coding it, i got lost, fast. Any advice on how i can code that? :confused:

sea otter
09-18-2004, 05:45 PM
Originally posted by gogocode

I would simplify the problem, remove the higest valued weapons until you reach or exceed the 3% threshold.

That would not make for very good gameplay. (As a former game developer, I'd know ;) )

1. It will bias play
2. It will be obvious to the user, who will then find it very annoying and submit a bug report/feature request change.

Sorry, I don't think there's any free lunch here :(