146
|
1 |
// Part 3 about finding a single tour using the Warnsdorf Rule
|
|
2 |
//=============================================================
|
|
3 |
|
|
4 |
// copy any function you need from files knight1.scala and
|
|
5 |
// knight2.scala
|
|
6 |
|
|
7 |
object CW7c {
|
|
8 |
|
|
9 |
type Pos = (Int, Int) // a position on a chessboard
|
|
10 |
type Path = List[Pos] // a path...a list of positions
|
|
11 |
|
|
12 |
//(3a) Complete the function that calculates a list of onward
|
|
13 |
// moves like in (1b) but orders them according to Warnsdorf’s
|
|
14 |
// rule. That means moves with the fewest legal onward moves
|
|
15 |
// should come first.
|
|
16 |
|
|
17 |
//def ordered_moves(dim: Int, path: Path, x: Pos) : List[Pos] = ..
|
|
18 |
|
|
19 |
|
|
20 |
//(3b) Complete the function that searches for a single *closed*
|
|
21 |
// tour using the ordered moves function.
|
|
22 |
|
|
23 |
//def first_closed_tour_heuristic(dim: Int, path: Path) : Option[Path] = ...
|
|
24 |
|
|
25 |
|
|
26 |
//(3c) Same as (3b) but searches for *non-closed* tours. However,
|
|
27 |
// you have to be careful to write a tail-recursive version as this
|
|
28 |
// function will be called with dimensions of up to 40 * 40.
|
|
29 |
|
|
30 |
//def first_tour_heuristic(dim: Int, path: Path) : Option[Path] = ...
|
|
31 |
|
|
32 |
|
|
33 |
}
|