Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Statsman1

Pages: 1 [2] 3
16
Programs / Re: GridWars game - going to add AI to it.
« on: October 28, 2021, 10:45:14 am »
Love it!  This looks like Ataxx, one of my favorite arcade games. 

And wowee, did that game’s AI ever get hard when you played the top 2 characters.

Looking forward to seeing how this turns out - GridWars would be a must-play, in my book!

17
QB64 Discussion / Re: Bad random numbers, or TIMER limitation...?
« on: October 26, 2021, 09:24:51 pm »
@Richard ...

Thank you very much for the code.  I modified it to behave somewhat in the way I am trying to do my thing...

Code: QB64: [Select]
  1. version$ = "Precision_timer-999"
  2. Declare Dynamic Library "kernel32" ' Acquiring high-resolution time stamps  ' https://docs.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps
  3.     Sub QueryPerformanceCounter (ByVal lpPerformanceCount As _Unsigned _Offset)
  4.     Sub QueryPerformanceFrequency (ByVal lpFrequency As _Unsigned _Offset)
  5. Dim Shared PerformanceCount As _Integer64
  6. Dim Shared StartingCount As _Integer64
  7. Dim Shared dElapsedTime As Double
  8. Dim Shared dElapsedTimeOLD As Double
  9.  
  10. For reps = 1 To 20
  11.     QueryPerformanceFrequency (_Offset(Frequency))
  12.     QueryPerformanceCounter (_Offset(StartingCount))
  13.  
  14.     TIMERe: dElapsedTimeOLD = dElapsedTime
  15.  
  16.     dist = 1440
  17.     draws = 0
  18.     Do
  19.  
  20.         steps = Int(Rnd(1) * 3) + 1
  21.         dist = dist - steps
  22.         draws = draws + 1
  23.  
  24.     Loop Until dist < 0
  25.  
  26.     TIMERe
  27.  
  28.     Print "Time to take 1440 steps =";: Print Using "####.###"; (dElapsedTime - dElapsedTimeOLD) * 1000000;: Print "    Loops =";: Print draws
  29.  
  30. Next reps
  31.  
  32.  
  33. Sub TIMERe
  34.     QueryPerformanceCounter (_Offset(PerformanceCount))
  35.     dElapsedTime = (CDbl(PerformanceCount - StartingCount)) / Frequency

...and attached the results in the first attachment.  I then did the same for 14,400 steps, if you will, and the results are in the second attachment.

Those outliers that you talk about - I guess that can be lived with, as that would impact every horse in a race, not just one.  I am encouraged by the results of the second run - the more loops, the more varied the times seem to be, even for the same number of loops to complete the test.

18
QB64 Discussion / Re: Bad random numbers, or TIMER limitation...?
« on: October 26, 2021, 04:39:39 pm »
@Statsman1

I do not know if it is of use to you but...

I use QB64 code to measure time intervals down to 100 nano seconds (rather than TIMER)

It might be just what I need, if you can offer some code to try!  Thank you!

19
QB64 Discussion / Re: Bad random numbers, or TIMER limitation...?
« on: October 26, 2021, 03:19:42 pm »
Thank you, bplus...I will try implementing the more-accurate storage of TIMER, maybe that changes things a bit.


20
QB64 Discussion / Re: Bad random numbers, or TIMER limitation...?
« on: October 26, 2021, 02:49:35 pm »
Thank you, everyone, for their efforts to help me.

I cannot stress enough that it is NOT the random numbers I question, it is the TIMER function.  The use of random numbers only contributed to why the various events should take different lengths of time.  But I cannot seem to get that point across...I know how random numbers work, I know how the mean is calculated, I know that over time, the random numbers will all converge to the mean, I know that there are no truly random numbers...I know all of that.

I question why separate events that take different cycles to complete can still have identical times to 1/100000th of a second.  Identical to the second...sure.  Even to 1/10th or 1/100th, occasionally.  But 1/100000th of a second?  No, that makes no sense to me.

I wish I hadn't brought up the random numbers, though I did think maybe something was amiss there, initially, maybe I could have made my question about TIMER and my odd results more clear.


21
QB64 Discussion / Re: Bad random numbers, or TIMER limitation...?
« on: October 26, 2021, 02:23:55 pm »
I wonder if...

A=RND
Randomize(TIMER + A)

...would work.

