Diablo Type: Referential Transparency?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

30 Replies - 7577 Views - Last Post: 18 June 2011 - 02:35 AM Rate Topic: -----

#1 Nekroze   User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Diablo Type: Referential Transparency?

Posted 09 June 2011 - 04:37 PM

Hello DIC,

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?

Is This A Good Question/Topic? 0
  • +

Replies To: Diablo Type: Referential Transparency?

#2 ishkabible   User is offline

  • spelling expret
  • member icon





Reputation: 1747
  • View blog
  • Posts: 5,898
  • Joined: 03-August 09

Re: Diablo Type: Referential Transparency?

Posted 09 June 2011 - 05:46 PM

well as for the having the same outcome for the same seed your in luck, that's how random number generators work. as for random terrain generation i think there are some decent algorithms out there. ill look for some and post back.

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

Was This Post Helpful? 1
  • +
  • -

#3 Nekroze   User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: Diablo Type: Referential Transparency?

Posted 09 June 2011 - 07:00 PM

thanks a heap mate, time to start reading. will post back if I find anything noteworthy for anyone else looking for help in this field.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6248
  • View blog
  • Posts: 24,015
  • Joined: 23-August 08

Re: Diablo Type: Referential Transparency?

Posted 10 June 2011 - 03:01 AM

Moved to Game Programming
Was This Post Helpful? 0
  • +
  • -

#5 Fib   User is offline

  • D.I.C Addict
  • member icon

Reputation: 163
  • View blog
  • Posts: 554
  • Joined: 12-March 09

Re: Diablo Type: Referential Transparency?

Posted 10 June 2011 - 07:29 AM

I just want to give you something to think about.

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

Was This Post Helpful? 0
  • +
  • -

#6 Nekroze   User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: Diablo Type: Referential Transparency?

Posted 10 June 2011 - 04:07 PM

Thanks for the support mate, i do realise this is how diablo worked on its maps and the items where practically completely procedurally generated however in my game it would not really work. After reading many articles on this stuff i realise my project also bears similarities to Dwarven Fortress i believe its called... yeah the entire world is randomly generated including the structure of the town and more.

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

Was This Post Helpful? 0
  • +
  • -

#7 Nekroze   User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: Diablo Type: Referential Transparency?

Posted 10 June 2011 - 09:04 PM

Quick Question:

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

Was This Post Helpful? 0
  • +
  • -

#8 stayscrisp   User is offline

  • フカユ
  • member icon

Reputation: 1040
  • View blog
  • Posts: 4,325
  • Joined: 14-February 08

Re: Diablo Type: Referential Transparency?

Posted 11 June 2011 - 03:01 AM

Posting some code would make it a lot easier to answer your questions :)
Was This Post Helpful? 0
  • +
  • -

#9 Nekroze   User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: Diablo Type: Referential Transparency?

Posted 11 June 2011 - 06:49 AM

um code for what... for the first part i guess:
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
Was This Post Helpful? 0
  • +
  • -

#10 bonyjoe   User is offline

  • D.I.C Addict
  • member icon

Reputation: 178
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: Diablo Type: Referential Transparency?

Posted 11 June 2011 - 07:12 AM

The way random number generators work is that they are initialised with a seed. If all of your generation uses random numbers as long as it always runs in the same order using the same seed for the random number generator then things will end up the same.

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.
Was This Post Helpful? 1
  • +
  • -

#11 Nekroze   User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: Diablo Type: Referential Transparency?

Posted 11 June 2011 - 07:16 PM

thanks for the passing objects thing, i think i got that now.

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
Was This Post Helpful? 0
  • +
  • -

#12 bonyjoe   User is offline

  • D.I.C Addict
  • member icon

Reputation: 178
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: Diablo Type: Referential Transparency?

Posted 12 June 2011 - 04:37 AM

View PostNekroze, on 11 June 2011 - 07:16 PM, said:

thanks for the passing objects thing, i think i got that now.

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.
Was This Post Helpful? 1
  • +
  • -

#13 Nekroze   User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: Diablo Type: Referential Transparency?

Posted 12 June 2011 - 04:44 AM

Ok, i think of follow, sorry im very new to using random number generators like this.

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
Was This Post Helpful? 0
  • +
  • -

#14 bonyjoe   User is offline

  • D.I.C Addict
  • member icon

Reputation: 178
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: Diablo Type: Referential Transparency?

Posted 12 June 2011 - 07:33 AM

That is how it would work yes. Most programming languages have their own random number classes which you can use which initialise from a seed, so you should probably start using one of those and then if you need to optimise it you could write your own class for generating them.
Was This Post Helpful? 1
  • +
  • -

#15 Nekroze   User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: Diablo Type: Referential Transparency?

Posted 12 June 2011 - 02:05 PM

Alright thanks, I believe I got enough to get a heap done on this now.

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
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3