| author | updated | 
| Fri, 07 Dec 2018 02:38:50 +0000 | |
| changeset 238 | 25d896ada26c | 
| parent 216 | 8fc6eba5f754 | 
| child 265 | 2692329287bb | 
| permissions | -rw-r--r-- | 
| 6 | 1 | \documentclass{article}
 | 
| 2 | \usepackage{chessboard}
 | |
| 3 | \usepackage[LSBC4,T1]{fontenc}
 | |
| 149 | 4 | \let\clipbox\relax | 
| 39 | 5 | \usepackage{../style}
 | 
| 213 | 6 | \usepackage{../langs}
 | 
| 166 | 7 | \usepackage{disclaimer}
 | 
| 6 | 8 | |
| 9 | \begin{document}
 | |
| 10 | ||
| 11 | \setchessboard{smallboard,
 | |
| 45 | 12 | zero, | 
| 6 | 13 | showmover=false, | 
| 14 | boardfontencoding=LSBC4, | |
| 15 |                hlabelformat=\arabic{ranklabel},
 | |
| 16 |                vlabelformat=\arabic{filelabel}}
 | |
| 17 | ||
| 45 | 18 | \mbox{}\\[-18mm]\mbox{}
 | 
| 6 | 19 | |
| 213 | 20 | \section*{Coursework 8 (Scala)}
 | 
