
diff -r 7550c816187a -r a4e1f63157d8 cws/main_cw04.tex
--- a/cws/main_cw04.tex	Sat Nov 04 18:53:37 2023 +0000
+++ b/cws/main_cw04.tex	Mon Nov 06 14:18:26 2023 +0000
@@ -48,7 +48,7 @@
 
 \mbox{}\\[-18mm]\mbox{}
 
-\section*{Main Part 4:\\ Implementing the Shogun Board Game (7 Marks)}
+\section*{Main Part 4:\\ Implementing the Shogun Board Game (8 Marks)}
 
 \mbox{}\hfill\textit{``The problem with object-oriented languages is they’ve got all this implicit,}\\
 \mbox{}\hfill\textit{environment that they carry around with them. You wanted a banana but}\\
@@ -388,12 +388,13 @@
   containing all these fields. Similarly in the other cases.
 \end{itemize}
 
-For example on the left board below, \texttt{eval} is called with the white
+For example in the left board below, \texttt{eval} is called with the white
 piece in the centre and the move \texttt{RU} generates then a set of
-new pieces corresponding to the blue fileds. The difference on the
+new pieces corresponding to the blue fields. The difference with the
 right board is that \texttt{eval} is called with a red piece and therefore the
 field (4, 8) is not reachable anymore because it is already occupied by
-another red piece.
+another red piece. But (7, 5) becomes reachable because it is occupied
+by a piece of the opposite colour.
 
 \begin{center}
 \begin{tabular}{cc}  
@@ -408,11 +409,11 @@
 \fill[blue!50] (5,5) rectangle ++ (1,1);
 \fill[blue!50] (3,7) rectangle ++ (1,1);
 \fill[blue!50] (4,6) rectangle ++ (1,1);
-\fill[blue!50] (6,4) rectangle ++ (1,1);
+%\fill[blue!50] (6,4) rectangle ++ (1,1);
 \fill[blue!50] (7,3) rectangle ++ (1,1);
 
 % black pieces
-\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}
+\foreach\x/\y/\e in {2/1/3,3/1/2,4/1/3,6/1/3,7/1/1,7/5/2}
   \pic[fill=white] at (\x,\y) {piece={\e}};
 % white pieces
 \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}
@@ -444,10 +445,10 @@
 \fill[blue!50] (7,3) rectangle ++ (1,1);
 
 % black pieces
-\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}
+\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}
   \pic[fill=white] at (\x,\y) {piece={\e}};
 % white pieces
-\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}
+\foreach\x/\y/\e in {1/8/4,2/8/2,3/8/4,5/8/4,6/8/2,7/8/3}
   \pic[fill=red] at (\x,\y)     {piece={\e}};
 \pic[fill=white] at (5.0,1.0) {king={1}};
 \pic[fill=red]   at (4.0,8.0) {king={2}};
@@ -466,15 +467,17 @@
 \end{center}\hfill[3 Marks]
 
 \item[(2)] Implement an \texttt{all\_moves} function that calculates for a
-  piece and a board, \textit{all} pieces on legal onward positions. For this
+  piece and a board, \textit{all} possible onward positions. For this
   you have to call \texttt{eval} for all possible moves \texttt{m} (that is \texttt{U},
-  \texttt{D}, \ldots, \texttt{DL}). An example for all moves for the red piece on (4, 4) are
-  shown in \eqref{moves} on page \pageref{moves}.\\ 
+  \texttt{D}, \ldots, \texttt{DL}). An example for all moves for the red piece on (4, 4) is
+  shown in \eqref{moves} on page \pageref{moves}. Be careful about possible modifications
+  you need to apply to the board  before you call the \texttt{eval} function.
+  Also for this task ignore the fact that a king cannot move onto an attacked field.\\ 
   \mbox{}\hfill[1 Mark]
 
 \item[(3)] Implement a function \texttt{attacked} that takes a colour and a board
   and calculates all pieces of the opposite side that are attacked. For example
-  below on the left are all the attacked pieces by red, and on the right for white:
+  below in the left board are all the attacked pieces by red, and on the right all for white:
 
 \begin{center}
 \begin{tabular}{cc}      
@@ -490,11 +493,11 @@
 \fill[blue!50] (6,0) rectangle ++ (1,1);
 
 
-% black pieces
+% red pieces
 \foreach\x/\y/\e in {6/1/3,4/4/4,5/3/4,6/5/3}
   \pic[fill=red] at (\x,\y) {piece={\e}};
 % white pieces
-\foreach\x/\y/\e in {8/4/2,4/1/2,8/7/3}
+\foreach\x/\y/\e in {8/4/1,4/1/2,8/7/3,6/7/2}
   \pic[fill=white] at (\x,\y)     {piece={\e}};
 
 \pic[fill=red] at (4,2) {king={2}};
