Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Resource Mining Techniques - GT6  (Read 1623 times)
0 Members and 1 Guest are viewing this topic.
Offline MickeyB

Senior Member




my game will work, my game will work!


« Posted 2004-04-21 15:09:47 »

I have natrual resources avaialable on asteroids, moons, planets, etc...
My data feed for these from file looks like so: 0 521 147487 1459 204 0 0 0
Defined as so:
Gemstones            0
Metal Alloys            521
Metal Ores            147487
Minerals            1459            
Precious Metals            204
Seeds                  0
Spices                  0
Water                  0

I am trying to rework my ship mining laser system and base it on a "most avaialable is more likely to be mined."  When a ships mining laser is fired, it pings the server, and gets a result back.  Right now it is based on a hardcoded percentage system with a Random int used to find what you get.  
That method works for the above quantities because it was designed on that default asteroid set up.  But...not all planetoids are the same.  A moon made of ice may only have water and minerals available.

Ice Moon example:
Gemstones            0
Metal Alloys            0
Metal Ores            0
Minerals            14591            
Precious Metals            0
Seeds                  0
Spices                  0
Water                  578471

Any suggestions on how to take my numbers and base a "selection criteria" on the quantities?  Should a mining laser ping possible return nothing?

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #1 - Posted 2004-04-21 15:30:48 »

Hi
 Add up the total amount of all resources for the whole object, and then divide each resource quantity by that number (skipping 0s)

0 521 147487 1459 204 0 0 0

total = 149671

0 0.00348 0.98540 0.00974 0.00136 0 0 0

then you can do a Math.random and go along adding them up untill you go over that value, and pick that one. eg

Math.random() = 0.5234

0 + 0.00348 < 0.5234 so carry on
0 + 0.00348 + 0.98540 >= 0.5234 so that is what they mined

in this case you are really heavily weighted to the metal ores, but I suspect that is the point, in the last case you will most likely end up on water when you go over the random value

I know I explained it like you are a 4 year old, but my explaination in text was really really bad, so I put in noddy examples of what I meant Smiley

As for returning nothing, I think unless you have a skill level attached to mining, then probably not, if you have some kind of skill level then you can just use that as an instant roll to work out if you even want to bother working out *what* they mined.

HTH

Endolf

Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #2 - Posted 2004-04-21 17:21:56 »

Sounds good.  But in cases where I have heavy weight in ore (for example), you will rarley get past it, and if you do, and the next item is less, then you will always get the next item and never make it further.....I think.  I will put it into code and give it a test.  Thanks!!

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #3 - Posted 2004-04-21 17:54:46 »

Hi
 Re not getting past heavily weighted objects, thats the point of them Smiley, you have as much chance of getting <0.1 as you do of getting >=0.9, if you had 3 types, at 0.1, 0.8 and 0.1, then you would get the bottom and top ones as often as each other, roughtly 10% of the time you get the first, and roughly 10% you get the top, the other 80% you get stuck in the middle, which is the point of the high weighting Smiley

I think that makes sence Smiley

Endolf

Offline CodexArcanum

Senior Newbie




Games == Life


« Reply #4 - Posted 2004-04-21 17:57:04 »

No, I don't think that's how it works.  Or maybe I'm reading it wrong.  It basically looks like Endolf calculates the percentage of each item in the rock, then rolls math.random to get a percentage value.  Whatever range the random falls into, that's the item you get.  In that case, you'd just have better odds of getting the material in greater quantity, but if a few other minerals had equal but smaller amounts, then you'd have an equally small chance of getting any one of them, as compared to the item you have the most of.
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #5 - Posted 2004-04-21 18:04:54 »

Hi
 Thats exactly it Smiley

Endolf

Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #6 - Posted 2004-04-21 19:26:38 »

makes sense, but is stumping me at one place...

items on rock

0 0 1400 50010 200 1900

You may get past #4 on rare occasion, but you would never get past #5 to get to #6 because being larger than what is need to get #4 will always be large enough to get #5, thus #6 is never reached...

or did my brain freeze Grin

...  ok after further review I understand and also relized I was increment the random, instead of the percentage totals..My last test got 4 #4's and 1 #5.  Now to see if I can get to # 6..

Thanks again!

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #7 - Posted 2004-04-22 08:48:04 »

Ok, I've written some test code, get it here. I get some nice looking results, like
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
Failed to mine anything: 9976
Gemstones              : 0
Metal Alloys           : 293
Metal Ores             : 88775
Minerals               : 843
Precious Metals        : 113
Seeds                  : 0
Spices                 : 0
Water                  : 0

Failed to mine anything: 9934
Gemstones              : 0
Metal Alloys           : 0
Metal Ores             : 0
Minerals               : 2167
Precious Metals        : 0
Seeds                  : 0
Spices                 : 0
Water                  : 87899

Thats over the two different objects you gave us with 100000 attempts to mine on each. It looks right, I've got in a 90% proficient miner there Smiley

HTH

Endolf

Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #8 - Posted 2004-04-22 13:20:55 »

Thanks a ton.  Appreciate tht time you put into that!  I actually took you reply lterally earlier and came up with this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
      public void sendMiningLaserResults(Connection con) {
            System.out.println();
            System.out.println();
            byte[][] args = new byte[3][];
            
            double total = 0.0;
            for(int i=0;i<naturalResources.length;i++) {      
                  total += naturalResources[i];
            }      
            // the chance roll d100
           double chance = Math.random();
            double runningTotal = 0.0;
            double[] percents = new double[naturalResources.length];
            for(int i=0;i<percents.length;i++) {
                  percents[i] = naturalResources[i]/total;
            }
            // get the resource mined
           for (int i=0;i<percents.length;i++) {
                  runningTotal += percents[i];
                  if(runningTotal > chance) {
                        // this is what is mined
                       if(con.hasCargoSpace(1)) {
                              // get resource
                             naturalResources[i]--;
                              int ind = getProductIndex(resourceNames[i]);
                              con.addCargo(ind, 1);

                              args[0] = ProtocolHelper.intToByteArray(1);  // 1 = success
                             args[1] = ProtocolHelper.intToByteArray(ind);// id of prod
                             args[2] = ProtocolHelper.intToByteArray(1);       // quantity
                             //con.addExperience(1);
                       }
                        else {
                              args[0] = ProtocolHelper.intToByteArray(0);
                        }
                        con.send(CMD_SHIPMININGLASER, args);
                        System.out.println(con.getAlias() + " mined: " + resourceNames[i]);
                        return;      
                  }      
            }
            
      }


This seems to work pretty well, but I may incorporate some of your system.  Mine is set up to not have a fail, but I may change that.  

Now that I review it again, I DO like your proficiency check...I have 9 blank skill slots in my player object...may have to make one mining_prof.

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (18 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (31 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (41 views)
2014-07-23 21:16:32

Riven (28 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (60 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!