Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 57 58 [59] 60 61 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886815 times)

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #870 on: January 25, 2012, 02:20:14 pm »

Wouldn't you be much better off using the time as a seed?

Time as a seed presents a few challenges.

For close calls, the time may not have changed, producing identical numbers.
For close calls, the change in the seed may be insignificant, and depending on the algorithm may produce a random number "near" the previous one more often than not.
If you want to be able to reproduce the sequence of random numbers at a later time, such as in procedural terrain generation, then time does not work at all.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #871 on: January 25, 2012, 02:24:29 pm »

Wouldn't you be much better off using the time as a seed?

Time as a seed presents a few challenges.

For close calls, the time may not have changed, producing identical numbers.
For close calls, the change in the seed may be insignificant, and depending on the algorithm may produce a random number "near" the previous one more often than not.

You don't manually seed it after every call. An LCG works by feeding the last value back into it to generate the next one. time is just used to get the starting seed that determines the pattern.

X[0] is the seed.
X[n+1] = (A * X[n] + C) mod M

So for the first value (X[1]), the seed of time (X[0]) is used. For the second (X[2]), the X[1] is used. X[3] uses X[2], X[4] uses X[3], X[5] uses X[4] and so-on ad infinitum.
« Last Edit: January 25, 2012, 02:37:58 pm by MorleyDev »
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #872 on: January 25, 2012, 02:29:39 pm »

Quote
For close calls, the time may not have changed, producing identical numbers.
This... isn't how seeds work. The number still changes each time. That's why it's called a seed, not a whole tree. (or whatever) You only need to seed once.

Quote
For close calls, the change in the seed may be insignificant, and depending on the algorithm may produce a random number "near" the previous one more often than not.
Again, this is not, from my understanding, how a seed works. Why would it?

Quote
If you want to be able to reproduce the sequence of random numbers at a later time, such as in procedural terrain generation, then time does not work at all.
Save your seed. Attach the seed to the generated data. Done.
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #873 on: January 25, 2012, 02:38:43 pm »

1: that isn't the way i read his question.

2: there are random number generators that take the current time as the seed for each random number in order to remove the pattern inherent in conventional seeds. For instance (IIRC), the default random number generators in javascript and java. For sufficiently low resolution timers combined with sufficiently high speed processors, this presents the problem I mentioned.

EDIT: yep. that is how javascript works, but not java.
« Last Edit: January 25, 2012, 02:45:26 pm by Nadaka »
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #874 on: January 25, 2012, 02:43:12 pm »

Since the seed is, by definition, the initial value used for a pattern of random results from an RNG, I do not see how it could reasonably be called a seed if you only generate one number with each seed. That's just... that's not anything, really.

If you have a decent algorithm there shouldn't BE a pattern inherent in a conventional seed.

Now, where it MIGHT cause problems is, I suppose, with forks, if the RNG in both forks continues along the same path...
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #875 on: January 25, 2012, 02:46:02 pm »


That's why you shouldn't fork an RNG in the first place, or at least be very careful about it.

Since the seed is, by definition, the initial value used for a pattern of random results from an RNG, I do not see how it could reasonably be called a seed if you only generate one number with each seed. That's just... that's not anything, really.
You're hashing the time then. Still, for that to work your hash function needs to be good, which is not necessarily the case for linear hashing (if the modulus is chosen wrongly you're not getting the whole space from 0 to m for example).
« Last Edit: January 25, 2012, 02:48:54 pm by Virex »
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #876 on: January 25, 2012, 02:51:17 pm »

Yeah, using a new time for each generation is more hashing than seeding, it's called a "seed" because all the other numbers grow from it ^^

If you need multiple generators to exist (multithreading is the main reason I can think of where this would be important), each would be seeded separately. That's one of the complaints people have with rand(), but that is a side-effect of it being part of the C library that simply gets dragged kicking and screaming into C++ xD

Of course mersenne twister has its faults too. It's can be...unfriendly on the cache, to say the least. Largely due to the large array of values it has to store.
« Last Edit: January 25, 2012, 03:17:52 pm by MorleyDev »
Logged

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #877 on: January 25, 2012, 07:28:04 pm »

Just finished the first beta of my first game in SDL

http://www.filefactory.com/file/c2d3f9f/n/RoboJuggle.zip

you can download from there,

there's only 1 ball right now, and a few bugs, such as it getting launched from the right hand too fast,
although thats purely cosmetic as it doesn't effect the time it takes to reach the left hand.

press space to drop a ball, currently only 1 ball can be on screen at a time.
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #878 on: January 25, 2012, 08:03:10 pm »

Awesome! Works quite well. The ball animation is flickering, though, that's kinda annoying.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #879 on: January 25, 2012, 08:18:25 pm »

I noticed that too, I think the sprite might be cycling too fast,

It doesn't flicker if the ball isn't moving.

And I should have mentioned, arrow keys move right hand, wads move left hand
« Last Edit: January 25, 2012, 08:28:02 pm by Valid_Dark »
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #880 on: January 25, 2012, 09:43:43 pm »

I can't figure this out, I slowed down the cycle rate of the sprite and it still flickers while moving, but at least now I have a variable to control spin speed, and I can't figure out whats causing the jump from the right hand. it doesn't make sense, and when I speed up the ball speed it doesn't happen.  So i'm going to find the slowest speed it can go and not skip and have that be the starting speed.
I have a variable that controls ball speed, so the ball can speed up later if you get so many in a row.
I think think if I try switching to triple buffering instead of double it'll stop the flickering, but that means I have to look up how to do that.  going to put the resources in a folder instead of being in the same folder as the .exe . 
then going to work on the score system, once that's in place going to add second ball.
any ideas as to what to work on next ?
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #881 on: January 25, 2012, 09:48:13 pm »

Have you tried using double buffering?
Logged

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #882 on: January 25, 2012, 09:53:40 pm »

I'm not sure how you do you graphics, but.... Are you freeing and loading the ball surfaces every single time it animates? If so, bad mojo. Pre-load them and instead. Animation can be done via deciding which surface to blit to the screen, rather than always blitting the same surface with different graphics applied to it.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #883 on: January 25, 2012, 10:07:56 pm »

I'm not loading the surface every time it animates, it's a pre loaded sprite sheet, I feel stupid because I had it set to there being 15 sprites in the sheet when there were only 14. I feel dumb for not noticing it, because I thought it didn't flicker when standing still but it did, I just didn't notice it.  So got that bug fixed.  also found out it's stupid hard to triple buffer with SDL, they should make a triple buffer flag like the double buffer one.  my distances were all intervals of 80 and I was dividing by 50, and for some reason it was making a +/- 50 or so pixel difference which really doesn't make sense. so I changed the 50 to 40 and now it runs a lot smoother.
that 50/40 variable controls the speed of the ball, by deciding how many ticks between min and max distance.
I really wish I could go to school for programming.  the only computer class I've ever taken was typing in high school,  I wanted to but was too busy with science classes. (During high school I was dual enrolled in my city Highschool and a Biotechnology acadamy) My code has a very bad structure to it and in every sense of the word is a mess.
but it works!

now to add features, i'm going to pile more crap on the already giant pile of crap.  can I have someone who's good at c++ and sdl take a look at my code and give me some structure pointers?
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #884 on: January 25, 2012, 10:42:00 pm »

Well, I'm good at C++, but have very minimal experience with SDL. I can probably figure it out if I have a reference open.
Pages: 1 ... 57 58 [59] 60 61 ... 796