I really appreciate all time you are taking to look at this, but again - it isn't about the various results, it is about using TIMER.  If you used the TIMER function to actually time how long each race took each horse, and you had a number of horses in different races run in the exact same time, down to the 1/100000th of a second...wouldn't you think that was a bit strange?


22
QB64 Discussion / Re: Bad random numbers, or TIMER limitation...?
« on: October 26, 2021, 01:34:07 pm »
Hey bplus!

Thanks for this, and yes, I know that the averages condense to a single value (for instance, the average of random numbers between 1 and 3 will end up narrowing down to 2).  My issue is that the TIMER function spits out exactly the same times to the 1/100000th of a second over a small sample size of events.

I have done the same thing you did…I count the number of loops it takes to finish a race (because I thought that was the cause) and the number of loops is almost always different.  Here, 11 races in question took the following number of loops to finish…

600, 610, 613, 604, 603, 609, 611, 619, 596, 604, 612

The average of that is 607, which actually never happened in those races.

So if a race that took 613 loops produced a 2nd place finish in 34.123456 seconds, how on earth did another race that took 596 loops have a 4th place finisher in 34.123456 seconds as well? 

The fact that those two events use TIMER to achieve the EXACT SAME TIME is my issue.  Not the random numbers generated to do it.

Maybe I am the only guy who thinks that two things that time to that level of identical accuracy is odd.

23
QB64 Discussion / Re: Bad random numbers, or TIMER limitation...?
« on: October 26, 2021, 10:05:26 am »
Thank you, Steve, for the insight here.  I have removed the second RANDOMIZE and only triggering one RANDOMIZE (TIMER) at the beginning of the program.  The goal of that 100-loop accumulation was simply to introduce a random delay on each sweep of the code that determines movement of the horses, because I am consistently getting identical times, which is really what I am asking about.

I agree 100 percent that the mean of a series of random numbers between 0 and .999999 approaches .5, and that loop wasn’t doing much, except that probably WASN’T exactly .5, and because _DELAY can use 1/1000ths, it should have been enough to prevent the identical times (to the 1/100000th) happening.  It wasn’t.

I am not the most optimized coder, no question about that, but when I time events using TIMER, with that precision, I still cannot figure out how I am getting identical times all the way to the 1/100000th of a second.  That should be, to my mind, quite impossible….or, since anything is possible, FAR less frequent.

There is too much code to paste here, but the gist of it is….

BEGIN
START RACE
StartTime = TIMER
Race is 1,440 pixels long
Begin Loop
Random numbers between 1 and 3 determine how many pixels forward each horse moves
All 6 horses move, in random order
All horses move forward
Eventually, each horse has moved 1,440 pixels (enough passes of 1, 2 or 3 have happened to add up to 1,440)
First horse crosses finish line
FirstTime = TIMER
FirstTime = FirstFinish - StartTime
Second horse crosses finish line
SecondFinish = TIMER
SecondTime = SecondFinish - TIMER
.
.
.
Sixth horse crosses finish line
SixthFinish = TIMER
SixthTime = SixthFinish - StartTime
End of loop
Race is done - display results
END

Sometimes, there are EXACT ties in a race.  Dead heats happen in horse races, I have no issue with that, though, again, a tie to the 1/100000th of a second seems kind of wildly unlikely.

But run a few of these, and I get some identical times, all the way down to the 1/100000 of a second (I posted a list of 10 races x 6 times).  The 4th place finisher in race #6 will have the identical time to the 2nd place finisher in race #3, for example.  Again, to the 1/100000th of a second.  That just should NOT happen. 

I tried this.  If I run a race where all horses move 3 pixels at a time, all 6 finish at basically the same time, but the first horse to move that last cycle wins by 2/100th of a second.  Makes sense, there is processing time being used.  However, all the other 5 horses have the exact same time down to the 5th decimal place.  Something is strange about this type of thing.

24
QB64 Discussion / Re: Bad random numbers, or TIMER limitation...?
« on: October 25, 2021, 09:27:57 pm »
So I just have RANDOMIZE (TIMER) at the start, no other occurrences of a randomize.

These are the sorted times of 10 races, 6 racers in each...still a ton of duplications.