| 6 | 21 | |
| 50 | 22 | This coursework is worth 10\%. It is about searching and | 
| 212 | 23 | backtracking. The first part is due on 29 November at 11pm; the | 
| 24 | second, more advanced part, is due on 20 December at 11pm. You are | |
| 50 | 25 | asked to implement Scala programs that solve various versions of the | 
| 212 | 26 | \textit{Knight's Tour Problem} on a chessboard. Note the second, more
 | 
| 27 | advanced, part might include material you have not yet seen in the | |
| 213 | 28 | first three lectures. \bigskip | 
| 50 | 29 | |
| 166 | 30 | \IMPORTANT{}
 | 
| 144 | 31 | Also note that the running time of each part will be restricted to a | 
| 213 | 32 | maximum of 30 seconds on my laptop: If you calculate a result once, | 
| 144 | 33 | try to avoid to calculate the result again. Feel free to copy any code | 
| 34 | you need from files \texttt{knight1.scala}, \texttt{knight2.scala} and
 | |
| 35 | \texttt{knight3.scala}.
 | |
| 39 | 36 | |
| 166 | 37 | \DISCLAIMER{}
 | 
| 39 | 38 | |
| 39 | \subsection*{Background}
 | |
| 40 | ||
| 41 | The \textit{Knight's Tour Problem} is about finding a tour such that
 | |
| 110 | 42 | the knight visits every field on an $n\times n$ chessboard once. For | 
| 43 | example on a $5\times 5$ chessboard, a knight's tour is: | |
| 45 | 44 | |
| 45 | \chessboard[maxfield=d4, | |
| 46 |             pgfstyle= {[base,at={\pgfpoint{0pt}{-0.5ex}}]text},
 | |
| 47 | text = \small 24, markfield=Z4, | |
| 48 | text = \small 11, markfield=a4, | |
| 49 | text = \small 6, markfield=b4, | |
| 50 | text = \small 17, markfield=c4, | |
| 51 | text = \small 0, markfield=d4, | |
| 52 | text = \small 19, markfield=Z3, | |
| 53 | text = \small 16, markfield=a3, | |
| 54 | text = \small 23, markfield=b3, | |
| 55 | text = \small 12, markfield=c3, | |
| 56 | text = \small 7, markfield=d3, | |
| 57 | text = \small 10, markfield=Z2, | |
| 58 | text = \small 5, markfield=a2, | |
| 59 | text = \small 18, markfield=b2, | |
| 60 | text = \small 1, markfield=c2, | |
| 61 | text = \small 22, markfield=d2, | |
| 62 | text = \small 15, markfield=Z1, | |
| 63 | text = \small 20, markfield=a1, | |
| 64 | text = \small 3, markfield=b1, | |
| 65 | text = \small 8, markfield=c1, | |
| 66 | text = \small 13, markfield=d1, | |
| 67 | text = \small 4, markfield=Z0, | |
| 68 | text = \small 9, markfield=a0, | |
| 69 | text = \small 14, markfield=b0, | |
| 70 | text = \small 21, markfield=c0, | |
| 71 | text = \small 2, markfield=d0 | |
| 72 | ] | |
| 144 | 73 | |
| 45 | 74 | \noindent | 
| 212 | 75 | This tour starts in the right-upper corner, then moves to field | 
| 45 | 76 | $(3,2)$, then $(4,0)$ and so on. There are no knight's tours on | 
| 77 | $2\times 2$, $3\times 3$ and $4\times 4$ chessboards, but for every | |
| 74 | 78 | bigger board there is. | 
| 45 | 79 | |
| 80 | A knight's tour is called \emph{closed}, if the last step in the tour
 | |
| 81 | is within a knight's move to the beginning of the tour. So the above | |
| 110 | 82 | knight's tour is \underline{not} closed because the last
 | 
| 45 | 83 | step on field $(0, 4)$ is not within the reach of the first step on | 
| 84 | $(4, 4)$. It turns out there is no closed knight's tour on a $5\times | |
| 50 | 85 | 5$ board. But there are on a $6\times 6$ board and on bigger ones, for | 
| 86 | example | |
| 6 | 87 | |
| 88 | \chessboard[maxfield=e5, | |
| 147 | 89 |             pgfstyle={[base,at={\pgfpoint{0pt}{-0.5ex}}]text},
 | 
| 45 | 90 | text = \small 10, markfield=Z5, | 
| 91 | text = \small 5, markfield=a5, | |
| 92 | text = \small 18, markfield=b5, | |
| 93 | text = \small 25, markfield=c5, | |
| 94 | text = \small 16, markfield=d5, | |
| 95 | text = \small 7, markfield=e5, | |
| 96 | text = \small 31, markfield=Z4, | |
| 97 | text = \small 26, markfield=a4, | |
| 98 | text = \small 9, markfield=b4, | |
| 99 | text = \small 6, markfield=c4, | |
| 100 | text = \small 19, markfield=d4, | |
| 101 | text = \small 24, markfield=e4, | |
| 102 | % 4 11 30 17 8 15 | |
| 103 | text = \small 4, markfield=Z3, | |
| 104 | text = \small 11, markfield=a3, | |
| 105 | text = \small 30, markfield=b3, | |
| 106 | text = \small 17, markfield=c3, | |
| 107 | text = \small 8, markfield=d3, | |
| 108 | text = \small 15, markfield=e3, | |
| 109 | %29 32 27 0 23 20 | |
| 110 | text = \small 29, markfield=Z2, | |
| 111 | text = \small 32, markfield=a2, | |
| 112 | text = \small 27, markfield=b2, | |
| 113 | text = \small 0, markfield=c2, | |
| 114 | text = \small 23, markfield=d2, | |
| 115 | text = \small 20, markfield=e2, | |
| 116 | %12 3 34 21 14 1 | |
| 117 | text = \small 12, markfield=Z1, | |
| 118 | text = \small 3, markfield=a1, | |
| 119 | text = \small 34, markfield=b1, | |
| 120 | text = \small 21, markfield=c1, | |
| 121 | text = \small 14, markfield=d1, | |
| 122 | text = \small 1, markfield=e1, | |
| 123 | %33 28 13 2 35 22 | |
| 124 | text = \small 33, markfield=Z0, | |
| 125 | text = \small 28, markfield=a0, | |
| 126 | text = \small 13, markfield=b0, | |
| 127 | text = \small 2, markfield=c0, | |
| 128 | text = \small 35, markfield=d0, | |
| 129 | text = \small 22, markfield=e0, | |
| 130 | vlabel=false, | |
| 131 | hlabel=false | |
| 6 | 132 | ] | 
| 133 | ||
| 45 | 134 | |
| 6 | 135 | \noindent | 
| 45 | 136 | where the 35th move can join up again with the 0th move. | 
| 137 | ||
| 48 | 138 | If you cannot remember how a knight moves in chess, or never played | 
| 45 | 139 | chess, below are all potential moves indicated for two knights, one on | 
| 48 | 140 | field $(2, 2)$ (blue moves) and another on $(7, 7)$ (red moves): | 
| 39 | 141 | |
| 213 | 142 | {\chessboard[maxfield=g7,
 | 
| 45 | 143 | color=blue!50, | 
| 6 | 144 | linewidth=0.2em, | 
| 145 | shortenstart=0.5ex, | |
| 146 | shortenend=0.5ex, | |
| 147 | markstyle=cross, | |
| 45 | 148 |             markfields={a4, c4, Z3, d3, Z1, d1, a0, c0},
 | 
| 6 | 149 | color=red!50, | 
| 45 | 150 |             markfields={f5, e6},
 | 
| 213 | 151 |             setpieces={Ng7, Nb2},
 | 
| 152 | boardfontsize=12pt,labelfontsize=9pt]} | |
| 153 | ||
| 154 | \subsection*{Reference Implementation}
 | |
| 155 | ||
| 216 | 156 | This Scala assignment comes with three reference implementations in form of | 
| 157 | \texttt{jar}-files. This allows you to run any test cases on your own
 | |
| 213 | 158 | computer. For example you can call Scala on the command line with the | 
| 159 | option \texttt{-cp knight1.jar} and then query any function from the
 | |
| 216 | 160 | \texttt{knight1.scala} template file. As usual you have to
 | 
| 161 | prefix the calls with \texttt{CW8a}, \texttt{CW8b} and \texttt{CW8c}.
 | |
| 162 | Since some of the calls are time sensitive, I included some timing | |
| 163 | information. For example | |
| 213 | 164 | |
| 165 | \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
 | |
| 166 | $ scala -cp knight1.jar | |
| 167 | scala> CW8a.enum_tours(5, List((0, 0))).length | |
| 168 | Time needed: 1.722 secs. | |
| 169 | res0: Int = 304 | |
| 170 | ||
| 171 | scala> CW8a.print_board(8, CW8a.first_tour(8, List((0, 0))).get) | |
| 172 | Time needed: 15.411 secs. | |
| 173 | ||
| 174 | 51 46 55 44 53 4 21 12 | |
| 175 | 56 43 52 3 22 13 24 5 | |
| 176 | 47 50 45 54 25 20 11 14 | |
| 177 | 42 57 2 49 40 23 6 19 | |
| 178 | 35 48 41 26 61 10 15 28 | |
| 179 | 58 1 36 39 32 27 18 7 | |
| 180 | 37 34 31 60 9 62 29 16 | |
| 181 | 0 59 38 33 30 17 8 63 | |
| 182 | \end{lstlisting}%$
 | |
| 183 | ||
| 184 | ||
| 185 | \subsection*{Hints}
 | |
| 186 | ||
| 187 | \noindent | |
| 188 | \textbf{Part 1} useful list functions: \texttt{.contains(..)} checks
 | |
| 189 | whether an element is in a list, \texttt{.flatten} turns a list of
 | |
| 190 | lists into just a list, \texttt{\_::\_} puts an element on the head of
 | |
| 191 | the list, \texttt{.head} gives you the first element of a list (make
 | |
| 192 | sure the list is not \texttt{Nil}); a useful option function:
 | |
| 193 | \texttt{.isDefined} returns true, if an option is \texttt{Some(..)};
 | |
| 194 | anonymous functions can be constructed using \texttt{(x:Int) => ...},
 | |
| 216 | 195 | this function takes an \texttt{Int} as an argument.\medskip
 | 
| 45 | 196 | |
| 212 | 197 | |
| 198 | \noindent | |
| 213 | 199 | \textbf{Part 2} a useful list function: \texttt{.sortBy} sorts a list
 | 
| 212 | 200 | according to a component given by the function; a function can be | 
| 216 | 201 | tested to be tail-recursive by annotation \texttt{@tailrec}, which is
 | 
| 202 | made available by importing \texttt{scala.annotation.tailrec}.\medskip
 | |
| 212 | 203 | |
| 213 | 204 | |
| 205 | ||
| 206 | ||
| 207 | \subsection*{Part 1 (6 Marks)}
 | |
| 45 | 208 | |
| 48 | 209 | You are asked to implement the knight's tour problem such that the | 
| 210 | dimension of the board can be changed. Therefore most functions will | |
| 50 | 211 | take the dimension of the board as an argument. The fun with this | 
| 60 
f099bcf9cff1
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
59diff
changeset | 212 | problem is that even for small chessboard dimensions it has already an | 
| 
f099bcf9cff1
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
59diff
changeset | 213 | incredibly large search space---finding a tour is like finding a | 
| 50 | 214 | needle in a haystack. In the first task we want to see how far we get | 
| 215 | with exhaustively exploring the complete search space for small | |
| 48 | 216 | chessboards.\medskip | 
| 6 | 217 | |
| 48 | 218 | \noindent | 
| 219 | Let us first fix the basic datastructures for the implementation. The | |
| 213 | 220 | board dimension is an integer. | 
| 221 | A \emph{position} (or field) on the chessboard is
 | |
| 48 | 222 | a pair of integers, like $(0, 0)$. A \emph{path} is a list of
 | 
| 223 | positions. The first (or 0th move) in a path is the last element in | |
| 224 | this list; and the last move in the path is the first element. For | |
| 225 | example the path for the $5\times 5$ chessboard above is represented | |
| 226 | by | |
| 6 | 227 | |
| 45 | 228 | \[ | 
| 229 | \texttt{List($\underbrace{\texttt{(0, 4)}}_{24}$,
 | |
| 48 | 230 |   $\underbrace{\texttt{(2, 3)}}_{23}$, ...,
 | 
| 231 |   $\underbrace{\texttt{(3, 2)}}_1$, $\underbrace{\texttt{(4, 4)}}_0$)}
 | |
| 45 | 232 | \] | 
| 233 | ||
| 234 | \noindent | |
| 235 | Suppose the dimension of a chessboard is $n$, then a path is a | |
| 236 | \emph{tour} if the length of the path is $n \times n$, each element
 | |
| 237 | occurs only once in the path, and each move follows the rules of how a | |
| 238 | knight moves (see above for the rules). | |
| 6 | 239 | |
| 240 | ||
| 45 | 241 | \subsubsection*{Tasks (file knight1.scala)}
 | 
| 242 | ||
| 243 | \begin{itemize}
 | |
| 212 | 244 | \item[(1)] Implement an \texttt{is\_legal} function that takes a
 | 
| 166 | 245 | dimension, a path and a position as arguments and tests whether the | 
| 50 | 246 | position is inside the board and not yet element in the | 
| 247 | path. \hfill[1 Mark] | |
| 45 | 248 | |
| 212 | 249 | \item[(2)] Implement a \texttt{legal\_moves} function that calculates for a
 | 
| 48 | 250 | position all legal onward moves. If the onward moves are | 
| 45 | 251 | placed on a circle, you should produce them starting from | 
| 145 | 252 | ``12-o'clock'' following in clockwise order. For example on an | 
| 166 | 253 | $8\times 8$ board for a knight at position $(2, 2)$ and otherwise | 
| 48 | 254 | empty board, the legal-moves function should produce the onward | 
| 50 | 255 | positions in this order: | 
| 6 | 256 | |
| 45 | 257 |   \begin{center}
 | 
| 258 |   \texttt{List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))}
 | |
