Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Some What Intelligent Random Map Generation
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
pers2981




PostPosted: Wed Dec 28, 2011 2:40 pm   Post subject: Some What Intelligent Random Map Generation

Hey there,

A few days ago I started working on a top down RPG game were you play as a night who has to protect the world from evil. The map is going to look something like this,


Posted Image, might have been reduced in size. Click Image to view fullscreen.

Were the Green brick is equal to grass and the Blue brick is water and the Brown brick is dirt (etc). Right now the generation system is completely random, as you can see there is water scattered across the world in illogical places. I would like to do something like this.

>Generate Lakes/Rivers (Water)
>Generate Paths (Dirt)
>Fill the rest with Grass (Grass)

But i'm not exactly sure how I would go about doing so.

Any advice/suggestions?



Turing:


%===========================================================================%
% = == = == = == = == = == =  Initial Setup = == = == = == = == = == = == = %
%===========================================================================%
setscreen ("graphics:500;500,nobuttonbar,offscreenonly")

%===========================================================================%
% = == = == = == = == = == =  GenerateWorld = == = == = == = == = == = == = %
%===========================================================================%
var RowX : int := 0
var RowY : int := 0
var TileType : array 1 .. 115 of string
var TempColor : int := 0
var Test : int := 0
procedure GenerateWorld
    for i : 1 .. 115
        if RowX > 10 then
            RowX := 0
            RowY := RowY + 1
        end if

        Test := Rand.Int (1, 3)
        if Test = 1 then
        TileType(i) := "Grass"
        end if
        if Test = 2 then
        TileType(i) := "Stone"
        end if
        if Test = 3 then
        TileType(i) := "Dirt"
        end if
       
       
        if TileType (i) = "Grass" then
            TempColor := 10
        end if
        if TileType (i) = "Stone" then
            TempColor := 100
        end if
        if TileType(i) = "Dirt" then
        TempColor := 187
        end if       

        Draw.FillBox (RowX * 50, RowY * 50, RowX * 50 + 50, RowY * 50 + 50, TempColor)
        RowX := RowX + 1
    end for
end GenerateWorld
%===========================================================================%
% = == = == = == = == = == =    Game Loop   = == = == = == = == = == = == = %
%===========================================================================%
GenerateWorld
loop
    View.Update
end loop

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Dec 28, 2011 3:28 pm   Post subject: Re: Some What Intelligent Random Map Generation

pers2981 @ Wed Dec 28, 2011 2:40 pm wrote:
you play as a night

would this night(man) be fighting day(man)? Laughing http://www.youtube.com/watch?v=TzaVd6zl2bA (it's always sunny in philadelphia)

Serious response -- a neat approach to world generation is to start with something plausible looking and then run that world in simulation mode for a few thousand years (of game time). In particular, I am a fan of Dwarf Fortress' approach http://df.magmawiki.com/index.php/DF2010:World_generation#The_Generation_Process
Quote:

You may notice that during various phases of the world generation process worlds will be rejected, leading to the rejection count going up and the process starting over. This happens because certain factors such as number of mountain tiles can't be determined ahead of time by the generation process. Instead worlds are generated with parameters which are likely to produce worlds that can support a required number of mountains, and are then checked to make sure they meet the criteria. For example, the random generation of the topography of the land may result in too few high elevation areas to place mountains.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
pers2981




PostPosted: Wed Dec 28, 2011 3:37 pm   Post subject: Re: Some What Intelligent Random Map Generation

Tony @ Wed Dec 28, 2011 3:28 pm wrote:
pers2981 @ Wed Dec 28, 2011 2:40 pm wrote:
you play as a night

would this night(man) be fighting day(man)? Laughing http://www.youtube.com/watch?v=TzaVd6zl2bA (it's always sunny in philadelphia)

Serious response -- a neat approach to world generation is to start with something plausible looking and then run that world in simulation mode for a few thousand years (of game time). In particular, I am a fan of Dwarf Fortress' approach http://df.magmawiki.com/index.php/DF2010:World_generation#The_Generation_Process
Quote:

