Last active
February 27, 2017 04:04
-
-
Save david-wm-sanders/5f42be5356f54f7dc338df956ea06030 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import itertools | |
import random | |
from csv import DictReader | |
from pathlib import Path | |
gems_csv= Path("./gems.csv") | |
Gem = collections.namedtuple("Gem", "name value") | |
GemCategory = collections.namedtuple("GemCategory", "weight diev dievmult avgv gems") | |
gem_categories = {} | |
with gems_csv.open() as csvf: | |
reader = DictReader(csvf) | |
for row in reader: | |
category = int(row["category"]) | |
weight = int(row["weight"]) | |
diev = row["diev"] | |
dievmult = int(row["dievmult"]) | |
avgv = int(row["avgv"]) | |
gems = row["gems"].split(", ") | |
gc = GemCategory(weight, diev, dievmult, avgv, gems) | |
gem_categories[category] = gc | |
population = list(gem_categories.keys()) | |
cweights = list(itertools.accumulate(gem_categories[category].weight for category in population)) | |
def check_weights(): | |
print("Checking weights...") | |
counter = collections.Counter(random.choices(population, cum_weights=cweights, k=1000)) | |
print(counter.most_common()) | |
def d(x): | |
return random.randint(1, x) | |
def make_random_gem(): | |
x = random.choices(population, cum_weights=cweights)[0] | |
gc = gem_categories[x] | |
name = random.choice(gc.gems) | |
diev = gc.diev | |
y, x = diev.split("d") | |
value = sum(d(int(x)) for i in range(int(y))) * gc.dievmult | |
return Gem(name, value) | |
if __name__ == '__main__': | |
check_weights() | |
for i in range(5): | |
gem = make_random_gem() | |
print(f"{gem.name}: {gem.value}gp") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
category | dpercentile | weight | diev | dievmult | avgv | gems | |
---|---|---|---|---|---|---|---|
1 | 1-25 | 25 | 4d4 | 1 | 10 | banded agate, eye agate, moss agate, azurite, blue quartz, hematite, lapis lazuli, malachite, obsidian, rhodochrosite, tiger eye turquoise, freshwater (irregular) pearl | |
2 | 26-50 | 25 | 2d4 | 10 | 50 | bloodstone, carnelian, chalcedony, chrysoprase, citrine, iolite, jasper, moonstone, onyx, peridot, rock crystal (clear quartz), sard, sardonyx, rose quartz, smoky quartz, star rose quartz, zircon | |
3 | 51-70 | 20 | 4d4 | 10 | 100 | amber, amethyst, chrysoberyl, coral, red garnet, brown-green garnet, jade, jet, white pearl, golden pearl, pink pearl, silver pearl, red spinel, red-brown spinel, deep green spinel, tourmaline | |
4 | 71-90 | 20 | 2d4 | 100 | 500 | alexandrite, aquamarine, violet garnet, black pearl, deep blue spinel, golden yellow topaz | |
5 | 91-99 | 9 | 4d4 | 100 | 1000 | emerald, white opal, black opal, fire opal, blue sapphire, fiery yellow corundum, rich purple corundum, blue star sapphire, black star sapphire, star ruby | |
6 | 100 | 1 | 2d4 | 1000 | 5000 | bright green emerald, white diamond, canary diamond, pink diamond, blue diamond, jacinth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment