Skip to content

Instantly share code, notes, and snippets.

@psygo
Last active November 6, 2021 22:11
Show Gist options
  • Save psygo/1efd32423f5b4ee95b525909e8247002 to your computer and use it in GitHub Desktop.
Save psygo/1efd32423f5b4ee95b525909e8247002 to your computer and use it in GitHub Desktop.
Scrabble on 19x19, as a background for a Goban
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{shapes.geometric}
\def\lettertoscrabblescore#1{%
\def\tmp{#1}%
\expandafter\count\expandafter0\expandafter`#1\relax\advance\count0 by-65\relax%
\ifcase\count0\relax%
1\or3\or3\or2\or1\or4\or2\or4\or1\or8\or5\or1\or3\or1\or1\or3\or10\or1\or1\or1\or1\or4\or4\or8\or4\or10\else\fi}
% It comes from here: https://tex.stackexchange.com/a/194797/64441
% And here: https://forums.online-go.com/t/board-backgrounds-library/29388/80
\tikzset{%
every score/.style={
font=\sffamily\bfseries\tiny,
align=center,
scale=0.75,
draw=none, fill=none,
},
pics/.cd,
spikes/.style args={#1#2#3}{
code={
\fill [#3,scale=0.5*(1-.1)] (-1,1)
\foreach \i in {0,1,2,3}{
[rotate=-\i*90] -- (-#1*#2,1)
\foreach \j in {1,...,#1} {-- ++(#2,#2) -- ++(#2,-#2)}
-- (1,1)} -- cycle;
}
},
triple word score/.style={
code={
\path pic {spikes={3}{.15}{red!75}};
\node [every score/.try] {TRIPLE\\WORD\\SCORE};
}
},
double word score/.style={
code={
\path pic {spikes={2}{.15}{red!25}};
\node [every score/.try] {DOUBLE\\WORD\\SCORE};
}
},
triple letter score/.style={
code={
\path pic {spikes={3}{.15}{blue!50!cyan!75}};
\node [every score/.try] {TRIPLE\\LETTER\\SCORE};
}
},
double letter score/.style={
code={
\path pic {spikes={2}{.15}{blue!50!cyan!50}};
\node [every score/.try] {DOUBLE\\LETTER\\SCORE};
}
},
center/.style={
code={
\path pic {spikes={0}{0}{red!25}};
\node [star,fill, star point ratio=2]{};
}
},
tile/.style={
code={
\node [fill=yellow!40, minimum size=0.9cm, rounded corners=0.2cm, font=\sffamily\bfseries] (@) {#1};
\node [font=\sffamily\tiny, anchor=south east] at (@.south east) {\lettertoscrabblescore{#1}};
}
},
word across/.style={
code={
\foreach \l [count=\x from 0] in {#1}
\path (\x,0) pic {tile={\l}};
}
},
word down/.style={
code={
\foreach \l [count=\y from 0] in {#1}
\path (0,-\y) pic {tile={\l}};
}
}
}
\begin{document}
\begin{tikzpicture}
\fill[gray!25] (-.5,-.5) rectangle ++(18,18);
\draw[white,line width=.1cm, shift={(-.5,-.5)}] grid (18,18);
\foreach \p in{(\x,\y),(\y, 17-\x),(17-\x, 17-\y),(17-\y, \x)}{
\foreach \x/\y in {0/0,7/0}
\path \p pic {triple word score};
\foreach \x/\y in {1/1,2/2,3/3,4/4,7/7,8/8}
\path \p pic {double word score};
\foreach \x/\y in {1/5,5/1,5/5}
\path \p pic {triple letter score};
\foreach \x/\y in {3/0,0/3,2/6,6/2,6/6}
\path \p pic {double letter score};
}
\path (9,9) pic {center};
\path (8,8) pic {center};
\path (8,9) pic {center};
\path (9,8) pic {center};
\path (0,14) pic {word across={G,O,T,E}};
\path (3,15) pic {word down={S,E,N,T,E}};
\path (3,12) pic {word across={T,E,N,U,K,I}};
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment