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

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




PostPosted: Fri Dec 30, 2011 2:27 pm   Post subject: Intelligent Random Map Generation V2

Hey there,

This thread is a continuation from my last. (Click Me). I managed to create a some what cool looking map generation but theres a problem. Sometimes it works perfectly with no errors were as others it breaks.


Posted Image, might have been reduced in size. Click Image to view fullscreen.
Image broken?
Direct url : http://img689.imageshack.us/img689/5422/sexygen.png


Turing:

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

%===========================================================================%
% = == = == = == = == = == =  GenerateWorld = == = == = == = == = == = == = %
%===========================================================================%
var RowX : int := 0
var RowY : int := 0
var TileType : array 1 .. 100 of string
var TempColor : int := 0
var TempOdds : int := 0
procedure GenerateWorld
    for i : 1 .. 100
        if RowX > 9 then
            RowX := 0
            RowY := RowY + 1
        end if
        if RowX > 0 and RowX < 9 and RowY > 0 and RowY < 9 then
           
            if TileType (i - 1) = "Water" and TileType (i - 10) = "Water" then
                TempOdds := TempOdds + 50 + Rand.Int (0, 50)
                if TempOdds > 75 then
                    TileType (i) := "Water"
                    TempColor := 100
                end if
                if TempOdds < 75 then
                    TileType (i) := "Sand"
                    TempColor := 14
                end if
            end if

            if TileType (i - 1) = "Sand" and TileType (i - 10) = "Water" then
                TempOdds := TempOdds + 50 + Rand.Int (0, 50)
                if TempOdds > 80 then
                    TileType (i) := "Water"
                    TempColor := 100
                end if
                if TempOdds < 80 then
                    TileType (i) := "Sand"
                    TempColor := 14
                end if
            end if
           
            if TileType (i - 1) = "Water" and TileType (i - 10) = "Sand" then
                TempOdds := TempOdds + 50 + Rand.Int (0, 50)
                if TempOdds > 95 then
                    TileType (i) := "Water"
                    TempColor := 100
                end if
                if TempOdds < 95 then
                    TileType (i) := "Sand"
                    TempColor := 14
                end if
            end if
           
            if TileType (i - 1) = "Sand" and TileType (i - 10) = "Sand" then
                TempOdds := TempOdds + 50 + Rand.Int (0, 50)
                if TempOdds > 95 then
                    TileType (i) := "Water"
                    TempColor := 100
                end if
                if TempOdds < 95 then
                    TileType (i) := "Sand"
                    TempColor := 14
                end if
            end if


        end if
        if RowX = 0 or RowX = 9 or RowY = 0 or RowY = 9 then
            TileType (i) := "Water"
            TempColor := 100
        end if
        Draw.FillBox (RowX * 50, RowY * 50, RowX * 50 + 50, RowY * 50 + 50, TempColor)
        RowX := RowX + 1
        TempOdds := 0
    end for
end GenerateWorld
%===========================================================================%
% = == = == = == = == = == =    Game Loop   = == = == = == = == = == = == = %
%===========================================================================%
GenerateWorld
loop
    View.Update
end loop


If you run it a few times you should get it to work. Im using Turing 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Fri Dec 30, 2011 3:42 pm   Post subject: RE:Intelligent Random Map Generation V2

Like I said you need to keep track of all your variables and see what variables are different in each execution and why they are causing an error. Instead of trying to have us do it for you
pers2981




PostPosted: Fri Dec 30, 2011 8:32 pm   Post subject: Re: RE:Intelligent Random Map Generation V2

Aange10 @ Fri Dec 30, 2011 3:42 pm wrote:
Like I said you need to keep track of all your variables and see what variables are different in each execution and why they are causing an error. Instead of trying to have us do it for you


I don't recall you ever telling me this, Also do you really think I didn't attempt to fix it already. I only post asking for help after several hours of trying to fix it myself. How dare you sir. How dare you. BooHoo
chipanpriest




PostPosted: Fri Dec 30, 2011 8:51 pm   Post subject: Re: Intelligent Random Map Generation V2

