cws/resit2.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Thu, 13 Jun 2024 13:13:33 +0100
changeset 491 e2ffe8642f55
child 492 4ffba2f72692
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
491
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
% !TEX program = xelatex
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
\documentclass{article}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
\usepackage{chessboard}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
\usepackage[LSBC4,T1]{fontenc}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
\let\clipbox\relax
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
\usepackage{../styles/style}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
\usepackage{../styles/langs}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
\usepackage{disclaimer}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
\usepackage{ulem}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
%\usepackage{tipauni}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    13
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    14
\tikzset
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    15
{%
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    16
  pics/piece/.style n args={1}{
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    17
    code={%
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    18
      \fill[rounded corners]                  (-0.1,-0.1) rectangle (-0.9, -0.9);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    19
      \fill[left color=white,rounded corners,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    20
            right color=gray,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    21
            opacity=0.7]      (-0.1,-0.1) rectangle (-0.9, -0.9);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    22
      \draw[line width=0.4mm,rounded corners] (-0.1,-0.1) rectangle (-0.9, -0.9);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    23
      \draw[line width=0.2mm,rounded corners] (-0.2,-0.2) rectangle (-0.8, -0.8);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    24
      \draw[anchor=mid] (-0.5,-0.6) node {#1};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    25
    }},
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    26
  pics/king/.style n args={1}{
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    27
    code={%
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    28
      \fill[rounded corners]                  (-0.1,-0.1) rectangle (-0.9, -0.9);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    29
      \fill[left color=white,rounded corners,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    30
            right color=gray,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    31
            opacity=0.7]      (-0.1,-0.1) rectangle (-0.9, -0.9);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    32
      \draw[line width=0.4mm,rounded corners] (-0.1,-0.1) rectangle (-0.9, -0.9);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    33
      \draw[line width=0.2mm,rounded corners] (-0.2,-0.2) rectangle (-0.8, -0.8);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    34
      \draw[anchor=mid] (-0.5,-0.6) node {#1};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    35
      \draw[anchor=center] (-0.5,-0.25) node {\includegraphics[scale=0.015]{crown.png}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    36
    }}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    37
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    38
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    39
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    40
\begin{document}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    41
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    42
\setchessboard{smallboard,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    43
               zero,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    44
               showmover=false,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    45
               boardfontencoding=LSBC4,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    46
               hlabelformat=\arabic{ranklabel},
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    47
               vlabelformat=\arabic{filelabel}}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    48
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    49
\mbox{}\\[-18mm]\mbox{}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    50
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    51
\section*{Resit:\\ Implementing the Shogun Board Game\\ (Scala, 8 Marks)}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    52
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    53
\noindent
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    54
You are asked to implement a Scala program for playing the Shogun
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    55
board game.  The deadline for your submission is on XXX at
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    56
16:00.  Make sure you use \texttt{scala-cli} and Scala version \textbf{3.XX}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    57
for the resit---the same version as during the lectures.  \medskip
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    58
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    59
\IMPORTANTNONE{}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    60
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    61
\noindent
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    62
Also note that the running time of each task will be restricted to a
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    63
maximum of 30 seconds on my laptop: If you calculate a result once,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    64
try to avoid to calculate the result again.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    65
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    66
\DISCLAIMER{}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    67
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    68
\subsection*{Background}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    69
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    70
Shogun
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    71
(\faVolumeUp\,[shōgoon]) is a game played by two players on a chess board and is somewhat
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    72
similar to chess and checkers. A real Shogun board looks
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    73
like in the pictures on the left.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    74
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    75
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    76
\begin{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    77
\begin{tabular}{@{}ccc@{}}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    78
\raisebox{2mm}{\includegraphics[scale=0.1]{shogun2.jpeg}}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    79
&
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    80
\raisebox{2mm}{\includegraphics[scale=0.14]{shogun.jpeg}}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    81
&
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    82
\begin{tikzpicture}[scale=0.45,every node/.style={scale=0.45}]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    83
% chessboard
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    84
\draw[very thick,gray] (0,0) rectangle (8,8);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    85
\foreach\x in {0,...,7}\foreach\y in {7,...,0}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    86
{
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    87
  \pgfmathsetmacro\blend{Mod(\x+\y,2)==0?75:25}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    88
  \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    89
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    90
% black pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    91
\foreach\x/\y/\e in {1/1/1,2/1/3,3/1/2,4/1/3,6/1/3,7/1/1,8/1/2}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    92
  \pic[fill=white] at (\x,\y) {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    93
% white pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    94
\foreach\x/\y/\e in {1/8/4,2/8/2,3/8/4,5/8/4,6/8/2,7/8/3,8/8/1}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    95
  \pic[fill=red] at (\x,\y)     {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    96
\pic[fill=white] at (5.0,1.0) {king={1}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    97
\pic[fill=red]   at (4.0,8.0) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    98
% numbers
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    99
\foreach\x in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   100
{\draw (\x - 0.5, -0.4) node {\x};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   101
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   102
\foreach\y in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   103
{\draw (-0.4, \y - 0.6, -0.4) node {\y};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   104
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   105
\end{tikzpicture}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   106
\end{tabular}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   107
\end{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   108
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   109
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   110
\noindent
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   111
In what follows we shall use board illustrations as shown on the right.  As
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   112
can be seen there are two colours in Shogun for the pieces, red and white. Each
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   113
player has 8 pieces, one of which is a king (the piece with the crown)
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   114
and seven are pawns. At the beginning the pieces are lined up as shown
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   115
above.  What sets Shogun apart from chess and checkers is that each
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   116
piece has, what I call, a kind of \textit{energy}---which for pawns is
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   117
a number between 1 and 4, and for kings between 1 and 2. The energy
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   118
determines how far a piece has to move. In the physical version of
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   119
Shogun, the pieces and the board have magnets that can change the
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   120
energy of a piece from move to move---so a piece on one field can have
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   121
energy 2 and on a different field the same piece might have energy
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   122
3. There are some further constraints on legal moves, which are
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   123
explained below.  The point of the resit is to implement functions
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   124
about moving pieces on the Shogun board.\medskip\medskip
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   125
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   126
%and testing for when a
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   127
%checkmate occurs---i.e.~the king is attacked and cannot move
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   128
%anymore to an ``unattacked'' field (to simplify matters for
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   129
%the resit we leave out the case where the checkmate can be averted by capturing
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   130
%the attacking piece).\medskip
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   131
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   132
\noindent
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   133
Like in chess, in Shogun the players take turns of moving and
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   134
possibly capturing opposing pieces.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   135
There are the following rules on how pieces can move:
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   136
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   137
\begin{itemize}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   138
\item The energy of a piece determines how far, that is how many
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   139
  fields, a piece has to move (remember pawns have an energy between 1 --
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   140
  4, kings have an energy of only 1 -- 2). The energy of a piece might
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   141
  change when the piece moves to new field.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   142
\item Pieces can move in straight lines (up, down, left, right), or in
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   143
  L-shape moves, meaning a move can make a single
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   144
  90$^{\circ}$-turn. S-shape moves with more than one turn are not
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   145
  allowed. Also in a single move a piece cannot go forward and then
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   146
  go backward---for example with energy 3 you cannot move 2 fields up and
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   147
  then 1 field down. A piece can never move diagonally.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   148
\item A piece cannot jump over another piece and cannot stack up on top of your own pieces.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   149
  But you can capture an opponent's piece if you move to an occupied field. A captured
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   150
  piece is removed from the board.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   151
\end{itemize}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   152
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   153
\noindent
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   154
Like in chess, checkmate is determined when the king of a player cannot
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   155
move anymore to a field that is not attacked, or a player cannot
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   156
capture or block the attacking piece, or the king is the only
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   157
piece left for a player. A non-trivial board that is checkmate is the following:
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   158
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   159
\begin{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   160
\begin{tikzpicture}[scale=0.5,every node/.style={scale=0.5}]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   161
% chessboard
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   162
\draw[very thick,gray] (0,0) rectangle (8,8);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   163
\foreach\x in {0,...,7}\foreach\y in {7,...,0}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   164
{
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   165
  \pgfmathsetmacro\blend{Mod(\x+\y,2)==0?75:25}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   166
  \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   167
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   168
% redpieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   169
\pic[fill=red]   at (4,2) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   170
\pic[fill=red]   at (6,1) {piece={3}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   171
\pic[fill=red]   at (4,4) {piece={4}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   172
\pic[fill=red]   at (5,3) {piece={4}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   173
% white pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   174
\pic[fill=white] at (7,1) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   175
\pic[fill=white] at (8,5) {piece={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   176
\pic[fill=white] at (4,1) {piece={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   177
% numbers
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   178
\foreach\x in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   179
{\draw (\x - 0.5, -0.4) node {\x};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   180
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   181
\foreach\y in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   182
{\draw (-0.4, \y - 0.6, -0.4) node {\y};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   183
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   184
\end{tikzpicture}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   185
\end{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   186
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   187
\noindent
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   188
The reason for the checkmate is that the white king on field (7, 1) is
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   189
attacked by the red pawn on \mbox{(5, 3)}. There is nowhere for the
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   190
white king to go, and no white pawn can be moved into the way of this
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   191
red pawn and white can also not capture it. When determining a possible
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   192
move, you need to be careful with pieces that might be in the
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   193
way. Consider the following position:
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   194
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   195
\begin{equation}\label{moves}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   196
\begin{tikzpicture}[scale=0.5,every node/.style={scale=0.5}]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   197
% chessboard
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   198
\draw[very thick,gray] (0,0) rectangle (8,8);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   199
\foreach\x in {0,...,7}\foreach\y in {7,...,0}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   200
{
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   201
  \pgfmathsetmacro\blend{Mod(\x+\y,2)==0?75:25}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   202
  \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   203
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   204
% redpieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   205
\fill[blue!50] (0,2) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   206
\fill[blue!50] (1,1) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   207
\fill[blue!50] (0,4) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   208
\fill[blue!50] (1,5) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   209
\fill[blue!50] (2,6) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   210
%%\fill[blue!50] (3,7) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   211
\fill[blue!50] (4,6) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   212
\fill[blue!50] (5,5) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   213
\fill[blue!50] (6,4) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   214
\fill[blue!50] (6,2) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   215
\fill[blue!50] (7,3) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   216
\fill[blue!50] (4,0) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   217
\fill[blue!50] (2,0) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   218
\pic[fill=red]   at (4,4) {piece={4}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   219
\pic[fill=red]   at (4,8) {piece={4}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   220
\pic[fill=white] at (2,5) {piece={3}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   221
\pic[fill=white] at (4,3) {piece={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   222
\pic[fill=white] at (6,3) {piece={1}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   223
\pic[fill=white] at (8,4) {piece={1}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   224
% numbers
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   225
\foreach\x in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   226
{\draw (\x - 0.5, -0.4) node {\x};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   227
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   228
\foreach\y in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   229
{\draw (-0.4, \y - 0.6, -0.4) node {\y};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   230
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   231
\end{tikzpicture}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   232
\end{equation}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   233
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   234
\noindent
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   235
The red piece in the centre on field (4, 4) can move to all the blue fields.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   236
In particular it can move to (2, 6), because it can move 2 fields up
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   237
and 2 fields to the left---it cannot reach this field by moving two
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   238
fields to the left and then two up, because jumping over the white
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   239
piece at (2, 5) is not allowed. Similarly, the field at (6, 2) is
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   240
unreachable for the red piece because of the two white pieces at (4,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   241
3) and (6, 3) are in the way and no S-shape move is allowed in
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   242
Shogun. The red piece on (4, 4) cannot move to the field (4, 8) at the
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   243
top, because a red piece is already there; but it can move to (8, 4)
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   244
and capture the white piece there. The moral is we always have to
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   245
explore all possible ways in order to determine whether a piece can be
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   246
moved to a field or not: in general there might be several ways and some of
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   247
them might be blocked.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   248
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   249
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   250
\subsection*{Hints}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   251
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   252
Useful functions about pieces and boards are defined at the beginning
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   253
of the template file. The function \texttt{.map} applies a function to
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   254
each element of a list or set; \texttt{.flatMap} works like
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   255
\texttt{map} followed by a \texttt{.flatten}---this is useful if a
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   256
function returns a set of sets, which need to be ``unioned up''.  Sets
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   257
can be partitioned according to a predicate with the function
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   258
\texttt{.partition}.  For example
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   259
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   260
\begin{lstlisting}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   261
val (even, odd) = Set(1,2,3,4,5).partition(_ % 2 == 0)
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   262
// --> even = Set(2,4)
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   263
//     odd  = Set(1,3,5)
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   264
\end{lstlisting}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   265
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   266
\noindent
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   267
The function \texttt{.toList} transforms a set into a list. The function
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   268
\texttt{.count} counts elements according to a predicate. For example
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   269
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   270
\begin{lstlisting}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   271
Set(1,2,3,4,5).count(_ % 2 == 0)
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   272
// --> 2
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   273
\end{lstlisting}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   274
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   275
%% \newpage
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   276
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   277
\subsection*{Tasks}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   278
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   279
You are asked to implement how pieces can move on a Shogun board.  Let
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   280
us first fix the basic datastructures for the implementation.  A
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   281
\emph{position} (or field) is a pair of integers, like $(3, 2)$. The
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   282
board's dimension is always 8 $\times$ 8.  A \emph{colour} is either
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   283
red (\texttt{Red}) or white (\texttt{Wht}).  A \emph{piece} is either
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   284
a pawn or a king, and has a position, a colour and an energy (an
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   285
integer).  In the template file there are functions \texttt{incx},
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   286
\texttt{decx}, \texttt{incy} and \texttt{decy} for incrementing and
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   287
decrementing the x- and y-coordinates of positions of pieces.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   288
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   289
A \emph{board} consists of a set of pieces. We always assume that we
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   290
start with a consistent board and every move only generates another
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   291
consistent board. In this way we do not need to check, for example,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   292
whether pieces are stacked on top of each other or located outside the
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   293
board, or have an energy outside the permitted range. There are
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   294
functions \texttt{-} and \texttt{+} for removing, respectively adding,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   295
single pieces to a board.  The function \texttt{occupied} takes a
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   296
position and a board as arguments, and returns an \texttt{Option} of a
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   297
piece when this position is occupied, otherwise \texttt{None}. The
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   298
function \texttt{occupied\_by} returns the colour of a potential piece
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   299
on that position. The function \texttt{is\_occupied} returns a boolean
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   300
for whether a position is occupied or not; \texttt{print\_board} is a
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   301
rough function that prints out a board on the console. This function
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   302
is meant for testing purposes.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   303
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   304
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   305
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   306
\begin{itemize}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   307
\item[(1)] You need to calculate all possible moves for a piece on a Shogun board. In order to
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   308
  make sure no piece moves forwards and backwards at the same time,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   309
  and also exclude all S-shape moves, the data-structure \texttt{Move}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   310
  is introduced. A \texttt{Move} encodes all simple moves (up, down, left,
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   311
  right) and L-shape moves (first right, then up and so on). This is defined
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   312
  as follows:
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   313
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   314
{\small\begin{lstlisting}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   315
abstract class Move
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   316
case object U extends Move    // up
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   317
case object D extends Move    // down
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   318
case object R extends Move    // right
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   319
case object L extends Move    // left
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   320
case object RU extends Move   // ...
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   321
case object LU extends Move
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   322
case object RD extends Move
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   323
case object LD extends Move
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   324
case object UR extends Move
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   325
case object UL extends Move
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   326
case object DR extends Move
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   327
case object DL extends Move
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   328
\end{lstlisting}}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   329
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   330
You need to implement an \texttt{eval} function that takes a piece
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   331
\texttt{pc}, a move \texttt{m}, an energy \texttt{en} and a board
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   332
\texttt{b} as arguments. The idea is to recursively calculate all
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   333
fields that can be reached by the move \texttt{m} (there might be more than
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   334
one). The energy acts as a counter and decreases in each recursive
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   335
call until 0 is reached (the final field). The function \texttt{eval} for a piece \texttt{pc}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   336
should behave as follows:
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   337
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   338
\begin{itemize}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   339
\item If the position of a piece is outside the board, then no field can be reached (represented by
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   340
  the empty set \texttt{Set()}).
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   341
\item If the energy is 0 and the position of the piece is \textit{not} occupied, then the field can be reached
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   342
  and the set \texttt{Set(pc)} is returned whereby \texttt{pc} is the piece given as argument.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   343
\item If the energy is 0 and the position of the piece \textit{is} occupied, but occupied by a piece
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   344
  of the opposite colour, then also the set \texttt{Set(pc)} is returned. Otherwise the empty set
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   345
    \texttt{Set()} is returned.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   346
\item In case the energy is > 0 and the position of the piece
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   347
  \texttt{pc} is occupied, then this move is blocked and the set
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   348
  \texttt{Set()} is returned.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   349
\item In all other cases we have to analyse the move
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   350
    \texttt{m}. First, the simple moves (that is \texttt{U}, \texttt{D},
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   351
    \texttt{L} and \texttt{R}) we only have to increment / decrement the
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   352
    x- or y-position of the piece, decrease the energy and call eval
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   353
    recursively with the updated arguments. For example for \texttt{U} (up)
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   354
    you need to increase the y-coordinate:
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   355
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   356
  \begin{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   357
  \texttt{U} $\quad\Rightarrow\quad$ new arguments: \texttt{incy(pc)}, \texttt{U}, energy - 1, same board
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   358
  \end{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   359
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   360
  The move \texttt{U} here acts like a ``mode'', meaning if you move
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   361
   up, you can only move up; the mode never changes for simple moves. Similarly for the other simple moves: if
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   362
   you move right, you can only move right and so on. In this way it is
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   363
   prevented to go first to the right, and then change direction in order to go
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   364
   left (same with up and down).
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   365
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   366
  For the L-shape moves (\texttt{RU}, \texttt{LU}, \texttt{RD} and so on) you need to calculate two
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   367
  sets of reachable fields. Say we analyse \texttt{RU}, then we first have to calculate all fields
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   368
  reachable by moving to the right; then we have to calculate all moves by changing the mode to \texttt{U}.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   369
  That means there are two recursive calls to \texttt{eval}:
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   370
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   371
  \begin{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   372
    \begin{tabular}{@{}lll@{}}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   373
    \texttt{RU} & $\Rightarrow$ & new args for call 1: \texttt{incx(pc)}, \texttt{RU}, energy - 1, same board\\
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   374
                &               & new args for call 2: \texttt{pc}, \texttt{U}, same energy, same board
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   375
    \end{tabular}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   376
    \end{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   377
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   378
  In each case we receive some new piece(s) on reachable fields and therefore we return the set
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   379
  containing all these fields. Similarly in the other cases.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   380
\end{itemize}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   381
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   382
For example in the left board below, \texttt{eval} is called with the white
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   383
piece in the centre and the move \texttt{RU} generates then a set of
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   384
new pieces corresponding to the blue fields. The difference with the
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   385
right board is that \texttt{eval} is called with a red piece and therefore the
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   386
field (4, 8) is not reachable anymore because it is already occupied by
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   387
another red piece. But (7, 5) becomes reachable because it is occupied
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   388
by a piece of the opposite colour.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   389
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   390
\begin{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   391
\begin{tabular}{cc}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   392
\begin{tikzpicture}[scale=0.45,every node/.style={scale=0.45}]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   393
% chessboard
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   394
\draw[very thick,gray] (0,0) rectangle (8,8);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   395
\foreach\x in {0,...,7}\foreach\y in {7,...,0}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   396
{
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   397
  \pgfmathsetmacro\blend{Mod(\x+\y,2)==0?75:25}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   398
  \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   399
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   400
\fill[blue!50] (5,5) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   401
\fill[blue!50] (3,7) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   402
\fill[blue!50] (4,6) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   403
%\fill[blue!50] (6,4) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   404
\fill[blue!50] (7,3) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   405
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   406
% black pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   407
\foreach\x/\y/\e in {2/1/3,3/1/2,4/1/3,6/1/3,7/1/1,7/5/2}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   408
  \pic[fill=white] at (\x,\y) {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   409
% white pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   410
\foreach\x/\y/\e in {1/8/4,2/8/2,3/8/4,5/8/4,6/8/2,7/8/3,8/8/1}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   411
  \pic[fill=red] at (\x,\y)     {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   412
\pic[fill=white] at (5.0,1.0) {king={1}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   413
\pic[fill=red]   at (4.0,8.0) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   414
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   415
\pic[fill=white] at (4,4) {piece={4}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   416
% numbers
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   417
\foreach\x in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   418
{\draw (\x - 0.5, -0.4) node {\x};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   419
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   420
\foreach\y in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   421
{\draw (-0.4, \y - 0.6, -0.4) node {\y};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   422
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   423
\end{tikzpicture}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   424
&
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   425
\begin{tikzpicture}[scale=0.45,every node/.style={scale=0.45}]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   426
% chessboard
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   427
\draw[very thick,gray] (0,0) rectangle (8,8);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   428
\foreach\x in {0,...,7}\foreach\y in {7,...,0}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   429
{
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   430
  \pgfmathsetmacro\blend{Mod(\x+\y,2)==0?75:25}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   431
  \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   432
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   433
\fill[blue!50] (5,5) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   434
\fill[blue!50] (4,6) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   435
\fill[blue!50] (6,4) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   436
\fill[blue!50] (7,3) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   437
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   438
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   439
% black pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   440
\foreach\x/\y/\e in {1/1/1,2/1/3,3/1/2,4/1/3,6/1/3,7/1/1,7/5/2}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   441
  \pic[fill=white] at (\x,\y) {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   442
% white pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   443
\foreach\x/\y/\e in {1/8/4,2/8/2,3/8/4,5/8/4,6/8/2,7/8/3}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   444
  \pic[fill=red] at (\x,\y)     {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   445
\pic[fill=white] at (5.0,1.0) {king={1}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   446
\pic[fill=red]   at (4.0,8.0) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   447
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   448
\pic[fill=red] at (4,4) {piece={4}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   449
% numbers
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   450
\foreach\x in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   451
{\draw (\x - 0.5, -0.4) node {\x};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   452
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   453
\foreach\y in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   454
{\draw (-0.4, \y - 0.6, -0.4) node {\y};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   455
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   456
\end{tikzpicture}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   457
\\[-5mm]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   458
\end{tabular}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   459
\end{center}\hfill[3 Marks]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   460
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   461
\item[(2)] Implement an \texttt{all\_moves} function that calculates for a
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   462
  piece and a board, \textit{all} possible onward positions. For this
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   463
  you have to call \texttt{eval} for all possible moves \texttt{m} (that is \texttt{U},
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   464
  \texttt{D}, \ldots, \texttt{DL}). An example for all moves for the red piece on (4, 4) is
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   465
  shown in \eqref{moves} on page \pageref{moves}. Be careful about possible modifications
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   466
  you need to apply to the board  before you call the \texttt{eval} function.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   467
  Also for this task, ignore the fact that a king cannot move onto an attacked field.\\
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   468
  \mbox{}\hfill[1 Mark]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   469
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   470
\item[(3)] Implement a function \texttt{attacked} that takes a colour and a board
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   471
  and calculates all pieces of the opposite side that are attacked. For example
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   472
  below in the left board are all the attacked pieces by red, and on the right all for white:
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   473
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   474
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   475
\begin{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   476
\begin{tabular}{cc}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   477
\begin{tikzpicture}[scale=0.45,every node/.style={scale=0.45}]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   478
% chessboard
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   479
\draw[very thick,gray] (0,0) rectangle (8,8);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   480
\foreach\x in {0,...,7}\foreach\y in {7,...,0}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   481
{
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   482
  \pgfmathsetmacro\blend{Mod(\x+\y,2)==0?75:25}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   483
  \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   484
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   485
\fill[blue!50] (7,3) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   486
\fill[blue!50] (6,0) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   487
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   488
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   489
% red pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   490
\foreach\x/\y/\e in {6/1/3,4/4/4,5/3/4,6/5/3}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   491
  \pic[fill=red] at (\x,\y) {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   492
% white pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   493
\foreach\x/\y/\e in {8/4/1,4/1/2,8/7/3,6/7/2}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   494
  \pic[fill=white] at (\x,\y)     {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   495
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   496
\pic[fill=red] at (4,2) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   497
\pic[fill=white] at (7,1) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   498
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   499
% numbers
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   500
\foreach\x in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   501
{\draw (\x - 0.5, -0.4) node {\x};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   502
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   503
\foreach\y in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   504
{\draw (-0.4, \y - 0.6, -0.4) node {\y};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   505
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   506
\end{tikzpicture}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   507
&
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   508
\begin{tikzpicture}[scale=0.45,every node/.style={scale=0.45}]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   509
% chessboard
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   510
\draw[very thick,gray] (0,0) rectangle (8,8);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   511
\foreach\x in {0,...,7}\foreach\y in {7,...,0}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   512
{
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   513
  \pgfmathsetmacro\blend{Mod(\x+\y,2)==0?75:25}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   514
  \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   515
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   516
\fill[blue!50] (5,0) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   517
\fill[blue!50] (5,4) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   518
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   519
% red pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   520
\foreach\x/\y/\e in {6/1/3,4/4/4,5/3/4,6/5/3}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   521
  \pic[fill=red] at (\x,\y) {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   522
% white pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   523
\foreach\x/\y/\e in {8/4/1,4/1/2,8/7/3,6/7/2}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   524
  \pic[fill=white] at (\x,\y)     {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   525
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   526
\pic[fill=red] at (4,2) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   527
\pic[fill=white] at (7,1) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   528
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   529
% numbers
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   530
\foreach\x in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   531
{\draw (\x - 0.5, -0.4) node {\x};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   532
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   533
\foreach\y in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   534
{\draw (-0.4, \y - 0.6, -0.4) node {\y};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   535
}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   536
\end{tikzpicture}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   537
\\[-5mm]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   538
\end{tabular}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   539
\end{center}\mbox{}\hfill[1 Mark]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   540
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   541
\item[(4)] Implement a function \texttt{attackedN} that takes a piece and a board
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   542
  and calculates the number of times this pieces is attacked by pieces of the opposite colour.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   543
  For example the piece on field (8, 4) above is attacked by 3 red pieces, and
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   544
  the piece on (6, 1) by 1 white piece. In this number also include kings even
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   545
  if they cannot move to this field because the would be in ``check''.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   546
  \mbox{}\hfill[1 Mark]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   547
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   548
\item[(5)] Implement a function \texttt{protectedN} that takes a piece and a board
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   549
  and calculates the number of times this pieces is protected by pieces of the same colour.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   550
  For example the piece on field (8, 4) above is protected by 1 white pieces (the one on (8, 7)),
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   551
  and the piece on (5, 3) is protected by three red pieces ((6, 1), (4, 2), and (6, 5)).
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   552
  Similarly to \texttt{attackedN}, include in the calculated number here also the king provided it
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   553
   can reach the given piece.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   554
  \\
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   555
  \mbox{}\hfill[1 Mark]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   556
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   557
  \item[(6)] Implement a function \texttt{legal\_moves} that behaves like \texttt{all\_moves} from (2) for
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   558
    pawns, but for kings, in addition, makes sure that they do not move to an attacked field.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   559
    For example in the board below on the left, there are three possible fields the white king can
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   560
    reach, but all of them are attacked by red pieces. In the board on the right where the
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   561
    white king has an energy of 1, there is only one legal move, namely to move to field (8, 1).
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   562
    The field (7, 2) is reachable, but is attacked; similarly capturing the red piece on field (6, 1) is
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   563
    not possible because it is protected by at least another red piece.
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   564
    %
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   565
    \begin{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   566
    \begin{tabular}{cc}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   567
    \begin{tikzpicture}[scale=0.45,every node/.style={scale=0.45}]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   568
  % chessboard
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   569
  \draw[very thick,gray] (0,0) rectangle (8,8);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   570
  \foreach\x in {0,...,7}\foreach\y in {7,...,0}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   571
  {
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   572
    \pgfmathsetmacro\blend{Mod(\x+\y,2)==0?75:25}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   573
    \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   574
  }
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   575
  \fill[blue!50] (5,1) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   576
  \fill[blue!50] (6,2) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   577
  \fill[blue!50] (7,1) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   578
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   579
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   580
  % red pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   581
  \foreach\x/\y/\e in {6/1/3,4/4/4,5/3/4,6/5/3}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   582
    \pic[fill=red] at (\x,\y) {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   583
  % white pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   584
  \foreach\x/\y/\e in {8/4/1,4/1/2,8/7/3,6/7/2}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   585
    \pic[fill=white] at (\x,\y)     {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   586
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   587
  \pic[fill=red] at (4,2) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   588
  \pic[fill=white] at (7,1) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   589
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   590
  % numbers
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   591
  \foreach\x in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   592
  {\draw (\x - 0.5, -0.4) node {\x};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   593
  }
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   594
  \foreach\y in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   595
  {\draw (-0.4, \y - 0.6, -0.4) node {\y};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   596
  }
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   597
  \end{tikzpicture}  &
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   598
   \begin{tikzpicture}[scale=0.45,every node/.style={scale=0.45}]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   599
  % chessboard
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   600
  \draw[very thick,gray] (0,0) rectangle (8,8);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   601
  \foreach\x in {0,...,7}\foreach\y in {7,...,0}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   602
  {
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   603
    \pgfmathsetmacro\blend{Mod(\x+\y,2)==0?75:25}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   604
    \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   605
  }
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   606
  \fill[blue!50] (5,0) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   607
  \fill[blue!50] (6,1) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   608
  \fill[blue!50] (7,0) rectangle ++ (1,1);
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   609
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   610
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   611
  % red pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   612
  \foreach\x/\y/\e in {6/1/3,4/4/4,5/3/3,6/5/3}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   613
    \pic[fill=red] at (\x,\y) {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   614
  % white pieces
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   615
  \foreach\x/\y/\e in {8/4/1,4/1/2,8/7/3,6/7/2}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   616
    \pic[fill=white] at (\x,\y)     {piece={\e}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   617
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   618
  \pic[fill=red] at (4,2) {king={2}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   619
  \pic[fill=white] at (7,1) {king={1}};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   620
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   621
  % numbers
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   622
  \foreach\x in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   623
  {\draw (\x - 0.5, -0.4) node {\x};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   624
  }
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   625
  \foreach\y in {1,...,8}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   626
  {\draw (-0.4, \y - 0.6, -0.4) node {\y};
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   627
  }
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   628
  \end{tikzpicture}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   629
  \end{tabular}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   630
  \end{center}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   631
  \mbox{}\hfill[1 Mark]
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   632
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   633
\end{itemize}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   634
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   635
\end{document}
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   636
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   637
%%% Local Variables:
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   638
%%% mode: latex
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   639
%%% TeX-master: t
e2ffe8642f55 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   640
%%% End: