-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path7bag-test.lua
50 lines (45 loc) · 1.29 KB
/
7bag-test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require("ypcall") -- must be first, as it changes globals
require("asm")
require("testing")
local labels = asm.loadlabels("build/7bag.lbl")
local spawnTable = {0x02, 0x07, 0x08, 0x0A, 0x0B, 0x0E, 0x12}
function test_fullbag ()
asm.waitexecute(0x813B) -- cmp gameModeState in @mainLoop
asm.jsr(labels.disableNmi)
local results = {}
for _, orientID in pairs(spawnTable) do
results[orientID] = 0
end
math.randomseed(1)
memory.writebyte(labels.spawnID, 0)
for i=1,14 do
memory.writebyte(labels.rng_seed, math.random(256))
asm.jsr(labels.pickRandomTetrimino_7bag)
local a = memory.getregister("a")
results[a] = results[a] + 1
end
print(results)
for orientID, cnt in pairs(results) do
assert(cnt == 2, "orientation: " .. orientID .. " count: " .. cnt)
end
end
function test_distribution ()
asm.waitexecute(0x813B) -- cmp gameModeState in @mainLoop
asm.jsr(labels.disableNmi)
local results = {}
for _, orientID in pairs(spawnTable) do
results[orientID] = 0
end
for i=0,255 do
memory.writebyte(labels.spawnID, 0x7F)
memory.writebyte(labels.rng_seed, i)
asm.jsr(labels.pickRandomTetrimino_7bag)
local a = memory.getregister("a")
results[a] = results[a] + 1
end
print(results)
for orientID, cnt in pairs(results) do
assert(cnt == 36 or cnt == 37, "Imbalanced")
end
end
testing.run()