Skip to content

Commit 64a501a

Browse files
committed
check top row bug
1 parent 8f9ec36 commit 64a501a

File tree

5 files changed

+337
-35
lines changed

5 files changed

+337
-35
lines changed

tests/src/floor.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ fn test_floor() {
5757
fn test_floor_linecap() {
5858
let mut emu = util::emulator(None);
5959

60-
for _ in 0..3 {
61-
emu.run_until_vblank();
62-
}
60+
for _ in 0..3 { emu.run_until_vblank(); }
6361

6462
let practise_type = labels::get("practiseType") as usize;
6563
let game_mode = labels::get("gameMode") as usize;
@@ -76,9 +74,7 @@ fn test_floor_linecap() {
7674

7775
emu.registers.pc = main_loop;
7876

79-
for _ in 0..5 {
80-
emu.run_until_vblank();
81-
}
77+
for _ in 0..5 { emu.run_until_vblank(); }
8278

8379
// get some tetrises
8480

@@ -96,9 +92,7 @@ fn test_floor_linecap() {
9692
##### ####
9793
##### ####"##);
9894

99-
for _ in 0..40 {
100-
emu.run_until_vblank();
101-
}
95+
for _ in 0..40 { emu.run_until_vblank(); }
10296
}
10397

10498
// check rows aren't pulled from the top in linecap floor mode
@@ -132,9 +126,7 @@ fn test_floor0() {
132126

133127
emu.registers.pc = main_loop;
134128

135-
for _ in 0..5 {
136-
emu.run_until_vblank();
137-
}
129+
for _ in 0..5 { emu.run_until_vblank(); }
138130

139131
// setup a tetris
140132

@@ -150,9 +142,7 @@ fn test_floor0() {
150142
##### ####
151143
##### ####"##);
152144

153-
for _ in 0..40 {
154-
emu.run_until_vblank();
155-
}
145+
for _ in 0..40 { emu.run_until_vblank(); }
156146

157147
// check floor 0 doesnt burn lines
158148
assert_ne!(playfield::get(&mut emu, 0, 19), 0xEF);

tests/src/main.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod pushdown;
1212
mod rng;
1313
mod score;
1414
mod sps;
15+
mod toprow;
1516

1617
use gumdrop::Options;
1718

@@ -43,17 +44,19 @@ fn main() {
4344
// run tests
4445
if options.test {
4546
floor::test();
46-
println!("floor works!");
47+
println!(">> floor ✅");
48+
toprow::test();
49+
println!(">> top row bug ✅");
4750
score::test();
48-
println!("score works!");
51+
println!(">> score ");
4952
score::test_render();
50-
println!("score rendering works!");
53+
println!(">> score rendering ");
5154
pushdown::test();
52-
println!("pushdown works!");
55+
println!(">> pushdown ");
5356
rng::test();
54-
println!("rng seeds are the same!");
57+
println!(">> rng seeds ");
5558
sps::test();
56-
println!("sps is the same!");
59+
println!(">> sps ");
5760
}
5861

5962
// count cycles

tests/src/playfield.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,60 @@
11
use rusticnes_core::nes::NesState;
2-
use crate::{labels};
2+
use crate::labels;
33

44
pub fn set(emu: &mut NesState, x: u16, y: u16, value: u8) {
55
let index = ((y * 10) + x) + labels::get("playfield");
66
emu.memory.iram_raw[index as usize] = value;
77
}
88

9-
pub fn get(emu: &mut NesState, x: u16, y: u16) -> u8 {
9+
pub fn get(emu: &NesState, x: u16, y: u16) -> u8 {
1010
let index = ((y * 10) + x) + labels::get("playfield");
1111
emu.memory.iram_raw[index as usize]
1212
}
1313

14-
#[allow(dead_code)]
1514
pub fn clear(emu: &mut NesState) {
16-
for line in 0..20 {
17-
self::fill_line(emu, line);
15+
for y in 0..20 {
16+
for x in 0..10 {
17+
self::set(emu, x, y, 0xEF);
18+
}
1819
}
1920
}
2021

22+
pub fn set_str(emu: &mut NesState, playfield: &str) {
23+
set_str_inner(emu, playfield, false);
24+
}
25+
2126
#[allow(dead_code)]
22-
pub fn fill_line(emu: &mut NesState, y: u16) {
23-
for x in 0..10 {
24-
self::set(emu, x, y, labels::get("BLOCK_TILES") as _);
25-
}
27+
pub fn set_str_top(emu: &mut NesState, playfield: &str) {
28+
set_str_inner(emu, playfield, true);
2629
}
2730

28-
pub fn set_str(emu: &mut NesState, playfield: &str) {
31+
fn set_str_inner(emu: &mut NesState, playfield: &str, top: bool) {
2932
let rows = playfield.trim_start_matches('\n').split("\n").collect::<Vec<_>>();
30-
let offset = 20 - rows.len() as u16;
33+
let offset = if top {
34+
0
35+
} else {
36+
20 - rows.len() as u16
37+
};
3138
rows.iter().enumerate().for_each(|(y, line)| {
3239
line.chars().enumerate().for_each(|(x, ch)| {
3340
self::set(emu, x as _, offset + y as u16, if ch == '#' { 0x7b } else { 0xef });
3441
});
3542
});
43+
3644
}
3745

3846
#[allow(dead_code)]
39-
pub fn get_str(emu: &mut NesState) -> String {
47+
pub fn get_str(emu: &NesState) -> String {
4048
let mut s = String::new();
4149
for y in 0..20 {
50+
let mut line = String::new();
4251
for x in 0..10 {
43-
s.push_str(if self::get(emu, x, y) == 0xEF { " " } else { "#" });
52+
line.push_str(if self::get(emu, x, y) == 0xEF { " " } else { "#" });
53+
}
54+
s.push_str(line.trim_end());
55+
if y != 19 {
56+
s.push_str("\n");
4457
}
45-
s.push_str("\n");
4658
}
4759

4860
s

tests/src/pushdown.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fn pushdown_impl(pushdown: u8, score: u16) -> u16 {
3535
let low = added & 0xF;
3636
let high = (added >> 4) * 10;
3737

38+
// you can dedupe the `- ones` here and just subtract it from `high` instead
3839
if high + low + hundredths - ones <= 100 {
3940
high + low - ones
4041
} else {

0 commit comments

Comments
 (0)