Turing:
var y : int := 500

View.Set ("graphics:500;500")

for i : 0 .. 500
    for j : 0 .. 500
        drawdot (j, y, Rand.Int (9, 14))
    end for
    y -= 1
end for


Heres my random map generation Very Happy
mirhagk




PostPosted: Fri Dec 30, 2011 8:59 pm   Post subject: RE:Intelligent Random Map Generation V2

Turing:

    for i : 1 .. 100
        if RowX > 9 then
            RowX := 0
            RowY := RowY + 1
        end if
        if RowX > 0 and RowX < 9 and RowY > 0 and RowY < 9 then

            if TileType (i - 1) = "Water" and TileType (i - 10) = "Water" then

There is your problem. Let's say that i is 1, and that the if statement for rowX is between 0 and 9 and rowY between 0 and 9, well then what is the value of TileType(i-10)? well that is TileType(-9), which doesn't exist.
pers2981




PostPosted: Fri Dec 30, 2011 9:10 pm   Post subject: Re: RE:Intelligent Random Map Generation V2

mirhagk @ Fri Dec 30, 2011 8:59 pm wrote:
Turing:

    for i : 1 .. 100
        if RowX > 9 then
            RowX := 0
            RowY := RowY + 1
        end if
        if RowX > 0 and RowX < 9 and RowY > 0 and RowY < 9 then

            if TileType (i - 1) = "Water" and TileType (i - 10) = "Water" then

There is your problem. Let's say that i is 1, and that the if statement for rowX is between 0 and 9 and rowY between 0 and 9, well then what is the value of TileType(i-10)? well that is TileType(-9), which doesn't exist.


In order for RowX to be between 0 and 9 and rowY between 0 and 9 "i" would have to be higher then 1. RowX/RowY are both set to 0 before the for loop and on each pass RowX is increased by one, If RowX is higher then 9 then its set to 0 and RowY is increased by one. Therefore if RowX is between 0 and 9 then I is between 11 and 88
Raknarg




PostPosted: Fri Dec 30, 2011 9:11 pm   Post subject: RE:Intelligent Random Map Generation V2

Also, he's not generating a fractal map, which is ugly and unrealistic. He's making a map that created tiles in a logical order. This makes an island, while yours creates nothing, in reality
RandomLetters




PostPosted: Fri Dec 30, 2011 9:32 pm   Post subject: RE:Intelligent Random Map Generation V2

Nature is not logical. Please do not generate circular islands

In fact, nature is quite well represented by fractals, http://gameprogrammer.com/fractal.html#heightmaps
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Fri Dec 30, 2011 9:40 pm   Post subject: Re: Intelligent Random Map Generation V2

So I couldn't find out why there were empty tiles, so instead I initially set all the tiles to water before random generation. It seems to had rectfied the issue.

A;so, I rewrote it, if you're interested. It's not better or anything, I just like it better this way Razz

Turing:

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

%===========================================================================%
% = == = == = == = == = == =  GenerateWorld = == = == = == = == = == = == = %
%===========================================================================%
var TileType : array 0 .. 9, 0 .. 9 of int
var TempOdds : int := 0
procedure GenerateWorld
    for j : 0 .. 9
        for i : 0 .. 9
            TileType (i, j) := 100
        end for
    end for
    for j : 0 .. 9
        for i : 0 .. 9
            if i > 0 and i < 9 and j > 0 and j < 9 then

                if TileType (i - 1, j) = 100 and TileType (i, j - 1) = 100 then
                    TempOdds := 50 + Rand.Int (0, 50)
                    if TempOdds > 75 then
                        TileType (i, j) := 100
                    end if
                    if TempOdds < 75 then
                        TileType (i, j) := 14
                    end if
                end if

                if TileType (i - 1, j) = 14 and TileType (i, j - 1) = 100 then
                    TempOdds := 50 + Rand.Int (0, 50)
                    if TempOdds > 80 then
                        TileType (i, j) := 100
                    end if
                    if TempOdds < 80 then
                        TileType (i, j) := 14
                    end if
                end if

                if TileType (i - 1, j) = 100 and TileType (i, j - 1) = 14 then
                    TempOdds := 50 + Rand.Int (0, 50)
                    if TempOdds > 95 then
                        TileType (i, j) := 100
                    end if
                    if TempOdds < 95 then
                        TileType (i, j) := 14
                    end if
                end if

                if TileType (i - 1, j) = 14 and TileType (i, j - 1) = 14 then
                    TempOdds := 50 + Rand.Int (0, 50)
                    if TempOdds > 95 then
                        TileType (i, j) := 100
                    end if
                    if TempOdds < 95 then
                        TileType (i, j) := 14
                    end if
                end if
            end if
            Draw.FillBox (i * 50, j * 50, i * 50 + 50, j * 50 + 50, TileType (i, j))
            TempOdds := 0
        end for
    end for
