Further random number improvements

This commit is contained in:
David Schmenk committed 2026-01-02 20:04:45 -08:00
1 parent 2522d1faab
commit e968a5911f
3 files changed
+48 -56

No files matched your search

+4 -1
View File
@@ -452,12 +452,14 @@ end
// Apple II routines.
//
def a2keypressed
*a2rndnum++
return ^keyboard >= 128 ?? ^keyboard :: 0
end
def a2getkey
byte key
repeat
*a2rndnum++
key = ^keyboard
if key == $80 | keyctrll
^keystrobe
@@ -516,6 +518,7 @@ def a2egetkey
byte key
repeat
*a2rndnum++
key = ^keyboard
until key >= 128
^keystrobe
@@ -811,7 +814,7 @@ def a2tone(duration, delay)
return 0
end
def a2rnd
*a2rndnum = ^a2rndh ^ ^a2rndl ^ (*a2rndnum << 1) + 127
*a2rndnum = ^a2rndh ^ ^a2rndl ^ (*a2rndnum << 1) + 125
return *a2rndnum & $7FFF
end
//
+44 -55
View File
@@ -105,24 +105,6 @@ def branchNew(x, y)
dir = 1 << (conio:rnd() & 3)
repeat
when dir
is DIR_DOWN
if y < MAZE_HEIGHT-1
flags = maze.[y + 1, x]
if (flags & CELL_SOLVED) or !(flags & CELL_TRACED)
return DIR_DOWN
fin
fin
cnt++
//break
is DIR_RIGHT
if x < MAZE_WIDTH-1
flags = maze.[y, x + 1]
if (flags & CELL_SOLVED) or !(flags & CELL_TRACED)
return DIR_RIGHT
fin
fin
cnt++
//break
is DIR_UP
if y > 0
flags = maze.[y - 1, x]
@@ -130,8 +112,9 @@ def branchNew(x, y)
return DIR_UP
fin
fin
dir = DIR_RIGHT
cnt++
//break
break
is DIR_LEFT
if x > 0
flags = maze.[y, x - 1]
@@ -139,8 +122,29 @@ def branchNew(x, y)
return DIR_LEFT
fin
fin
dir = DIR_DOWN
cnt++
//break
break
is DIR_DOWN
if y < MAZE_HEIGHT-1
flags = maze.[y + 1, x]
if (flags & CELL_SOLVED) or !(flags & CELL_TRACED)
return DIR_DOWN
fin
fin
dir = DIR_LEFT
cnt++
break
is DIR_RIGHT
if x < MAZE_WIDTH-1
flags = maze.[y, x + 1]
if (flags & CELL_SOLVED) or !(flags & CELL_TRACED)
return DIR_RIGHT
fin
fin
dir = DIR_UP
cnt++
break
wend
until cnt > 3
return 0
@@ -283,25 +287,10 @@ def mazeInit#0
fin
end
def moveUp(x, y)
return !(maze.[y, x] & WALL_TOP)
end
def moveLeft(x, y)
return !(maze.[y, x] & WALL_LEFT)
end
def moveDown(x, y)
return !(maze.[y + 1, x] & WALL_TOP)
end
def moveRight(x, y)
return !(maze.[y, x + 1] & WALL_LEFT)
end
def mazePlay
byte x, y, quit, key
cellSetFlags(0, entry, WALL_LEFT) // Block off entry
x = 0
y = entry
while TRUE
@@ -345,26 +334,26 @@ def mazePlay
end
def atoi(strptr)#1
var num, len, sign
var num, len, sign
sign = 1
num = 0
len = ^strptr
strptr++
if ^strptr == '-'
sign = -1
sign = 1
num = 0
len = ^strptr
strptr++
len--
elsif ^strptr == '+'
strptr++
len--
fin
while len and ^strptr >= '0' and ^strptr <= '9'
num = num * 10 + ^strptr - '0'
strptr++
len--
loop
return num * sign
if ^strptr == '-'
sign = -1
strptr++
len--
elsif ^strptr == '+'
strptr++
len--
fin
while len and ^strptr >= '0' and ^strptr <= '9'
num = num * 10 + ^strptr - '0'
strptr++
len--
loop
return num * sign
end
arg = argNext(argFirst)
@@ -379,8 +368,8 @@ else
loop
getc
fin
seed = *rndnum
repeat
seed = *rndnum
conio:textmode(40)
hgrMode(hgrPage1)
tileDrawBuf(hgrPage1)