Computer Science Canada Pacman Ghost Random Moving Pattern...WTF? |
Author: | Aziz [ Thu Dec 01, 2005 9:41 pm ] | ||
Post subject: | Pacman Ghost Random Moving Pattern...WTF? | ||
Why does this guy go through walls? (btw, EMPTY is a constant with value 1, the empty spaces in the map
|
Author: | Jorbalax [ Fri Dec 02, 2005 12:07 am ] | ||||
Post subject: | |||||
It's really hard to determine what the problem is with just that small line of coding. Perhaps you should post a bit more. Also...
While this is an easy way of returning a random value within a certain set of numbers, I'm not sure if it's the safest way to do so. Making an exit when statement dependent on a random number means there is a possibility of your program staying in that loop for quite some time, especially if you choose to later increase those values. It also means that the time spent in the loop isn't always going to be relatively constant, which could be a problem. My suggestion would be to first randomly select which variable is going to be 0 and then to randomly select an element from a predefined list of values in an arrayand the assign that value to your variable. Here's a comparison of the two methods.
Run it through a couple times, and watch the time for method 1. Occasionally, it will be an odd number like 0.007 or something. Compare this to method 2, which stays relatively constant to two different times (0 and 0.001 for me). |
Author: | Tony [ Fri Dec 02, 2005 9:41 am ] | ||||||||
Post subject: | |||||||||
Jorbalax wrote: It's really hard to determine what the problem is with just that small line of coding.
Oh no, it's all there - look closer ![]()
rChange and cChange are our random directions, pretty simple
I don't quite understand this, but there's a 10% chance to assign g.rChange and g.cChange the random values we picked a step above, if we're allowed to move in that direction
We check once again if we can move in rChange/cChange direction, and is so, proceed to go in... g.rChange / g.cChange direction instead. Though there's only a 10% chance to actually have those values the same, so 90% of the time, if a random direction is valid, the ghost will continue to proceed straight through the wall ![]() you need
basically look and go in the same direction. |
Author: | Aziz [ Sat Dec 03, 2005 2:12 pm ] |
Post subject: | |
Omg ![]() ![]() |
Author: | Aziz [ Tue Dec 06, 2005 8:16 am ] | ||||||
Post subject: | |||||||
Jorbalax wrote: It's really hard to determine what the problem is with just that small line of coding. Perhaps you should post a bit more.
Also...
While this is an easy way of returning a random value within a certain set of numbers, I'm not sure if it's the safest way to do so. Making an exit when statement dependent on a random number means there is a possibility of your program staying in that loop for quite some time, especially if you choose to later increase those values. It also means that the time spent in the loop isn't always going to be relatively constant, which could be a problem. My suggestion would be to first randomly select which variable is going to be 0 and then to randomly select an element from a predefined list of values in an arrayand the assign that value to your variable. Here's a comparison of the two methods.
Run it through a couple times, and watch the time for method 1. Occasionally, it will be an odd number like 0.007 or something. Compare this to method 2, which stays relatively constant to two different times (0 and 0.001 for me). You're absolutely right. That does make sense. But in that example, there was 200 different possibilities. I made it with only 2, and both methods were about the same. However, I am going to incorporate this into pacman and remember it for future use, as I have used this method (method #1 in the example) before and I think it is a lot better. Just pointing out that it didn't make much of i difference, but I do understand and you're wholly correct. (hahah....hole)
|