You may notice that during various phases of the world generation process worlds will be rejected, leading to the rejection count going up and the process starting over. This happens because certain factors such as number of mountain tiles can't be determined ahead of time by the generation process. Instead worlds are generated with parameters which are likely to produce worlds that can support a required number of mountains, and are then checked to make sure they meet the criteria. For example, the random generation of the topography of the land may result in too few high elevation areas to place mountains.



I forgot the K Shocked


Thanks for that I'll look into it more.
pers2981




PostPosted: Wed Dec 28, 2011 3:53 pm   Post subject: Re: Some What Intelligent Random Map Generation

Hey so I looked more into dwarf fortress world generation but i'm still a bit lost. Not to sound like a lecher but how would I implement something like that into my code?
Tony




PostPosted: Wed Dec 28, 2011 4:01 pm   Post subject: RE:Some What Intelligent Random Map Generation

Study up on some geology -- http://en.wikipedia.org/wiki/Geology#Geological_evolution_of_an_area
Quote:

The geology of an area evolves through time as rock units are deposited and inserted and deformational processes change their shapes and locations.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Insectoid




PostPosted: Wed Dec 28, 2011 6:09 pm   Post subject: RE:Some What Intelligent Random Map Generation

A common method is to use a fractal height map, where different heights represent different textures, ie the lowest heights are water, followed by sand, grass, rock, and snow.
pers2981




PostPosted: Wed Dec 28, 2011 8:30 pm   Post subject: Re: RE:Some What Intelligent Random Map Generation

Insectoid @ Wed Dec 28, 2011 6:09 pm wrote:
A common method is to use a fractal height map, where different heights represent different textures, ie the lowest heights are water, followed by sand, grass, rock, and snow.

Yeah that would work for a side scrolling game such as terraria but for me it simply wont work. The game is a TOP DOWN rpg.
Insectoid




PostPosted: Wed Dec 28, 2011 8:38 pm   Post subject: RE:Some What Intelligent Random Map Generation

Oh, it works. There are 2 examples of exactly what you're looking for in the wiki.
Sponsor
Sponsor
Sponsor
sponsor
pers2981




PostPosted: Wed Dec 28, 2011 8:55 pm   Post subject: Re: RE:Some What Intelligent Random Map Generation

Insectoid @ Wed Dec 28, 2011 8:38 pm wrote:
Oh, it works. There are 2 examples of exactly what you're looking for in the wiki.

Okay? Like I said above. I have no idea on how i would do something like this in turing
Aange10




PostPosted: Wed Dec 28, 2011 8:59 pm   Post subject: RE:Some What Intelligent Random Map Generation

Haha, let's figure it out then. I'll code one too :p
pers2981




PostPosted: Wed Dec 28, 2011 9:14 pm   Post subject: Re: RE:Some What Intelligent Random Map Generation

Aange10 @ Wed Dec 28, 2011 8:59 pm wrote:
Haha, let's figure it out then. I'll code one too :p

Ha, Sounds like a plan. I have never done any "Map" related stuff before so this will be quiet complex for me, any advice?
Tony




PostPosted: Wed Dec 28, 2011 9:22 pm   Post subject: Re: RE:Some What Intelligent Random Map Generation

pers2981 @ Wed Dec 28, 2011 9:14 pm wrote:
any advice?

Start simple. Taking on the entire project at once is overwhelming. Pick one key feature, and focus on that first.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Aange10




PostPosted: Wed Dec 28, 2011 9:30 pm   Post subject: RE:Some What Intelligent Random Map Generation

No advise. I'm working on a recursive way to get an ocean to go from "shallow > average > deep". Just an idea. PM for skype and we can talk there!
pers2981




PostPosted: Wed Dec 28, 2011 9:56 pm   Post subject: Re: RE:Some What Intelligent Random Map Generation

I was playing around with it and I managed to make a bit more "Logical" map generation system. Its still random but if the block to the left of it is grass then it will have a 50% chance that the next block will be grass aswell. It makes it look a bit more "Group" ish, but only horizontally.

