Skip to content

Commit 6a7b6de

Browse files
committed
drought probability generation
1 parent ba05516 commit 6a7b6de

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

tests/src/drought.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use crate::{labels, util, block};
2+
3+
pub fn print_probabilities() {
4+
let mut emu = util::emulator(None);
5+
let rng_seed = labels::get("rng_seed");
6+
let drought_modifier = labels::get("droughtModifier");
7+
let next_rng = labels::get("pickRandomTetrimino");
8+
9+
let seed = 0x8988;
10+
emu.memory.iram_raw[(rng_seed + 0) as usize] = (seed >> 8) as _;
11+
emu.memory.iram_raw[(rng_seed + 1) as usize] = seed as u8;
12+
emu.memory.iram_raw[labels::get("practiseType") as usize] = labels::get("MODE_DROUGHT") as u8;
13+
14+
for modifier in 0..19 {
15+
emu.memory.iram_raw[drought_modifier as usize] = modifier;
16+
17+
let mut longbars = 0;
18+
let mut total = 0;
19+
20+
for _ in 0..100000 {
21+
emu.registers.pc = next_rng;
22+
23+
util::run_to_return(&mut emu, false);
24+
25+
let block: block::Block = emu.memory.iram_raw[labels::get("spawnID") as usize].into();
26+
27+
if block == block::Block::I {
28+
longbars += 1;
29+
}
30+
31+
total += 1;
32+
}
33+
println!(
34+
"{} longbar%: {:.2}",
35+
"0123456789ABCDEFGHI".as_bytes()[modifier as usize] as char,
36+
(longbars as f64 / total as f64) * 100.
37+
);
38+
}
39+
}

tests/src/main.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod block;
2+
mod drought;
23
mod input;
34
mod labels;
45
mod pushdown;
@@ -8,7 +9,6 @@ mod sps;
89
mod util;
910
mod video;
1011

11-
1212
use gumdrop::Options;
1313

1414
fn parse_hex(s: &str) -> Result<u32, std::num::ParseIntError> {
@@ -26,6 +26,8 @@ struct TestOptions {
2626
sps_qty: u32,
2727
#[options(help = "list RNG seeds")]
2828
rng_seeds: bool,
29+
#[options(help = "list drought mode probabilities")]
30+
drought_probs: bool,
2931
foo: bool,
3032
}
3133

@@ -64,6 +66,10 @@ fn main() {
6466
println!("{:?}", rng::seeds());
6567
}
6668

69+
if options.drought_probs {
70+
drought::print_probabilities();
71+
}
72+
6773
// other stuff
6874

6975
if options.foo {
@@ -79,11 +85,12 @@ fn main() {
7985
let mode_typeb = labels::get("MODE_TYPEB") as u8;
8086

8187
rng::seeds().iter().for_each(|seed| {
82-
8388
emu.reset();
8489

8590
// spend a few frames bootstrapping
86-
for _ in 0..3 { emu.run_until_vblank(); }
91+
for _ in 0..3 {
92+
emu.run_until_vblank();
93+
}
8794

8895
emu.memory.iram_raw[practise_type] = mode_typeb;
8996
emu.memory.iram_raw[game_mode] = 4;
@@ -103,7 +110,7 @@ fn main() {
103110
emu.ppu.render_ntsc(video::WIDTH);
104111
view.update(&emu.ppu.filtered_screen);
105112
});
106-
loop {
107-
}
113+
loop {}
108114
}
115+
109116
}

0 commit comments

Comments
 (0)