variable change exhaustive search

This commit is contained in:
2026-04-23 14:53:31 +02:00
parent 4386cb72e9
commit a6d4647105
3 changed files with 101 additions and 35 deletions
+39 -14
View File
@@ -1,5 +1,6 @@
from tea3.pretty_print import pretty_print
from tea3.tea3model import Tea3Model
from tea3.variable_search import run_exhaustive
def prompt_int(message: str, lo: int, hi: int) -> int:
@@ -15,28 +16,28 @@ def prompt_int(message: str, lo: int, hi: int) -> int:
print(f"Value must be between {lo} and {hi} (inclusive).")
def main() -> None:
print("=" * 50)
print(" Tea3 Model ")
print("=" * 50)
def prompt_choice(message: str, choices: set[int]) -> int:
choices_str = ", ".join(map(str, sorted(choices)))
while True:
raw = input(message).strip()
try:
value = int(raw)
except ValueError:
print("Please enter a number.")
continue
if value in choices:
return value
print(f"Value must be one of: {choices_str}")
steps = prompt_int("\nHow many steps do you want to run? (1100): ", 1, 100)
def run_classic_cli():
print("\nR registers are indexed 07; bits within each register are 07.")
print("Enter -1 to print all registers, or all bits.")
steps = prompt_int("How many steps do you want to run? (1100): ", 1, 100)
reg = prompt_int("Which R register do you want to inspect? (-1 or 07): ", -1, 7)
bit = prompt_int("Which bit of that register? (-1 or 07): ", -1, 7)
if reg == -1 and bit == -1:
print(f"\nRunning {steps} step(s), watching all R registers and all bits")
elif reg == -1:
print(f"\nRunning {steps} step(s), watching all R registers, bit [{bit}]")
elif bit == -1:
print(f"\nRunning {steps} step(s), watching R[{reg}] and all bits")
else:
print(f"\nRunning {steps} step(s), watching R[{reg}][{bit}]")
print("-" * 50)
model = Tea3Model()
@@ -59,4 +60,28 @@ def main() -> None:
print("Done.")
def main():
print("=" * 50)
print(" Tea3 Model ")
print("=" * 50)
print("\nChoose a mode:")
print(" 1) Classic inspection")
print(" 2) Exhaustive variable-change search")
mode = prompt_choice("Your choice (1 or 2): ", {1, 2})
if mode == 1:
run_classic_cli()
else:
steps = prompt_int("How many steps? (1100): ", 1, 100)
target_reg = prompt_int("Target register (07): ", 0, 7)
print("-" * 50)
run_exhaustive(steps, target_reg)
print("\n" + "=" * 50)
print("Done.")
main()