| 259 |   \end{center}
 | |
| 260 | ||
| 50 | 261 | If the board is not empty, then maybe some of the moves need to be | 
| 262 | filtered out from this list. For a knight on field $(7, 7)$ and an | |
| 263 | empty board, the legal moves are | |
| 45 | 264 | |
| 265 |   \begin{center}
 | |
| 266 |   \texttt{List((6,5), (5,6))}
 | |
| 48 | 267 |   \end{center}
 | 
| 268 |   \mbox{}\hfill[1 Mark]
 | |
| 45 | 269 | |
| 212 | 270 | \item[(3)] Implement two recursive functions (\texttt{count\_tours} and
 | 
| 166 | 271 |   \texttt{enum\_tours}). They each take a dimension and a path as
 | 
| 110 | 272 | arguments. They exhaustively search for tours starting | 
| 273 | from the given path. The first function counts all possible | |
| 50 | 274 | tours (there can be none for certain board sizes) and the second | 
| 216 | 275 | collects all tours in a list of paths. These functions will be | 
| 276 | called with a path containing a single position---the starting field. | |
| 277 | They are expected to extend this path so as to find all tours starting | |
| 278 | from the given position.\\ | |
| 279 |   \mbox{}\hfill[2 Marks]
 | |
| 45 | 280 | \end{itemize}
 | 
