%%
%% This is file `logicpuzzle.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% logicpuzzle.dtx  (with options: `package')
%% 
%% Copyright (C) 2013-2014 by:
%% Josef Kleber
%% <josef.kleber@gmx.de>
%% 
%% This file 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 this
%% 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/12/01 or later.
%% 
%% This work has the LPPL maintenance status "author-maintained".
%% 
%% The Current Maintainer of this work is Josef Kleber.
%% 
%% This work consists of all files listed in manifest.txt.
%% 
\NeedsTeXFormat{LaTeX2e}%
\ProvidesPackage{logicpuzzle}[2014/06/15 v2.5 logicpuzzle.sty%
                 - Josef Kleber (C) 2013-2014]%
\RequirePackage{xkeyval}%
\RequirePackage{ifthen}%
\RequirePackage{ragged2e}%
\RequirePackage{marginnote}%
\RequirePackage{tikz}%
\usetikzlibrary{decorations.pathmorphing,decorations.pathreplacing,%
                calc,shapes.geometric}%
\pgfdeclarelayer{LPdump}%
\pgfdeclarelayer{LPbgcolor}%
\pgfdeclarelayer{LPbackgroundtwo}%
\pgfdeclarelayer{LPbackground}%
\pgfdeclarelayer{LPforeground}%
\pgfdeclarelayer{LPforegroundtwo}%
\pgfsetlayers{LPdump,LPbgcolor,LPbackgroundtwo,LPbackground,main,%
              LPforeground,LPforegroundtwo}%
