30 Replies - 2527 Views - Last Post: 18 June 2011 - 02:35 AM
#1
Diablo Type: Referential Transparency?
Posted 09 June 2011 - 04:37 PM
I am working on a game project that has a few similarities to Diablo 1/2, in that many areas of the game and items are to be randomly generated. However, I also want to have randomly generated worlds based off of a seed.
However I do not know how to even begin to achieve the last. I need to create a random generator that takes a seed to base its calculations off, but I need it to give the same results for the same seed.
I do have not been able to find much on implementing this so does anyone have any articles on this?
Replies To: Diablo Type: Referential Transparency?
#2
Re: Diablo Type: Referential Transparency?
Posted 09 June 2011 - 05:46 PM
edit:
i goggled "cave generation algorithm" and these where the first 3 things that came up.
http://pcg.wikidot.c...geon-generation
http://properundead....-generator.html
http://pixelenvy.ca/wa/ca_cave.html
there where many more on the List as well.
This post has been edited by ishkabible: 09 June 2011 - 05:57 PM
#3
Re: Diablo Type: Referential Transparency?
Posted 09 June 2011 - 07:00 PM
#4
Re: Diablo Type: Referential Transparency?
Posted 10 June 2011 - 03:01 AM
#5
Re: Diablo Type: Referential Transparency?
Posted 10 June 2011 - 07:29 AM
I was a huge Diablo 2 fan back in the day (I still am, I'm just waiting for Diablo 3 now). I think that game stole 5 years of my life away. But that's not the point, the point has to do with randomly generated worlds.
Diablo 2 uses a set of pre-defined maps for each act, then when a game is created the game randomly chooses which pre-defined map to display. Which really isn't random map generation. I think I've played enough Diablo 2 to know this for sure. So that is one way that you could do it. Just create like 5 maps for 1 area, then when the player begins the game, pick a random number between 1 and 5 and just display the map that has that number corresponding to it.
I point this out because random map generation algorithms can be very difficult to implement (you have to make sure your algorithm doesn't create a wall blocking off the stairs to the next level, or puts a chest with high level gear in the starting area, ect).
So I just thought I would give you that tidbit to think about since choosing between a set of pre-defined maps is way easier than generating a true random map (pre-defined maps would probably take a lot more time due to creating each map individually, but would be easier to implement). Plus this gives you the benefit to more thoroughly, and intentionally design each experience in a map, which could benefit the overall experience for the player.
I hope that helps you out. Good luck with your game, the world can always use more games like D2. If you have any more questions then don't hesitate to ask
This post has been edited by Fib: 10 June 2011 - 07:33 AM
#6
Re: Diablo Type: Referential Transparency?
Posted 10 June 2011 - 04:07 PM
I don't want to go into to much detail and ruin the fun of discovery when i drop a tech demo but yeah.
I realise as well that item placement will be an issue but i have both found and come up with some ways to help make sure that there will be as few anomalies as possible and the few that do slip through... Wow end user you sure got lucky... yeah special secret random treasure... lol.
EDIT: Oh thanks for the move, sorry about that new here.
Once again, thanks for being very supportive guys.
Nekroze
This post has been edited by Nekroze: 10 June 2011 - 04:08 PM
#7
Re: Diablo Type: Referential Transparency?
Posted 10 June 2011 - 09:04 PM
Can i pass a function an instanced class?
I have a map class instanced as MAP01, i want to pass that to a function that will randomly draw on the map space, which is a 2d array within MAP01.
Can this be accomplished, i imagine it would require the use of pointers right?
One more thing i don't exactly get: then above links to random map gen stuff is completely random, i mean each and ever time. however i need to create an entire map based off of a seed (such as 12345 (bad example lol)).
but if i have a tile and give it say a a 20% chance of continuing based on randomly generating a number up to 100 then every single tile i place that equation on will respond the same as the last and that would probably just make either a blob or a circle... but if i make it truly random (not using a static seed but say the clock) then the same room will be different each and every time i draw it.
considering my game is supposed to ask the player before starting for a seed and then makes the whole world based off of that (not too unlike minecraft at the beginning i guess) and players could share cool seeds... how tho... just thinking
thanks,
Nekroze
This post has been edited by Nekroze: 10 June 2011 - 09:31 PM
#8
Re: Diablo Type: Referential Transparency?
Posted 11 June 2011 - 03:01 AM
#9
Re: Diablo Type: Referential Transparency?
Posted 11 June 2011 - 06:49 AM
class smallMap{
public:
smallMap();
int setTile( int iX, int iY, int iN );
void pixDrawMap();
void clearMap();
protected:
int map[30][30];
int tileS; //x/y size in pixels per tile
};
And in my main code i have:
smallmap MAP01; MAP01.settile( 1, 1, 1 ); MAP01.settile( 1, 2, 1 ); MAP01.settile( 1, 3, 1 );
what i want to do is something like this:
generatejungle( MAP01 ); //takes my instance of smallmap and generates a jungle on MAP01.map[][]
as for the second part the point of that is i don't know where to even begin my code to make an entire map out of the same seed for a random generator. at least not in a way the is "referentially transparent" (ie, the same each time its generated on that seed) so that's why i asked, does anyone have any experience on this. Even anything to do with how minecraft can take a seed and produce identical maps across different machines even with the exact same seed?
Nekroze
#10
Re: Diablo Type: Referential Transparency?
Posted 11 June 2011 - 07:12 AM
You can pass objects as functions, just like any other variable a function would use. Passing in a pointer to the object would allow the original object to be edited by the function without the need to return it.
#11
Re: Diablo Type: Referential Transparency?
Posted 11 June 2011 - 07:16 PM
As for the random thing i should try express my logic problems with psudo code ok:
setRandomSeed(12235432536);
function drawMapRandomly(int startx, int starty){
if getTileAbove(startx, starty) != 1 then
20% chance to draw a tile above
}
But if i implement the 20% chance thing as i would with a normal clock based seed
int rando = rnd(100) if rando <= 20 then drawTile()
The result on every single call of "drawMapRandomly()" would be the same?
So how when the same numbers always come out of a random function with the same seed can i preserve the seed yet call that function and not have to be the same chance to draw the next tile on the map?
Thanks for being so very helpful guys,
Nekroze
#12
Re: Diablo Type: Referential Transparency?
Posted 12 June 2011 - 04:37 AM
Nekroze, on 11 June 2011 - 07:16 PM, said:
As for the random thing i should try express my logic problems with psudo code ok:
setRandomSeed(12235432536);
function drawMapRandomly(int startx, int starty){
if getTileAbove(startx, starty) != 1 then
20% chance to draw a tile above
}
But if i implement the 20% chance thing as i would with a normal clock based seed
int rando = rnd(100) if rando <= 20 then drawTile()
The result on every single call of "drawMapRandomly()" would be the same?
So how when the same numbers always come out of a random function with the same seed can i preserve the seed yet call that function and not have to be the same chance to draw the next tile on the map?
Thanks for being so very helpful guys,
Nekroze
If you initialise the random number generator with the clock then the map generation every time you run the app will be different. But if you use a static seed every time you run the app it should be the same. If you're thinking that having the same seed will cause every random number generated after the seed is entered to be the same number then you're thinking wrong. The way it works is that you initialise the generator and that will give you a practically neverending sequence of numbers, so you initialise once and then just keep calling for the next random number in the sequence.
With a static seed this sequence will be the same every time you initialise to the seed, so if you initialise it once it won't repeat, but if you initialise it every time you want a new number the number will always be the first in the sequence.
#13
Re: Diablo Type: Referential Transparency?
Posted 12 June 2011 - 04:44 AM
So the following statement:
rndSeed(12345) //setting the seed for a rnd() type function int num1 = rnd(100); int num2 = rnd(100); if num1 != num2 then return 1
so far as what you are saying, this would indeed return 1 as num1 and num2 would be different as the second calling of rnd() get the second number on the stack?
Sorry I am just really unclear on all this number generator stuff... maybe I should make a little basic one to figure it out better.
Thanks,
Nekroze
#14
Re: Diablo Type: Referential Transparency?
Posted 12 June 2011 - 07:33 AM
#15
Re: Diablo Type: Referential Transparency?
Posted 12 June 2011 - 02:05 PM
Once I get something basic going for the maps i will drop a demo exe or something hey? or just screenies?
Thanks to all for the assistance, Repped up for the massive help.
Nekroze
|
|

New Topic/Question
Reply




MultiQuote










|