From 6899e11aadab724761e5639f0388be23a680bdc6 Mon Sep 17 00:00:00 2001 From: Chris Mounce Date: Sat, 24 Jan 2026 15:02:33 -0800 Subject: [PATCH] Add reciprocal marker to board exit comments --- src/zzt/text.rs | 56 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/src/zzt/text.rs b/src/zzt/text.rs index abf1a0d..4a2f354 100644 --- a/src/zzt/text.rs +++ b/src/zzt/text.rs @@ -157,7 +157,7 @@ fn write_board(output: &mut String, index: Option, board: &Board, boards: // Board properties cluster (may be empty) let mut props = String::new(); - write_board_properties(&mut props, board, boards); + write_board_properties(&mut props, index, board, boards); // Stats cluster (may be empty) let mut stats_output = String::new(); @@ -178,29 +178,61 @@ fn write_board(output: &mut String, index: Option, board: &Board, boards: } } -fn write_board_properties(output: &mut String, board: &Board, boards: Option<&[Board]>) { +fn write_board_properties( + output: &mut String, + current_idx: Option, + board: &Board, + boards: Option<&[Board]>, +) { kv!(output, "shots", board.max_shots, 255); kv_bool!(output, "dark", board.is_dark); - // Helper to write exit with optional board title comment + // Helper to write exit with optional board title comment and reciprocal marker fn write_exit( output: &mut String, - name: &str, + direction: char, index: Option>, + current_idx: Option, boards: Option<&[Board]>, ) { if let Some(n) = index { - let comment = boards - .map(|b| board_title_comment(b, n.get())) - .unwrap_or_default(); - writeln!(output, "{} = {}{}", name, n, comment).unwrap(); + let target_idx = n.get() as usize; + + // Check if connection is reciprocal + let is_reciprocal = boards.map_or(false, |b| { + current_idx.map_or(false, |cur| { + b.get(target_idx).map_or(false, |target_board| { + let opposite_exit = match direction { + 'n' => target_board.exit_south, + 's' => target_board.exit_north, + 'e' => target_board.exit_west, + 'w' => target_board.exit_east, + _ => None, + }; + opposite_exit.map_or(false, |e| e.get() as usize == cur) + }) + }) + }); + + let reciprocal_marker = if is_reciprocal { "[*] " } else { "" }; + let title = boards + .and_then(|b| b.get(target_idx)) + .map(|b| b.name.as_str()) + .unwrap_or(""); + + writeln!( + output, + "exit_{} = {} # {}{}", + direction, n, reciprocal_marker, title + ) + .unwrap(); } } - write_exit(output, "exit_n", board.exit_north, boards); - write_exit(output, "exit_s", board.exit_south, boards); - write_exit(output, "exit_e", board.exit_east, boards); - write_exit(output, "exit_w", board.exit_west, boards); + write_exit(output, 'n', board.exit_north, current_idx, boards); + write_exit(output, 's', board.exit_south, current_idx, boards); + write_exit(output, 'e', board.exit_east, current_idx, boards); + write_exit(output, 'w', board.exit_west, current_idx, boards); kv_bool!(output, "reenter", board.restart_on_zap); kv!(output, "time_limit", board.time_limit, 0);