\newcounter{LP@rows}%
\newcounter{LP@columns}%
\newcounter{LP@counter@unique}%
\newcounter{LP@counti}%
\newcounter{LP@countii}%
\newcounter{LP@countiii}%
\newcounter{LP@whiledo@i}%
\newcounter{LP@whiledo@ii}%
\newcounter{LP@count@ig@i}%
\newcounter{LP@count@ig@ii}%
\newcounter{LP@count@ig@iii}%
\newcounter{LP@count@ig@iv}%
\newcounter{LP@puzzlecounter}%
\setcounter{LP@puzzlecounter}{1}%
\newlength\LP@length%
\gdef\LP@rows{}%
\gdef\LP@columns{}%
\gdef\LP@scale{1}%
\gdef\LP@color{black}%
\gdef\LP@bgcolor{}%
\gdef\LP@fontsize\Large%
\gdef\LP@cvoffset{0pt}%
\newcommand*\LP@counterstyle{none}%
\newcommand*\LP@titleformat{}%
\gdef\LP@env@prefix{}%
\gdef\LP@package{}%
\def\LP@normallines{0.5pt}%
\def\LP@thicklines{1.5pt}%
\def\LP@grid@linestyle{}%
\def\LP@draw@opacity{1}%
\def\LP@rel@tikzpath{}%
\def\LP@tracks@scale{.3}%
\def\LP@fw@linestyle{-|}%
\newcommand*\LP@Pfive{.5}%
\newcommand*\LP@define@key[4]%
{%
  \expandafter\gdef\csname#1@#3\endcsname{#4}%
  \define@key{#2.sty}{#3}[#4]%
  {%
    \expandafter\gdef\csname#1@#3\endcsname{##1}%
  }%
  \define@key{#2}{#3}%
  {%
    \expandafter\def\csname#1@#3\endcsname{##1}%
  }%
}%
\newcommand*\LP@define@choicekey@fontsize[3]%
{%
  \expandafter\gdef\csname#1@fontsize\endcsname{\Large}%
  \define@choicekey*{#2.sty}{fontsize}[\LP@dck@fontsize\nr]{%
                    tiny,scriptsize,footnotesize,small,normalsize,%
                    large,Large,LARGE,huge,Huge}[#3]%
  {%
    \ifcase\nr\relax%
      \expandafter\gdef\csname#1@fontsize\endcsname{\tiny}%
    \or%
      \expandafter\gdef\csname#1@fontsize\endcsname{\scriptsize}%
    \or%
      \expandafter\gdef\csname#1@fontsize\endcsname{\footnotesize}%
    \or%
      \expandafter\gdef\csname#1@fontsize\endcsname{\small}%
    \or%
      \expandafter\gdef\csname#1@fontsize\endcsname{\normalsize}%
    \or%
      \expandafter\gdef\csname#1@fontsize\endcsname{\large}%
    \or%
      \expandafter\gdef\csname#1@fontsize\endcsname{\Large}%
    \or%
      \expandafter\gdef\csname#1@fontsize\endcsname{\LARGE}%
    \or%
      \expandafter\gdef\csname#1@fontsize\endcsname{\huge}%
    \or%
      \expandafter\gdef\csname#1@fontsize\endcsname{\Huge}%
    \fi%
  }%
  \define@choicekey*{#2}{fontsize}[\LP@dck@fontsize\nr]{%
                    tiny,scriptsize,footnotesize,small,normalsize,%
                    large,Large,LARGE,huge,Huge}[#3]%
  {%
    \ifcase\nr\relax%
      \expandafter\def\csname#1@fontsize\endcsname{\tiny}%
    \or%
      \expandafter\def\csname#1@fontsize\endcsname{\scriptsize}%
    \or%
      \expandafter\def\csname#1@fontsize\endcsname{\footnotesize}%
    \or%
      \expandafter\def\csname#1@fontsize\endcsname{\small}%
    \or%
      \expandafter\def\csname#1@fontsize\endcsname{\normalsize}%
    \or%
      \expandafter\def\csname#1@fontsize\endcsname{\large}%
    \or%
      \expandafter\def\csname#1@fontsize\endcsname{\Large}%
    \or%
      \expandafter\def\csname#1@fontsize\endcsname{\LARGE}%
    \or%
      \expandafter\def\csname#1@fontsize\endcsname{\huge}%
    \or%
      \expandafter\def\csname#1@fontsize\endcsname{\Huge}%
    \fi%
  }%
}%
\newcommand*\LP@definecolor[2]%
{%
  \definecolor{#1}{rgb}{#2}%
}%
\LP@definecolor{LP@c@i}{.9,.9,.98}%
\LP@definecolor{LP@c@ii}{.688,.932,.932}%
\LP@definecolor{LP@c@iii}{.88,1,1}%
\LP@definecolor{LP@c@iv}{1,1,.88}%
\LP@definecolor{LP@c@v}{1,.855,.725}%
\LP@definecolor{LP@c@vi}{.498,1,0}%
\LP@definecolor{LP@c@vii}{.53,.808,.98}%
\LP@definecolor{LP@c@viii}{.196,.804,.196}%
\LP@definecolor{LP@c@ix}{1,.96,.932}%
\LP@definecolor{LP@c@griddots}{.25,.51,.33}%
\LP@definecolor{LP@c@cross}{.25,.51,.33}%
\LP@definecolor{LP@c@mirror}{.8,.8,.8}%
\LP@definecolor{LP@c@tunnel}{.7,.7,.7}%
\LP@definecolor{LP@c@tunnel@i}{.8,.8,.8}%
\LP@definecolor{LP@c@tunnel@ii}{.5,.5,.5}%
\LP@definecolor{LP@c@bridge}{1,0,0}%
\colorlet{LP@c@track}{black!80}%
\newcommand*\LP@drawgrid[5]%
{%
  \setcounter{LP@counti}{#3}% max column
  \setcounter{LP@countii}{#4}% max row
  \stepcounter{LP@counti}%
  \stepcounter{LP@countii}%
  \draw[step=#5,line width=\LP@normallines,\LP@grid@linestyle,%
        draw opacity=\LP@draw@opacity]%
        (#1,#2) grid (\value{LP@counti},\value{LP@countii});%
}%
\newcommand*\LP@drawbackground[5]%
{%
  \ifthenelse{\equal{#5}{}}%
  {}% no bgcolor
  {%
    \setcounter{LP@counti}{#3}% max column
    \setcounter{LP@countii}{#4}% max row
    \stepcounter{LP@counti}%
    \stepcounter{LP@countii}%
    \begin{pgfonlayer}{LPbgcolor}%
      \fill[color=#5] (#1,#2) rectangle%
                      (\value{LP@counti},\value{LP@countii});%
    \end{pgfonlayer}%
  }%
}%
\newcommand*\LP@ingrid[5]%
{%
  \setcounter{LP@count@ig@i}{#1}% column
  \setcounter{LP@count@ig@ii}{#2}% row
  \setcounter{LP@count@ig@iii}{#3}% max column
  \setcounter{LP@count@ig@iv}{#4}% max row
  \ifnum\value{LP@count@ig@i}<1%
    \PackageError{#5}%
      {element outside of the grid}%
      {You tried to set an element at (#1,#2),\MessageBreak%
       which is outside the grid (1,1) .. (#3,#4)}%
  \fi%
  \ifnum\value{LP@count@ig@ii}<1%
    \PackageError{#5}%
      {element outside of the grid}%
      {You tried to set an element at (#1,#2),\MessageBreak%
       which is outside the grid (1,1) .. (#3,#4)}%
  \fi%
  \ifnum\value{LP@count@ig@i}>\value{LP@count@ig@iii}%
    \PackageError{#5}%
      {element outside of the grid}%
      {You tried to set an element at (#1,#2),\MessageBreak%
       which is outside the grid (1,1) .. (#3,#4)}%
  \fi%
  \ifnum\value{LP@count@ig@ii}>\value{LP@count@ig@iv}%
    \PackageError{#5}%
      {element outside of the grid}%
      {You tried to set an element at (#1,#2),\MessageBreak%
       which is outside the grid (1,1) .. (#3,#4)}%
  \fi%
}%
\newcommand*\setrule[3]%
{%
  \LP@set@LP@scale{\LP@env@prefix}%
  \LP@set@LP@bgcolor{\LP@env@prefix}%
  \ifthenelse{\equal{\LP@bgcolor}{}}%
  {\gdef\LP@sr@bgcolor{white}}%
  {\gdef\LP@sr@bgcolor{\LP@bgcolor}}%
  \stepcounter{LP@counter@unique}%
  \begin{pgfonlayer}{LPdump}%
    \node [shape=rectangle,inner sep=0pt] (A_\theLP@counter@unique)%
    at (#1\LP@Pfive,#2\LP@Pfive)%
       {\tikz\draw[scale=\LP@scale,color=\LP@sr@bgcolor]%
                  (0.08,0.1) rectangle (0.92,0.9);};%
  \end{pgfonlayer}%
  \node [shape=rectangle,inner sep=0pt,anchor=north west,%
         scale=\LP@scale,font=\tiny] at%
        (A_\theLP@counter@unique.north west) {$#3$};%
}%
\define@key{LP@G@setcellcontent}{vcenter}[\LP@Pfive]%
{%
  \def\LP@scc@v{\LP@Pfive}%
}%
\define@key{LP@G@setcellcontent}{hcenter}[\LP@Pfive]%
{%
  \def\LP@scc@h{\LP@Pfive}%
}%
\newcommand*\LP@G@setcellcontent[4][]%
{%
  \def\LP@scc@h{}%
  \def\LP@scc@v{}%
  \setkeys{LP@G@setcellcontent}{#1}%
  \node at (#2\LP@scc@h,#3\LP@scc@v){#4};%
}%
\newcommand*\LP@setcellcontent[3]%
{%
  \LP@G@setcellcontent[hcenter,vcenter]{#1}{#2}{#3}%
}%
\newcommand*\LP@setcellcontentC[3]%
{%
  \LP@G@setcellcontent{#1}{#2}{#3}%
}%
\newcommand*\LP@setcellcontentVE[3]%
{%
  \LP@G@setcellcontent[vcenter]{#1}{#2}{#3}%
}%
\newcommand*\LP@setcellcontentHE[3]%
{%
  \LP@G@setcellcontent[hcenter]{#1}{#2}{#3}%
}%
\newcommand*\LP@setrowcontents[3]%
{%
  \LP@set@LP@fontsize{\LP@env@prefix}%
  \setcounter{LP@counti}{#2}%
  \setcounter{LP@countii}{#3}%
  \foreach \LP@element in {#1}%
  {%
    \LP@G@setcellcontent[vcenter,hcenter]%
      {\arabic{LP@counti}}{\arabic{LP@countii}}%
      {\LP@fontsize\LP@element}%
    \stepcounter{LP@counti}%
  }%
}%
\newcommand*\LP@setcolumncontents[3]%
{%
  \LP@set@LP@fontsize{\LP@env@prefix}%
  \setcounter{LP@counti}{#2}%
  \setcounter{LP@countii}{#3}%
  \foreach \LP@element in {#1}%
  {%
    \LP@G@setcellcontent[vcenter,hcenter]%
      {\arabic{LP@counti}}{\arabic{LP@countii}}%
      {\LP@fontsize\LP@element}%
    \stepcounter{LP@countii}%
  }%
}%
\newcommand*\LP@setrowcontents@edge[3]%
{%
  \LP@set@LP@fontsize{\LP@env@prefix}%
  \setcounter{LP@counti}{#2}%
  \setcounter{LP@countii}{#3}%
  \foreach \LP@element in {#1}%
  {%
    \LP@G@setcellcontent[vcenter]%
      {\arabic{LP@counti}}{\arabic{LP@countii}}%
      {\LP@fontsize\LP@element}%
    \stepcounter{LP@counti}%
  }%
}%
\newcommand*\LP@setcolumncontents@edge[3]%
{%
  \LP@set@LP@fontsize{\LP@env@prefix}%
  \setcounter{LP@counti}{#2}%
  \setcounter{LP@countii}{#3}%
  \foreach \LP@element in {#1}%
  {%
    \LP@G@setcellcontent[hcenter]%
      {\arabic{LP@counti}}{\arabic{LP@countii}}%
      {\LP@fontsize\LP@element}%
    \stepcounter{LP@countii}%
  }%
}%
\newcommand*\setrow[2]%
{%
  \LP@set@LP@scale{\LP@env@prefix}%
  \LP@setrowcontents{#2}{1}{#1}%
}%
\newcommand*\setcolumn[2]%
{%
  \LP@set@LP@scale{\LP@env@prefix}%
  \LP@setcolumncontents{#2}{#1}{1}%
}%
\newcommand*\setcell[3]%
{%
  \LP@set@LP@scale{\LP@env@prefix}%
  \LP@set@LP@fontsize{\LP@env@prefix}%
  \LP@set@LP@rows{\LP@env@prefix}%
  \LP@set@LP@columns{\LP@env@prefix}%
  \LP@ingrid{#1}{#2}{\LP@columns}{\LP@rows}{\LP@package}%
  \LP@G@setcellcontent[hcenter,vcenter]{#1}{#2}{\LP@fontsize#3}%
}%
\newcommand*\setcells[2]%
{%
  \LP@set@LP@scale{\LP@env@prefix}%
  \LP@set@LP@fontsize{\LP@env@prefix}%
  \LP@set@LP@rows{\LP@env@prefix}%
  \LP@set@LP@columns{\LP@env@prefix}%
  \foreach \LP@sc@column/\LP@sc@row in {#1}%
  {%
    \LP@ingrid{\LP@sc@column}{\LP@sc@row}%
      {\LP@columns}{\LP@rows}{\LP@package}%
    \LP@G@setcellcontent[hcenter,vcenter]%
      {\LP@sc@column}{\LP@sc@row}{\LP@fontsize#2}%
  };%
}%
\newcommand*\setbigcell[4][Huge]%
{%
  \LP@set@LP@scale{\LP@env@prefix}%
  \LP@set@LP@bgcolor{\LP@env@prefix}%
  \ifthenelse{\equal{\LP@bgcolor}{}}%
  {\gdef\LP@sbc@bgcolor{white}}%
  {\gdef\LP@sbc@bgcolor{\LP@bgcolor}}%
  \setcounter{LP@counti}{#2}%
  \setcounter{LP@countii}{#3}%
  \stepcounter{LP@counti}%
  \stepcounter{LP@countii}%
  \draw[line width=\LP@normallines,fill=\LP@sbc@bgcolor,%
        \LP@grid@linestyle]%
       (#2,#3) rectangle ++(2,2);%
  \begin{pgfonlayer}{LPforegroundtwo}%
    \fill[color=\LP@sbc@bgcolor]%
      (\arabic{LP@counti},\arabic{LP@countii})%
      circle [radius=3.5pt*\LP@scale];%
    \node at (\arabic{LP@counti},\arabic{LP@countii})%
      {\csname#1\endcsname#4};%
  \end{pgfonlayer}%
}%
\newcommand*\setcolorrow[2]%
{%
  \setcounter{LP@counti}{1}%
  \setcounter{LP@countii}{#1}%
  \foreach \LP@element in {#2}%
  {%
    \ifthenelse{\equal{\LP@element}{0}}%
    {%
      \gdef\LP@HT@color{black}%
      \begin{puzzlebackground}%
        \fillcell{\arabic{LP@counti}}{\arabic{LP@countii}}%
      \end{puzzlebackground}%
    }%
    {%
      \expandafter\gdef\expandafter\LP@HT@color%
        {LP@c@\romannumeral\LP@element}%
      \begin{puzzlebackground}%
        \fillcell{\arabic{LP@counti}}{\arabic{LP@countii}}%
      \end{puzzlebackground}%
      \setcell{\arabic{LP@counti}}{\arabic{LP@countii}}{\LP@element}%
    }%
    \stepcounter{LP@counti}%
  }%
}%
\newcommand*\setcolorcolumn[2]%
{%
  \setcounter{LP@counti}{#1}%
  \setcounter{LP@countii}{1}%
  \foreach \LP@element in {#2}%
  {%
    \ifthenelse{\equal{\LP@element}{0}}%
    {%
      \gdef\LP@HT@color{black}%
      \begin{puzzlebackground}%
        \fillcell{\arabic{LP@counti}}{\arabic{LP@countii}}%
      \end{puzzlebackground}%
    }%
    {%
      \expandafter\gdef\expandafter\LP@HT@color%
        {LP@c@\romannumeral\LP@element}%
      \begin{puzzlebackground}%
        \fillcell{\arabic{LP@counti}}{\arabic{LP@countii}}%
      \end{puzzlebackground}%
      \setcell{\arabic{LP@counti}}{\arabic{LP@countii}}{\LP@element}%
    }%
    \stepcounter{LP@countii}%
  }%
}%
\newcommand*\fillcell[2]%
{%
  \LP@set@LP@scale{\LP@env@prefix}%
  \LP@set@LP@color{\LP@env@prefix}%
  \LP@set@LP@rows{\LP@env@prefix}%
  \LP@set@LP@columns{\LP@env@prefix}%
  \LP@ingrid{#1}{#2}{\LP@columns}{\LP@rows}{\LP@package}%
  \LP@G@setcellcontent[hcenter,vcenter]{#1}{#2}{\LP@Block}%
}%
\newcommand*\fillrow[2]%
{%
  \setcounter{LP@counti}{1}%
  \setcounter{LP@countii}{#1}%
  \foreach \LP@element in {#2}%
  {%
    \ifthenelse{\equal{\LP@element}{1}}%
    {\fillcell{\arabic{LP@counti}}{\arabic{LP@countii}}}%
    {}%
    \stepcounter{LP@counti}%
  }%
}%
\newcommand*\fillcolumn[2]%
{%
  \setcounter{LP@counti}{#1}%
  \setcounter{LP@countii}{1}%
  \foreach \LP@element in {#2}%
  {%
    \ifthenelse{\equal{\LP@element}{1}}%
    {\fillcell{\arabic{LP@counti}}{\arabic{LP@countii}}}%
    {}%
    \stepcounter{LP@countii}%
  }%
}%
\newcommand*\framearea[2]%
{%
  \draw[line width=\LP@thicklines,color=#1] #2;%
}%
\newcommand*\fillarea[2]%
{%
  \draw[line width=\LP@thicklines,fill=#1] #2;%
}%
\newcommand*\colorarea[2]%
{%
  \fill[color=#1] #2 ;%
}%
\newcommand*\tikzpath[3]%
{%
  (#1\LP@rel@tikzpath,#2\LP@rel@tikzpath)%
  \foreach \LP@direction in {#3}%
  {%
    \ifnum\LP@direction=1%
    --++(-1,-1)%
    \fi%
    \ifnum\LP@direction=2%
    --++(0,-1)%
    \fi%
    \ifnum\LP@direction=3%
    --++(1,-1)%
    \fi%
    \ifnum\LP@direction=4%
    --++(-1,0)%
    \fi%
    \ifnum\LP@direction=6%
    --++(1,0)%
    \fi%
    \ifnum\LP@direction=7%
    --++(-1,1)%
    \fi%
    \ifnum\LP@direction=8%
    --++(0,1)%
    \fi%
    \ifnum\LP@direction=9%
    --++(1,1)%
    \fi%
  };%
}%
\newcommand*\xtikzpath[3]%
{%
  (#1\LP@rel@tikzpath,#2\LP@rel@tikzpath)%
  \foreach \LP@dir/\LP@plength in {#3}%
  {%
    \ifnum\LP@dir=1%
    --++(-\LP@plength,-\LP@plength)%
    \fi%
    \ifnum\LP@dir=2%
    --++(0,-\LP@plength)%
    \fi%
    \ifnum\LP@dir=3%
    --++(\LP@plength,-\LP@plength)%
    \fi%
    \ifnum\LP@dir=4%
    --++(-\LP@plength,0)%
    \fi%
    \ifnum\LP@dir=6%
    --++(\LP@plength,0)%
    \fi%
    \ifnum\LP@dir=7%
    --++(-\LP@plength,\LP@plength)%
    \fi%
    \ifnum\LP@dir=8%
    --++(0,\LP@plength)%
    \fi%
    \ifnum\LP@dir=9%
    --++(\LP@plength,\LP@plength)%
    \fi%
  };%
}%
\newcommand*\filldiagonals[1][yellow!20]%
{%
  \LP@set@LP@columns{\LP@env@prefix}%
  \LP@set@LP@rows{\LP@env@prefix}%
  \LP@set@LP@scale{\LP@env@prefix}%
  \setcounter{LP@counti}{\LP@columns}%
  \setcounter{LP@countii}{\LP@rows}%
  \stepcounter{LP@counti}%
  \stepcounter{LP@countii}%
  \ifnum\value{LP@counti}=\value{LP@countii}%
    \begin{puzzlebackground}%
      \def\LP@color{#1}%
      \setcounter{LP@whiledo@i}{1}%
      \setcounter{LP@whiledo@ii}{\LP@rows}%
      \whiledo{\value{LP@whiledo@i}<\value{LP@counti}}%
      {%
        \LP@G@setcellcontent[hcenter,vcenter]%
          {\arabic{LP@whiledo@i}}{\arabic{LP@whiledo@i}}{\LP@Block}%
        \LP@G@setcellcontent[hcenter,vcenter]%
          {\arabic{LP@whiledo@i}}{\arabic{LP@whiledo@ii}}{\LP@Block}%
        \stepcounter{LP@whiledo@i}%
        \addtocounter{LP@whiledo@ii}{-1}%
      }%
    \end{puzzlebackground}%
  \else%
    \PackageError{\LP@package}%
      {non quadratic grid (\filldiagonals)}%
      {You tried to fill diagonals,\MessageBreak in a non quadratic%
       grid (1,1) .. (\arabic{LP@counti},\arabic{LP@countii})%
       \MessageBreak doesn't make sense!}%
  \fi%
}%
\newcommand*\framepuzzle[1][black]%
{%
  \LP@set@LP@columns{\LP@env@prefix}%
  \LP@set@LP@rows{\LP@env@prefix}%
  \setcounter{LP@counti}{\LP@columns}%
  \setcounter{LP@countii}{\LP@rows}%
  \stepcounter{LP@counti}%
  \stepcounter{LP@countii}%
  \draw[line width=\LP@thicklines,color=#1]%
    (1,1)--(1,\arabic{LP@countii});%
  \draw[line width=\LP@thicklines,color=#1]%
    (1,\arabic{LP@countii})--%
    (\arabic{LP@counti},\arabic{LP@countii});%
  \draw[line width=\LP@thicklines,color=#1]%
    (\arabic{LP@counti},\arabic{LP@countii})--%
    (\arabic{LP@counti},1);%
  \draw[line width=\LP@thicklines,color=#1]%
    (\arabic{LP@counti},1)--(1,1);%
}%
\newenvironment{puzzlebackground}%
{%
  \begin{pgfonlayer}{LPbackground}%
}%
{%
  \end{pgfonlayer}%
}%
\newenvironment{puzzleforeground}%
{%
  \begin{pgfonlayer}{LPforeground}%
}%
{%
  \end{pgfonlayer}%
}%
\newcommand*\LP@bottomrow[1]%
{%
  \LP@setrowcontents{#1}{1}{0}%
}%
\newcommand*\LP@bottomrow@edge[1]%
{%
  \LP@setrowcontents@edge{#1}{1}{0}%
}%
\newcommand*\LP@leftcolumn[1]%
{%
  \LP@setcolumncontents{#1}{0}{1}%
}%
\newcommand*\LP@toprow[1]%
{%
  \LP@setrowcontents{#1}{1}{\theLP@rows}%
}%
\newcommand*\LP@rightcolumn[1]%
{%
  \LP@setcolumncontents{#1}{\theLP@columns}{1}%
}%
\newcommand*\LP@rightcolumn@edge[1]%
{%
  \LP@setcolumncontents@edge{#1}{\theLP@columns}{1}%
}%
\newcommand*\titleformat[1]%
{%
  \renewcommand*\LP@titleformat{#1}%
}%
\titleformat{\centering\Large\color{blue}}%
\newcommand*\puzzlecounter{\theLP@puzzlecounter}%
\newcommand*\setpuzzlecounter[1]%
{%
  \setcounter{LP@puzzlecounter}{#1}%
}%
\newcommand*\LP@drawcounter[1]%
{%
  \LP@set@LP@cvoffset{\LP@env@prefix}%
  \csname LP@cs@#1\endcsname%
}%
\newcommand*{\definecounterstyle}[2]%
{%
  \expandafter\gdef\csname LP@cs@#1\endcsname{#2}%
}%
\definecounterstyle{none}{}%
\definecounterstyle{left}{%
  \begingroup\reversemarginpar%
    \marginnote{%
      \tikz\node[shape=rectangle,fill=yellow!40,inner sep=7pt,draw,%
                 rounded corners=3pt,thick]%
                  {\Huge\puzzlecounter};}[\LP@cvoffset]%
  \endgroup%
}%
\definecounterstyle{right}{%
  \marginnote{%
    \tikz\node[shape=rectangle,fill=yellow!40,inner sep=7pt,draw,%
               rounded corners=3pt,thick]%
                {\Huge\puzzlecounter};%
  }[\LP@cvoffset]%
}%
\newcommand*\LP@Block{%
  \tikz[scale=\LP@scale]%
    \draw[line width=\LP@normallines,fill=\LP@color]%
      (0,0) rectangle (1,1);}%
\define@key{LP@Line}{double}[double]%
{%
  \def\LP@Line@double{double}%
}%
\define@key{LP@Line}{color}[LP@c@bridge]%
{%
  \def\LP@Line@linecolor{#1}%
}%
\define@key{LP@Line}{linewidth}[1mm]%
{%
  \def\LP@Line@linewidth{#1}%
}%
\newcommand*\LP@Line[2][]%
{%
  \def\LP@Line@double{}%
  \def\LP@Line@linecolor{LP@c@bridge}%
  \def\LP@Line@linewidth{1mm}%
  \setkeys{LP@Line}{#1}%
  \LP@set@LP@scale{\LP@env@prefix}%
  \begin{pgfonlayer}{LPbackgroundtwo}%
    \ifthenelse{\equal{\LP@Line@double}{double}}%
    {\draw[double,double distance=\LP@Line@linewidth*\LP@scale,%
           color=\LP@Line@linecolor,%
           line width=\LP@Line@linewidth*\LP@scale] #2;}%
    {\draw[color=\LP@Line@linecolor,%
           line width=\LP@Line@linewidth*\LP@scale] #2;}%
  \end{pgfonlayer}%
}%
\newcommand*\LP@set@LP@scale[1]%
{%
  \expandafter\xdef\expandafter\LP@scale{\csname #1@scale\endcsname}%
}%
\newcommand*\LP@set@LP@color[1]%
{%
  \expandafter\xdef\expandafter\LP@color{\csname #1@color\endcsname}%
}%
\newcommand*\LP@set@LP@rows[1]%
{%
  \expandafter\xdef\expandafter\LP@rows{\csname #1@rows\endcsname}%
}%
\newcommand*\LP@set@LP@columns[1]%
{%
  \expandafter\xdef\expandafter\LP@columns{\csname #1@columns\endcsname}%
}%
\newcommand*\LP@set@LP@cvoffset[1]%
{%
  \expandafter\xdef\expandafter\LP@cvoffset{\csname #1@cvoffset\endcsname}%
}%
\newcommand*\LP@set@LP@bgcolor[1]%
{%
  \expandafter\xdef\expandafter\LP@bgcolor{\csname #1@bgcolor\endcsname}%
}%
\newcommand*\LP@set@LP@extracells[1]%
{%
  \expandafter\xdef\expandafter\LP@extracells{\csname #1@extracells\endcsname}%
}%
\newcommand*\LP@set@LP@fontsize[1]%
{%
  \expandafter\gdef\expandafter\LP@fontsize{\csname #1@fontsize\endcsname}%
}%
\newcommand*\LP@set@env@prefix[1]%
{%
  \gdef\LP@env@prefix{#1}%
}%
\newcommand*\LP@set@package[1]%
{%
  \gdef\LP@package{#1}%
}%
\newcommand*\setgridlinestyle[1]%
{%
  \def\LP@grid@linestyle{#1}%
}%
\newcommand*\setnormallinewidth[1]%
{%
  \def\LP@normallines{#1}%
}%
\newcommand*\setthicklinewidth[1]%
{%
  \def\LP@thicklines{#1}%
}%
\newcommand*\puzzlestrut%
{%
  \LP@set@LP@rows{\LP@env@prefix}%
  \ifthenelse{\equal{\LP@package}{nonogram}}%
  {%
    \LP@set@LP@extracells{\LP@env@prefix}%
    \setcounter{LP@counti}{\LP@rows}% max row
    \stepcounter{LP@counti}%
    \addtocounter{LP@counti}{\LP@NG@extracells}%
    \draw[line width=\LP@thicklines, transparent]%
      (1,1) -- (1,\arabic{LP@counti});%
  }{}%
}%
\newcommand*\setTikZpreset[1]%
{%
  \tikzset{%
    LPpreset/.style={#1}%
  }%
}%
\setTikZpreset{line cap=rect,line join=round}%
\newcommand*\LP@LP@init@prefix{LP@LP}%
\newcommand*\LP@LP@init@package{logicpuzzle}%
\LP@define@key{\LP@LP@init@prefix}{\LP@LP@init@package}%
{rows}{5}%
\LP@define@key{\LP@LP@init@prefix}{\LP@LP@init@package}%
{columns}{5}%
\LP@define@key{\LP@LP@init@prefix}{\LP@LP@init@package}%
{scale}{1}%
\LP@define@key{\LP@LP@init@prefix}{\LP@LP@init@package}%
{counterstyle}{none}%
\LP@define@key{\LP@LP@init@prefix}{\LP@LP@init@package}%
{color}{}%
\LP@define@key{\LP@LP@init@prefix}{\LP@LP@init@package}%
{bgcolor}{}%
\LP@define@key{\LP@LP@init@prefix}{\LP@LP@init@package}%
{width}{5.1cm}%
\LP@define@key{\LP@LP@init@prefix}{\LP@LP@init@package}%
{cvoffset}{-23pt}%
\LP@define@key{\LP@LP@init@prefix}{\LP@LP@init@package}%
{title}{}%
\LP@define@key{\LP@LP@init@prefix}{\LP@LP@init@package}%
{titleindent}{0cm}%
\LP@define@key{\LP@LP@init@prefix}{\LP@LP@init@package}%
{titlewidth}{5.1cm}%
\LP@define@choicekey@fontsize{\LP@LP@init@prefix}%
{\LP@LP@init@package}{Large}%
\ExecuteOptionsX{rows,columns,width,fontsize,scale,bgcolor%
,cvoffset,counterstyle,title,titleindent,titlewidth}%
\ProcessOptionsX\relax%
\let\logicpuzzlecell\setcell%
\newcommand*\logicpuzzlesetup[1]%
{%
  \setkeys{logicpuzzle.sty}{#1}%
}%
\newenvironment{logicpuzzle}[1][]%
{%
  \setkeys{logicpuzzle}{#1}%
  \LP@set@package{logicpuzzle}%
  \LP@set@env@prefix{LP@LP}%
  \setcounter{LP@rows}{\LP@LP@rows}%
  \setcounter{LP@columns}{\LP@LP@columns}%
  \stepcounter{LP@rows}%
  \stepcounter{LP@columns}%
  \begin{minipage}[t]{\LP@LP@width}%
    \ifthenelse{\equal{\LP@LP@title}{}}%
    {\par\enspace\par}% empty
    {\enspace\par\noindent\hspace{\LP@LP@titleindent}%
    \parbox{\LP@LP@titlewidth}{\strut\LP@titleformat\LP@LP@title}%
    \vspace{3mm}\par}%
    \begin{tikzpicture}[scale=\LP@LP@scale]%
      \LP@drawbackground{1}{1}{\LP@LP@columns}{\LP@LP@rows}%
      {\LP@LP@bgcolor}%
      \LP@drawgrid{1}{1}{\LP@LP@columns}{\LP@LP@rows}{1cm}%
}%
{%
    \end{tikzpicture}%
    \LP@drawcounter{\LP@LP@counterstyle}%
    \stepcounter{LP@puzzlecounter}%
  \end{minipage}%
}%
\RequirePackage{lpenv}%
\endinput
%%
%% End of file `logicpuzzle.sty'.
