Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 714 715 [716] 717 718 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 890134 times)

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10725 on: March 08, 2018, 06:14:33 pm »

Little theoretical question (python again), I have:

22 resource types

9 terrain types (+ 1 "is forested" modifier for most of those too)

3 temperatures

How would I go about semi-randomly distributing those resources over a map? would it be easier to build some sort of accepted terrain and scarcity modifiers into the Resource class from which all resources are derived? Then for every tile, go through some kind of formula that randomly chooses which resource based on the terrain (and temperature and is_forested) and scarcity weights?

Also, if anyone is curious the map generator is almost complete! After the resource generator is finished and I make some tweaks to the heat map that will allow it to operate at any scale, it will pretty fully fleshed out and I can move on to actual gameplay stuff. I would post an example, but .txt files suck to reformat on here.
Logged
This conversation is getting disturbing fast, disturbingly erotic.

strainer

  • Bay Watcher
  • Goatherd
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10726 on: March 08, 2018, 08:25:43 pm »

@McScoopbeard - You can experiment with multiple procedures to create and combine intresting patterns, the more approaches combined the more interesting the combination tends to get.
I see some relevant discussion and python code in wikipedias maze generation article.
Logged
Klok the Kloker !

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10727 on: March 09, 2018, 01:35:12 pm »

I'd take a look at random distribution functions (gaussian, poisson, etc) and play with that for a while to make something that generates "well".

Or else you could (depending on your setup) throw a bunch of "seeds" into your terrain overlay and have them iterate growth into the empty cells. And once that's done, you could seed forests and reduce the chance of forest growth per tile away from seed.

Then you could run something like a gaussian/poisson distribution underneath the terrain for the resources, weighted based on terrain type but all with a single seed beneath. You could run temp like DF where up is hot and down is cold, or it's hot in the middle and colder to the edges.... Or run another distribution and make the terrain types the average temperature of their distribution (which would lead to more average temps)

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #10728 on: March 09, 2018, 03:41:41 pm »

  • want to make a game
  • get sidetracked into making a tool, like a sprite editor or map editor
  • end up making a great tool with all the features i want
  • lose interest in making a game right after finishing the tool
I don't understand
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10729 on: March 09, 2018, 05:09:37 pm »

I've discovered that there's actually a pretty big hurdle to jump over once you get to the point of needing to make assets for a game.  Until you get to that point (coding, making tools, whatever) you don't let the enormity of the task set in, but once you start trying to make that first sprite or 3D model, it really hammers home.  I've made something like 120 models in the past 4 months or so and I don't even have enough to finish my intro level yet...

Having a functional game engine and editor helps at least.  With Unreal Engine 4, being able to have things on screen quickly and being able to kind of play the game even with just the first few placeholder pieces helped to keep my motivation up and to power through the initial feeling of never being able to finish.  Working slowly and steadily helps too.
Logged
Through pain, I find wisdom.

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10730 on: March 09, 2018, 05:33:23 pm »

First of all thank you for all the wonderful suggestions! (I apologize if my posts were a little disjointed, I kept writing down my problems, finding my solutions in what I wrote, and subsequently not posting.)

The map generator is... functional, if not as fine-tuned as I like it to be, but in the interest of pushing myself I'm going to get started on integrating my map generator which just outputs to .txt files right now into an actual application.

So speaking of making assets for games and then getting a little lost, I'm not too sure how to proceed here... I think right now handling anything too graphical is a bit much for me so I'm going to constrain myself to an ascii-based graphical approach.

Honestly I have no idea where to begin with python and pygame and displaying the information I have stored in a Rogue-like/DF-like way? Can anyone point me in the right direction?
Logged
This conversation is getting disturbing fast, disturbingly erotic.

bloop_bleep

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10731 on: March 09, 2018, 05:44:10 pm »

Store a list of pygame.Surface objects, corresponding to the characters you want to display on screen. Have a map from terrain elevation, heat, etc. to character ids. Then, when you want to display the map on screen, simply loop through the map cells, follow the terrain map, then the character map, and finally place the image in the corresponding location on the screen.
Logged
Quote from: KittyTac
The closest thing Bay12 has to a flamewar is an argument over philosophy that slowly transitioned to an argument about quantum mechanics.
Quote from: thefriendlyhacker
The trick is to only make predictions semi-seriously.  That way, I don't have a 98% failure rate. I have a 98% sarcasm rate.

