So I tried to make a unit that randomly places other units on map. And I noticed that the behaviour is exactly the same for every restart of the map. Is there a way to initiate a different random seed? Something like time(null)?
Quote from: pawel345 on December 10, 2013, 12:59:53 PM
So I tried to make a unit that randomly places other units on map. And I noticed that the behaviour is exactly the same for every restart of the map. Is there a way to initiate a different random seed? Something like time(null)?
I had this issue before. I ended up being forced to place each unit on the map manually, and this led to me giving up on that project.
Well I have a way of changing that, as one can make a random variable from the player actions, like the number of units or the place of the CN but still a way to change the seed would be cool.
SOmething like this is usually good enough for game work:
once
ElapsedTime asint ->randSeed
endonce
@GetRandFloat mul (MAPWIDTH) ->x
@GetRandFloat mul (MAPHEIGHT) ->y
SetWall(<-x <-y 1)
:GetRandFloat
<-randSeed mul (16807) mod (2147483647) ->randSeed
<-randSeed abs 2147483647.0 div
Basically, initialize a seed based on the elapsed time since game start (since the exe was first started). Then use a trusty pseudo random number function of your own. " <-randSeed mul (16807) mod (2147483647) ->randSeed ". That is what does the trick. "randSeed" will flop around in the +-int range. You can of course clip this or do whatever with it. In the example above I return a positive float in the range 0-1.
To see this in action in the example, I just pick random coordinates and put walls there. Note that you might want to initialize the seed some place other than in a 'once' section. You might want to do it each time the game is loaded, or based on player action, or let the player pick the seed... etc.
Quote from: pawel345 on December 10, 2013, 12:59:53 PM
So I tried to make a unit that randomly places other units on map. And I noticed that the behaviour is exactly the same for every restart of the map. Is there a way to initiate a different random seed? Something like time(null)?
i believe that should be the behavior of a "random" placement. if that was not the case the map would not be replayable and you could not develop a strategy for attack based on previous failures
I'm using the RandInt and RandFloat, and different randCoords CRPL functions for my random numbers, and my question is mostly if it's possible to change their seed as it seems to be tied to the map itself.
Quote from: MizInIA on December 10, 2013, 01:24:01 PM
i believe that should be the behavior of a "random" placement. if that was not the case the map would not be replayable and you could not develop a strategy for attack based on previous failures
Often yes but in my approach I would much rather have a different behaviour.
The seed is set at map start and persisted in the save game. So there isn't a way to change it. If you want the seed to float, you'll have to use something like the example I posted above. You can make your own RandInt and RandFloat functions with that example.
Quote from: pawel345 on December 10, 2013, 02:02:57 PM
Often yes but in my approach I would much rather have a different behaviour.
If players are to compete and post scores for a map, don't you think they should have the same sequence of events/times/locations?
Quote from: Grauniad on December 10, 2013, 02:18:31 PM
Quote from: pawel345 on December 10, 2013, 02:02:57 PM
Often yes but in my approach I would much rather have a different behaviour.
If players are to compete and post scores for a map, don't you think they should have the same sequence of events/times/locations?
No, I say that's the point of the map. If the map maker wants it to be random it should be random.
UNLESS it's something like "999/1000 chance of instant death, 1/1000 chance of instant win. Chances of winning increased if your name is Clean0nion" because that is completely stupid.
I see Pawel now has a spokesperson. :(
Quote from: Grauniad on December 10, 2013, 02:26:44 PM
I see Pawel now has a spokesperson. :(
I don't see your point. I am merely expressing my own views. If you refer to the use of my username, it was the only username I could use without offending anyone (with the exception of a fictional username).
Exactly. Chance of winning should only improve if your name starts with "G" -- using Clean0nion would be stupid! :D
It depends on the map. Things like Troublesome Trains get some replay value out of being random. Sure, a lucky run can affect your score, but so be it. I wouldn't want such a map in a tournament, but it might be fun to play multiple times.
Ok I guess that if I manage the to make the idea I have then I will start worrying about making a new random algorithm and indeed the algorithm posted by Virgilw seems great for that. Thanks!! :D
Quote from: Grayzzur on December 10, 2013, 02:32:00 PM
Exactly. Chance of winning should only improve if your name starts with "G" -- using Clean0nion would be stupid! :D
It depends on the map. Things like Troublesome Trains get some replay value out of being random. Sure, a lucky run can affect your score, but so be it. I wouldn't want such a map in a tournament, but it might be fun to play multiple times.
Thanks for the mention! I wish I could have gotten non-repeated random numbers for those maps.
Hmm, I probably could have used something like Virgil's algorithm there. Okay, maybe time for a new map. I have so many ideas, so little time.