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