strainer

  • Bay Watcher
  • Goatherd
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10732 on: March 09, 2018, 08:33:58 pm »

I suggest not digging too hard into theory on probability distributions unless its especially interesting - just a few basics are sufficient to experiment with what can be involved in procedural generation of worlds/landscapes.

If its ok to be casual here about the technicalities within, here's an overview:

Most basic and useful distribution is most familar one, the *uniform* distribution which is characterised by being boringly flat and bounded (bounded by default convention between 0 and 1)
Not much needs said about it except its great and the most useful.

The gaussian distribution is the other really fundamental one - it is the curve we get from adding zillions of uniform rands, zillions of times. Its pretty much same as the 'bell curve' and even the poisson curve maps to it, just distorted to degrees by extra considerations.

The shape of gaussian is as fundamental to reality as the shape of the square roots.
Its the only random distribution which will produce a radially smooth blotch when plotted in two dimensions - or a sphericaly smooth blob in 3D - or hypersphericaly smooth cluster in 4D etc.
It is precisely perfectly balanced in that geometric respect and probably others too - a mystical distribution in my reckoning. 

Anyway, there's some others such as "cauchy" distribution which iirc is two gaussians multiplied together and important to some theory/calculations, and 'beta' distribution in quantum theory or something, but in game programming the other fundamental distributions can get generated *accidentally* and *unknowingly* while we are tallying and juggling with uniform and gaussian rands.

A proper gaussian random variate (number) can be an odd thing to use in a procedure even when we want the mystical natural curve, because occasionally it can return a HUGE value - the gaussian distribution has no bounds, we cant request a random number between 0 and 10 from a gaussian distribution because the range of all gaussians is infinite.

Quite a smooth approximation of gaussian is doable by adding together, say 5 uniform rands. The max result will then be 5 and min will be 0, most likely will be 2.5 and the likelyhood curve of the values in between will be somewhat close to the perfect gaussian shape.

Likewise the simplest approximation of gaussian which can be perfectly fine in some gaming contexts is the *triangular* distribution resulting from adding just two (uniform) rands together. This is can be known as a *uniform sum* of order 2. Add 3 for *uniform sum* order 3. The uniform sum of order infinity is... gaussian.

I did spend time reading through stuff about other distributions in the course of doing some work with them but the uniform, uniform sums and gaussian are what sticks out as practical and accessible.
Logged
Klok the Kloker !

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10733 on: March 10, 2018, 12:42:02 pm »

A proper gaussian random variate (number) can be an odd thing to use in a procedure even when we want the mystical natural curve, because occasionally it can return a HUGE value - the gaussian distribution has no bounds, we cant request a random number between 0 and 10 from a gaussian distribution because the range of all gaussians is infinite.

The chance of getting any kind of large number from the Gaussian distribution is really really damn low though. The chance not to land between -20 and 20 when choosing a normalized Gaussian distributed value is about
0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000055%. That's so ridiculously low that if you assigned every particle in the known universe a normalized Gaussian distributed random value, there'd still be less than a one-in-a-million chance any particle's number would fall outside the [-20,20] range.

Aside from that, bell-curve distributions really aren't particularly practical in video games; for most any application you'd prefer bounded uniform distributions, or maybe triangular ones as you mentioned. Gaussian randomness is great if you want to produce uniform random points on a sphere, though: Simply choose three Gaussian random values as coordinates for some vector, then normalize the vector. The spherical symmetry you mentioned ensures uniformity of the resulting vector on the unit sphere.
Logged

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10734 on: March 10, 2018, 02:33:44 pm »

I just used turmite/ant-based methods. Basically drawing lines in random directions to form a kind of spline that I just generate more trees/height/whatever around. It's not the most elegant method, but it does produce fairly good maps.
Logged
This conversation is getting disturbing fast, disturbingly erotic.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10735 on: March 10, 2018, 03:10:19 pm »