| 6 | 281 | |
| 212 | 282 | \noindent \textbf{Test data:} For the marking, the functions in (3)
 | 
| 50 | 283 | will be called with board sizes up to $5 \times 5$. If you search | 
| 110 | 284 | for tours on a $5 \times 5$ board starting only from field $(0, 0)$, | 
| 50 | 285 | there are 304 of tours. If you try out every field of a $5 \times | 
| 110 | 286 | 5$-board as a starting field and add up all tours, you obtain | 
| 48 | 287 | 1728. A $6\times 6$ board is already too large to be searched | 
| 110 | 288 | exhaustively.\footnote{For your interest, the number of tours on
 | 
| 48 | 289 | $6\times 6$, $7\times 7$ and $8\times 8$ are 6637920, 165575218320, | 
| 213 | 290 | 19591828170979904, respectively.}\smallskip | 
| 148 | 291 | |
| 212 | 292 | |
| 45 | 293 | |
| 213 | 294 | \subsubsection*{Tasks (cont.)}
 | 
| 45 | 295 | |
| 296 | \begin{itemize}
 | |
| 212 | 297 | \item[(4)] Implement a \texttt{first}-function. This function takes a list of
 | 
| 166 | 298 | positions and a function $f$ as arguments; $f$ is the name we give to | 
| 299 | this argument). The function $f$ takes a position as argument and | |
| 300 |   produces an optional path. So $f$'s type is \texttt{Pos =>
 | |