45.81797
46.00336
46.00336
46.00336
46.01936
46.01936
46.18875
46.37414
46.37414
46.55953
46.74492
46.77141
46.78741
46.93031
46.93031
46.9568
47.1157
47.1157
47.1157
47.1317
47.1317
47.30109
47.30109
47.48648
47.67188
47.68787
47.88375
47.88375
47.88375
47.89975
47.89975
48.25453
48.41344
48.41344
48.42944
48.43992
48.59883
48.59883
48.78422
48.96961
48.96961
48.96961
49.34039
49.52578
49.73766
50.08195
50.47922
50.66461
50.85
51.03539
51.59156
51.77695
51.96235

25
QB64 Discussion / Re: Bad random numbers, or TIMER limitation...?
« on: October 25, 2021, 09:01:52 pm »
Thanks bplus...

I use RANDOMIZE (-TIMER) at the very start of my program, and it is called only once.

Are you saying I shouldn't bother with the second RANDOMIZE (TIMER)?  Or is there just a better way to pick a random number? 

All I am doing is trying to figure out how the heck two separate events can time exactly the same to the 5th decimal point when everything that contributes to that time is a series of apparently random numbers.

26
QB64 Discussion / Bad random numbers, or TIMER limitation...?
« on: October 25, 2021, 08:18:02 pm »
Hey guys...

Picture 6 horses in a race, using the TIMER function at the START and FINISH to calculate elapsed time.  They finish with the following times (in seconds)...

Racer 1    31.30453     
Racer 2    31.48992     
Racer 3    31.50592     
Racer 4    31.8607     
Racer 5    32.23148     
Racer 6    32.41687

Then picture 6 different horses in a race, but same distance as race 1.  This time, the results (in seconds) are...

Racer 7    30.93375     
Racer 8    30.94975     
Racer 9    31.11914     
Racer 10  31.30453     
Racer 11  31.48992     
Racer 12  31.50592

Note that Racer 11 and Racer 12 have EXACTLY the same times as Racer 2 and Racer 3.  The fact that all 6 times are not the same is encouraging, but how on earth could two identical times be possible, let alone have it happen twice?

I have seen this happen over a series of races...duplicate times (but not duplicate places in finish) come up a LOT.  For instance, the time 32.77441 has happened 6 times in 30 races.  That just doesn't seem to be right.

I have used the RANDOMIZE (-TIMER) and RANDOMIZE (TIMER) functions within the program - the first is used to determine how far forward the horse moves (the maximum is 3 pixels, the minimum is 1 pixel, so in practice, thus the average is 2 pixels).   The second is invoked after every horse has moved, to calculate a random-length system delay between each move.  To me, this means a new seed is generated every single time the program accesses the routine used to create the delay, I then take the average of 100 random numbers, and use this as the delay..maybe I misunderstand this function.

        Randomize (Timer)
        L = 0
        For J = 1 To 100
            K = Rnd(1) / 1000
            L = L + K
        Next J

        m = L / 10

        _Delay (m)

Anyway, I get that over running a series of random numbers between 1 and 3 will average 2, and that if you do that constantly over the same distance, you will get very similar times to complete the race...but introducing that random delay should be enough to avoid timing duplication down to the 100,000th of a second, shouldn't it?



27
QB64 Discussion / Re: Plotting / erasing points on a circle
« on: October 02, 2021, 10:30:23 am »
Yeah maybe, how are you coming along?

Well, I got away from it for a few days with other stuff to do (bought an Apple III, 6 Apple IIe and a II+), and chores and the like, but got back to it last night and things seem to be coming together.

I have decided, though, to use the framework I have created and instead of auto racing (which would involve collision detection and user inputs, and an AI I am prepared for just yet), I am going to make this a horse racing program.  Wagering model, stable management, etc.

One of my favorite games ever was Sport of Kings by Omni-Play (later Virgin)…

https://www.myabandonware.com/game/sport-of-kings-19p

…so why not?

28
QB64 Discussion / Re: Plotting / erasing points on a circle
« on: September 29, 2021, 10:08:56 pm »
I feel like my inquiry really started something.....

29
QB64 Discussion / Re: Plotting / erasing points on a circle
« on: September 29, 2021, 09:25:45 am »
You guys are awesome.  :)

Thank you so much for the help and the laughs, first thing in the morning.

30
QB64 Discussion / Re: Plotting / erasing points on a circle
« on: September 28, 2021, 10:32:22 pm »
Actually, I am 51 years old, and gave up homework a LONG time ago.

I am working on a particular game idea that is just to make myself happy, that’s all, not an assignment or anything. Just a racing program, and trying to get the cars around the curves is proving a challenge.

Hope this clarifies the requirements.

Pages: 1 [2] 3