# How to change battleship grid using logicpuzzle package?

I designed the naval battle grid using the logicpuzzle package. I would like to make some changes, could you help me?

1. I would like to move ABCDE letters to the bottom of the grid.

2. I would like to be able to write a letter inside the green motorboat.

\documentclass{standalone}
\usepackage{logicpuzzle}
\let\puzzletitleformat\titleformat
\let\titleformat\relax
\usepackage{titlesec}
\begin{document}
% sffamily
\tikzset{every node/.style={font=\sffamily}}
% use scale and fontsize options to change size
%\begin{center}
\begin{battleship}
\placesegment{5}{2}{\ShipR}
\placesegment{1}{5}{\ShipL}
\placesegment{1}{1}{\ShipR}
\placesegment{4}{4}{\ShipL}
\placesegment{2}{3}{\ShipL}
\shipH{A,B,C,D,E}
\shipV{1,2,3,4,5}
\end{battleship}
\end{document}

• Solution (first question): Add \makeatletter \renewcommand*\shipH[1]% {% \LP@setrowcontents{#1}{1}{0}% }% \makeatother to your preamble. – Bobyandbob Nov 18 '17 at 17:14

Bobyandbob answered the first question in his comment, and I implemented that in the code below.

To place a letter inside a \ShipL/\ShipR, you can simply add a second \placesegment with the same coordinates, after it. For example,

\placesegment{5}{2}{\ShipR}
\placesegment{5}{2}{a}


will place the a on top of the \ShipR. If you want a simpler syntax, such as \ShipR[a], you can redefine the \ShipR/\ShipL macros for example as in the code below.

\documentclass{standalone}
\usepackage{logicpuzzle}
\makeatletter
\renewcommand*\shipH[1]{%
\LP@setrowcontents{#1}{1}{0}%
}%
\renewcommand*\ShipL[1][]{%
\tikz[scale=\LP@BS@scale]
\draw[scale=.36,fill=\LP@BS@shipcolor,
path picture={\node at (path picture bounding box.center) {#1};}
](1,2)--(2,2)--(2,0)--(1,0) arc (270:90:1);}%
\renewcommand*\ShipR[1][]{%
\tikz[scale=\LP@BS@scale]
\draw[scale=.36,fill=\LP@BS@shipcolor,
path picture={\node at (path picture bounding box.center) {#1};}
](1,2)--(0,2)--(0,0)--(1,0) arc (270:450:1);}%
\makeatother
\let\puzzletitleformat\titleformat
\let\titleformat\relax
\usepackage{titlesec}
\begin{document}
% sffamily
\tikzset{every node/.style={font=\sffamily}}
% use scale and fontsize options to change size
%\begin{center}
\begin{battleship}
\placesegment{5}{2}{\ShipR[A]}
\placesegment{1}{5}{\ShipL[B]}
\placesegment{1}{1}{\ShipR[C]}
\placesegment{4}{4}{\ShipL[D]}
\placesegment{2}{3}{\ShipL[E]}
\shipH{A,B,C,D,E}
\shipV{1,2,3,4,5}
\end{battleship}
\end{document}


Alternativ you could create \ShipLmod{Input Text} and \ShipRmod{Input Text} (with \renewcommand*). The text centering is not perfect (maybe we could find a better solution for that (together).

- 1.Move ABCDE letters to the bottom of the grid with:

\makeatletter
\renewcommand*\shipH[1]%
{%
\LP@setrowcontents{#1}{1}{0}%
}%
\makeatother


- 2. Write a letter inside the green motorboat: with \ShipLmod and \ShipRmod

\makeatletter
\newcommand*\ShipRmod[1]{\tikz[scale=\LP@BS@scale]\draw[scale=.36,fill=\LP@BS@shipcolor](1,2)--(0,2)--(0,0)--(1,0) arc (270:450:1) node[xshift=-0.05cm,yshift=-0.37cm] {#1};}%
\makeatother

\makeatletter
\newcommand*\ShipLmod[1]{\tikz[scale=\LP@BS@scale]\draw[scale=.36,fill=\LP@BS@shipcolor](1,2)--(2,2)--(2,0)--(1,0) arc (270:90:1) node[xshift=0.05cm,yshift=-0.37cm] {#1};}%
\makeatother


MWE:

\documentclass{standalone}
\usepackage{logicpuzzle}
\let\puzzletitleformat\titleformat
\let\titleformat\relax
\usepackage{titlesec}

\makeatletter
\renewcommand*\shipH[1]%
{%
\LP@setrowcontents{#1}{1}{0}%
}%
\makeatother

\makeatletter
\newcommand*\ShipRmod[1]{\tikz[scale=\LP@BS@scale]\draw[scale=.36,fill=\LP@BS@shipcolor](1,2)--(0,2)--(0,0)--(1,0) arc (270:450:1) node[xshift=-0.05cm,yshift=-0.37cm] {#1};}%
\makeatother

\makeatletter
\newcommand*\ShipLmod[1]{\tikz[scale=\LP@BS@scale]\draw[scale=.36,fill=\LP@BS@shipcolor](1,2)--(2,2)--(2,0)--(1,0) arc (270:90:1) node[xshift=0.05cm,yshift=-0.37cm] {#1};}%
\makeatother

\begin{document}
% sffamily
\tikzset{every node/.style={font=\sffamily}}
\begin{battleship}
\placesegment{5}{2}{\ShipR}
\placesegment{1}{5}{\ShipL}
\placesegment{1}{1}{\ShipRmod{A}}
\placesegment{4}{4}{\ShipLmod{B}}
\placesegment{2}{3}{\ShipL}
\shipH{A,B,C,D,E}
\shipV{1,2,3,4,5}
\end{battleship}
\end{document}

• @TorbjørnT.(+1) for your solution. Can i adapt your solution with path picture bounding box.center for positioning text input in my solution, because shifting with xshift=0.05cm,yshift=-0.37cm isen't nice. – Bobyandbob Nov 18 '17 at 18:03
• @Bobyandbob Go right ahead, I stole your solution for the first part after all. You could alternatively use something like \node at (1.5,1) {#1}; for \ShipRmod, that would be about in the center of the shape. (By the way, @-pings only works for other commenters and editors of the post, so I wasn't notified of your comment.) – Torbjørn T. Nov 18 '17 at 18:59