summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/sudokubundle/printsudoku.sty
blob: 09dae133f6de462ae3d9b98d30e80772b79bf48e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
%%
%% This is file `printsudoku.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% sudokubundle.dtx  (with options: `print')
%% 
%% -----------------------------------------------------------------
%%   Author: Peter Wilson (herries dot press at earthlink dot net)
%%           Herries Press
%%   Copyright 2006 Peter R. Wilson
%% 
%%   This work may be distributed and/or modified under the
%%   conditions of the LaTeX Project Public License, either
%%   version 1.3 of this license or (at your option) any
%%   later version.
%%   The latest version of the license is in
%%      http://www.latex-project.org/lppl.txt
%%   and version 1.3 or later is part of all distributions of
%%   LaTeX version 2003/06/01 or later.
%% 
%%   This work has the LPPL maintenance status "author-maintained".
%% 
%%   This work consists of the files listed in the README file.
%% -----------------------------------------------------------------
%% 
%%%% solvethem.tex   Solve Sudoku files
%%%%                 Peter Wilson
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{printsudoku}[2006/02/16 v1.0 typeset sudoku puzzles]

\newread\s@dread
\newwrite\s@dwrite

%%%% open game file
\newcommand*{\reads@dgame}[1]{%
  \closein\s@dread
  \openin\s@dread=#1}

%%% set size of a game cell
\newlength\halfs@dcell
\newcommand*{\cellsize}[1]{%
  \halfs@dcell=#1\relax
  \halfs@dcell=0.5\halfs@dcell}
\cellsize{2.5\baselineskip}
%% set font for the numbers
\newcommand*{\cluefont}[1]{\def\s@dfont{#1}}
\cluefont{\Huge}

%% counts for looping and cell positions
\newcount\s@dncol
\newcount\s@dnrow
\newcount\s@dcolpos
\newcount\s@drowpos

%% insert the clues into the game array
\newcommand*{\adds@dclues}{%
  \firsts@dcluetrue
  \s@dnrow\@ne
  \loop
    \ifnum\s@dnrow<10\relax
    \read\s@dread to \s@dline
    \firsts@dcluetrue
    \s@drowpos=\s@dnrow
    \multiply\s@drowpos\tw@
    \advance\s@drowpos\m@ne
    \s@dncol\@ne
    \dos@dcols
    \advance\s@dnrow\@ne
  \repeat
  \closein\s@dread}

%% insert a row of clues
\newcommand*{\dos@dcols}{%
\bgroup
  \loop
    \ifnum\s@dncol<10\relax
    \s@dcolpos=\s@dncol
    \multiply\s@dcolpos\tw@
    \advance\s@dcolpos\m@ne
    \put(\s@dcolpos,-\s@drowpos){\makebox(0,0){\s@dfont\gets@dclue}}%
    \advance\s@dncol\@ne
  \repeat
\egroup}

%% get the next character in a string
\def\gettwo#1#2\nowt{%
  \gdef\istchar{#1}\gdef\restchars{#2}}
\def\splitoff#1{\gettwo#1\nowt}
%% a full stop (period)
\gdef\s@dfstop{.}

%% get the next clue in the line
\newif\iffirsts@dclue
\firsts@dcluetrue
\newcommand*{\gets@dclue}{%
  \iffirsts@dclue
    \expandafter\splitoff\expandafter{\s@dline}%
    \global\firsts@dcluefalse
  \else
    \expandafter\splitoff\expandafter{\restchars}%
  \fi
  \ifx\s@dfstop\istchar
  \else
    \istchar
  \fi}

%% typeset the grid, then add the clues
\newcommand*{\s@dgame}{%
  \setlength\unitlength\halfs@dcell
  \begin{picture}(18,18)(0,-18)
    \thinlines
    \multiput(0,0)(2,0){10}{\line(0,-1){18}}
    \multiput(0,0)(0,-2){10}{\line(1,0){18}}
    \thicklines \linethickness{1pt}
    \multiput(0,0)(6,0){4}{\line(0,-1){18}}
    \multiput(0,0)(0,-6){4}{\line(1,0){18}}
    \adds@dclues
  \end{picture}}

%% the whole shebang, where #1 is the name of the game file
\newcommand*{\sudoku}[1]{%
  \reads@dgame{#1}%
  \s@dgame}

\newcommand*{\puzzlefile}{puzz.sud}
\newcommand*{\writepuzzle}[9]{%
  \immediate\closeout\s@dwrite
  \immediate\openout\s@dwrite=\puzzlefile
  \immediate\write\s@dwrite{#1}%
  \immediate\write\s@dwrite{#2}%
  \immediate\write\s@dwrite{#3}%
  \immediate\write\s@dwrite{#4}%
  \immediate\write\s@dwrite{#5}%
  \immediate\write\s@dwrite{#6}%
  \immediate\write\s@dwrite{#7}%
  \immediate\write\s@dwrite{#8}%
  \immediate\write\s@dwrite{#9}%
  \writes@dpuzzend}
\newcommand*{\writes@dpuzzend}[1][\@empty]{
  \ifx\@empty #1\else
    \immediate\write\s@dwrite{ }%
    \immediate\write\s@dwrite{#1}%
  \fi
  \immediate\closeout\s@dwrite}
\newcommand*{\sudpuzznewline}{^^J}

\endinput
%%
%% End of file `printsudoku.sty'.