| 301 |     Option[Path]}. The idea behind the \texttt{first}-function is as follows:
 | |
| 45 | 302 | |
| 303 | \[ | |
| 304 |   \begin{array}{lcl}
 | |
| 48 | 305 |   \textit{first}(\texttt{Nil}, f) & \dn & \texttt{None}\\  
 | 
| 306 |   \textit{first}(x\!::\!xs, f) & \dn & \begin{cases}
 | |
| 45 | 307 |     f(x) & \textit{if}\;f(x) \not=\texttt{None}\\
 | 
| 48 | 308 |     \textit{first}(xs, f) & \textit{otherwise}\\
 | 
| 45 | 309 |                               \end{cases}
 | 
| 310 |   \end{array}
 | |
| 311 | \] | |
| 312 | ||
| 48 | 313 | \noindent That is, we want to find the first position where the | 
| 166 | 314 |   result of $f$ is not \texttt{None}, if there is one. Note that
 | 
| 315 |   `inside' \texttt{first}, you do not (need to) know anything about
 | |
| 316 |   the argument $f$ except its type, namely \texttt{Pos =>
 | |
| 213 | 317 | Option[Path]}. If you want to find out what the result of $f$ is | 
| 318 | on a particular argument, say $x$, you can just write $f(x)$. | |
| 319 | There is one additional point however you should | |
| 166 | 320 |   take into account when implementing \texttt{first}: you will need to
 | 
| 321 | calculate what the result of $f(x)$ is; your code should do this | |
| 322 |   only \textbf{once} and for as \textbf{few} elements in the list as
 | |
| 323 | possible! Do not calculate $f(x)$ for all elements and then see which | |
| 324 |   is the first \texttt{Some}.\\\mbox{}\hfill[1 Mark]
 | |
| 48 | 325 | |
| 212 | 326 | \item[(5)] Implement a \texttt{first\_tour} function that uses the
 | 
| 213 | 327 |   \texttt{first}-function from (4), and searches recursively for single tour.
 | 
| 166 | 328 |   As there might not be such a tour at all, the \texttt{first\_tour} function
 | 
| 329 | needs to return a value of type | |
| 212 | 330 |   \texttt{Option[Path]}.\\\mbox{}\hfill[1 Mark]
 | 
| 48 | 331 | \end{itemize}
 | 
| 332 | ||
| 333 | \noindent | |
| 166 | 334 | \textbf{Testing:} The \texttt{first\_tour} function will be called with board
 | 
| 148 | 335 | sizes of up to $8 \times 8$. | 
| 336 | \bigskip | |
| 6 | 337 | |
| 148 | 338 | |
| 339 | ||
| 166 | 340 | %%\newpage | 
| 213 | 341 | \subsection*{Advanced Part 2 (4 Marks)}
 | 
| 45 | 342 | |
| 145 | 343 | As you should have seen in Part 1, a naive search for tours beyond | 
| 344 | $8 \times 8$ boards and also searching for closed tours even on small | |
| 166 | 345 | boards takes too much time. There is a heuristic, called \emph{Warnsdorf's
 | 
| 346 | Rule} that can speed up finding a tour. This heuristic states that a | |
| 145 | 347 | knight is moved so that it always proceeds to the field from which the | 
| 48 | 348 | knight will have the \underline{fewest} onward moves.  For example for
 | 
| 349 | a knight on field $(1, 3)$, the field $(0, 1)$ has the fewest possible | |
| 350 | onward moves, namely 2. | |
| 45 | 351 | |
| 352 | \chessboard[maxfield=g7, | |
| 353 |             pgfstyle= {[base,at={\pgfpoint{0pt}{-0.5ex}}]text},
 | |
| 354 | text = \small 3, markfield=Z5, | |
| 355 | text = \small 7, markfield=b5, | |
| 356 | text = \small 7, markfield=c4, | |
| 357 | text = \small 7, markfield=c2, | |
| 358 | text = \small 5, markfield=b1, | |
| 359 | text = \small 2, markfield=Z1, | |
| 360 |             setpieces={Na3}]
 | |
| 361 | ||
| 362 | \noindent | |
| 166 | 363 | Warnsdorf's Rule states that the moves on the board above should be | 
| 50 | 364 | tried in the order | 
| 45 | 365 | |
| 366 | \[ | |
| 46 | 367 | (0, 1), (0, 5), (2, 1), (2, 5), (3, 4), (3, 2) | 
| 45 | 368 | \] | 
| 369 | ||
| 46 | 370 | \noindent | 
| 60 
f099bcf9cff1
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
59diff
changeset | 371 | Whenever there are ties, the corresponding onward moves can be in any | 
| 45 | 372 | order. When calculating the number of onward moves for each field, we | 
| 373 | do not count moves that revisit any field already visited. | |
| 374 | ||
| 213 | 375 | \subsubsection*{Tasks (file knight2.scala)}
 | 
| 45 | 376 | |
| 377 | \begin{itemize}
 | |
| 212 | 378 | \item[(6)] Write a function \texttt{ordered\_moves} that calculates a list of
 | 
| 216 | 379 | onward moves like in (2) but orders them according to | 
| 166 | 380 | Warnsdorf’s Rule. That means moves with the fewest legal onward moves | 
| 86 | 381 | should come first (in order to be tried out first). \hfill[1 Mark] | 
| 50 | 382 | |
| 213 | 383 | \item[(7)] Implement a \texttt{first\_closed\_tour\_heuristic}
 | 
| 384 | function that searches for a single | |
| 385 |   \textbf{closed} tour on a $6\times 6$ board. It should try out
 | |
| 386 | onward moves according to | |
| 387 |   the \texttt{ordered\_moves} function from (6). It is more likely to find
 | |
| 50 | 388 | a solution when started in the middle of the board (that is | 
| 86 | 389 | position $(dimension / 2, dimension / 2)$). \hfill[1 Mark] | 
| 45 | 390 | |
| 212 | 391 | \item[(8)] Implement a \texttt{first\_tour\_heuristic} function
 | 
| 166 | 392 | for boards up to | 
| 213 | 393 | $30\times 30$. It is the same function as in (7) but searches for | 
| 394 | tours (not just closed tours). It might be called with any field on the | |
| 216 | 395 | board as starting field.\\ | 
| 213 | 396 | %You have to be careful to write a | 
| 397 |   %tail-recursive function of the \texttt{first\_tour\_heuristic} function
 | |
| 398 | %otherwise you will get problems with stack-overflows.\\ | |
| 399 |   \mbox{}\hfill[1 Mark]
 | |
| 400 | \end{itemize}    
 | |
| 401 | ||
| 402 | \subsubsection*{Task (file knight3.scala)}
 | |
| 403 | \begin{itemize}
 | |
| 404 | \item[(9)] Implement a function \texttt{tour\_on\_mega\_board} which is
 | |
| 216 | 405 |   the same function as in (8), \textbf{but} should be able to
 | 
| 406 | deal with boards up to | |
| 407 |   $70\times 70$ \textbf{within 30 seconds} (on my laptop). This will be tested
 | |
| 213 | 408 | by starting from field $(0, 0)$. You have to be careful to | 
| 409 | write a tail-recursive function otherwise you will get problems | |
| 410 | with stack-overflows. Please observe the requirements about | |
| 411 |   the submissions: no tricks involving \textbf{.par}.\medskip
 | |
| 412 | ||
| 216 | 413 | The timelimit of 30 seconds is with respect to the laptop on which the | 
| 414 | marking will happen. You can roughly estimate how well your | |
| 213 | 415 |   implementation performs by running \texttt{knight3.jar} on your
 | 
| 216 | 416 | computer. For example the reference implementation shows | 
| 417 | on my laptop: | |
| 213 | 418 | |
| 419 |   \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
 | |
| 420 | $ scala -cp knight3.jar | |
| 421 | ||
| 422 | scala> CW8c.tour_on_mega_board(70, List((0, 0))) | |
| 423 | Time needed: 9.484 secs. | |
| 424 | ...<<long_list>>... | |
| 425 | \end{lstlisting}%$
 | |
| 426 | ||
| 145 | 427 |   \mbox{}\hfill[1 Mark]
 | 
| 45 | 428 | \end{itemize}  
 | 
| 148 | 429 | \bigskip | 
| 430 | ||
| 431 | ||
| 432 | ||
| 6 | 433 | |
| 434 | \end{document}
 | |
| 435 | ||
| 436 | %%% Local Variables: | |
| 437 | %%% mode: latex | |
| 438 | %%% TeX-master: t | |
| 439 | %%% End: |