@@ -518,13 +521,13 @@
   \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
 }
 \fill[blue!50] (5,0) rectangle ++ (1,1);
-
+\fill[blue!50] (5,4) rectangle ++ (1,1);
 
-% black pieces
+% red pieces
 \foreach\x/\y/\e in {6/1/3,4/4/4,5/3/4,6/5/3}
   \pic[fill=red] at (\x,\y) {piece={\e}};
 % white pieces
-\foreach\x/\y/\e in {8/4/2,4/1/2,8/7/3}
+\foreach\x/\y/\e in {8/4/1,4/1/2,8/7/3,6/7/2}
   \pic[fill=white] at (\x,\y)     {piece={\e}};
 
 \pic[fill=red] at (4,2) {king={2}};
@@ -555,6 +558,83 @@
   and the piece on (5, 3) is protected by three red pieces ((6, 1), (4, 2), and (6, 5)).
   \\
   \mbox{}\hfill[1 Mark]
+
+\item[(6)] Implement a function \texttt{legal\_moves} that behaves like \texttt{all\_moves} from (2) for
+  pawns, but for kings, in addition, makes sure that they do not move to an attacked field.
+  For example in the board below on the left, there are three possible fields the white king can
+  reach, but all of them are attacked by red pieces. In the board on the right where the
+  white king has an energy of 1, there is only one legal move, namely to move to field (8, 1).
+  The field (7, 2) is reachable, but is attacked; similarly capturing the red piece on field (6, 1) is
+  not possible because it is protected by at least another red piece.
+
+  \begin{center}
+  \begin{tabular}{cc}    
+  \begin{tikzpicture}[scale=0.45,every node/.style={scale=0.45}]    
+% chessboard
+\draw[very thick,gray] (0,0) rectangle (8,8);
+\foreach\x in {0,...,7}\foreach\y in {7,...,0}
+{
+  \pgfmathsetmacro\blend{Mod(\x+\y,2)==0?75:25} 
+  \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
+}
+\fill[blue!50] (5,1) rectangle ++ (1,1);
+\fill[blue!50] (6,2) rectangle ++ (1,1);
+\fill[blue!50] (7,1) rectangle ++ (1,1);
+
+
+% red pieces
+\foreach\x/\y/\e in {6/1/3,4/4/4,5/3/4,6/5/3}
+  \pic[fill=red] at (\x,\y) {piece={\e}};
+% white pieces
+\foreach\x/\y/\e in {8/4/1,4/1/2,8/7/3,6/7/2}
+  \pic[fill=white] at (\x,\y)     {piece={\e}};
+
+\pic[fill=red] at (4,2) {king={2}};
+\pic[fill=white] at (7,1) {king={2}};
+
+% numbers
+\foreach\x in {1,...,8}
+{\draw (\x - 0.5, -0.4) node {\x};
+}
+\foreach\y in {1,...,8}
+{\draw (-0.4, \y - 0.6, -0.4) node {\y};
+}
+\end{tikzpicture}  &
+ \begin{tikzpicture}[scale=0.45,every node/.style={scale=0.45}]    
+% chessboard
+\draw[very thick,gray] (0,0) rectangle (8,8);
+\foreach\x in {0,...,7}\foreach\y in {7,...,0}
+{
+  \pgfmathsetmacro\blend{Mod(\x+\y,2)==0?75:25} 
+  \fill[gray!\blend] (\x,\y) rectangle ++ (1,1);
+}
+\fill[blue!50] (5,0) rectangle ++ (1,1);
+\fill[blue!50] (6,1) rectangle ++ (1,1);
+\fill[blue!50] (7,0) rectangle ++ (1,1);
+
+
+% red pieces
+\foreach\x/\y/\e in {6/1/3,4/4/4,5/3/3,6/5/3}
+  \pic[fill=red] at (\x,\y) {piece={\e}};
+% white pieces
+\foreach\x/\y/\e in {8/4/1,4/1/2,8/7/3,6/7/2}
+  \pic[fill=white] at (\x,\y)     {piece={\e}};
+
+\pic[fill=red] at (4,2) {king={2}};
+\pic[fill=white] at (7,1) {king={1}};
+
+% numbers
+\foreach\x in {1,...,8}
+{\draw (\x - 0.5, -0.4) node {\x};
+}
+\foreach\y in {1,...,8}
+{\draw (-0.4, \y - 0.6, -0.4) node {\y};
+}
+\end{tikzpicture}                      
+\end{tabular}                     
+\end{center}
+\mbox{}\\ \mbox{}\hfill[1 Mark]
+
 \end{itemize}
 
 \end{document}




