50 |
50 |
51 \section*{Resit:\\ Implementing the Shogun Board Game\\ (Scala, 8 Marks)} |
51 \section*{Resit:\\ Implementing the Shogun Board Game\\ (Scala, 8 Marks)} |
52 |
52 |
53 \noindent |
53 \noindent |
54 You are asked to implement a Scala program for playing the Shogun |
54 You are asked to implement a Scala program for playing the Shogun |
55 board game. The deadline for your submission is on 26th July at |
55 board game. The deadline for your submission is on 31th July at |
56 16:00. Make sure you use \texttt{scala-cli} and Scala version \textbf{3.XX} |
56 16:00. Make sure you use \texttt{scala-cli} and Scala version \textbf{3.XX} |
57 for the resit---the same version as during the lectures. \medskip |
57 for the resit. \medskip |
58 |
58 |
59 \IMPORTANTNONE{} |
59 \IMPORTANTNONE{} |
60 |
60 |
61 \noindent |
61 \noindent |
62 Also note that the running time of each task will be restricted to a |
62 Also note that the running time of each task will be restricted to a |
113 player has 8 pieces, one of which is a king (the piece with the crown) |
113 player has 8 pieces, one of which is a king (the piece with the crown) |
114 and seven are pawns. At the beginning the pieces are lined up as shown |
114 and seven are pawns. At the beginning the pieces are lined up as shown |
115 above. What sets Shogun apart from chess and checkers is that each |
115 above. What sets Shogun apart from chess and checkers is that each |
116 piece has, what I call, a kind of \textit{energy}---which for pawns is |
116 piece has, what I call, a kind of \textit{energy}---which for pawns is |
117 a number between 1 and 4, and for kings between 1 and 2. The energy |
117 a number between 1 and 4, and for kings between 1 and 2. The energy |
118 determines how far a piece has to move. In the physical version of |
118 determines how far a piece can move. In the physical version of |
119 Shogun, the pieces and the board have magnets that can change the |
119 Shogun, the pieces and the board have magnets that can change the |
120 energy of a piece from move to move---so a piece on one field can have |
120 energy of a piece from move to move---so a piece on one field can have |
121 energy 2 and on a different field the same piece might have energy |
121 energy 2 and on a different field the same piece might have energy |
122 3. There are some further constraints on legal moves, which are |
122 3. There are some further constraints on legal moves, which are |
123 explained below. The point of the resit is to implement functions |
123 explained below. The point of the resit is to implement functions |
134 possibly capturing opposing pieces. |
134 possibly capturing opposing pieces. |
135 There are the following rules on how pieces can move: |
135 There are the following rules on how pieces can move: |
136 |
136 |
137 \begin{itemize} |
137 \begin{itemize} |
138 \item The energy of a piece determines how far, that is how many |
138 \item The energy of a piece determines how far, that is how many |
139 fields, a piece has to move (remember pawns have an energy between 1 -- |
139 fields, a piece can move (remember pawns have an energy between 1 -- |
140 4, kings have an energy of only 1 -- 2). The energy of a piece might |
140 4, kings have an energy of only 1 -- 2). The energy of a piece might |
141 change when the piece moves to new field. |
141 change when the piece moves to new field. |
142 \item Pieces can move in straight lines (up, down, left, right), or in |
142 \item Pieces can move in straight lines (up, down, left, right), or in |
143 L-shape moves, meaning a move can make a single |
143 L-shape moves, meaning a move can make a single |
144 90$^{\circ}$-turn. S-shape moves with more than one turn are not |
144 90$^{\circ}$-turn. S-shape moves with more than one turn are not |
249 |
249 |
250 \subsection*{Hints} |
250 \subsection*{Hints} |
251 |
251 |
252 Useful functions about pieces and boards are defined at the beginning |
252 Useful functions about pieces and boards are defined at the beginning |
253 of the template file. The function \texttt{.map} applies a function to |
253 of the template file. The function \texttt{.map} applies a function to |
254 each element of a list or set; \texttt{.flatMap} works like |
254 each element of a list or a set; \texttt{.flatMap} works like |
255 \texttt{map} followed by a \texttt{.flatten}---this is useful if a |
255 \texttt{map} followed by a \texttt{.flatten}---this is useful if a |
256 function returns a set of sets, which need to be ``unioned up''. Sets |
256 function returns a set of sets, which need to be ``unioned up''. Sets |
257 can be partitioned according to a predicate with the function |
257 can be partitioned according to a predicate with the function |
258 \texttt{.partition}. For example |
258 \texttt{.partition}. For example |
259 |
259 |
315 abstract class Move |
315 abstract class Move |
316 case object U extends Move // up |
316 case object U extends Move // up |
317 case object D extends Move // down |
317 case object D extends Move // down |
318 case object R extends Move // right |
318 case object R extends Move // right |
319 case object L extends Move // left |
319 case object L extends Move // left |
320 case object RU extends Move // ... |
320 case object RU extends Move // right-up |
321 case object LU extends Move |
321 case object LU extends Move // ... |
322 case object RD extends Move |
322 case object RD extends Move |
323 case object LD extends Move |
323 case object LD extends Move |
324 case object UR extends Move |
324 case object UR extends Move |
325 case object UL extends Move |
325 case object UL extends Move |
326 case object DR extends Move |
326 case object DR extends Move |