#! /bin/sh #------------------------------------------------------------------------------ # Read command-line arguments # $1: a BCG file containing the puzzle solutions # $2: number of the month (0 ... 12) # $3: number of the day (0 ... 31) LTS=$1 if [ $2 -eq 0 ] then # Current month number MONTH=`date '+%m' | sed -e 's/0\([1-9]\)/\1/'` else # Given month number MONTH=$2 fi if [ $3 -eq 0 ] then # Current day number DAY=`date '+%d' | sed -e 's/0\([1-9]\)/\1/'` else # Given day number DAY=$3 fi # Three-letter name of a month case $MONTH in 1 ) MONTH_NAME="Jan" ;; 2 ) MONTH_NAME="Feb" ;; 3 ) MONTH_NAME="Mar" ;; 4 ) MONTH_NAME="Apr" ;; 5 ) MONTH_NAME="May" ;; 6 ) MONTH_NAME="Jun" ;; 7 ) MONTH_NAME="Jul" ;; 8 ) MONTH_NAME="Aug" ;; 9 ) MONTH_NAME="Sep" ;; 10 ) MONTH_NAME="Oct" ;; 11 ) MONTH_NAME="Nov" ;; 12 ) MONTH_NAME="Dec" ;; esac #------------------------------------------------------------------------------ # Convert a solution grid to graphical data TEXT2GRID () { sed -e 's/.*GRID_LINE (\([^)]*\)), GRID_LINE (\([^)]*\)), GRID_LINE (\([^)]*\)), GRID_LINE (\([^)]*\)), GRID_LINE (\([^)]*\)), GRID_LINE (\([^)]*\)), GRID_LINE (\([^)]*\)).*/7 \1\n6 \2\n5 \3\n4 \4\n3 \5\n2 \6\n1 \7/' | \ sed -e 's/\([1-7]\) \([A-Z]\), \([A-Z]\), \([A-Z]\), \([A-Z]\), \([A-Z]\), \([A-Z]\), \([A-Z]\)/1 \1 \2\n2 \1 \3\n3 \1 \4\n4 \1 \5\n5 \1 \6\n6 \1 \7\n7 \1 \8/g' | \ sed -e "s/A/150 85 0 \"\"/g" | \ sed -e "s/B/230 0 0 \"\"/g" | \ sed -e "s/C/0 0 230 \"\"/g" | \ sed -e "s/D/255 150 0 \"\"/g" | \ sed -e "s/E/240 100 240 \"\"/g" | \ sed -e "s/F/255 240 0 \"\"/g" | \ sed -e "s/G/120 0 120 \"\"/g" | \ sed -e "s/H/0 180 0 \"\"/g" | \ sed -e "s/Y/247 232 206 \"$DAY\"/g" | \ sed -e "s/X/247 232 206 \"$MONTH_NAME\"/g" | \ sed -e "s/Z/255 255 255 \"\"/g" # Colors of the grid cells: # piece A: brown # piece B: red # piece C: blue # piece D: orange # piece E: pink # piece F: yellow # piece G: magenta # piece H: green # cell X: beige (month name) # cell Y: beige (day number) # cell Z: white (cell absent from the grid) } #------------------------------------------------------------------------------ # Convert puzzle solution(s) to drawing # Collect the transition labels of the LTS that denote solution grids. # These labels have the following form (e.g., a solution for Jan 1): # "PRINT !GRID (7, 7, GRID_ARRAY (GRID_LINE (X, H, H, B, B, B, Z), GRID_LINE (H, H, H, B, C, B, Z), GRID_LINE (Y, E, E, C, C, C, C), GRID_LINE (F, F, E, E, E, D, G), GRID_LINE (F, A, A, D, D, D, G), GRID_LINE (F, A, A, D, G, G, G), GRID_LINE (F, A, A, Z, Z, Z, Z)))" # This label corresponds to the following solution grid (where X denotes the # month, Y denotes the day, and Z denotes the cells absent from the grid): # XHHBBBZ # HHHBCBZ # YEECCCC # FFEEEDG # FAADDDG # FAADGGG # FAAZZZZ bcg_info -labels $LTS | grep PRINT > solution.txt NB_LINES=`wc -l solution.txt | sed -e 's/[^0-9]*\([0-9]*\).*/\1/'` if [ $NB_LINES -eq 0 ] then # This case should never occur echo "no solution found" exit 1 fi # Generate the header of the plot script cat > solution.plot << \EOF set term postscript color portrait set output "solution.ps" set size square 1, 1 set origin 0, 0 set margins 0, 0, 0, 0 unset border unset tics unset colorbox unset key EOF if [ $NB_LINES -eq 1 ] then # A single solution: one-page plot # Convert the solution grid to graphical data cat solution.txt | TEXT2GRID > grid.dat # Generate the drawing of the solution ( echo "set lmargin 10" echo "set rmargin 10" echo "set title \"One puzzle solution for $MONTH_NAME $DAY\\\\n\"" echo "plot \"grid.dat\" with rgbimage pixels, \"grid.dat\" using 1:2:6 with labels font \"Arial,10\"" ) >> solution.plot else # Several solutions: possibly multi-page plot # First page of the plot echo "set multiplot title \"\\\\nAll $NB_LINES puzzle solutions for $MONTH_NAME $DAY\\\\n\" font \"Arial,14\" layout 4,3 downwards scale 0.8, 0.8" >> solution.plot N=1 while [ $N -le $NB_LINES ] do # Convert the current solution grid to graphical data head -n $N solution.txt | tail -n 1 | TEXT2GRID > grid_${N}.dat echo "plot \"grid_${N}.dat\" with rgbimage pixels, \"grid_${N}.dat\" using 1:2:6 with labels font \"Arial,8\"" >> solution.plot N=`expr $N + 1` if [ `expr $N % 12` -eq 1 ] then # Current page filled: next page of the plot echo "unset multiplot" >> solution.plot echo "set multiplot layout 4,3 downwards scale 0.8, 0.8" >> solution.plot fi done echo "unset multiplot" >> solution.plot fi # Generate the drawing of one or all solutions gnuplot solution.plot $CADP/src/com/cadp_rm grid*.dat $CADP/src/com/cadp_rm "solution.txt" $CADP/src/com/cadp_rm "solution.plot"