Skip to content

Commit 608b5b1

Browse files
committed
guess output visualizer for an interactive problem
1 parent fbe60cb commit 608b5b1

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import sys
2+
from pathlib import Path
3+
4+
5+
with open(sys.argv[1]) as in_file, open(sys.argv[3] / Path("judgemessage.txt"), "r") as msg_file:
6+
mode = in_file.read().split()[0]
7+
assert mode in ("random", "fixed", "adaptive"), mode
8+
judgemessages = iter(msg_file)
9+
10+
print(r"""\documentclass[varwidth]{standalone}
11+
\usepackage{tikz}
12+
\usetikzlibrary{patterns}
13+
\tikzset{every node/.style={font=\sffamily}}
14+
\begin{document}
15+
\begin{tikzpicture}
16+
""")
17+
if not mode == "adaptive":
18+
secret = int(next(judgemessages).split()[-1])
19+
print(rf"\node at ({secret/100},-1.5) {{ {secret} ({mode}) }};")
20+
else:
21+
next(judgemessages)
22+
print(rf"\node at (5,-.5) {{ adaptive }};")
23+
for line in judgemessages:
24+
rnd, guess = int(line.split()[1]), int(line.split()[3])
25+
y = -1 - rnd
26+
print(rf"\draw [very thick, blue!20] (0, {y}) -- (10, {y});")
27+
print(rf"\node at ({guess/100}, {y})[anchor=north]", r"{$\uparrow$};")
28+
print(rf"\node at ({guess/100}, {y-.5})[anchor=north] {{ { guess } }};")
29+
if not mode == "adaptive":
30+
print(rf"\draw [red] ({secret/100}, {-rnd-1}) -- ({secret/100}, 0);")
31+
32+
print(r"\end{tikzpicture}\end{document}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Set script directory
4+
SCRIPT_DIR="$(dirname "$0")"
5+
6+
# Check if visualize.py exists
7+
if [[ ! -f "$SCRIPT_DIR/guess-visualizer.py" ]]; then
8+
echo "Error: guess-visualizer.py not found in $SCRIPT_DIR" >&2
9+
exit 1
10+
fi
11+
12+
tmptexdir=$(mktemp -d) # Create a unique temporary directory
13+
OUTPUT_FILE="$tmptexdir/judgeimage.tex"
14+
15+
# Run visualize.py
16+
python3 "$SCRIPT_DIR/guess-visualizer.py" $1 $2 $3 > "$OUTPUT_FILE"
17+
if [[ $? -ne 0 ]]; then
18+
echo "Error: guess-visualizer.py failed" >&2
19+
exit 1
20+
fi
21+
22+
# Check if judgeimage.tex exists
23+
if [[ ! -f "$OUTPUT_FILE" ]]; then
24+
echo "Error: texfile not found in $SCRIPT_DIR" >&2
25+
exit 1
26+
fi
27+
28+
# Run pdflatex
29+
(
30+
cd "$tmptexdir" && pdflatex judgeimage.tex
31+
)
32+
if [[ $? -ne 0 ]]; then
33+
echo "Error: pdflatex failed" >&2
34+
exit 1
35+
fi
36+
37+
mv "$tmptexdir/judgeimage.pdf" $3
38+
rm -r "$tmptexdir"
39+
40+
echo "Script completed successfully."
41+
exit 0

0 commit comments

Comments
 (0)