Jump to content
IGNORED

random distribution not working - any ideas?


Fort Apocalypse

Recommended Posts

When I run this, all the black dots should turn red because of the randomization, but they don't. Have tried seeding the randomizer with other random numbers, but that doesn't help. Any ideas on how to get random dots to fill in all of the black dots here? Note that there is one randomized number I'm not yet using, but will.

 

Note that if you turn:

 

m = (room * 2) - 1 : n = (floor * 2) - 1 : pfpixel m n on

 

into

 

m = (room * 2) - 1 : n = (floor * 2) - 1 : pfpixel m n flip

 

That is still only setting that subset of pixels even though it would seem as if it should set all of the black windows red.

 

Thanks!

deltaforcesniper0.1.bas

deltaforcesniper0.1.bas.bin

Link to comment
Share on other sites

When I run this, all the black dots should turn red because of the randomization, but they don't. Have tried seeding the randomizer with other random numbers, but that doesn't help. Any ideas on how to get random dots to fill in all of the black dots here? Note that there is one randomized number I'm not yet using, but will.

 

Note that if you turn:

 

m = (room * 2) - 1 : n = (floor * 2) - 1 : pfpixel m n on

 

into

 

m = (room * 2) - 1 : n = (floor * 2) - 1 : pfpixel m n flip

 

That is still only setting that subset of pixels even though it would seem as if it should set all of the black windows red.

 

Thanks!

The standard random number generator is suitable for most situations, but this isn't one of them. In this case, you'll want to use the 16-bit random number generator.

 

You need to reserve one of your 26 variables to use it. For example, if you set aside x, enable the 16-bit generator by:

dim rand16=x

Link to comment
Share on other sites

When I run this, all the black dots should turn red because of the randomization, but they don't. Have tried seeding the randomizer with other random numbers, but that doesn't help. Any ideas on how to get random dots to fill in all of the black dots here?

You're calling rand three times in resettarget to set three random values-- let's refer to them collectively as a "random triplet"-- and bB's random number generator produces a sequence of 255 values between 1 and 255. Since 255 / 3 = 85 with no remainder, you're getting 85 random triplets, repeating in a cycle. And since you're throwing away some of those random triplets if one of the values exceeds the desired range, you're ending up with fewer than 85 acceptable triplets. Furthermore, the way you're reducing the random numbers to a desired range is causing some of the triplets to occur more than once during each cycle, and some of the dots (rooms) aren't getting hit.

 

I think a better approach would be to generate only one random value for the room, and then use that value to determine what the two separate values for the location should be (room and floor). Here's one way you could do it-- note that the room is now 0 to 14, and the floor is now 0 to 4, so the formulas for the pfpxel parameters (m and n) have been changed accordingly:

 

   rem Delta Force Sniper
  rem by Fort Apocalypse

  set kernel_options no_blank_lines
  include div_mul.asm
  set smartbranching on

aim
  player0:
  %00010000
  %00010000
  %11000110
  %00010000
  %00010000
end

lettera
  player1:
  %00100100
  %00100100
  %00111100
  %00100100
  %00011000
  %00000000
end

  dim room = a
  rem 0-4
  dim floor = b
  rem 0-3
  dim side = c
  dim level = l

  playfield:
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
  X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
  X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
  X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
  X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
  X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
end

resettarget
  room = (rand - 1) / 3
  if room > 74 then room = (room - 75) * 2
  floor = room / 15
  room = room - 15 * floor
  side = rand
  side = side / 51

mainloop
  COLUP0 = 14
  COLUBK = 0
  COLUPF = 68
  if joy0up then player0y = player0y - 1
  if joy0down then player0y = player0y + 1
  if joy0left then player0x = player0x - 1
  if joy0right then player0x = player0x + 1

  m = room * 2 + 1 : n = floor * 2 + 1 : pfpixel m n on

  if joy0fire then m = player0x + 3: n = player0y - 2 : gosub blink
  if switchreset then goto resettarget
  drawscreen
  goto resettarget
  goto mainloop

blink
  if m > 16 then m = m - 17
  m = m / 4
  n = n / 8
  pfpixel m n flip
  return

Since 75 doesn't divide evenly into 255, the line that says "room = (room - 75) * 2" subtracts 75 from the random room number if needed, and then multiples the difference by 2 so the rooms that are repeated an extra time are spaced out a bit rather than being all together.

 

Michael

Link to comment
Share on other sites

resettarget
  room = (rand - 1) / 3
  if room > 74 then room = (room - 75) * 2
  floor = room / 15
  room = room - 15 * floor
  side = rand
  side = side / 51

Since 75 doesn't divide evenly into 255, the line that says "room = (room - 75) * 2" subtracts 75 from the random room number if needed, and then multiples the difference by 2 so the rooms that are repeated an extra time are spaced out a bit rather than being all together.

I should point out that the reason I did that was so rand would be called only twice during the routine. Since there are 255 possible values for rand (if you're using bB's standard 8-bit random number generator), and 255 is *not* evenly divisible by 2, that means if you call rand twice each time-- once for one variable, and then once more for another variable-- after two times through the cycle, each variable will have cycled through all 255 possible random (or pseudo-random) values. On the other hand, if you change the line that begins "if room > 74" to say "if room > 74 then resettarget" so it branches back to get a different value, you won't get a hit on all 75 rooms-- try it and see.

 

Here's another variation that tries to improve the distribution a bit:

 

resettarget
  room = rand - 1
  if room > 224 then room = room - 225 : room = room * 5 / 2 + 1
reduce1
  if room > 74 then room = room - 75 : goto reduce1
  rem * or use if room > 74 then room = room / 3
  floor = room / 15
  room = room - (15 * floor)
  side = rand - 1
reduce2
  if side > 4 then side = side - 5 : goto reduce2
  rem * or use side = side / 51

In the first version, room values of 1, 2, 3, 4, 5, 6, 7, 8, 9, ..., 223, 224, 225 will become 0, 0, 0, 1, 1, 1, 2, 2, 2, ..., 74, 74, 74, and room values of 226, 227, 228, 229, 230, 231, 232, 233, 234, ..., 253, 254, 255 will become 0, 0, 0, 2, 2, 2, 4, 4, 4, ..., 18, 18, 18. That was a mistake; I had been trying for something different.

 

In the second version, room values of 1, 2, 3, ..., 75, 76, 77, 78, ..., 150, 151, 152, 153, ... 225 will become 0, 1, 2, ..., 74, 0, 1, 2, ..., 74, 0, 1, 2, ..., 74, and room values of 226, 227, 228, 229, 230, 231, 232, 233, 234, ..., 253, 254, 255 will become 1, 3, 6, 8, 11, 13, 16, 18, 21, ..., 68, 71, 73, which distributes the extra occurrences across the range of rooms.

 

If you want to use the first approach-- 0, 0, 0, 1, 1, 1, etc.-- then replace the two "if" statements in reduce1 and reduce2 with the remarked-out lines. However, the extra occurrences will still be spread out across the range of rooms as shown in the second version.

 

Michael

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...