end GenerateWorld
%===========================================================================%
% = == = == = == = == = == =    Game Loop   = == = == = == = == = == = == = %
%===========================================================================%
GenerateWorld
loop
    View.Update
end loop


One change you'll notice is that I made the TempColour obsolete by saving the type as an integer according to its colour. If you end up using my code, you may want to change that to accomodate for tiles other than solid colours. Anyways, hope that helps.
pers2981




PostPosted: Fri Dec 30, 2011 9:40 pm   Post subject: Re: RE:Intelligent Random Map Generation V2

RandomLetters @ Fri Dec 30, 2011 9:32 pm wrote:
Nature is not logical. Please do not generate circular islands

In fact, nature is quite well represented by fractals, http://gameprogrammer.com/fractal.html#heightmaps


Nature doesn't exactly look like this either.

Posted Image, might have been reduced in size. Click Image to view fullscreen.
In event of image failure click the link below.
http://img207.imageshack.us/img207/1682/choop392bb11917a3198cf1.png

I want sometime in-between. Something 'Logical' hence the title of the thread, Intelligent-Random map generation.
Raknarg




PostPosted: Fri Dec 30, 2011 9:42 pm   Post subject: RE:Intelligent Random Map Generation V2

@Randomletters no, it isnt logical. However, it's not absolutely random, either. It's a mixture of both, technically. However, if I were to make a choice, a logical island would make more sense than a fractal island, with sand more common in the middle than the outside.
RandomLetters




PostPosted: Fri Dec 30, 2011 9:47 pm   Post subject: RE:Intelligent Random Map Generation V2

I don't know what you're talking about. This looks pretty real to me

http://www.nextrevision.com/r5/multifractal0.jpg
Raknarg




PostPosted: Fri Dec 30, 2011 9:49 pm   Post subject: RE:Intelligent Random Map Generation V2

You should note that some things in nature are more chaotic than others. You can use this island as an example. If you look at an island as a single entity, the island itself isnt very random. It has a logical order where the innermost parts of the island are higher than the outside. The shape may vary, but that idea is constant. If you were to look at a string of islands, than that heightmap example is more meaningful, as islands occur in random places in a non logical order.

Same thing goes with that picture. The island is the same as a mountain. In itself, a mountain is less of a fractal than the land altogether is.
pers2981




PostPosted: Fri Dec 30, 2011 9:56 pm   Post subject: Re: RE:Intelligent Random Map Generation V2

RandomLetters @ Fri Dec 30, 2011 9:47 pm wrote:
I don't know what you're talking about. This looks pretty real to me

http://www.nextrevision.com/r5/multifractal0.jpg


Exactly. I don't want my island to be a perfect circle BUT I do want the sand to be on the outside (As seen in your picture), stone on the steep areas and what not.

Can we get this back on topic instead of debating the "More realistic" forms of map generation.
Raknarg




PostPosted: Fri Dec 30, 2011 9:59 pm   Post subject: RE:Intelligent Random Map Generation V2

Sure. Now do you have any other questions? IF you didnt read it back there, all I did was set all the tiles to water to begin with and it worked fine.
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 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: