Highlights
Task:
(file knight1.scala)
(1) Implement an is_legal function that takes a dimension, a path and a position as arguments and tests whether the position is inside the board and not yet element in the path. [1 Mark]
(2) Implement a legal_moves function that calculates for a position all legal onward moves. If the onward moves are placed on a circle, you should produce them starting from “12?o’clock” following in clockwise order. For example on an 8 × 8 board for a knight at position (2, 2) and other? wise empty board, the legal?moves function should produce the onward positions in this order:
List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))
If the board is not empty, then maybe some of the moves need to be fil? tered out from this list. For a knight on field (7, 7) and an empty board, the legal moves are
List((6,5), (5,6))
[1 Mark]
(3) Implement two recursive functions (count_tours and enum_tours). They each take a dimension and a path as arguments. They exhaustively search for tours starting from the given path. The first function counts all possi? ble tours (there can be none for certain board sizes) and the second collects all tours in a list of paths. These functions will be called with a path con? taining a single position—the starting field. They are expected to extend this path so as to find all tours starting from the given position.
[2 Marks]
Test data: For the marking, the functions in (3) will be called with board sizes up to 5 × 5. If you search for tours on a 5 × 5 board starting only from field (0, 0), there are 304 of tours. If you try out every field of a 5 × 5?board as a starting field and add up all tours, you obtain 1728. A 6 × 6 board is already too large to be searched exhaustively.2
Core Part (6 Marks)
Tasks (file knight1.scala cont.)
You need to copy your knight1.scala from the preliminary part to the main part and then solve Tasks 4 and 5 inside the copied file. Do not forget to “git add” the file for pushing the results to the directory main4.
(4) Implement a first?function. This function takes a list of positions and a function f as arguments; f is the name we give to this argument). The function f takes a position as argument and produces an optional path. So f ’s type is Pos => Option[Path]. The idea behind the first?function
is as follows:
first(Nil, f) def = None
first(x :: xs, f)
def = (
f(x) if f(x) ?= None
first(xs, f) otherwise
That is, we want to find the first position where the result of f is not None, if there is one. Note that ‘inside’ first, you do not (need to) know any? thing about the argument f except its type, namely Pos => Option[Path]. If you want to find out what the result of f is on a particular argument, say x, you can just write f(x). There is one additional point however you
This IT Assignment has been solved by our IT Experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.
Be it a used or new solution, the quality of the work submitted by our assignment Experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.
© Copyright 2026 My Uni Papers – Student Hustle Made Hassle Free. All rights reserved.