Could you explain that in more detail? Also I'd love to see some screenshots.
Logged

bloop_bleep

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10736 on: March 10, 2018, 03:27:38 pm »

I just used turmite/ant-based methods. Basically drawing lines in random directions to form a kind of spline that I just generate more trees/height/whatever around. It's not the most elegant method, but it does produce fairly good maps.
Do you mean randomized depth-first search like in the Wikipedia article? That is, do you essentially go in random directions, until you hit a dead end, then backtrack and keep going?
Logged
Quote from: KittyTac
The closest thing Bay12 has to a flamewar is an argument over philosophy that slowly transitioned to an argument about quantum mechanics.
Quote from: thefriendlyhacker
The trick is to only make predictions semi-seriously.  That way, I don't have a 98% failure rate. I have a 98% sarcasm rate.

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10737 on: March 10, 2018, 03:40:59 pm »

Sorry, I'm not yet up to speed on the specific jargon of programming, but this is gist of it:

Code: [Select]
#peak generation
        for peaks in range(0, round(self.size/8)):
            y = random.randint(0,self.size + 1)
            x = random.randint(0,self.size + 1)
            for dist in range(0, random.randint(self.size/5, self.size/2)):
                if((y <= self.size) & (x <= self.size)):
                    heightarray[y][x] = "9"
                y += random.randint(-1,2)
                x += random.randint(-1,2)

Like I said, pretty simplistic, but it with some extra layers of height generation it gives you this:
Spoiler (click to show/hide)
The 'X's are the peaks (some are eroded, so it's not 100% what peak generation outputs).

EDIT: Peak generation just doesn't generate when it goes outside of bounds. ON THE OTHERHAND, my wind map generation does keep itself in bounds, but tends to just stick the bottom right edge because I only cap the maximum and minimum values it can achieve (which accounts for less deserts in that corner but more in the bottom left and mid right. Deserts are "`" and dunes are " ' ".
« Last Edit: March 10, 2018, 03:55:59 pm by Urist McScoopbeard »
Logged
This conversation is getting disturbing fast, disturbingly erotic.

strainer

  • Bay Watcher
  • Goatherd
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10738 on: March 10, 2018, 04:30:18 pm »

The chance not to land between -20 and 20 when choosing a normalized Gaussian distributed value is about  ...1/10^80.
Ah, hadn't noticed it was that low, I was just using gaussians once and noticed getting occasional sporadic overflows. They were scaled up and generated by the billion though.

Some approximation of Gaussian distribution seems the natural choice for a random number which has a target value - like an arrow shot at an archery range; its not likely to hit very close to its target but is also increasingly unlikely to land very far away from it. If we shoot an arrow like a uniform distribution it will be equally likely to go any direction within the firing range.

Too approximate a distribution can make noticeable patterns appear in some cases.

I made some other 'targetting distributions' for convenience:
   'thorn' - quite often returns values very close to its target but the miss distances slope off slowly.
   'teat' - quite rarely returns close but clear misses slope of rapidly.

Those and the other distributions are rendered in this test page.

Quote from: Urist McScoopbeard
Code: [Select]
((x and y)) += random.randint(-1,2)

The landscape looks good. This kind of little change might affect resulting structures:
Code: [Select]
  ((x and y)) += random.randint(-1,1) + random.randint(0,1)
That would make the large steps (-1 and 2) half as frequent as the lesser steps (0 and 1)

I think the average will still be 1/2 an int per iteration there.
Logged
Klok the Kloker !

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10739 on: March 12, 2018, 01:45:00 am »

Spoiler (click to show/hide)

Spoiler (click to show/hide)

EDIT2: Success! The map is now beginning to display properly.

EDIT3: Fricken happy! Screenshot of successful rendering below!

Spoiler (click to show/hide)

EDIT4: Apparently holding ~60k characters in buffering is a bit of a haul for pygame. Update times are pretty slow switching between map modes? Is that normal? or is my code just very inefficient?
« Last Edit: March 12, 2018, 04:12:56 am by Urist McScoopbeard »
Logged
This conversation is getting disturbing fast, disturbingly erotic.
Pages: 1 ... 714 715 [716] 717 718 ... 796