azkanan Posted April 18, 2013 Author Share Posted April 18, 2013 Why does the below keep creating a pattern, example image shown below.The theory is that this should generate a grid-based map, based on the ID of each point in the array (AlphaSpace.area(0,63)).ID 1 is a planet (blue), ID 2 is a second planet (red)."i" generates the columns and "i" generates the rows… So for each passing of **"i"** it should generate 64 (including 0) ID spaces in the rows.For each ID space, there is a 10% chance of planet 1 and a 10% chance of planet 2, with 80% chance of space… The process seems random, sowhy is it making a godamn pattern?Note: "i" and "i2" are Public variables.```For i = 0 To 63 For i2 = 0 To 63 x = Rand(1, 100) If x > 0 And x < 10 Then AlphaSpace.area(i, i2).ID = 1 ElseIf x >= 9 And x < 20 Then AlphaSpace.area(i, i2).ID = 2 End If Next i2Next i```![](http://puu.sh/2Cund.png)========================================================This is my display code, which loads the graphics.``` For i = 0 To 20 For i2 = 0 To 20 If AlphaSpace.area(i2, i).ID = 0 Then SpacePic.Picture = LoadPicture(App.Path & "\graphics\spacemap\void.jpg") ElseIf AlphaSpace.area(i2, i).ID = 1 Then SpacePic.Picture = LoadPicture(App.Path & "\graphics\spacemap\planet.jpg") ElseIf AlphaSpace.area(i2, i).ID = 2 Then SpacePic.Picture = LoadPicture(App.Path & "\graphics\spacemap\planet2.jpg") End If 'End If SpacePicture.PaintPicture SpacePic, (i2 * 20), (i * 20) Next i2 Next i``` Link to comment Share on other sites More sharing options...
azkanan Posted April 18, 2013 Author Share Posted April 18, 2013 And here is the Rand() function;```Public Function Rand(LowerNumber, HigherNumber) Randomize Rand = Int((HigherNumber - LowerNumber + 1) * Rnd) + LowerNumberEnd Function``` Link to comment Share on other sites More sharing options...
kris_hole Posted April 18, 2013 Share Posted April 18, 2013 i'd suggest that it's because you're not using your random function as ridiculously enough.There is no such thing as truly random generation in code. so there will always be a pattern. if you narrow it so simply "1-10,10-20"You're gunna get pretty much the same results.SO, i'd suggest instead of trying to randomly generate per tile in a loop. just use random tiles. something likefor i = 1 to max_objectsrandx = 1 to screenwidthrandY = 1 to screen widthtile[x,y]= object.Works better IMO Link to comment Share on other sites More sharing options...
DMF Posted April 18, 2013 Share Posted April 18, 2013 nice idea kris XD : ) that should do it for him Link to comment Share on other sites More sharing options...
azkanan Posted April 18, 2013 Author Share Posted April 18, 2013 > ' timestamp='1366317482' post='894413']> > i'd suggest that it's because you're not using your random function as ridiculously enough.> > There is no such thing as truly random generation in code. so there will always be a pattern. if you narrow it so simply "1-10,10-20"> > You're gunna get pretty much the same results.> > SO, i'd suggest instead of trying to randomly generate per tile in a loop. just use random tiles. something like> > for i = 1 to max_objects> > randx = 1 to screenwidth> > randY = 1 to screen width> > tile[x,y]= object.> > Works better IMO```Public Sub GenerateSpace()Dim x As IntegerDim i As IntegerDim i2 As IntegerDim emptytile As Integeremptytile = 1Do Until emptytile = 0i = Rand(0, 63)i2 = Rand(0, 63)If AlphaSpace.area(i, i2).ID <> 0 Then i = Rand(1, 63) i2 = Rand(1, 63)Else x = Rand(1, 3) Select Case x Case 1: AlphaSpace.area(i, i2).ID = 1 Case 2: AlphaSpace.area(i, i2).ID = 2 Case 3: AlphaSpace.area(i, i2).ID = 3 End SelectEnd Ifemptytile = 0For i = 0 To 63 For i2 = 0 To 63 If AlphaSpace.area(i, i2).ID = 0 Then emptytile = emptytile + 1 End IfNext i2Next iLoopEnd Sub```Well, in theory it works, but in practice, the game freezes for a long, long time as it tries to cover all those tiles…The problem is, there are 4096 tiles, so there's a 1/4096 chance every time it tries of actually filling a tile. Odds are against the computer hitting those last 2 or 3 empty tiles. Link to comment Share on other sites More sharing options...
azkanan Posted April 18, 2013 Author Share Posted April 18, 2013 5x5 (25), takes <1 second. Works fine.![](http://puu.sh/2CBlX.png) Link to comment Share on other sites More sharing options...
azkanan Posted April 18, 2013 Author Share Posted April 18, 2013 Turns out it's random if it crashes. So, I decided to make my zones smaller (63,63) to (29,29)…Now, it loads quicker, I can fit it all in one viewscreen without need for scrolling, and I'm ready to move on with my game's development - thanks everyone for the help! ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png)![](http://puu.sh/2CBU7.png) Link to comment Share on other sites More sharing options...
Exception Posted April 18, 2013 Share Posted April 18, 2013 Er. Could've just put a seed based on a manipulated calculation of the system time, for example, in your random function, or some other manipulable variable. ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)Randomize can have an argument. That argument would be the seed used. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now