Turing:

%===========================================================================%
% = == = == = == = == = == =  Initial Setup = == = == = == = == = == = == = %
%===========================================================================%
setscreen ("graphics:500;500,nobuttonbar,offscreenonly")

%===========================================================================%
% = == = == = == = == = == =  GenerateWorld = == = == = == = == = == = == = %
%===========================================================================%
var RowX : int := 0
var RowY : int := 0
var TileType : array 1 .. 115 of string
var TempColor : int := 0
var Test : int := 0
var TempNumber : int := 0
procedure GenerateWorld
    for i : 1 .. 115
        if RowX > 10 then
            RowX := 0
            RowY := RowY + 1
        end if

        if i = 1 then
            Test := Rand.Int (1, 3)
            if Test = 1 then
                TileType (i) := "Grass"
                TempColor := 10
            end if
            if Test = 2 then
                TileType (i) := "Stone"
                TempColor := 100
            end if
            if Test = 3 then
                TileType (i) := "Dirt"
                TempColor := 187
            end if
        end if
        if i > 1 then
            TempNumber := i - 1
            if TileType (TempNumber) = "Grass" then
                Test := Rand.Int (1, 9)

                if Test = 1 or Test = 2 or Test = 3 or Test = 4 or Test = 5 then
                    TileType (i) := "Grass"
                    TempColor := 10
                end if
                if Test = 6 or Test = 7 then
                    TileType (i) := "Stone"
                    TempColor := 100
                end if
                if Test = 8 or Test = 9 then
                    TileType (i) := "Dirt"
                    TempColor := 187
                end if
            end if

            if TileType (TempNumber) = "Stone" then
                Test := Rand.Int (1, 9)

                if Test = 1 or Test = 2 or Test = 3 or Test = 4 or Test = 5 then
                    TileType (i) := "Stone"
                    TempColor := 100
                end if
                if Test = 6 or Test = 7 then
                    TileType (i) := "Grass"
                    TempColor := 10
                end if
                if Test = 8 or Test = 9 then
                    TileType (i) := "Dirt"
                    TempColor := 187
                end if
            end if

            if TileType (TempNumber) = "Dirt" then
                Test := Rand.Int (1, 9)

                if Test = 1 or Test = 2 or Test = 3 or Test = 4 or Test = 5 then
                    TileType (i) := "Dirt"
                    TempColor := 187
                end if
                if Test = 6 or Test = 7 then
                    TileType (i) := "Grass"
                    TempColor := 10
                end if
                if Test = 8 or Test = 9 then
                    TileType (i) := "Stone"
                    TempColor := 100
                end if
            end if

        end if
         /*
         Test := Rand.Int (1, 3)
         if Test = 1 then
         TileType(i) := "Grass"
         end if
         if Test = 2 then
         TileType(i) := "Stone"
         end if
         if Test = 3 then
         TileType(i) := "Dirt"
         end if


         if TileType (i) = "Grass" then
         TempColor := 10
         end if
         if TileType (i) = "Stone" then
         TempColor := 100
         end if
         if TileType(i) = "Dirt" then
         TempColor := 187
         end if
         */

        Draw.FillBox (RowX * 50, RowY * 50, RowX * 50 + 50, RowY * 50 + 50, TempColor)
        RowX := RowX + 1
    end for
end GenerateWorld
%===========================================================================%
% = == = == = == = == = == =    Game Loop   = == = == = == = == = == = == = %
%===========================================================================%
GenerateWorld
loop
    View.Update
end loop

Aange10




PostPosted: Wed Dec 28, 2011 11:28 pm   Post subject: Re: Some What Intelligent Random Map Generation

Haha, well, here is my failed attempt. The goal was to have the Dark Blue in the middle, the green around it, and the light blue on the outside. Though that failed haha.

[Don't need to read the code, just glaze through the comments if you;d like. And do run the program xD]



Project.t
 Description:

Download
 Filename:  Project.t
 Filesize:  10.62 KB
 Downloaded:  76 Time(s)

Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: